Skip to content

Commit 6747356

Browse files
committed
fix: selection plugin configs
1 parent 16e8322 commit 6747356

File tree

8 files changed

+175
-119
lines changed

8 files changed

+175
-119
lines changed

plugins/selection/src/rowSelection/actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export const CheckRow = (rowId: string) => (state) => {
2+
const rowIds = state.rowSelection?.rowIds || [];
3+
24
// rowId already exists
3-
if (state.rowSelection.rowIds.indexOf(rowId) > -1) return state;
5+
if (rowIds.indexOf(rowId) > -1) return state;
46

57
return {
68
...state,
79
rowSelection: {
8-
rowIds: [rowId, ...state.rowSelection.rowIds],
10+
rowIds: [rowId, ...rowIds],
911
},
1012
};
1113
};

plugins/selection/src/rowSelection/rowSelection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { h } from 'preact';
12
import * as actions from './actions';
23
import { useStore, className, useEffect, useState, useSelector } from 'gridjs';
34
import { Row } from 'gridjs';
Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,68 @@
1-
import { Dispatcher } from 'gridjs';
2-
import { RowSelectionActions } from '../../src/rowSelection/actions';
1+
import * as Actions from '../../src/rowSelection/actions';
32

43
describe('Actions', () => {
5-
const dispatcher = new Dispatcher();
4+
it('should trigger CHECK', () => {
5+
const state = Actions.CheckRow('42')({});
66

7-
beforeEach(() => {
8-
dispatcher.dispatch = jest.fn();
7+
expect(state).toStrictEqual({
8+
rowSelection: {
9+
rowIds: ['42'],
10+
},
11+
});
912
});
1013

11-
it('should trigger CHECK', () => {
12-
const actions = new RowSelectionActions(dispatcher);
13-
actions.check('42');
14+
it('should trigger CHECK when rowIds already exists', () => {
15+
const state = Actions.CheckRow('42')({
16+
rowSelection: {
17+
rowIds: ['24'],
18+
},
19+
});
20+
21+
expect(state).toStrictEqual({
22+
rowSelection: {
23+
rowIds: ['42', '24'],
24+
},
25+
});
26+
});
1427

15-
expect(dispatcher.dispatch).toBeCalledTimes(1);
16-
expect(dispatcher.dispatch).toBeCalledWith({
17-
payload: {
18-
ROW_ID: '42',
28+
it('should trigger UNCHECK', () => {
29+
const state = Actions.UncheckRow('42')({
30+
rowSelection: {
31+
rowIds: ['42'],
32+
},
33+
});
34+
35+
expect(state).toStrictEqual({
36+
rowSelection: {
37+
rowIds: [],
1938
},
20-
type: 'CHECK',
2139
});
2240
});
2341

24-
it('should trigger CHECK twice', () => {
25-
const actions = new RowSelectionActions(dispatcher);
26-
actions.check('1');
27-
actions.check('2');
28-
expect(dispatcher.dispatch).toBeCalledTimes(2);
42+
it('should trigger UNCHECK when rowIds is empty', () => {
43+
const state = Actions.UncheckRow('42')({
44+
rowSelection: {
45+
rowIds: [],
46+
},
47+
});
48+
49+
expect(state).toStrictEqual({
50+
rowSelection: {
51+
rowIds: [],
52+
},
53+
});
2954
});
3055

31-
it('should trigger UNCHECK', () => {
32-
const actions = new RowSelectionActions(dispatcher);
33-
actions.uncheck('24');
56+
it('should CHECK and UNCHECK', () => {
57+
let state = {};
58+
state = Actions.CheckRow('42')(state);
59+
state = Actions.CheckRow('24')(state);
60+
state = Actions.UncheckRow('42')(state);
3461

35-
expect(dispatcher.dispatch).toBeCalledTimes(1);
36-
expect(dispatcher.dispatch).toBeCalledWith({
37-
payload: {
38-
ROW_ID: '24',
62+
expect(state).toStrictEqual({
63+
rowSelection: {
64+
rowIds: ['24'],
3965
},
40-
type: 'UNCHECK',
4166
});
4267
});
4368
});

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

Lines changed: 0 additions & 80 deletions
This file was deleted.

plugins/selection/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"removeComments": true
6+
},
7+
"include": [
8+
"index.ts",
9+
"src/**/*",
10+
"tests/**/*"
11+
]
12+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
2-
"extends": "../../tsconfig.json",
2+
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"rootDir": ".",
55
"removeComments": true
66
},
77
"include": [
88
"index.ts",
9-
"src/**/*",
9+
"src/**/*"
10+
],
11+
"exclude": [
1012
"tests/**/*"
1113
]
1214
}

plugins/selection/tsconfig.test.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["jest"],
5+
"esModuleInterop": true
6+
}
7+
}

tests/dev-server/package-lock.json

Lines changed: 96 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)