forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item key stringify tests (deephaven#1909)
- Loading branch information
Showing
4 changed files
with
98 additions
and
13 deletions.
There are no files selected for viewing
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
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
65 changes: 65 additions & 0 deletions
65
packages/components/src/spectrum/utils/useStringifiedMultiSelection.test.ts
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,65 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { NormalizedItem } from './itemUtils'; | ||
import { useStringifiedMultiSelection } from './useStringifiedMultiSelection'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
expect.hasAssertions(); | ||
}); | ||
|
||
describe('useStringifiedMultiSelection', () => { | ||
const normalizedItems: NormalizedItem[] = [1, 2, 3, 4, 5, 6, 7, 8, 9].map( | ||
i => ({ | ||
key: i, | ||
item: { key: i, content: `Item ${i}` }, | ||
}) | ||
); | ||
|
||
const selectedKeys = [1, 2, 3]; | ||
const defaultSelectedKeys = [4, 5, 6]; | ||
const disabledKeys = [7, 8, 9]; | ||
|
||
const selectedStringKeys = new Set(['1', '2', '3']); | ||
const defaultSelectedStringKeys = new Set(['4', '5', '6']); | ||
const disabledStringKeys = new Set(['7', '8', '9']); | ||
|
||
it('should stringify selections', () => { | ||
const { result } = renderHook(() => | ||
useStringifiedMultiSelection({ | ||
normalizedItems, | ||
selectedKeys, | ||
defaultSelectedKeys, | ||
disabledKeys, | ||
}) | ||
); | ||
|
||
expect(result.current.selectedStringKeys).toEqual(selectedStringKeys); | ||
expect(result.current.defaultSelectedStringKeys).toEqual( | ||
defaultSelectedStringKeys | ||
); | ||
expect(result.current.disabledStringKeys).toEqual(disabledStringKeys); | ||
}); | ||
|
||
it.each([ | ||
['all', 'all'], | ||
[new Set(['1', '2', '3']), new Set([1, 2, 3])], | ||
] as const)( | ||
`should call onChange with 'all' or actual keys`, | ||
(given, expected) => { | ||
const onChange = jest.fn(); | ||
const { result } = renderHook(() => | ||
useStringifiedMultiSelection({ | ||
normalizedItems, | ||
selectedKeys, | ||
defaultSelectedKeys, | ||
disabledKeys, | ||
onChange, | ||
}) | ||
); | ||
|
||
result.current.onStringSelectionChange(given); | ||
|
||
expect(onChange).toHaveBeenCalledWith(expected); | ||
} | ||
); | ||
}); |
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