Skip to content

Commit 46ffad2

Browse files
committed
[sorter] More tests
1 parent 689fd5a commit 46ffad2

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎test/unit/core/other/indexes.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,11 @@ describe('Miscellaneous', () => {
20312031
expect(getIndexesObject(indexes)['i1']).toBeUndefined();
20322032
});
20332033

2034+
test('removes missing index definition', () => {
2035+
expect(indexes.delIndexDefinition('i1')).toBe(indexes);
2036+
expect(indexes.getIndexIds()).toEqual([]);
2037+
});
2038+
20342039
test('destroys', () => {
20352040
expect(indexes.getStore().getListenerStats().table).toEqual(0);
20362041
expect(indexes.getStore().getListenerStats().row).toEqual(0);

‎test/unit/core/ui-react/hooks.test.tsx‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,16 +2216,29 @@ describe('React-specific', () => {
22162216
{JSON.stringify(
22172217
useSortedRowIds({tableId: 't2', sorter: numericSorter}, store),
22182218
)}
2219+
{JSON.stringify(
2220+
useSortedRowIds(
2221+
't2',
2222+
undefined,
2223+
undefined,
2224+
undefined,
2225+
undefined,
2226+
numericSorter,
2227+
store,
2228+
),
2229+
)}
22192230
</>,
22202231
);
22212232
const {container, unmount} = render(<Test />);
22222233

22232234
expect(container.textContent).toEqual(
2224-
JSON.stringify(['0', '1', '2', '10']),
2235+
JSON.stringify(['0', '1', '2', '10']) +
2236+
JSON.stringify(['0', '1', '2', '10']),
22252237
);
22262238
act(() => store.setRow('t2', '3', {c1: true}));
22272239
expect(container.textContent).toEqual(
2228-
JSON.stringify(['0', '1', '2', '3', '10']),
2240+
JSON.stringify(['0', '1', '2', '3', '10']) +
2241+
JSON.stringify(['0', '1', '2', '3', '10']),
22292242
);
22302243

22312244
unmount();
@@ -3814,6 +3827,33 @@ describe('React-specific', () => {
38143827
unmount();
38153828
});
38163829

3830+
test('useSortedRowIdsListener, object arg, custom sorter', () => {
3831+
expect.assertions(3);
3832+
const numericSorter = (sortKey1: any, sortKey2: any) =>
3833+
Number(sortKey1) - Number(sortKey2);
3834+
['1', '10', '2'].forEach((rowId) =>
3835+
store.setRow('t2', rowId, {c1: true}),
3836+
);
3837+
const listener = vi.fn();
3838+
const Test = () => {
3839+
useSortedRowIdsListener(
3840+
{tableId: 't2', sorter: numericSorter},
3841+
listener,
3842+
[listener],
3843+
false,
3844+
store,
3845+
);
3846+
return <button />;
3847+
};
3848+
const {unmount} = render(<Test />);
3849+
3850+
store.setRow('t2', '3', {c1: true});
3851+
expect(listener).toHaveBeenCalledTimes(1);
3852+
expect(listener.mock.calls[0][6]).toEqual(['1', '2', '3', '10']);
3853+
unmount();
3854+
expect(store.getListenerStats().sortedRowIds).toEqual(0);
3855+
});
3856+
38173857
test('useMetricListener (no deps)', () => {
38183858
expect.assertions(4);
38193859
const metrics = createMetrics(store).setMetricDefinition(

‎test/unit/core/ui-solid/primitives.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,8 +1479,8 @@ describe('Solid-specific', () => {
14791479
positionalSortedRowIds = useSortedRowIds(
14801480
't1',
14811481
undefined,
1482-
false,
1483-
0,
1482+
undefined,
1483+
undefined,
14841484
undefined,
14851485
numericSorter,
14861486
store,

‎test/unit/core/ui-svelte/components/FunctionSortedRowIdsObject.svelte‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
const positionalRowIds = getSortedRowIds(
1717
't1',
1818
undefined,
19-
false,
20-
0,
19+
() => undefined,
20+
() => undefined,
2121
undefined,
2222
numericSorter,
2323
() => store,

0 commit comments

Comments
 (0)