Skip to content

Commit 86d67b1

Browse files
committed
tests: selection actions tests
1 parent efb4142 commit 86d67b1

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

plugins/selection/src/rowSelection/actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export const CheckRow = (rowId: string) => (state) => {
1313
};
1414

1515
export const UncheckRow = (rowId: string) => (state) => {
16-
const index = state.rowSelection.rowIds.indexOf(rowId);
16+
const rowIds = state.rowSelection?.rowIds || [];
17+
const index = rowIds.indexOf(rowId);
1718

1819
// rowId doesn't exist
19-
if (index === -1) state;
20+
if (index === -1) return state;
2021

21-
const cloned = [...state.rowSelection.rowIds];
22+
const cloned = [...rowIds];
2223
cloned.splice(index, 1);
2324

2425
return {

plugins/selection/tests/rowSelection/actions.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ describe('Actions', () => {
3939
});
4040
});
4141

42+
it('should UNCHECK the correct item', () => {
43+
const state = Actions.UncheckRow('42')({
44+
rowSelection: {
45+
rowIds: ['22', '11'],
46+
},
47+
});
48+
49+
expect(state).toStrictEqual({
50+
rowSelection: {
51+
rowIds: ['22', '11'],
52+
},
53+
});
54+
});
55+
56+
it('should UNCHECK when rowIds is null', () => {
57+
const state = Actions.UncheckRow('42')({});
58+
59+
expect(state).toStrictEqual({});
60+
});
61+
4262
it('should trigger UNCHECK when rowIds is empty', () => {
4363
const state = Actions.UncheckRow('42')({
4464
rowSelection: {

0 commit comments

Comments
 (0)