@patternfly/react-table 4.72.0 → 4.73.0
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/CHANGELOG.md +27 -0
- package/dist/umd/react-table.css +102 -14
- package/dist/umd/react-table.min.css +102 -14
- package/package.json +6 -6
- package/src/components/Table/{RowWrapper.test.tsx → __tests__/RowWrapper.test.tsx} +7 -5
- package/src/components/Table/__tests__/Table.test.tsx +358 -0
- package/src/components/Table/{__snapshots__ → __tests__/__snapshots__}/RowWrapper.test.tsx.snap +4 -4
- package/src/components/Table/{__snapshots__ → __tests__/__snapshots__}/Table.test.tsx.snap +2050 -1954
- package/src/components/Table/utils/__snapshots__/transformers.test.tsx.snap +0 -10
- package/src/components/Table/utils/transformers.test.tsx +37 -33
- package/src/components/Table/Table.test.tsx +0 -344
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Table,
|
|
8
|
+
TableHeader,
|
|
9
|
+
TableBody,
|
|
10
|
+
TableGridBreakpoint,
|
|
11
|
+
TableVariant,
|
|
12
|
+
RowSelectVariant,
|
|
13
|
+
cellWidth,
|
|
14
|
+
headerCol,
|
|
15
|
+
sortable,
|
|
16
|
+
expandable,
|
|
17
|
+
compoundExpand,
|
|
18
|
+
IRow,
|
|
19
|
+
OnCollapse,
|
|
20
|
+
OnExpand,
|
|
21
|
+
OnSelect,
|
|
22
|
+
OnRowEdit,
|
|
23
|
+
OnSort,
|
|
24
|
+
wrappable,
|
|
25
|
+
nowrap,
|
|
26
|
+
truncate,
|
|
27
|
+
breakWord,
|
|
28
|
+
fitContent,
|
|
29
|
+
ICell
|
|
30
|
+
} from '../index';
|
|
31
|
+
import { rows, columns, editableRows, editableColumns, actions } from '../../../test-helpers/data-sets';
|
|
32
|
+
import { ColumnsType } from '../base';
|
|
33
|
+
|
|
34
|
+
describe('Table', () => {
|
|
35
|
+
describe('simple', () => {
|
|
36
|
+
test('caption', () => {
|
|
37
|
+
const { asFragment } = render(
|
|
38
|
+
<Table caption="Simple Table" cells={columns} rows={rows}>
|
|
39
|
+
<TableHeader />
|
|
40
|
+
<TableBody />
|
|
41
|
+
</Table>
|
|
42
|
+
);
|
|
43
|
+
expect(asFragment()).toMatchSnapshot();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('header', () => {
|
|
47
|
+
const { asFragment } = render(
|
|
48
|
+
<Table header={<h4>Header title</h4>} cells={columns} rows={rows}>
|
|
49
|
+
<TableHeader />
|
|
50
|
+
<TableBody />
|
|
51
|
+
</Table>
|
|
52
|
+
);
|
|
53
|
+
expect(asFragment()).toMatchSnapshot();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('aria-label', () => {
|
|
57
|
+
const { asFragment } = render(
|
|
58
|
+
<Table aria-label="Aria labeled" cells={columns} rows={rows}>
|
|
59
|
+
<TableHeader />
|
|
60
|
+
<TableBody />
|
|
61
|
+
</Table>
|
|
62
|
+
);
|
|
63
|
+
expect(asFragment()).toMatchSnapshot();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('Editable table', () => {
|
|
67
|
+
const onRowEdit: OnRowEdit = () => undefined;
|
|
68
|
+
const { asFragment } = render(
|
|
69
|
+
<Table caption="Editable Table" cells={editableColumns} rows={editableRows} onRowEdit={onRowEdit}>
|
|
70
|
+
<TableHeader />
|
|
71
|
+
<TableBody />
|
|
72
|
+
</Table>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(asFragment()).toMatchSnapshot();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('Sortable table', () => {
|
|
79
|
+
columns[0] = { ...(columns[0] as object), transforms: [sortable] };
|
|
80
|
+
|
|
81
|
+
const onSortCall: OnSort = () => undefined;
|
|
82
|
+
const { asFragment } = render(
|
|
83
|
+
<Table aria-label="Aria labeled" onSort={onSortCall} sortBy={{}} cells={columns} rows={rows}>
|
|
84
|
+
<TableHeader />
|
|
85
|
+
<TableBody />
|
|
86
|
+
</Table>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(asFragment()).toMatchSnapshot();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('Row click table', () => {
|
|
93
|
+
const rowClickHandler = jest.fn();
|
|
94
|
+
const { asFragment } = render(
|
|
95
|
+
<Table aria-label="Row click table" cells={columns} rows={rows}>
|
|
96
|
+
<TableHeader />
|
|
97
|
+
<TableBody onRowClick={rowClickHandler} />
|
|
98
|
+
</Table>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
expect(asFragment()).toMatchSnapshot();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('Table variants', () => {
|
|
106
|
+
Object.values(TableGridBreakpoint).forEach(oneBreakpoint => {
|
|
107
|
+
test(`Breakpoint - ${oneBreakpoint}`, () => {
|
|
108
|
+
const { asFragment } = render(
|
|
109
|
+
<Table aria-label="Aria labeled" gridBreakPoint={oneBreakpoint} cells={columns} rows={rows}>
|
|
110
|
+
<TableHeader />
|
|
111
|
+
<TableBody />
|
|
112
|
+
</Table>
|
|
113
|
+
);
|
|
114
|
+
expect(asFragment()).toMatchSnapshot();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
Object.values(TableVariant).forEach(onevariant => {
|
|
119
|
+
test(`Size - ${onevariant}`, () => {
|
|
120
|
+
const { asFragment } = render(
|
|
121
|
+
<Table aria-label="Aria labeled" variant={onevariant} cells={columns} rows={rows}>
|
|
122
|
+
<TableHeader />
|
|
123
|
+
<TableBody />
|
|
124
|
+
</Table>
|
|
125
|
+
);
|
|
126
|
+
expect(asFragment()).toMatchSnapshot();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('Simple Actions table', () => {
|
|
132
|
+
const rowsWithDisabledAction = [
|
|
133
|
+
...rows,
|
|
134
|
+
{
|
|
135
|
+
cells: ['one', 'two', 'three', 'four', 'five'],
|
|
136
|
+
disableActions: true
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
const { asFragment } = render(
|
|
140
|
+
<Table aria-label="Aria labeled" actions={actions} cells={columns} rows={rowsWithDisabledAction}>
|
|
141
|
+
<TableHeader />
|
|
142
|
+
<TableBody />
|
|
143
|
+
</Table>
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(asFragment()).toMatchSnapshot();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('Actions table', () => {
|
|
150
|
+
const { asFragment } = render(
|
|
151
|
+
<Table
|
|
152
|
+
aria-label="Aria labeled"
|
|
153
|
+
actionResolver={() => actions}
|
|
154
|
+
areActionsDisabled={() => false}
|
|
155
|
+
cells={columns}
|
|
156
|
+
rows={rows}
|
|
157
|
+
>
|
|
158
|
+
<TableHeader />
|
|
159
|
+
<TableBody />
|
|
160
|
+
</Table>
|
|
161
|
+
);
|
|
162
|
+
expect(asFragment()).toMatchSnapshot();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('Cell header table', () => {
|
|
166
|
+
columns[0] = { ...(columns[0] as object), cellTransforms: [headerCol('test-headercol-')] };
|
|
167
|
+
const { asFragment } = render(
|
|
168
|
+
<Table aria-label="Aria labeled" cells={columns} rows={rows}>
|
|
169
|
+
<TableHeader />
|
|
170
|
+
<TableBody />
|
|
171
|
+
</Table>
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
expect(asFragment()).toMatchSnapshot();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('Collapsible table', () => {
|
|
178
|
+
rows[0] = { ...rows[0], isOpen: true };
|
|
179
|
+
rows[1] = { ...rows[1], parent: 0 };
|
|
180
|
+
rows[3] = { ...rows[3], isOpen: false };
|
|
181
|
+
rows[4] = { ...rows[4], parent: 3 };
|
|
182
|
+
columns[0] = { ...(columns[0] as object), cellFormatters: [expandable] };
|
|
183
|
+
|
|
184
|
+
const onCollapse: OnCollapse = () => undefined;
|
|
185
|
+
const { asFragment } = render(
|
|
186
|
+
<Table aria-label="Aria labeled" onCollapse={onCollapse} cells={columns} rows={rows}>
|
|
187
|
+
<TableHeader />
|
|
188
|
+
<TableBody />
|
|
189
|
+
</Table>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(asFragment()).toMatchSnapshot();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('Compound Expandable table', () => {
|
|
196
|
+
const compoundColumns: ColumnsType = [
|
|
197
|
+
{ title: 'col1', cellTransforms: [compoundExpand] },
|
|
198
|
+
{ title: 'col2', cellTransforms: [compoundExpand] }
|
|
199
|
+
];
|
|
200
|
+
const compoundRows: IRow[] = [
|
|
201
|
+
{
|
|
202
|
+
isOpen: true,
|
|
203
|
+
cells: [
|
|
204
|
+
{ title: '1', props: { isOpen: true } },
|
|
205
|
+
{ title: '2', props: { isOpen: false } }
|
|
206
|
+
]
|
|
207
|
+
},
|
|
208
|
+
{ parent: 0, compoundParent: 0, cells: [{ title: 'expanded', props: { colSpan: 2 } }] },
|
|
209
|
+
{
|
|
210
|
+
isOpen: false,
|
|
211
|
+
cells: [
|
|
212
|
+
{ title: '3', props: { isOpen: false } },
|
|
213
|
+
{ title: '4', props: { isOpen: false } }
|
|
214
|
+
]
|
|
215
|
+
},
|
|
216
|
+
{ parent: 2, compoundParent: 0, cells: [{ title: 'expanded', props: { colSpan: 2 } }] }
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
const onExpand: OnExpand = () => undefined;
|
|
220
|
+
const { asFragment } = render(
|
|
221
|
+
<Table aria-label="Aria labeled" onExpand={onExpand} cells={compoundColumns} rows={compoundRows}>
|
|
222
|
+
<TableHeader />
|
|
223
|
+
<TableBody />
|
|
224
|
+
</Table>
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
expect(asFragment()).toMatchSnapshot();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('Collapsible nested table', () => {
|
|
231
|
+
rows[0] = { ...rows[0], isOpen: false };
|
|
232
|
+
rows[1] = { ...rows[1], parent: 0, isOpen: true };
|
|
233
|
+
rows[2] = { ...rows[2], parent: 1 };
|
|
234
|
+
|
|
235
|
+
const onCollapse: OnCollapse = () => undefined;
|
|
236
|
+
const { asFragment } = render(
|
|
237
|
+
<Table aria-label="Aria labeled" onCollapse={onCollapse} cells={columns} rows={rows}>
|
|
238
|
+
<TableHeader />
|
|
239
|
+
<TableBody />
|
|
240
|
+
</Table>
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
expect(asFragment()).toMatchSnapshot();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('Selectable table', () => {
|
|
247
|
+
const onSelect: OnSelect = () => undefined;
|
|
248
|
+
const { asFragment } = render(
|
|
249
|
+
<Table aria-label="Aria labeled" onSelect={onSelect} cells={columns} rows={rows}>
|
|
250
|
+
<TableHeader />
|
|
251
|
+
<TableBody />
|
|
252
|
+
</Table>
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
expect(asFragment()).toMatchSnapshot();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('Selectable table with Radio', () => {
|
|
259
|
+
const onSelect: OnSelect = () => undefined;
|
|
260
|
+
const { asFragment } = render(
|
|
261
|
+
<Table
|
|
262
|
+
aria-label="Aria labeled"
|
|
263
|
+
selectVariant={RowSelectVariant.radio}
|
|
264
|
+
onSelect={onSelect}
|
|
265
|
+
cells={columns}
|
|
266
|
+
rows={rows}
|
|
267
|
+
>
|
|
268
|
+
<TableHeader />
|
|
269
|
+
<TableBody />
|
|
270
|
+
</Table>
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(asFragment()).toMatchSnapshot();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('Control text table', () => {
|
|
277
|
+
const controlTextColumns: ICell[] = [
|
|
278
|
+
{ ...(columns[0] as object), transforms: [nowrap] },
|
|
279
|
+
{ title: 'new object column', transforms: [wrappable] },
|
|
280
|
+
{ ...(columns[2] as object), transforms: [breakWord] },
|
|
281
|
+
{ title: 'new object column', transforms: [truncate] },
|
|
282
|
+
{ ...(columns[4] as object), transforms: [fitContent] }
|
|
283
|
+
];
|
|
284
|
+
|
|
285
|
+
const { asFragment } = render(
|
|
286
|
+
<Table aria-label="Aria labeled" cells={controlTextColumns} rows={rows}>
|
|
287
|
+
<TableHeader />
|
|
288
|
+
<TableBody />
|
|
289
|
+
</Table>
|
|
290
|
+
);
|
|
291
|
+
expect(asFragment()).toMatchSnapshot();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('Header width table', () => {
|
|
295
|
+
columns[0] = { ...(columns[0] as object), transforms: [cellWidth(10)] };
|
|
296
|
+
columns[2] = { ...(columns[2] as object), transforms: [cellWidth(30)] };
|
|
297
|
+
columns[4] = { ...(columns[4] as object), transforms: [cellWidth(100)] };
|
|
298
|
+
const { asFragment } = render(
|
|
299
|
+
<Table aria-label="Aria labeled" cells={columns} rows={rows}>
|
|
300
|
+
<TableHeader />
|
|
301
|
+
<TableBody />
|
|
302
|
+
</Table>
|
|
303
|
+
);
|
|
304
|
+
expect(asFragment()).toMatchSnapshot();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('Selectable table with selected expandable row', () => {
|
|
308
|
+
const data = {
|
|
309
|
+
cells: ['column'],
|
|
310
|
+
rows: [
|
|
311
|
+
{
|
|
312
|
+
cells: ['one'],
|
|
313
|
+
selected: true
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
cells: ['one'],
|
|
317
|
+
parent: 0
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
onSelect: (e: React.FormEvent<HTMLInputElement>) => e
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const { asFragment } = render(
|
|
324
|
+
<Table aria-label="Aria labeled" {...data}>
|
|
325
|
+
<TableHeader />
|
|
326
|
+
<TableBody />
|
|
327
|
+
</Table>
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
expect(asFragment()).toMatchSnapshot();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('Empty state table', () => {
|
|
334
|
+
const data = {
|
|
335
|
+
cells: ['Hostname', 'IP address', 'Role', 'Team'],
|
|
336
|
+
rows: [
|
|
337
|
+
{
|
|
338
|
+
heightAuto: true,
|
|
339
|
+
cells: [
|
|
340
|
+
{
|
|
341
|
+
title: <div>Empty State Component</div>,
|
|
342
|
+
props: { colSpan: 8 }
|
|
343
|
+
}
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
]
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
render(
|
|
350
|
+
<Table aria-label="Aria labeled" {...data}>
|
|
351
|
+
<TableHeader />
|
|
352
|
+
<TableBody />
|
|
353
|
+
</Table>
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
expect(screen.getByText('Empty State Component').parentElement.getAttribute('colspan')).toEqual('8');
|
|
357
|
+
});
|
|
358
|
+
});
|
package/src/components/Table/{__snapshots__ → __tests__/__snapshots__}/RowWrapper.test.tsx.snap
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`RowWrapper renders correctly 1`] = `
|
|
4
|
-
<
|
|
4
|
+
<DocumentFragment>
|
|
5
5
|
<table>
|
|
6
6
|
<tbody>
|
|
7
7
|
<tr
|
|
@@ -12,11 +12,11 @@ exports[`RowWrapper renders correctly 1`] = `
|
|
|
12
12
|
/>
|
|
13
13
|
</tbody>
|
|
14
14
|
</table>
|
|
15
|
-
</
|
|
15
|
+
</DocumentFragment>
|
|
16
16
|
`;
|
|
17
17
|
|
|
18
18
|
exports[`RowWrapper renders expanded correctly 1`] = `
|
|
19
|
-
<
|
|
19
|
+
<DocumentFragment>
|
|
20
20
|
<table>
|
|
21
21
|
<tbody>
|
|
22
22
|
<tr
|
|
@@ -27,5 +27,5 @@ exports[`RowWrapper renders expanded correctly 1`] = `
|
|
|
27
27
|
/>
|
|
28
28
|
</tbody>
|
|
29
29
|
</table>
|
|
30
|
-
</
|
|
30
|
+
</DocumentFragment>
|
|
31
31
|
`;
|