-
Notifications
You must be signed in to change notification settings - Fork 18
fix: DH-18770: Chart builder support for ui.table #1356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
228 changes: 228 additions & 0 deletions
228
plugins/ui/src/js/src/elements/UITable/UITable.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,228 @@ | ||
| import React from 'react'; | ||
| import { act, render, waitFor } from '@testing-library/react'; | ||
| import { TestUtils } from '@deephaven/test-utils'; | ||
| import type { | ||
| ChartBuilderSettings, | ||
| IrisGridModel, | ||
| IrisGridTableModel, | ||
| } from '@deephaven/iris-grid'; | ||
| import { type dh } from '@deephaven/jsapi-types'; | ||
| import { UITable } from './UITable'; | ||
|
|
||
| const mockEmit = jest.fn(); | ||
| const mockTable = {} as dh.Table; | ||
| const mockModel = { | ||
| columns: [] as dh.Column[], | ||
| isChartBuilderAvailable: true, | ||
| description: 'test_table', | ||
| table: mockTable, | ||
| close: jest.fn(), | ||
| setColorMap: jest.fn(), | ||
| getColumnIndexByName: jest.fn(), | ||
| } as unknown as IrisGridTableModel; | ||
|
|
||
| jest.mock('@deephaven/dashboard', () => { | ||
| const react = jest.requireActual('react'); | ||
| return { | ||
| useLayoutManager: () => ({ | ||
| eventHub: { emit: mockEmit, on: jest.fn(), off: jest.fn() }, | ||
| }), | ||
| useListener: jest.fn(), | ||
| usePersistentState: (initialValue: unknown) => { | ||
| // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| const [state, setState] = react.useState(initialValue); | ||
| return [state, setState]; | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('./UITableModel', () => ({ | ||
| makeUiTableModel: jest.fn(() => Promise.resolve(mockModel)), | ||
| })); | ||
|
|
||
| jest.mock('../hooks', () => ({ | ||
| useExportedObject: () => ({ | ||
| widget: {}, | ||
| api: {}, | ||
| isLoading: false, | ||
| error: null, | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@deephaven/dashboard-core-plugins', () => ({ | ||
| InputFilterEvent: { CLEAR_ALL_FILTERS: 'CLEAR_ALL_FILTERS' }, | ||
| IrisGridEvent: { CREATE_CHART: 'IrisGridevent.CREATE_CHART' }, | ||
| useDashboardColumnFilters: () => [], | ||
| useGridLinker: () => ({ | ||
| alwaysFetchColumns: [], | ||
| columnSelectionValidator: undefined, | ||
| isSelectingColumn: false, | ||
| onColumnSelected: jest.fn(), | ||
| onDataSelected: jest.fn(), | ||
| }), | ||
| useTablePlugin: () => ({ | ||
| Plugin: null, | ||
| customFilters: [], | ||
| alwaysFetchColumns: [], | ||
| onContextMenu: () => [], | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@deephaven/redux', () => ({ | ||
| getSettings: () => () => ({ | ||
| timeZone: 'America/New_York', | ||
| defaultDateTimeFormat: 'yyyy-MM-dd HH:mm:ss', | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@deephaven/components', () => ({ | ||
| ...jest.requireActual('@deephaven/components'), | ||
| LoadingOverlay: () => null, | ||
| useTheme: () => ({}), | ||
| useStyleProps: () => ({ styleProps: {} }), | ||
| resolveCssVariablesInRecord: (record: Record<string, string>) => record, | ||
| })); | ||
|
|
||
| // Capture the onCreateChart prop passed to IrisGrid | ||
| let capturedOnCreateChart: | ||
| | ((settings: ChartBuilderSettings, model: IrisGridModel) => void) | ||
| | undefined; | ||
|
|
||
| jest.mock('@deephaven/iris-grid', () => { | ||
| const actual = jest.requireActual('@deephaven/iris-grid'); | ||
| return { | ||
| ...actual, | ||
| IrisGrid: jest.fn(props => { | ||
| capturedOnCreateChart = props.onCreateChart; | ||
| return <div data-testid="iris-grid" />; | ||
| }), | ||
| IrisGridUtils: jest.fn(() => ({ | ||
| hydrateSort: jest.fn(), | ||
| hydrateQuickFilters: jest.fn(), | ||
| })), | ||
| IrisGridCacheUtils: { | ||
| makeMemoizedCombinedGridStateDehydrator: jest.fn(() => jest.fn()), | ||
| }, | ||
| isIrisGridTableModelTemplate: (model: unknown) => | ||
| model != null && 'table' in (model as Record<string, unknown>), | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('react-redux', () => ({ | ||
| useSelector: (selector: (state: unknown) => unknown) => selector({}), | ||
| })); | ||
|
|
||
| const mockExportedTable = {} as dh.WidgetExportedObject; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| capturedOnCreateChart = undefined; | ||
| }); | ||
|
|
||
| describe('UITable chart builder', () => { | ||
| async function renderAndWaitForModel() { | ||
| await act(async () => { | ||
| render( | ||
| <UITable | ||
| table={mockExportedTable} | ||
| showSearch={false} | ||
| showQuickFilters={false} | ||
| showGroupingColumn={false} | ||
| reverse={false} | ||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(capturedOnCreateChart).toBeDefined(); | ||
| }); | ||
| } | ||
|
|
||
| it('passes onCreateChart to IrisGrid', async () => { | ||
| await renderAndWaitForModel(); | ||
| expect(capturedOnCreateChart).toBeDefined(); | ||
| }); | ||
|
|
||
| it('emits IrisGridEvent.CREATE_CHART with correct metadata', async () => { | ||
| await renderAndWaitForModel(); | ||
|
|
||
| const chartSettings: ChartBuilderSettings = { | ||
| type: 'LINE' as never, | ||
| series: ['col1'], | ||
| xAxis: 'col0', | ||
| isLinked: false, | ||
| }; | ||
|
|
||
| const irisGridModel = TestUtils.createMockProxy<IrisGridTableModel>({ | ||
| description: 'my_table', | ||
| table: TestUtils.createMockProxy<dh.Table>(), | ||
| }); | ||
|
|
||
| capturedOnCreateChart!(chartSettings, irisGridModel); | ||
|
|
||
| expect(mockEmit).toHaveBeenCalledWith('IrisGridevent.CREATE_CHART', { | ||
| metadata: { | ||
| settings: chartSettings, | ||
| table: 'my_table', | ||
| tableSettings: {}, | ||
| }, | ||
| table: irisGridModel.table, | ||
| }); | ||
|
jnumainville marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('uses fallback table name when description is empty', async () => { | ||
| await renderAndWaitForModel(); | ||
|
|
||
| const chartSettings: ChartBuilderSettings = { | ||
| type: 'LINE' as never, | ||
| series: ['col1'], | ||
| xAxis: 'col0', | ||
| isLinked: false, | ||
| }; | ||
|
|
||
| const irisGridModel = TestUtils.createMockProxy<IrisGridTableModel>({ | ||
| description: '', | ||
| table: TestUtils.createMockProxy<dh.Table>(), | ||
| }); | ||
|
|
||
| capturedOnCreateChart!(chartSettings, irisGridModel); | ||
|
|
||
| expect(mockEmit).toHaveBeenCalledWith( | ||
| 'IrisGridevent.CREATE_CHART', | ||
| expect.objectContaining({ | ||
| metadata: expect.objectContaining({ | ||
| table: 'Table', | ||
| }), | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('passes undefined table when model is not a table template', async () => { | ||
| await renderAndWaitForModel(); | ||
|
|
||
| const chartSettings: ChartBuilderSettings = { | ||
| type: 'LINE' as never, | ||
| series: ['col1'], | ||
| xAxis: 'col0', | ||
| isLinked: false, | ||
| }; | ||
|
|
||
| // Model without a 'table' property (e.g. tree table model) | ||
| const irisGridModel = TestUtils.createMockProxy<IrisGridModel>({ | ||
| description: 'tree_table', | ||
| }); | ||
| // Remove 'table' from proxy so isIrisGridTableModelTemplate returns false | ||
| delete (irisGridModel as unknown as Record<string, unknown>).table; | ||
|
|
||
| capturedOnCreateChart!(chartSettings, irisGridModel); | ||
|
|
||
| expect(mockEmit).toHaveBeenCalledWith('IrisGridevent.CREATE_CHART', { | ||
| metadata: { | ||
| settings: chartSettings, | ||
| table: 'tree_table', | ||
| tableSettings: {}, | ||
| }, | ||
| table: undefined, | ||
| }); | ||
|
jnumainville marked this conversation as resolved.
Outdated
|
||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.