@qoretechnologies/reqore 0.34.13 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/helpers/table.test.tsx +47 -0
- package/__tests__/table.test.tsx +356 -124
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Button/index.js +7 -4
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Collection/index.d.ts +2 -1
- package/dist/components/Collection/index.d.ts.map +1 -1
- package/dist/components/Collection/index.js +5 -11
- package/dist/components/Collection/index.js.map +1 -1
- package/dist/components/ControlGroup/index.d.ts.map +1 -1
- package/dist/components/ControlGroup/index.js +4 -3
- package/dist/components/ControlGroup/index.js.map +1 -1
- package/dist/components/Dropdown/index.d.ts +4 -1
- package/dist/components/Dropdown/index.d.ts.map +1 -1
- package/dist/components/Dropdown/index.js +2 -2
- package/dist/components/Dropdown/index.js.map +1 -1
- package/dist/components/Dropdown/list.d.ts +4 -1
- package/dist/components/Dropdown/list.d.ts.map +1 -1
- package/dist/components/Dropdown/list.js +10 -5
- package/dist/components/Dropdown/list.js.map +1 -1
- package/dist/components/Input/index.js +4 -4
- package/dist/components/Input/index.js.map +1 -1
- package/dist/components/Panel/index.d.ts +4 -1
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/Table/cell.d.ts +13 -0
- package/dist/components/Table/cell.d.ts.map +1 -0
- package/dist/components/Table/cell.js +89 -0
- package/dist/components/Table/cell.js.map +1 -0
- package/dist/components/Table/header.d.ts +15 -2
- package/dist/components/Table/header.d.ts.map +1 -1
- package/dist/components/Table/header.js +31 -14
- package/dist/components/Table/header.js.map +1 -1
- package/dist/components/Table/headerCell.d.ts +9 -6
- package/dist/components/Table/headerCell.d.ts.map +1 -1
- package/dist/components/Table/headerCell.js +73 -51
- package/dist/components/Table/headerCell.js.map +1 -1
- package/dist/components/Table/helpers.d.ts +43 -1
- package/dist/components/Table/helpers.d.ts.map +1 -1
- package/dist/components/Table/helpers.js +145 -1
- package/dist/components/Table/helpers.js.map +1 -1
- package/dist/components/Table/index.d.ts +45 -25
- package/dist/components/Table/index.d.ts.map +1 -1
- package/dist/components/Table/index.js +167 -52
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Table/row.d.ts +11 -5
- package/dist/components/Table/row.d.ts.map +1 -1
- package/dist/components/Table/row.js +32 -55
- package/dist/components/Table/row.js.map +1 -1
- package/dist/hooks/useQueryWithDelay.d.ts +8 -0
- package/dist/hooks/useQueryWithDelay.d.ts.map +1 -0
- package/dist/hooks/useQueryWithDelay.js +25 -0
- package/dist/hooks/useQueryWithDelay.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Button/index.tsx +6 -1
- package/src/components/Collection/index.tsx +9 -15
- package/src/components/ControlGroup/index.tsx +10 -5
- package/src/components/Dropdown/index.tsx +9 -0
- package/src/components/Dropdown/list.tsx +18 -6
- package/src/components/Input/index.tsx +3 -3
- package/src/components/Panel/index.tsx +3 -1
- package/src/components/Table/cell.tsx +120 -0
- package/src/components/Table/header.tsx +102 -45
- package/src/components/Table/headerCell.tsx +133 -80
- package/src/components/Table/helpers.ts +211 -1
- package/src/components/Table/index.tsx +334 -91
- package/src/components/Table/row.tsx +51 -127
- package/src/hooks/useQueryWithDelay.ts +30 -0
- package/src/index.tsx +3 -0
- package/src/mock/tableData.ts +40 -20
- package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +1 -1
- package/src/stories/Button/Button.stories.tsx +1 -1
- package/src/stories/Checkbox/Checkbox.stories.tsx +1 -1
- package/src/stories/Collection/Collection.stories.tsx +19 -1
- package/src/stories/Columns/Columns.stories.tsx +1 -1
- package/src/stories/Comment/Comment.stories.tsx +1 -1
- package/src/stories/ControlGroup/ControlGroup.stories.tsx +1 -1
- package/src/stories/Drawer/Drawer.stories.tsx +5 -5
- package/src/stories/Dropdown/Dropdown.stories.tsx +11 -1
- package/src/stories/Header/Header.stories.tsx +1 -1
- package/src/stories/Icon/Icon.stories.tsx +1 -1
- package/src/stories/Input/Input.stories.tsx +1 -1
- package/src/stories/Menu/Menu.stories.tsx +1 -1
- package/src/stories/Message/Message.stories.tsx +1 -1
- package/src/stories/Modal/Modal.stories.tsx +1 -1
- package/src/stories/MultiSelect/MultiSelect.stories.tsx +1 -1
- package/src/stories/Navbar/Navbar.stories.tsx +1 -1
- package/src/stories/Notifications/Interactive.stories.tsx +1 -1
- package/src/stories/Notifications/Notification.stories.tsx +1 -1
- package/src/stories/Notifications/Notifications.stories.tsx +1 -1
- package/src/stories/Paging/Paging.stories.tsx +1 -1
- package/src/stories/Panel/Panel.stories.tsx +5 -5
- package/src/stories/Paragraph/Paragraph.stories.tsx +1 -1
- package/src/stories/Popover/Popover.stories.tsx +2 -2
- package/src/stories/RadioGroup/RadioGroup.stories.tsx +1 -1
- package/src/stories/Sidebar/Sidebar.stories.tsx +2 -2
- package/src/stories/Spacer/Spacer.stories.tsx +1 -1
- package/src/stories/Spinner/Spinner.stories.tsx +1 -1
- package/src/stories/Table/Table.stories.tsx +297 -78
- package/src/stories/Tabs/Tabs.stories.tsx +1 -1
- package/src/stories/Tag/Tag.stories.tsx +1 -1
- package/src/stories/TextArea/TextArea.stories.tsx +2 -2
- package/src/stories/Tree/Tree.stories.tsx +2 -2
- package/src/stories/utils/args.ts +1 -1
- package/tests.json +1 -1
package/__tests__/table.test.tsx
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { fireEvent, render } from '@testing-library/react';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { act } from 'react-dom/test-utils';
|
|
3
4
|
import { ReqoreLayoutContent, ReqoreTable, ReqoreUIProvider } from '../src';
|
|
4
|
-
import { IReqoreTableColumn,
|
|
5
|
+
import { IReqoreTableColumn, IReqoreTableProps } from '../src/components/Table';
|
|
5
6
|
import tableData from '../src/mock/tableData';
|
|
6
7
|
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
jest.setTimeout(30000);
|
|
10
|
+
});
|
|
11
|
+
|
|
7
12
|
test('Renders basic <Table /> properly', () => {
|
|
8
13
|
render(
|
|
9
14
|
<ReqoreUIProvider>
|
|
@@ -13,39 +18,44 @@ test('Renders basic <Table /> properly', () => {
|
|
|
13
18
|
</ReqoreUIProvider>
|
|
14
19
|
);
|
|
15
20
|
|
|
16
|
-
expect(document.querySelectorAll('.reqore-table-header
|
|
21
|
+
expect(document.querySelectorAll('.reqore-table-column-group-header').length).toBe(2);
|
|
22
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(10);
|
|
17
23
|
expect(document.querySelectorAll('.reqore-table-row').length).toBe(10);
|
|
18
24
|
});
|
|
19
25
|
|
|
20
26
|
test('Renders <Table /> with grouped columns properly', () => {
|
|
21
|
-
const data = {
|
|
27
|
+
const data: IReqoreTableProps = {
|
|
22
28
|
...tableData,
|
|
23
29
|
columns: [
|
|
24
30
|
{
|
|
25
31
|
dataId: 'id',
|
|
26
|
-
header:
|
|
32
|
+
header: {
|
|
33
|
+
label: 'ID',
|
|
34
|
+
},
|
|
27
35
|
width: 50,
|
|
28
36
|
align: 'center',
|
|
29
37
|
},
|
|
30
38
|
{
|
|
31
|
-
header:
|
|
39
|
+
header: {
|
|
40
|
+
label: 'Name',
|
|
41
|
+
columns: [
|
|
42
|
+
{ dataId: 'firstName', header: { label: 'First Name' }, width: 150, grow: 2 },
|
|
43
|
+
{ dataId: 'lastName', header: { label: 'Last Name' }, width: 150, grow: 1 },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
32
46
|
dataId: 'name',
|
|
33
47
|
grow: 3,
|
|
34
|
-
columns: [
|
|
35
|
-
{ dataId: 'firstName', header: 'First Name', width: 150, grow: 2 },
|
|
36
|
-
{ dataId: 'lastName', header: 'Last Name', width: 150, grow: 1 },
|
|
37
|
-
],
|
|
38
48
|
},
|
|
39
|
-
{ dataId: 'address', header: 'Address', width: 300, grow: 2 },
|
|
49
|
+
{ dataId: 'address', header: { label: 'Address' }, width: 300, grow: 2 },
|
|
40
50
|
{
|
|
41
51
|
dataId: 'age',
|
|
42
|
-
header: 'Really long age header',
|
|
52
|
+
header: { label: 'Really long age header' },
|
|
43
53
|
width: 50,
|
|
44
54
|
align: 'center',
|
|
45
55
|
},
|
|
46
|
-
{ dataId: 'occupation', header: 'Ocuppation', width: 200 },
|
|
47
|
-
{ dataId: 'group', header: 'Group', width: 150 },
|
|
48
|
-
]
|
|
56
|
+
{ dataId: 'occupation', header: { label: 'Ocuppation' }, width: 200 },
|
|
57
|
+
{ dataId: 'group', header: { label: 'Group' }, width: 150 },
|
|
58
|
+
],
|
|
49
59
|
};
|
|
50
60
|
|
|
51
61
|
render(
|
|
@@ -57,39 +67,43 @@ test('Renders <Table /> with grouped columns properly', () => {
|
|
|
57
67
|
);
|
|
58
68
|
|
|
59
69
|
expect(document.querySelectorAll('.reqore-table-column-group').length).toBe(1);
|
|
60
|
-
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(
|
|
70
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(8);
|
|
61
71
|
});
|
|
62
72
|
|
|
63
73
|
test('Renders <Table /> with custom content', () => {
|
|
64
|
-
const data = {
|
|
74
|
+
const data: IReqoreTableProps = {
|
|
65
75
|
...tableData,
|
|
66
76
|
columns: [
|
|
67
77
|
{
|
|
68
78
|
dataId: 'id',
|
|
69
|
-
header: 'ID',
|
|
79
|
+
header: { label: 'ID' },
|
|
70
80
|
width: 50,
|
|
71
81
|
align: 'center',
|
|
72
|
-
|
|
82
|
+
cell: {
|
|
83
|
+
content: ({ id }) => <span>ID {id}</span>,
|
|
84
|
+
},
|
|
73
85
|
},
|
|
74
86
|
{
|
|
75
|
-
header:
|
|
87
|
+
header: {
|
|
88
|
+
label: 'Name',
|
|
89
|
+
columns: [
|
|
90
|
+
{ dataId: 'firstName', header: { label: 'First Name' }, width: 150, grow: 2 },
|
|
91
|
+
{ dataId: 'lastName', header: { label: 'Last Name' }, width: 150, grow: 1 },
|
|
92
|
+
],
|
|
93
|
+
},
|
|
76
94
|
dataId: 'name',
|
|
77
95
|
grow: 3,
|
|
78
|
-
columns: [
|
|
79
|
-
{ dataId: 'firstName', header: 'First Name', width: 150, grow: 2 },
|
|
80
|
-
{ dataId: 'lastName', header: 'Last Name', width: 150, grow: 1 },
|
|
81
|
-
],
|
|
82
96
|
},
|
|
83
|
-
{ dataId: 'address', header: 'Address', width: 300, grow: 2 },
|
|
97
|
+
{ dataId: 'address', header: { label: 'Address' }, width: 300, grow: 2 },
|
|
84
98
|
{
|
|
85
99
|
dataId: 'age',
|
|
86
|
-
header: 'Really long age header',
|
|
100
|
+
header: { label: 'Really long age header' },
|
|
87
101
|
width: 50,
|
|
88
102
|
align: 'center',
|
|
89
103
|
},
|
|
90
|
-
{ dataId: 'occupation', header: 'Ocuppation', width: 200 },
|
|
91
|
-
{ dataId: 'group', header: 'Group', width: 150 },
|
|
92
|
-
]
|
|
104
|
+
{ dataId: 'occupation', header: { label: 'Ocuppation' }, width: 200 },
|
|
105
|
+
{ dataId: 'group', header: { label: 'Group' }, width: 150 },
|
|
106
|
+
],
|
|
93
107
|
};
|
|
94
108
|
|
|
95
109
|
render(
|
|
@@ -101,54 +115,68 @@ test('Renders <Table /> with custom content', () => {
|
|
|
101
115
|
);
|
|
102
116
|
|
|
103
117
|
const firstRow = document.querySelector('.reqore-table-row');
|
|
104
|
-
const idCell = firstRow
|
|
118
|
+
const idCell = firstRow!.querySelector('.reqore-table-cell');
|
|
105
119
|
|
|
106
|
-
expect(idCell
|
|
120
|
+
expect(idCell!.textContent).toBe('ID 1');
|
|
107
121
|
});
|
|
108
122
|
|
|
109
123
|
test('Renders <Table /> with predefined content', () => {
|
|
110
|
-
const data = {
|
|
124
|
+
const data: IReqoreTableProps = {
|
|
111
125
|
...tableData,
|
|
112
126
|
columns: [
|
|
113
127
|
{
|
|
114
128
|
dataId: 'id',
|
|
115
|
-
header: 'ID',
|
|
129
|
+
header: { label: 'ID' },
|
|
116
130
|
width: 50,
|
|
117
131
|
align: 'center',
|
|
118
|
-
|
|
132
|
+
cell: {
|
|
133
|
+
content: 'tag:info',
|
|
134
|
+
},
|
|
119
135
|
},
|
|
120
136
|
{
|
|
121
|
-
header:
|
|
137
|
+
header: {
|
|
138
|
+
label: 'Name',
|
|
139
|
+
columns: [
|
|
140
|
+
{
|
|
141
|
+
dataId: 'firstName',
|
|
142
|
+
header: { label: 'First Name' },
|
|
143
|
+
width: 150,
|
|
144
|
+
grow: 2,
|
|
145
|
+
cell: {
|
|
146
|
+
content: 'tag:#000000',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
dataId: 'lastName',
|
|
151
|
+
header: { label: 'Last Name' },
|
|
152
|
+
width: 150,
|
|
153
|
+
grow: 1,
|
|
154
|
+
cell: {
|
|
155
|
+
content: 'title:success',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
122
160
|
dataId: 'name',
|
|
123
161
|
grow: 3,
|
|
124
|
-
columns: [
|
|
125
|
-
{
|
|
126
|
-
dataId: 'firstName',
|
|
127
|
-
header: 'First Name',
|
|
128
|
-
width: 150,
|
|
129
|
-
grow: 2,
|
|
130
|
-
content: 'tag:#000000',
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
dataId: 'lastName',
|
|
134
|
-
header: 'Last Name',
|
|
135
|
-
width: 150,
|
|
136
|
-
grow: 1,
|
|
137
|
-
content: 'title:success',
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
162
|
},
|
|
141
|
-
{
|
|
163
|
+
{
|
|
164
|
+
dataId: 'address',
|
|
165
|
+
header: { label: 'Address' },
|
|
166
|
+
width: 300,
|
|
167
|
+
grow: 2,
|
|
168
|
+
cell: { content: 'text:warning' },
|
|
169
|
+
},
|
|
142
170
|
{
|
|
143
171
|
dataId: 'age',
|
|
144
|
-
header: 'Really long age header',
|
|
172
|
+
header: { label: 'Really long age header' },
|
|
145
173
|
width: 50,
|
|
146
174
|
align: 'center',
|
|
147
175
|
},
|
|
148
|
-
{ dataId: 'occupation', header: 'Ocuppation', width: 200 },
|
|
149
|
-
{ dataId: 'group', header: 'Group', width: 150 },
|
|
150
|
-
{ dataId: 'date', header: 'Date', content: 'time-ago' },
|
|
151
|
-
]
|
|
176
|
+
{ dataId: 'occupation', header: { label: 'Ocuppation' }, width: 200 },
|
|
177
|
+
{ dataId: 'group', header: { label: 'Group' }, width: 150 },
|
|
178
|
+
{ dataId: 'date', header: { label: 'Date' }, cell: { content: 'time-ago' } },
|
|
179
|
+
],
|
|
152
180
|
};
|
|
153
181
|
|
|
154
182
|
render(
|
|
@@ -161,11 +189,11 @@ test('Renders <Table /> with predefined content', () => {
|
|
|
161
189
|
|
|
162
190
|
const firstRow = document.querySelector('.reqore-table-row');
|
|
163
191
|
|
|
164
|
-
const idCell = firstRow
|
|
165
|
-
const firstNameCell = firstRow
|
|
166
|
-
const lastNameCell = firstRow
|
|
167
|
-
const addressCell = firstRow
|
|
168
|
-
const dateCell = firstRow
|
|
192
|
+
const idCell = firstRow!.querySelectorAll('.reqore-table-cell')[0];
|
|
193
|
+
const firstNameCell = firstRow!.querySelectorAll('.reqore-table-cell')[1];
|
|
194
|
+
const lastNameCell = firstRow!.querySelectorAll('.reqore-table-cell')[2];
|
|
195
|
+
const addressCell = firstRow!.querySelectorAll('.reqore-table-cell')[3];
|
|
196
|
+
const dateCell = firstRow!.querySelectorAll('.reqore-table-cell')[7];
|
|
169
197
|
|
|
170
198
|
expect(idCell.querySelector('.reqore-tag')).toBeTruthy();
|
|
171
199
|
expect(firstNameCell.querySelector('.reqore-tag')).toBeTruthy();
|
|
@@ -175,33 +203,33 @@ test('Renders <Table /> with predefined content', () => {
|
|
|
175
203
|
});
|
|
176
204
|
|
|
177
205
|
test('Sorting on <Table /> works properly', () => {
|
|
178
|
-
const data = {
|
|
206
|
+
const data: IReqoreTableProps = {
|
|
179
207
|
...tableData,
|
|
180
208
|
columns: [
|
|
181
209
|
{
|
|
182
210
|
dataId: 'id',
|
|
183
|
-
header: 'ID',
|
|
211
|
+
header: { label: 'ID' },
|
|
184
212
|
width: 50,
|
|
185
213
|
align: 'center',
|
|
186
214
|
sortable: true,
|
|
187
215
|
},
|
|
188
|
-
{ dataId: 'firstName', header: 'First Name', width: 150 },
|
|
189
|
-
{ dataId: 'lastName', header: 'Last Name', width: 150, sortable: true },
|
|
190
|
-
{ dataId: 'address', header: 'Address', width: 300, grow: 2 },
|
|
216
|
+
{ dataId: 'firstName', header: { label: 'First Name' }, width: 150 },
|
|
217
|
+
{ dataId: 'lastName', header: { label: 'Last Name' }, width: 150, sortable: true },
|
|
218
|
+
{ dataId: 'address', header: { label: 'Address' }, width: 300, grow: 2 },
|
|
191
219
|
{
|
|
192
220
|
dataId: 'age',
|
|
193
|
-
header: 'Really long age header',
|
|
221
|
+
header: { label: 'Really long age header' },
|
|
194
222
|
width: 50,
|
|
195
223
|
align: 'center',
|
|
196
224
|
sortable: true,
|
|
197
225
|
},
|
|
198
|
-
{ dataId: 'occupation', header: 'Ocuppation', width: 200 },
|
|
199
|
-
{ dataId: 'group', header: 'Group', width: 150 },
|
|
200
|
-
]
|
|
226
|
+
{ dataId: 'occupation', header: { label: 'Ocuppation' }, width: 200 },
|
|
227
|
+
{ dataId: 'group', header: { label: 'Group' }, width: 150 },
|
|
228
|
+
],
|
|
201
229
|
sort: {
|
|
202
230
|
by: 'id',
|
|
203
231
|
direction: 'desc',
|
|
204
|
-
}
|
|
232
|
+
},
|
|
205
233
|
};
|
|
206
234
|
|
|
207
235
|
const fn = jest.fn();
|
|
@@ -215,16 +243,16 @@ test('Sorting on <Table /> works properly', () => {
|
|
|
215
243
|
);
|
|
216
244
|
|
|
217
245
|
const firstRow = document.querySelector('.reqore-table-row');
|
|
218
|
-
const idCell = firstRow
|
|
246
|
+
const idCell = firstRow!.querySelector('.reqore-table-cell');
|
|
219
247
|
|
|
220
|
-
expect(idCell
|
|
248
|
+
expect(idCell!.textContent).toBe('1000');
|
|
221
249
|
|
|
222
250
|
const lastNameHeaderCell = document.querySelectorAll('.reqore-table-header-cell')[2];
|
|
223
251
|
|
|
224
252
|
fireEvent.click(lastNameHeaderCell);
|
|
225
253
|
expect(fn).toHaveBeenCalledWith({ by: 'lastName', direction: 'desc' });
|
|
226
254
|
|
|
227
|
-
const lastNameCell = firstRow
|
|
255
|
+
const lastNameCell = firstRow!.querySelectorAll('.reqore-table-cell')[2];
|
|
228
256
|
|
|
229
257
|
expect(lastNameCell.textContent).toBe('Zold');
|
|
230
258
|
|
|
@@ -232,7 +260,7 @@ test('Sorting on <Table /> works properly', () => {
|
|
|
232
260
|
|
|
233
261
|
expect(fn).toHaveBeenLastCalledWith({ by: 'lastName', direction: 'asc' });
|
|
234
262
|
expect(lastNameCell.textContent).toBe('Abbess');
|
|
235
|
-
expect(idCell
|
|
263
|
+
expect(idCell!.textContent).toBe('543');
|
|
236
264
|
});
|
|
237
265
|
|
|
238
266
|
test('Rows on <Table /> can be selected', () => {
|
|
@@ -252,20 +280,51 @@ test('Rows on <Table /> can be selected', () => {
|
|
|
252
280
|
);
|
|
253
281
|
|
|
254
282
|
const firstRow = document.querySelector('.reqore-table-row');
|
|
255
|
-
const firstCheckCell = firstRow
|
|
283
|
+
const firstCheckCell = firstRow!.querySelector('.reqore-table-cell');
|
|
256
284
|
|
|
257
|
-
fireEvent.click(firstCheckCell);
|
|
285
|
+
fireEvent.click(firstCheckCell!);
|
|
258
286
|
|
|
259
287
|
expect(fn).toHaveBeenCalledWith([1]);
|
|
260
288
|
|
|
261
289
|
const secondRow = document.querySelectorAll('.reqore-table-row')[1];
|
|
262
290
|
const secondCheckCell = secondRow.querySelector('.reqore-table-cell');
|
|
263
291
|
|
|
264
|
-
fireEvent.click(secondCheckCell);
|
|
292
|
+
fireEvent.click(secondCheckCell!);
|
|
265
293
|
|
|
266
294
|
expect(fn).toHaveBeenLastCalledWith([1, 2]);
|
|
267
295
|
});
|
|
268
296
|
|
|
297
|
+
test('Rows on <Table /> can be selected, does not keep internal state', () => {
|
|
298
|
+
const data = {
|
|
299
|
+
...tableData,
|
|
300
|
+
selectable: true,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const fn = jest.fn();
|
|
304
|
+
|
|
305
|
+
render(
|
|
306
|
+
<ReqoreUIProvider>
|
|
307
|
+
<ReqoreLayoutContent>
|
|
308
|
+
<ReqoreTable {...data} onSelectClick={fn} />
|
|
309
|
+
</ReqoreLayoutContent>
|
|
310
|
+
</ReqoreUIProvider>
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const firstRow = document.querySelector('.reqore-table-row');
|
|
314
|
+
const firstCheckCell = firstRow!.querySelector('.reqore-table-cell');
|
|
315
|
+
|
|
316
|
+
fireEvent.click(firstCheckCell!);
|
|
317
|
+
|
|
318
|
+
expect(fn).toHaveBeenCalledWith(1);
|
|
319
|
+
|
|
320
|
+
const secondRow = document.querySelectorAll('.reqore-table-row')[1];
|
|
321
|
+
const secondCheckCell = secondRow.querySelector('.reqore-table-cell');
|
|
322
|
+
|
|
323
|
+
fireEvent.click(secondCheckCell!);
|
|
324
|
+
|
|
325
|
+
expect(fn).toHaveBeenLastCalledWith(2);
|
|
326
|
+
});
|
|
327
|
+
|
|
269
328
|
test('Rows on <Table /> cannot be selected if _selectId is missing', () => {
|
|
270
329
|
const data = {
|
|
271
330
|
...tableData,
|
|
@@ -285,18 +344,18 @@ test('Rows on <Table /> cannot be selected if _selectId is missing', () => {
|
|
|
285
344
|
const thirdRow = document.querySelectorAll('.reqore-table-row')[2];
|
|
286
345
|
const thirdCheckCell = thirdRow.querySelector('.reqore-table-cell');
|
|
287
346
|
|
|
288
|
-
fireEvent.click(thirdCheckCell);
|
|
347
|
+
fireEvent.click(thirdCheckCell!);
|
|
289
348
|
|
|
290
349
|
const fourthRow = document.querySelectorAll('.reqore-table-row')[3];
|
|
291
350
|
const fourthCheckCell = fourthRow.querySelector('.reqore-table-cell');
|
|
292
351
|
|
|
293
|
-
fireEvent.click(fourthCheckCell);
|
|
352
|
+
fireEvent.click(fourthCheckCell!);
|
|
294
353
|
|
|
295
354
|
expect(fn).toHaveBeenCalledTimes(1);
|
|
296
355
|
});
|
|
297
356
|
|
|
298
357
|
test('Rows on <Table /> are all selected/deselected when clicking on header', () => {
|
|
299
|
-
const data = {
|
|
358
|
+
const data: IReqoreTableProps = {
|
|
300
359
|
...tableData,
|
|
301
360
|
selectable: true,
|
|
302
361
|
};
|
|
@@ -312,91 +371,103 @@ test('Rows on <Table /> are all selected/deselected when clicking on header', ()
|
|
|
312
371
|
);
|
|
313
372
|
|
|
314
373
|
const header = document.querySelector('.reqore-table-header-wrapper');
|
|
315
|
-
const firstHeaderCell = header
|
|
374
|
+
const firstHeaderCell = header!.querySelector('.reqore-table-header-cell');
|
|
316
375
|
|
|
317
|
-
fireEvent.click(firstHeaderCell);
|
|
376
|
+
fireEvent.click(firstHeaderCell!);
|
|
318
377
|
|
|
319
|
-
const selectableData
|
|
378
|
+
const selectableData = tableData.data
|
|
320
379
|
.filter((datum) => datum._selectId ?? false)
|
|
321
380
|
.map((datum) => datum._selectId);
|
|
322
381
|
|
|
323
382
|
expect(fn).toHaveBeenCalledWith(selectableData);
|
|
324
383
|
|
|
325
|
-
fireEvent.click(firstHeaderCell);
|
|
384
|
+
fireEvent.click(firstHeaderCell!);
|
|
326
385
|
|
|
327
386
|
expect(fn).toHaveBeenLastCalledWith([]);
|
|
328
387
|
|
|
329
388
|
const firstRow = document.querySelector('.reqore-table-row');
|
|
330
|
-
const firstCheckCell = firstRow
|
|
389
|
+
const firstCheckCell = firstRow!.querySelector('.reqore-table-cell');
|
|
331
390
|
|
|
332
|
-
fireEvent.click(firstCheckCell);
|
|
333
|
-
fireEvent.click(firstHeaderCell);
|
|
391
|
+
fireEvent.click(firstCheckCell!);
|
|
392
|
+
fireEvent.click(firstHeaderCell!);
|
|
334
393
|
|
|
335
394
|
expect(fn).toHaveBeenLastCalledWith(selectableData);
|
|
336
395
|
});
|
|
337
396
|
|
|
338
397
|
test('Cells on <Table /> are interactive', () => {
|
|
339
398
|
const fn = jest.fn();
|
|
340
|
-
const data = {
|
|
399
|
+
const data: IReqoreTableProps = {
|
|
341
400
|
...tableData,
|
|
342
401
|
columns: [
|
|
343
402
|
{
|
|
344
403
|
dataId: 'id',
|
|
345
|
-
header: 'ID',
|
|
404
|
+
header: { label: 'ID', tooltip: 'Custom ID tooltip nice' },
|
|
346
405
|
width: 50,
|
|
347
406
|
align: 'center',
|
|
348
407
|
sortable: true,
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
408
|
+
cell: {
|
|
409
|
+
onClick: ({ id }) => {
|
|
410
|
+
fn(id);
|
|
411
|
+
},
|
|
352
412
|
},
|
|
353
413
|
},
|
|
354
414
|
{
|
|
355
|
-
header:
|
|
415
|
+
header: {
|
|
416
|
+
label: 'Name',
|
|
417
|
+
columns: [
|
|
418
|
+
{
|
|
419
|
+
dataId: 'firstName',
|
|
420
|
+
header: {
|
|
421
|
+
label: 'First Name',
|
|
422
|
+
icon: 'SlideshowLine',
|
|
423
|
+
effect: {
|
|
424
|
+
gradient: {
|
|
425
|
+
colors: {
|
|
426
|
+
0: 'success',
|
|
427
|
+
100: 'info',
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
width: 150,
|
|
433
|
+
grow: 2,
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
dataId: 'lastName',
|
|
437
|
+
header: { label: 'Last Name', icon: 'SlideshowLine' },
|
|
438
|
+
width: 150,
|
|
439
|
+
grow: 1,
|
|
440
|
+
sortable: true,
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
},
|
|
356
444
|
dataId: 'name',
|
|
357
445
|
grow: 3,
|
|
358
|
-
columns: [
|
|
359
|
-
{
|
|
360
|
-
icon: 'SlideshowLine',
|
|
361
|
-
dataId: 'firstName',
|
|
362
|
-
header: 'First Name',
|
|
363
|
-
width: 150,
|
|
364
|
-
grow: 2,
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
icon: 'SlideshowLine',
|
|
368
|
-
dataId: 'lastName',
|
|
369
|
-
header: 'Last Name',
|
|
370
|
-
width: 150,
|
|
371
|
-
grow: 1,
|
|
372
|
-
sortable: true,
|
|
373
|
-
},
|
|
374
|
-
],
|
|
375
446
|
},
|
|
376
447
|
{
|
|
377
448
|
dataId: 'address',
|
|
378
|
-
header: 'Address',
|
|
449
|
+
header: { label: 'Address', onClick: () => alert('clicked address') },
|
|
379
450
|
width: 300,
|
|
380
451
|
grow: 2,
|
|
381
|
-
onClick: () => alert('clicked address'),
|
|
382
452
|
},
|
|
383
453
|
{
|
|
384
|
-
icon: 'User4Line',
|
|
385
454
|
dataId: 'age',
|
|
386
|
-
header: 'Really long age header',
|
|
455
|
+
header: { label: 'Really long age header', icon: 'User4Line' },
|
|
387
456
|
width: 50,
|
|
388
457
|
align: 'center',
|
|
389
458
|
sortable: true,
|
|
390
459
|
},
|
|
391
460
|
{
|
|
392
|
-
header:
|
|
461
|
+
header: {
|
|
462
|
+
label: 'Data',
|
|
463
|
+
columns: [
|
|
464
|
+
{ dataId: 'occupation', header: { label: 'Ocuppation' }, width: 200 },
|
|
465
|
+
{ dataId: 'group', header: { label: 'Groups' }, width: 150 },
|
|
466
|
+
],
|
|
467
|
+
},
|
|
393
468
|
dataId: 'data',
|
|
394
|
-
columns: [
|
|
395
|
-
{ dataId: 'occupation', header: 'Ocuppation', width: 200 },
|
|
396
|
-
{ dataId: 'group', header: 'Groups', width: 150 },
|
|
397
|
-
],
|
|
398
469
|
},
|
|
399
|
-
]
|
|
470
|
+
],
|
|
400
471
|
};
|
|
401
472
|
|
|
402
473
|
render(
|
|
@@ -408,9 +479,170 @@ test('Cells on <Table /> are interactive', () => {
|
|
|
408
479
|
);
|
|
409
480
|
|
|
410
481
|
const firstRow = document.querySelector('.reqore-table-row');
|
|
411
|
-
const firstCheckCell = firstRow
|
|
482
|
+
const firstCheckCell = firstRow!.querySelector('.reqore-table-cell');
|
|
412
483
|
|
|
413
|
-
fireEvent.click(firstCheckCell);
|
|
484
|
+
fireEvent.click(firstCheckCell!);
|
|
414
485
|
|
|
415
486
|
expect(fn).toHaveBeenCalledWith(1);
|
|
416
487
|
});
|
|
488
|
+
|
|
489
|
+
const TestingTableWithState = () => {
|
|
490
|
+
const [columns, setColumns] = useState<IReqoreTableColumn[]>([
|
|
491
|
+
{
|
|
492
|
+
dataId: 'id',
|
|
493
|
+
header: { label: 'ID', tooltip: 'Custom ID tooltip nice' },
|
|
494
|
+
width: 50,
|
|
495
|
+
align: 'center',
|
|
496
|
+
sortable: true,
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
header: {
|
|
500
|
+
label: 'Name',
|
|
501
|
+
columns: [
|
|
502
|
+
{
|
|
503
|
+
dataId: 'firstName',
|
|
504
|
+
header: {
|
|
505
|
+
label: 'First Name',
|
|
506
|
+
icon: 'SlideshowLine',
|
|
507
|
+
effect: {
|
|
508
|
+
gradient: {
|
|
509
|
+
colors: {
|
|
510
|
+
0: 'success',
|
|
511
|
+
100: 'info',
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
width: 150,
|
|
517
|
+
grow: 2,
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
dataId: 'lastName',
|
|
521
|
+
header: { label: 'Last Name', icon: 'SlideshowLine' },
|
|
522
|
+
width: 150,
|
|
523
|
+
grow: 1,
|
|
524
|
+
sortable: true,
|
|
525
|
+
},
|
|
526
|
+
],
|
|
527
|
+
},
|
|
528
|
+
dataId: 'name',
|
|
529
|
+
grow: 3,
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
dataId: 'address',
|
|
533
|
+
header: { label: 'Address', onClick: () => alert('clicked address') },
|
|
534
|
+
width: 300,
|
|
535
|
+
grow: 2,
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
dataId: 'age',
|
|
539
|
+
header: { label: 'Really long age header', icon: 'User4Line' },
|
|
540
|
+
width: 50,
|
|
541
|
+
align: 'center',
|
|
542
|
+
sortable: true,
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
header: {
|
|
546
|
+
label: 'Data',
|
|
547
|
+
columns: [
|
|
548
|
+
{ dataId: 'occupation', header: { label: 'Ocuppation' }, width: 200 },
|
|
549
|
+
{ dataId: 'group', header: { label: 'Groups' }, width: 150 },
|
|
550
|
+
],
|
|
551
|
+
},
|
|
552
|
+
dataId: 'data',
|
|
553
|
+
},
|
|
554
|
+
]);
|
|
555
|
+
|
|
556
|
+
return (
|
|
557
|
+
<ReqoreTable
|
|
558
|
+
{...tableData}
|
|
559
|
+
columns={columns}
|
|
560
|
+
actions={[
|
|
561
|
+
{
|
|
562
|
+
className: 'reqore-test-action',
|
|
563
|
+
label: 'Test Action',
|
|
564
|
+
onClick: () => {
|
|
565
|
+
setColumns((prev) => {
|
|
566
|
+
return prev.map((column) => {
|
|
567
|
+
if (column.dataId === 'id') {
|
|
568
|
+
return {
|
|
569
|
+
...column,
|
|
570
|
+
header: {
|
|
571
|
+
...column.header,
|
|
572
|
+
label: 'New ID',
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
return column;
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
]}
|
|
582
|
+
/>
|
|
583
|
+
);
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
test('Data on <Table /> headers are not reset when columns are updated', () => {
|
|
587
|
+
jest.useFakeTimers();
|
|
588
|
+
jest.setTimeout(30000);
|
|
589
|
+
|
|
590
|
+
act(() => {
|
|
591
|
+
render(
|
|
592
|
+
<ReqoreUIProvider>
|
|
593
|
+
<ReqoreLayoutContent>
|
|
594
|
+
<TestingTableWithState />
|
|
595
|
+
</ReqoreLayoutContent>
|
|
596
|
+
</ReqoreUIProvider>
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(9);
|
|
601
|
+
|
|
602
|
+
fireEvent.click(document.querySelector('.reqore-table-header-cell-options')!);
|
|
603
|
+
|
|
604
|
+
jest.advanceTimersByTime(1);
|
|
605
|
+
|
|
606
|
+
fireEvent.click(document.querySelector('.reqore-table-header-hide')!);
|
|
607
|
+
|
|
608
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(8);
|
|
609
|
+
|
|
610
|
+
fireEvent.click(document.querySelector('.reqore-test-action')!);
|
|
611
|
+
|
|
612
|
+
// The column is still hidden even after columns data have changed
|
|
613
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(8);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
test('<Table /> is reset to default', () => {
|
|
617
|
+
jest.useFakeTimers();
|
|
618
|
+
jest.setTimeout(30000);
|
|
619
|
+
|
|
620
|
+
act(() => {
|
|
621
|
+
render(
|
|
622
|
+
<ReqoreUIProvider>
|
|
623
|
+
<ReqoreLayoutContent>
|
|
624
|
+
<TestingTableWithState />
|
|
625
|
+
</ReqoreLayoutContent>
|
|
626
|
+
</ReqoreUIProvider>
|
|
627
|
+
);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(9);
|
|
631
|
+
|
|
632
|
+
fireEvent.click(document.querySelector('.reqore-table-header-cell-options')!);
|
|
633
|
+
|
|
634
|
+
jest.advanceTimersByTime(1);
|
|
635
|
+
|
|
636
|
+
fireEvent.click(document.querySelector('.reqore-table-header-hide')!);
|
|
637
|
+
|
|
638
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(8);
|
|
639
|
+
|
|
640
|
+
fireEvent.click(document.querySelector('.reqore-table-more')!);
|
|
641
|
+
|
|
642
|
+
jest.advanceTimersByTime(1);
|
|
643
|
+
|
|
644
|
+
fireEvent.click(document.querySelector('.reqore-table-reset')!);
|
|
645
|
+
|
|
646
|
+
// The column is still hidden even after columns data have changed
|
|
647
|
+
expect(document.querySelectorAll('.reqore-table-header-cell').length).toBe(9);
|
|
648
|
+
});
|