-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
45 lines (36 loc) · 1.18 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { renderHook, act } from "@testing-library/react-hooks";
import useSelection from ".";
interface TestItem {
key: string;
}
const NUM_ITEMS = 20;
describe("api", () => {
const mockItems = Array.from({ length: NUM_ITEMS }).map((_, i) => ({
key: `Item-${i}`,
}));
const getKey = (item: TestItem): string => item.key;
it("default state", () => {
const { result } = renderHook(() => useSelection(mockItems, getKey));
expect(result.current.onSelect).toEqual(expect.any(Function));
expect(result.current.selectedItems).toEqual([]);
});
describe("onSelect", () => {
it.each([[0], [5], [NUM_ITEMS - 1]])(
`first selection index = %s of ${NUM_ITEMS}`,
(itemIndex: number) => {
const { result } = renderHook(() => useSelection(mockItems, getKey));
const selectedItem = mockItems[itemIndex];
act(() => {
result.current.onSelect(selectedItem);
});
expect(result.current.selectedItems.length).toBe(1);
expect(result.current.selectedItems.indexOf(selectedItem) > -1).toBe(
true
);
}
);
// TODO: regular clicks
// TODO: shift clicks
// TODO: ctrl clicks
});
});