-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/jsapi-components/src/spectrum/Picker/PickerUtils.test.tsx
This file contains 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,49 @@ | ||
import { type dh } from '@deephaven/jsapi-types'; | ||
import { TestUtils } from '@deephaven/utils'; | ||
import { getPickerKeyColumn, getPickerLabelColumn } from './PickerUtils'; | ||
|
||
const { createMockProxy } = TestUtils; | ||
|
||
const keyColumn = createMockProxy<dh.Column>({ name: 'keyColumn' }); | ||
const labelColumn = createMockProxy<dh.Column>({ name: 'labelColumn' }); | ||
const otherColumn = createMockProxy<dh.Column>({ name: 'otherColumn' }); | ||
|
||
const columns = [keyColumn, labelColumn, otherColumn]; | ||
|
||
const table = createMockProxy<dh.Table>({ | ||
columns, | ||
findColumn: jest.fn( | ||
columnName => columns.find(column => column.name === columnName)! | ||
), | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
expect.hasAssertions(); | ||
}); | ||
|
||
describe('getPickerKeyColumn', () => { | ||
it.each([ | ||
['keyColumn', keyColumn], | ||
[undefined, columns[0]], | ||
])( | ||
'should return the given key column or fallback to the first column', | ||
(keyColumnName, expectedColumn) => { | ||
const actual = getPickerKeyColumn(table, keyColumnName); | ||
expect(actual).toBe(expectedColumn); | ||
} | ||
); | ||
}); | ||
|
||
describe('getPickerLabelColumn', () => { | ||
it.each([ | ||
['labelColumn', labelColumn], | ||
[undefined, keyColumn], | ||
])( | ||
'should return the given label column or fallback to the key column', | ||
(labelColumnName, expectedColumn) => { | ||
const actual = getPickerLabelColumn(table, keyColumn, labelColumnName); | ||
expect(actual).toBe(expectedColumn); | ||
} | ||
); | ||
}); |