diff --git a/packages/jsapi-components/src/spectrum/Picker/PickerUtils.test.tsx b/packages/jsapi-components/src/spectrum/Picker/PickerUtils.test.tsx new file mode 100644 index 000000000..a0f4a4373 --- /dev/null +++ b/packages/jsapi-components/src/spectrum/Picker/PickerUtils.test.tsx @@ -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({ name: 'keyColumn' }); +const labelColumn = createMockProxy({ name: 'labelColumn' }); +const otherColumn = createMockProxy({ name: 'otherColumn' }); + +const columns = [keyColumn, labelColumn, otherColumn]; + +const table = createMockProxy({ + 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); + } + ); +});