@instructure/ui-table 10.19.2-snapshot-3 → 10.19.2-snapshot-5
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 +1 -1
- package/package.json +17 -17
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/Table/__new-tests__/Table.test.js +0 -431
- package/lib/Table/__new-tests__/Table.test.js +0 -432
- package/src/Table/__new-tests__/Table.test.tsx +0 -439
- package/types/Table/__new-tests__/Table.test.d.ts +0 -2
- package/types/Table/__new-tests__/Table.test.d.ts.map +0 -1
@@ -1,431 +0,0 @@
|
|
1
|
-
var _Table$Head, _Table$Body, _Table, _Table2, _Table$Cell, _Table$Body2, _span, _span2, _Table$Row, _span3, _span4, _Table$Row2, _Table$Body3, _Table$RowHeader, _Table$Cell2, _Table$Head2, _Table$Row3, _Table$ColHeader, _Table$RowHeader2, _Table$Cell3;
|
2
|
-
/*
|
3
|
-
* The MIT License (MIT)
|
4
|
-
*
|
5
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
6
|
-
*
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
12
|
-
* furnished to do so, subject to the following conditions:
|
13
|
-
*
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
15
|
-
* copies or substantial portions of the Software.
|
16
|
-
*
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
* SOFTWARE.
|
24
|
-
*/
|
25
|
-
|
26
|
-
import { Component } from 'react';
|
27
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
28
|
-
import { vi } from 'vitest';
|
29
|
-
import { userEvent } from '@testing-library/user-event';
|
30
|
-
import '@testing-library/jest-dom';
|
31
|
-
import { Table } from '../index';
|
32
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
33
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
34
|
-
describe('<Table />', async () => {
|
35
|
-
let consoleErrorMock;
|
36
|
-
beforeEach(() => {
|
37
|
-
// Mocking console to prevent test output pollution
|
38
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
39
|
-
});
|
40
|
-
afterEach(() => {
|
41
|
-
consoleErrorMock.mockRestore();
|
42
|
-
});
|
43
|
-
const renderTable = props => render(_jsxs(Table, {
|
44
|
-
caption: "Test table",
|
45
|
-
...props,
|
46
|
-
children: [_Table$Head || (_Table$Head = _jsx(Table.Head, {
|
47
|
-
children: _jsxs(Table.Row, {
|
48
|
-
children: [_jsx(Table.ColHeader, {
|
49
|
-
id: "foo",
|
50
|
-
children: "ColHeader"
|
51
|
-
}), _jsx(Table.ColHeader, {
|
52
|
-
id: "bar",
|
53
|
-
children: "Bar-header"
|
54
|
-
})]
|
55
|
-
})
|
56
|
-
})), _Table$Body || (_Table$Body = _jsx(Table.Body, {
|
57
|
-
children: _jsxs(Table.Row, {
|
58
|
-
children: [_jsx(Table.RowHeader, {
|
59
|
-
children: "RowHeader"
|
60
|
-
}), _jsx(Table.Cell, {
|
61
|
-
children: "Cell"
|
62
|
-
})]
|
63
|
-
})
|
64
|
-
}))]
|
65
|
-
}));
|
66
|
-
it('should render a caption', async () => {
|
67
|
-
const _renderTable = renderTable(),
|
68
|
-
container = _renderTable.container;
|
69
|
-
const caption = container.querySelector('caption');
|
70
|
-
expect(caption).toBeInTheDocument();
|
71
|
-
expect(caption).toHaveTextContent('Test table');
|
72
|
-
});
|
73
|
-
it('should meet a11y standards', async () => {
|
74
|
-
const _renderTable2 = renderTable(),
|
75
|
-
container = _renderTable2.container;
|
76
|
-
const axeCheck = await runAxeCheck(container);
|
77
|
-
expect(axeCheck).toBe(true);
|
78
|
-
});
|
79
|
-
it('applies a fixed column layout', async () => {
|
80
|
-
await renderTable({
|
81
|
-
layout: 'fixed'
|
82
|
-
});
|
83
|
-
const table = screen.getByRole('table');
|
84
|
-
expect(table).toHaveStyle({
|
85
|
-
tableLayout: 'fixed'
|
86
|
-
});
|
87
|
-
});
|
88
|
-
it('passes hover to table row', async () => {
|
89
|
-
renderTable({
|
90
|
-
hover: true
|
91
|
-
});
|
92
|
-
const tableRows = screen.getAllByRole('row');
|
93
|
-
tableRows.forEach(tableRow => {
|
94
|
-
expect(tableRow).not.toHaveAttribute('border-left', 'none');
|
95
|
-
expect(tableRow).not.toHaveAttribute('border-right', 'none');
|
96
|
-
});
|
97
|
-
});
|
98
|
-
it('sets the scope of column header to col', async () => {
|
99
|
-
await renderTable();
|
100
|
-
const columnHeaders = screen.getAllByRole('columnheader');
|
101
|
-
columnHeaders.forEach(columnHeader => {
|
102
|
-
expect(columnHeader).toHaveAttribute('scope', 'col');
|
103
|
-
});
|
104
|
-
});
|
105
|
-
it('sets the scope of row header to row', async () => {
|
106
|
-
renderTable();
|
107
|
-
const rowHeaders = screen.getAllByRole('rowheader');
|
108
|
-
rowHeaders.forEach(rowHeader => {
|
109
|
-
expect(rowHeader).toHaveAttribute('scope', 'row');
|
110
|
-
});
|
111
|
-
});
|
112
|
-
it('can render table in stacked layout', async () => {
|
113
|
-
renderTable({
|
114
|
-
layout: 'stacked'
|
115
|
-
});
|
116
|
-
const stackedTable = screen.getByRole('table');
|
117
|
-
expect(stackedTable).toBeInTheDocument();
|
118
|
-
expect(stackedTable).toHaveTextContent('RowHeader');
|
119
|
-
expect(stackedTable).toHaveTextContent('Cell');
|
120
|
-
expect(stackedTable).not.toHaveTextContent('ColHeader');
|
121
|
-
});
|
122
|
-
it('can handle non-existent head in stacked layout', async () => {
|
123
|
-
render(_Table || (_Table = _jsx(Table, {
|
124
|
-
caption: "Test table",
|
125
|
-
layout: "stacked",
|
126
|
-
children: _jsx(Table.Body, {})
|
127
|
-
})));
|
128
|
-
const stackedTable = screen.getByRole('table');
|
129
|
-
expect(stackedTable).toBeInTheDocument();
|
130
|
-
});
|
131
|
-
it('can handle empty head in stacked layout', async () => {
|
132
|
-
render(_Table2 || (_Table2 = _jsx(Table, {
|
133
|
-
caption: "Test table",
|
134
|
-
layout: "stacked",
|
135
|
-
children: _jsx(Table.Head, {})
|
136
|
-
})));
|
137
|
-
const stackedTable = screen.getByRole('table');
|
138
|
-
expect(stackedTable).toBeInTheDocument();
|
139
|
-
});
|
140
|
-
it('can handle invalid header in stacked layout', async () => {
|
141
|
-
render(_jsxs(Table, {
|
142
|
-
caption: "Test table",
|
143
|
-
layout: "stacked",
|
144
|
-
children: [_jsx(Table.Head, {
|
145
|
-
children: _jsxs(Table.Row, {
|
146
|
-
children: [_Table$Cell || (_Table$Cell = _jsx(Table.Cell, {
|
147
|
-
children: "Foo"
|
148
|
-
})), false]
|
149
|
-
})
|
150
|
-
}), _Table$Body2 || (_Table$Body2 = _jsxs(Table.Body, {
|
151
|
-
children: [_jsxs(Table.Row, {
|
152
|
-
children: [_jsx(Table.RowHeader, {
|
153
|
-
children: "1"
|
154
|
-
}), _jsx(Table.Cell, {
|
155
|
-
children: "The Shawshank Redemption"
|
156
|
-
}), _jsx(Table.Cell, {
|
157
|
-
children: "1994"
|
158
|
-
}), _jsx(Table.Cell, {
|
159
|
-
children: "9.3"
|
160
|
-
})]
|
161
|
-
}), _jsxs(Table.Row, {
|
162
|
-
children: [_jsx(Table.RowHeader, {
|
163
|
-
children: "2"
|
164
|
-
}), _jsx(Table.Cell, {
|
165
|
-
children: "The Godfather"
|
166
|
-
}), _jsx(Table.Cell, {
|
167
|
-
children: "1972"
|
168
|
-
}), _jsx(Table.Cell, {
|
169
|
-
children: "9.2"
|
170
|
-
})]
|
171
|
-
})]
|
172
|
-
}))]
|
173
|
-
}));
|
174
|
-
const stackedTable = screen.getByRole('table');
|
175
|
-
expect(stackedTable).toBeInTheDocument();
|
176
|
-
expect(stackedTable).not.toHaveTextContent('Foo');
|
177
|
-
});
|
178
|
-
it('does not crash for invalid children in stacked layout', async () => {
|
179
|
-
render(_jsxs(Table, {
|
180
|
-
caption: "Test table",
|
181
|
-
layout: "stacked",
|
182
|
-
children: ["test1", _span || (_span = _jsx("span", {
|
183
|
-
children: "test"
|
184
|
-
})), _jsxs(Table.Head, {
|
185
|
-
children: [_span2 || (_span2 = _jsx("span", {
|
186
|
-
children: "test"
|
187
|
-
})), "test2", _Table$Row || (_Table$Row = _jsxs(Table.Row, {
|
188
|
-
children: ["test3", _jsx("span", {
|
189
|
-
children: "test"
|
190
|
-
}), _jsx(Table.Cell, {
|
191
|
-
children: "Foo"
|
192
|
-
})]
|
193
|
-
})), "test4", _span3 || (_span3 = _jsx("span", {
|
194
|
-
children: "test"
|
195
|
-
}))]
|
196
|
-
}), "test5", _jsxs(Table.Body, {
|
197
|
-
children: ["test", _span4 || (_span4 = _jsx("span", {
|
198
|
-
children: "test"
|
199
|
-
})), _Table$Row2 || (_Table$Row2 = _jsxs(Table.Row, {
|
200
|
-
children: ["test", _jsx("span", {
|
201
|
-
children: "test"
|
202
|
-
}), _jsx(Table.Cell, {
|
203
|
-
children: "Foo"
|
204
|
-
}), "test", _jsx("span", {
|
205
|
-
children: "test"
|
206
|
-
})]
|
207
|
-
}))]
|
208
|
-
})]
|
209
|
-
}));
|
210
|
-
const table = screen.getByRole('table');
|
211
|
-
expect(table).toBeInTheDocument();
|
212
|
-
expect(table).toHaveTextContent('Foo');
|
213
|
-
});
|
214
|
-
describe('when table is sortable', async () => {
|
215
|
-
const renderSortableTable = (props, handlers = {}, layout = 'auto') => render(_jsxs(Table, {
|
216
|
-
caption: "Sortable table",
|
217
|
-
layout: layout,
|
218
|
-
children: [_jsx(Table.Head, {
|
219
|
-
children: _jsxs(Table.Row, {
|
220
|
-
children: [_jsx(Table.ColHeader, {
|
221
|
-
id: "foo",
|
222
|
-
...props,
|
223
|
-
...handlers,
|
224
|
-
children: "Foo"
|
225
|
-
}), _jsx(Table.ColHeader, {
|
226
|
-
id: "bar",
|
227
|
-
...handlers,
|
228
|
-
children: "Bar"
|
229
|
-
})]
|
230
|
-
})
|
231
|
-
}), _Table$Body3 || (_Table$Body3 = _jsxs(Table.Body, {
|
232
|
-
children: [_jsx(Table.Row, {}), _jsx(Table.Row, {})]
|
233
|
-
}))]
|
234
|
-
}));
|
235
|
-
it('can render up arrow for ascending order', async () => {
|
236
|
-
const _renderSortableTable = renderSortableTable({
|
237
|
-
id: 'id',
|
238
|
-
sortDirection: 'ascending'
|
239
|
-
}),
|
240
|
-
container = _renderSortableTable.container;
|
241
|
-
const arrow = container.querySelector('svg');
|
242
|
-
expect(arrow).toHaveAttribute('name', 'IconMiniArrowUp');
|
243
|
-
});
|
244
|
-
it('can render down arrow for descending order', async () => {
|
245
|
-
const _renderSortableTable2 = renderSortableTable({
|
246
|
-
id: 'id',
|
247
|
-
sortDirection: 'descending'
|
248
|
-
}),
|
249
|
-
container = _renderSortableTable2.container;
|
250
|
-
const arrow = container.querySelector('svg');
|
251
|
-
expect(arrow).toHaveAttribute('name', 'IconMiniArrowDown');
|
252
|
-
});
|
253
|
-
it('calls onRequestSort when column header is clicked', async () => {
|
254
|
-
const onRequestSort = vi.fn();
|
255
|
-
renderSortableTable({
|
256
|
-
id: 'id'
|
257
|
-
}, {
|
258
|
-
onRequestSort
|
259
|
-
});
|
260
|
-
const button = screen.getByRole('button', {
|
261
|
-
name: 'Foo'
|
262
|
-
});
|
263
|
-
userEvent.click(button);
|
264
|
-
await waitFor(() => {
|
265
|
-
expect(onRequestSort).toHaveBeenCalledTimes(1);
|
266
|
-
});
|
267
|
-
});
|
268
|
-
it('can display custom label in the select in stacked layout', async () => {
|
269
|
-
renderSortableTable({
|
270
|
-
id: 'id',
|
271
|
-
stackedSortByLabel: 'Custom Text'
|
272
|
-
}, {
|
273
|
-
onRequestSort: vi.fn()
|
274
|
-
}, 'stacked');
|
275
|
-
const input = screen.getByRole('combobox');
|
276
|
-
userEvent.click(input);
|
277
|
-
await waitFor(async () => {
|
278
|
-
const options = screen.getAllByRole('option');
|
279
|
-
expect(options[0]).toHaveTextContent('Custom Text');
|
280
|
-
expect(options[1]).toHaveTextContent('bar');
|
281
|
-
});
|
282
|
-
});
|
283
|
-
it('can render check mark for sorted column in stacked layout', async () => {
|
284
|
-
const _renderSortableTable3 = renderSortableTable({
|
285
|
-
id: 'id',
|
286
|
-
sortDirection: 'ascending'
|
287
|
-
}, {
|
288
|
-
onRequestSort: vi.fn()
|
289
|
-
}, 'stacked'),
|
290
|
-
container = _renderSortableTable3.container;
|
291
|
-
const icon = container.querySelector('svg');
|
292
|
-
expect(icon).toHaveAttribute('name', 'IconCheck');
|
293
|
-
});
|
294
|
-
it('creates proper aria-sort attributes (ascending)', async () => {
|
295
|
-
renderSortableTable({
|
296
|
-
id: 'id',
|
297
|
-
sortDirection: 'ascending'
|
298
|
-
});
|
299
|
-
const header = screen.getByRole('columnheader', {
|
300
|
-
name: 'Foo'
|
301
|
-
});
|
302
|
-
expect(header).toHaveAttribute('aria-sort', 'ascending');
|
303
|
-
});
|
304
|
-
it('creates proper aria-sort attributes (descending)', async () => {
|
305
|
-
renderSortableTable({
|
306
|
-
id: 'id',
|
307
|
-
sortDirection: 'descending'
|
308
|
-
});
|
309
|
-
const header = screen.getByRole('columnheader', {
|
310
|
-
name: 'Foo'
|
311
|
-
});
|
312
|
-
expect(header).toHaveAttribute('aria-sort', 'descending');
|
313
|
-
});
|
314
|
-
});
|
315
|
-
describe('when using custom components', () => {
|
316
|
-
it('should render wrapper HOCs', () => {
|
317
|
-
var _CustomTableCell2;
|
318
|
-
class CustomTableCell extends Component {
|
319
|
-
render() {
|
320
|
-
return _jsx(Table.Cell, {
|
321
|
-
...this.props,
|
322
|
-
children: this.props.children
|
323
|
-
});
|
324
|
-
}
|
325
|
-
}
|
326
|
-
CustomTableCell.displayName = "CustomTableCell";
|
327
|
-
class CustomTableRow extends Component {
|
328
|
-
render() {
|
329
|
-
return _jsxs(Table.Row, {
|
330
|
-
...this.props,
|
331
|
-
children: [_Table$RowHeader || (_Table$RowHeader = _jsx(Table.RowHeader, {
|
332
|
-
children: "1"
|
333
|
-
})), _Table$Cell2 || (_Table$Cell2 = _jsx(Table.Cell, {
|
334
|
-
children: "The Shawshank Redemption"
|
335
|
-
})), _CustomTableCell2 || (_CustomTableCell2 = _jsx(CustomTableCell, {
|
336
|
-
children: "9.3"
|
337
|
-
}))]
|
338
|
-
});
|
339
|
-
}
|
340
|
-
}
|
341
|
-
CustomTableRow.displayName = "CustomTableRow";
|
342
|
-
const table = render(_jsxs(Table, {
|
343
|
-
caption: "Test custom table",
|
344
|
-
children: [_Table$Head2 || (_Table$Head2 = _jsx(Table.Head, {
|
345
|
-
children: _jsxs(Table.Row, {
|
346
|
-
children: [_jsx(Table.ColHeader, {
|
347
|
-
id: "foo",
|
348
|
-
children: "ColHeader"
|
349
|
-
}), _jsx(Table.ColHeader, {
|
350
|
-
id: "bar",
|
351
|
-
children: "Bar-header"
|
352
|
-
}), _jsx(Table.ColHeader, {
|
353
|
-
id: "baz",
|
354
|
-
children: "Bar-header"
|
355
|
-
})]
|
356
|
-
})
|
357
|
-
})), _jsxs(Table.Body, {
|
358
|
-
children: [_jsx(CustomTableRow, {}), _Table$Row3 || (_Table$Row3 = _jsxs(Table.Row, {
|
359
|
-
children: [_jsx(Table.RowHeader, {
|
360
|
-
children: "RowHeader"
|
361
|
-
}), _jsx(Table.Cell, {
|
362
|
-
children: "Cell"
|
363
|
-
}), _jsx(Table.Cell, {
|
364
|
-
children: "Cell2"
|
365
|
-
})]
|
366
|
-
}))]
|
367
|
-
})]
|
368
|
-
}));
|
369
|
-
const stackedTable = screen.getByRole('table');
|
370
|
-
expect(stackedTable).toBeInTheDocument();
|
371
|
-
const container = table.container;
|
372
|
-
expect(container).toBeInTheDocument();
|
373
|
-
expect(container).toHaveTextContent('The Shawshank Redemption');
|
374
|
-
expect(container).toHaveTextContent('9.3');
|
375
|
-
});
|
376
|
-
it('should render fully custom components', () => {
|
377
|
-
class CustomTableCell extends Component {
|
378
|
-
render() {
|
379
|
-
return _jsx("td", {
|
380
|
-
children: this.props.children
|
381
|
-
});
|
382
|
-
}
|
383
|
-
}
|
384
|
-
CustomTableCell.displayName = "CustomTableCell";
|
385
|
-
class CustomTableRow extends Component {
|
386
|
-
render() {
|
387
|
-
return _jsx("tr", {
|
388
|
-
children: this.props.children
|
389
|
-
});
|
390
|
-
}
|
391
|
-
}
|
392
|
-
CustomTableRow.displayName = "CustomTableRow";
|
393
|
-
const table = render(_jsxs(Table, {
|
394
|
-
caption: "Test custom table",
|
395
|
-
children: [_jsx(Table.Head, {
|
396
|
-
children: _jsxs(CustomTableRow, {
|
397
|
-
children: [_jsx(CustomTableCell, {
|
398
|
-
id: "foo",
|
399
|
-
children: "ColHeader"
|
400
|
-
}), _jsx(CustomTableCell, {
|
401
|
-
id: "bar",
|
402
|
-
children: "Bar-header"
|
403
|
-
}), _Table$ColHeader || (_Table$ColHeader = _jsx(Table.ColHeader, {
|
404
|
-
id: "baz",
|
405
|
-
children: "Bar-header"
|
406
|
-
}))]
|
407
|
-
})
|
408
|
-
}), _jsx(Table.Body, {
|
409
|
-
children: _jsxs(CustomTableRow, {
|
410
|
-
children: [_Table$RowHeader2 || (_Table$RowHeader2 = _jsx(Table.RowHeader, {
|
411
|
-
children: "RowHeader2"
|
412
|
-
})), _jsx(CustomTableCell, {
|
413
|
-
children: "Cell"
|
414
|
-
}), _Table$Cell3 || (_Table$Cell3 = _jsx(Table.Cell, {
|
415
|
-
children: "Cell2"
|
416
|
-
}))]
|
417
|
-
})
|
418
|
-
})]
|
419
|
-
}));
|
420
|
-
const stackedTable = screen.getByRole('table');
|
421
|
-
expect(stackedTable).toBeInTheDocument();
|
422
|
-
const container = table.container;
|
423
|
-
expect(container).toBeInTheDocument();
|
424
|
-
expect(container).toHaveTextContent('ColHeader');
|
425
|
-
expect(container).toHaveTextContent('Bar-header');
|
426
|
-
expect(container).toHaveTextContent('RowHeader2');
|
427
|
-
expect(container).toHaveTextContent('Cell');
|
428
|
-
expect(container).toHaveTextContent('Cell2');
|
429
|
-
});
|
430
|
-
});
|
431
|
-
});
|