Skip to content

Commit c3c262b

Browse files
committed
adding some additional test cases
1 parent b95a619 commit c3c262b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/@react-stately/data/test/useListData.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ describe('useListData', function () {
5555
expect(result.current.selectedKeys).not.toBe(initialResult.selectedKeys);
5656
expect(result.current.selectedKeys).toEqual(new Set(['Sam', 'Julia']));
5757
});
58+
59+
it('should support adding "all" to selected keys', function () {
60+
let {result} = renderHook(() => useListData({initialItems: initial, getKey, initialSelectedKeys: ['Sam']}));
61+
let initialResult = result.current;
62+
63+
act(() => {
64+
result.current.addKeysToSelection('all');
65+
});
66+
expect(result.current.selectedKeys).not.toBe(initialResult.selectedKeys);
67+
expect(result.current.selectedKeys).toEqual('all');
68+
});
69+
70+
it('should still return "all" if selected keys was already "all"', function () {
71+
let {result} = renderHook(() => useListData({initialItems: initial, getKey, initialSelectedKeys: 'all'}));
72+
73+
act(() => {
74+
result.current.addKeysToSelection(['Same']);
75+
});
76+
expect(result.current.selectedKeys).toEqual('all');
77+
});
5878
});
5979

6080
describe('removeKeysFromSelection', function () {
@@ -79,6 +99,28 @@ describe('useListData', function () {
7999
expect(result.current.selectedKeys).not.toBe(initialResult.selectedKeys);
80100
expect(result.current.selectedKeys).toEqual(new Set(['Julia']));
81101
});
102+
103+
it('should remove the selected keys from an "all" set', function () {
104+
let {result} = renderHook(() => useListData({initialItems: initial, getKey, initialSelectedKeys: 'all'}));
105+
let initialResult = result.current;
106+
107+
act(() => {
108+
result.current.removeKeysFromSelection(['Sam', 'David']);
109+
});
110+
expect(result.current.selectedKeys).not.toBe(initialResult.selectedKeys);
111+
expect(result.current.selectedKeys).toEqual(new Set(['Julia']));
112+
});
113+
114+
it('should support removing "all"', function () {
115+
let {result} = renderHook(() => useListData({initialItems: initial, getKey, initialSelectedKeys: ['Sam', 'Julia']}));
116+
let initialResult = result.current;
117+
118+
act(() => {
119+
result.current.removeKeysFromSelection('all');
120+
});
121+
expect(result.current.selectedKeys).not.toBe(initialResult.selectedKeys);
122+
expect(result.current.selectedKeys).toEqual(new Set([]));
123+
});
82124
});
83125

84126
it('should get an item by key', function () {

0 commit comments

Comments
 (0)