@instructure/ui-table 9.5.0 → 9.5.1-snapshot-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 +8 -0
- package/es/Table/__new-tests__/Table.test.js +219 -0
- package/lib/Table/__new-tests__/Table.test.js +221 -0
- package/package.json +21 -16
- package/src/Table/__new-tests__/Table.test.tsx +293 -0
- package/tsconfig.build.json +1 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/__new-tests__/Table.test.d.ts +2 -0
- package/types/Table/__new-tests__/Table.test.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [9.5.1-snapshot-0](https://github.com/instructure/instructure-ui/compare/v9.5.0...v9.5.1-snapshot-0) (2024-07-26)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @instructure/ui-table
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
6
14
|
# [9.5.0](https://github.com/instructure/instructure-ui/compare/v9.3.0...v9.5.0) (2024-07-26)
|
7
15
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-table
|
@@ -0,0 +1,219 @@
|
|
1
|
+
var _Table$Head, _Table$Body, _Table, _Table2, _Table3, _Table$Body2;
|
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 React 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
|
+
describe('<Table />', async () => {
|
34
|
+
let consoleErrorMock;
|
35
|
+
beforeEach(() => {
|
36
|
+
// Mocking console to prevent test output pollution
|
37
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
38
|
+
});
|
39
|
+
afterEach(() => {
|
40
|
+
consoleErrorMock.mockRestore();
|
41
|
+
});
|
42
|
+
const renderTable = props => render( /*#__PURE__*/React.createElement(Table, Object.assign({
|
43
|
+
caption: "Test table"
|
44
|
+
}, props), _Table$Head || (_Table$Head = /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.ColHeader, {
|
45
|
+
id: "foo"
|
46
|
+
}, "ColHeader"), /*#__PURE__*/React.createElement(Table.ColHeader, {
|
47
|
+
id: "bar"
|
48
|
+
}, "Bar-header")))), _Table$Body || (_Table$Body = /*#__PURE__*/React.createElement(Table.Body, null, /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.RowHeader, null, "RowHeader"), /*#__PURE__*/React.createElement(Table.Cell, null, "Cell"))))));
|
49
|
+
it('should render a caption', async () => {
|
50
|
+
const _renderTable = renderTable(),
|
51
|
+
container = _renderTable.container;
|
52
|
+
const caption = container.querySelector('caption');
|
53
|
+
expect(caption).toBeInTheDocument();
|
54
|
+
expect(caption).toHaveTextContent('Test table');
|
55
|
+
});
|
56
|
+
it('should meet a11y standards', async () => {
|
57
|
+
const _renderTable2 = renderTable(),
|
58
|
+
container = _renderTable2.container;
|
59
|
+
const axeCheck = await runAxeCheck(container);
|
60
|
+
expect(axeCheck).toBe(true);
|
61
|
+
});
|
62
|
+
it('applies a fixed column layout', async () => {
|
63
|
+
await renderTable({
|
64
|
+
layout: 'fixed'
|
65
|
+
});
|
66
|
+
const table = screen.getByRole('table');
|
67
|
+
expect(table).toHaveStyle({
|
68
|
+
tableLayout: 'fixed'
|
69
|
+
});
|
70
|
+
});
|
71
|
+
it('passes hover to table row', async () => {
|
72
|
+
renderTable({
|
73
|
+
hover: true
|
74
|
+
});
|
75
|
+
const tableRows = screen.getAllByRole('row');
|
76
|
+
tableRows.forEach(tableRow => {
|
77
|
+
expect(tableRow).not.toHaveAttribute('border-left', 'none');
|
78
|
+
expect(tableRow).not.toHaveAttribute('border-right', 'none');
|
79
|
+
});
|
80
|
+
});
|
81
|
+
it('sets the scope of column header to col', async () => {
|
82
|
+
await renderTable();
|
83
|
+
const columnHeaders = screen.getAllByRole('columnheader');
|
84
|
+
columnHeaders.forEach(columnHeader => {
|
85
|
+
expect(columnHeader).toHaveAttribute('scope', 'col');
|
86
|
+
});
|
87
|
+
});
|
88
|
+
it('sets the scope of row header to row', async () => {
|
89
|
+
renderTable();
|
90
|
+
const rowHeaders = screen.getAllByRole('rowheader');
|
91
|
+
rowHeaders.forEach(rowHeader => {
|
92
|
+
expect(rowHeader).toHaveAttribute('scope', 'row');
|
93
|
+
});
|
94
|
+
});
|
95
|
+
it('can render table in stacked layout', async () => {
|
96
|
+
renderTable({
|
97
|
+
layout: 'stacked'
|
98
|
+
});
|
99
|
+
const stackedTable = screen.getByRole('table');
|
100
|
+
expect(stackedTable).toBeInTheDocument();
|
101
|
+
expect(stackedTable).toHaveTextContent('RowHeader');
|
102
|
+
expect(stackedTable).toHaveTextContent('Cell');
|
103
|
+
expect(stackedTable).not.toHaveTextContent('ColHeader');
|
104
|
+
});
|
105
|
+
it('can handle non-existent head in stacked layout', async () => {
|
106
|
+
render(_Table || (_Table = /*#__PURE__*/React.createElement(Table, {
|
107
|
+
caption: "Test table",
|
108
|
+
layout: "stacked"
|
109
|
+
}, /*#__PURE__*/React.createElement(Table.Body, null))));
|
110
|
+
const stackedTable = screen.getByRole('table');
|
111
|
+
expect(stackedTable).toBeInTheDocument();
|
112
|
+
});
|
113
|
+
it('can handle empty head in stacked layout', async () => {
|
114
|
+
render(_Table2 || (_Table2 = /*#__PURE__*/React.createElement(Table, {
|
115
|
+
caption: "Test table",
|
116
|
+
layout: "stacked"
|
117
|
+
}, /*#__PURE__*/React.createElement(Table.Head, null))));
|
118
|
+
const stackedTable = screen.getByRole('table');
|
119
|
+
expect(stackedTable).toBeInTheDocument();
|
120
|
+
});
|
121
|
+
it('can handle invalid header in stacked layout', async () => {
|
122
|
+
render(_Table3 || (_Table3 = /*#__PURE__*/React.createElement(Table, {
|
123
|
+
caption: "Test table",
|
124
|
+
layout: "stacked"
|
125
|
+
}, /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.Cell, null, "Foo"))))));
|
126
|
+
const stackedTable = screen.getByRole('table');
|
127
|
+
expect(stackedTable).toBeInTheDocument();
|
128
|
+
expect(stackedTable).not.toHaveTextContent('Foo');
|
129
|
+
});
|
130
|
+
describe('when table is sortable', async () => {
|
131
|
+
const renderSortableTable = (props, handlers = {}, layout = 'auto') => render( /*#__PURE__*/React.createElement(Table, {
|
132
|
+
caption: "Sortable table",
|
133
|
+
layout: layout
|
134
|
+
}, /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.ColHeader, Object.assign({
|
135
|
+
id: "foo"
|
136
|
+
}, props, handlers), "Foo"), /*#__PURE__*/React.createElement(Table.ColHeader, Object.assign({
|
137
|
+
id: "bar"
|
138
|
+
}, handlers), "Bar"))), _Table$Body2 || (_Table$Body2 = /*#__PURE__*/React.createElement(Table.Body, null, /*#__PURE__*/React.createElement(Table.Row, null), /*#__PURE__*/React.createElement(Table.Row, null)))));
|
139
|
+
it('can render up arrow for ascending order', async () => {
|
140
|
+
const _renderSortableTable = renderSortableTable({
|
141
|
+
id: 'id',
|
142
|
+
sortDirection: 'ascending'
|
143
|
+
}),
|
144
|
+
container = _renderSortableTable.container;
|
145
|
+
const arrow = container.querySelector('svg');
|
146
|
+
expect(arrow).toHaveAttribute('name', 'IconMiniArrowUp');
|
147
|
+
});
|
148
|
+
it('can render down arrow for descending order', async () => {
|
149
|
+
const _renderSortableTable2 = renderSortableTable({
|
150
|
+
id: 'id',
|
151
|
+
sortDirection: 'descending'
|
152
|
+
}),
|
153
|
+
container = _renderSortableTable2.container;
|
154
|
+
const arrow = container.querySelector('svg');
|
155
|
+
expect(arrow).toHaveAttribute('name', 'IconMiniArrowDown');
|
156
|
+
});
|
157
|
+
it('calls onRequestSort when column header is clicked', async () => {
|
158
|
+
const onRequestSort = vi.fn();
|
159
|
+
renderSortableTable({
|
160
|
+
id: 'id'
|
161
|
+
}, {
|
162
|
+
onRequestSort
|
163
|
+
});
|
164
|
+
const button = screen.getByRole('button', {
|
165
|
+
name: 'Foo'
|
166
|
+
});
|
167
|
+
userEvent.click(button);
|
168
|
+
await waitFor(() => {
|
169
|
+
expect(onRequestSort).toHaveBeenCalledTimes(1);
|
170
|
+
});
|
171
|
+
});
|
172
|
+
it('can display custom label in the select in stacked layout', async () => {
|
173
|
+
renderSortableTable({
|
174
|
+
id: 'id',
|
175
|
+
stackedSortByLabel: 'Custom Text'
|
176
|
+
}, {
|
177
|
+
onRequestSort: vi.fn()
|
178
|
+
}, 'stacked');
|
179
|
+
const input = screen.getByRole('combobox');
|
180
|
+
userEvent.click(input);
|
181
|
+
await waitFor(async () => {
|
182
|
+
const options = screen.getAllByRole('option');
|
183
|
+
expect(options[0]).toHaveTextContent('Custom Text');
|
184
|
+
expect(options[1]).toHaveTextContent('bar');
|
185
|
+
});
|
186
|
+
});
|
187
|
+
it('can render check mark for sorted column in stacked layout', async () => {
|
188
|
+
const _renderSortableTable3 = renderSortableTable({
|
189
|
+
id: 'id',
|
190
|
+
sortDirection: 'ascending'
|
191
|
+
}, {
|
192
|
+
onRequestSort: vi.fn()
|
193
|
+
}, 'stacked'),
|
194
|
+
container = _renderSortableTable3.container;
|
195
|
+
const icon = container.querySelector('svg');
|
196
|
+
expect(icon).toHaveAttribute('name', 'IconCheck');
|
197
|
+
});
|
198
|
+
it('creates proper aria-sort attributes (ascending)', async () => {
|
199
|
+
renderSortableTable({
|
200
|
+
id: 'id',
|
201
|
+
sortDirection: 'ascending'
|
202
|
+
});
|
203
|
+
const header = screen.getByRole('columnheader', {
|
204
|
+
name: 'Foo'
|
205
|
+
});
|
206
|
+
expect(header).toHaveAttribute('aria-sort', 'ascending');
|
207
|
+
});
|
208
|
+
it('creates proper aria-sort attributes (descending)', async () => {
|
209
|
+
renderSortableTable({
|
210
|
+
id: 'id',
|
211
|
+
sortDirection: 'descending'
|
212
|
+
});
|
213
|
+
const header = screen.getByRole('columnheader', {
|
214
|
+
name: 'Foo'
|
215
|
+
});
|
216
|
+
expect(header).toHaveAttribute('aria-sort', 'descending');
|
217
|
+
});
|
218
|
+
});
|
219
|
+
});
|
@@ -0,0 +1,221 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
5
|
+
var _react2 = require("@testing-library/react");
|
6
|
+
var _vitest = require("vitest");
|
7
|
+
var _userEvent = require("@testing-library/user-event");
|
8
|
+
require("@testing-library/jest-dom");
|
9
|
+
var _index = require("../index");
|
10
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
11
|
+
var _Table$Head, _Table$Body, _Table, _Table2, _Table3, _Table$Body2;
|
12
|
+
/*
|
13
|
+
* The MIT License (MIT)
|
14
|
+
*
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
16
|
+
*
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
22
|
+
* furnished to do so, subject to the following conditions:
|
23
|
+
*
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
25
|
+
* copies or substantial portions of the Software.
|
26
|
+
*
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
33
|
+
* SOFTWARE.
|
34
|
+
*/
|
35
|
+
describe('<Table />', async () => {
|
36
|
+
let consoleErrorMock;
|
37
|
+
beforeEach(() => {
|
38
|
+
// Mocking console to prevent test output pollution
|
39
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
40
|
+
});
|
41
|
+
afterEach(() => {
|
42
|
+
consoleErrorMock.mockRestore();
|
43
|
+
});
|
44
|
+
const renderTable = props => (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Table, Object.assign({
|
45
|
+
caption: "Test table"
|
46
|
+
}, props), _Table$Head || (_Table$Head = /*#__PURE__*/_react.default.createElement(_index.Table.Head, null, /*#__PURE__*/_react.default.createElement(_index.Table.Row, null, /*#__PURE__*/_react.default.createElement(_index.Table.ColHeader, {
|
47
|
+
id: "foo"
|
48
|
+
}, "ColHeader"), /*#__PURE__*/_react.default.createElement(_index.Table.ColHeader, {
|
49
|
+
id: "bar"
|
50
|
+
}, "Bar-header")))), _Table$Body || (_Table$Body = /*#__PURE__*/_react.default.createElement(_index.Table.Body, null, /*#__PURE__*/_react.default.createElement(_index.Table.Row, null, /*#__PURE__*/_react.default.createElement(_index.Table.RowHeader, null, "RowHeader"), /*#__PURE__*/_react.default.createElement(_index.Table.Cell, null, "Cell"))))));
|
51
|
+
it('should render a caption', async () => {
|
52
|
+
const _renderTable = renderTable(),
|
53
|
+
container = _renderTable.container;
|
54
|
+
const caption = container.querySelector('caption');
|
55
|
+
expect(caption).toBeInTheDocument();
|
56
|
+
expect(caption).toHaveTextContent('Test table');
|
57
|
+
});
|
58
|
+
it('should meet a11y standards', async () => {
|
59
|
+
const _renderTable2 = renderTable(),
|
60
|
+
container = _renderTable2.container;
|
61
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
62
|
+
expect(axeCheck).toBe(true);
|
63
|
+
});
|
64
|
+
it('applies a fixed column layout', async () => {
|
65
|
+
await renderTable({
|
66
|
+
layout: 'fixed'
|
67
|
+
});
|
68
|
+
const table = _react2.screen.getByRole('table');
|
69
|
+
expect(table).toHaveStyle({
|
70
|
+
tableLayout: 'fixed'
|
71
|
+
});
|
72
|
+
});
|
73
|
+
it('passes hover to table row', async () => {
|
74
|
+
renderTable({
|
75
|
+
hover: true
|
76
|
+
});
|
77
|
+
const tableRows = _react2.screen.getAllByRole('row');
|
78
|
+
tableRows.forEach(tableRow => {
|
79
|
+
expect(tableRow).not.toHaveAttribute('border-left', 'none');
|
80
|
+
expect(tableRow).not.toHaveAttribute('border-right', 'none');
|
81
|
+
});
|
82
|
+
});
|
83
|
+
it('sets the scope of column header to col', async () => {
|
84
|
+
await renderTable();
|
85
|
+
const columnHeaders = _react2.screen.getAllByRole('columnheader');
|
86
|
+
columnHeaders.forEach(columnHeader => {
|
87
|
+
expect(columnHeader).toHaveAttribute('scope', 'col');
|
88
|
+
});
|
89
|
+
});
|
90
|
+
it('sets the scope of row header to row', async () => {
|
91
|
+
renderTable();
|
92
|
+
const rowHeaders = _react2.screen.getAllByRole('rowheader');
|
93
|
+
rowHeaders.forEach(rowHeader => {
|
94
|
+
expect(rowHeader).toHaveAttribute('scope', 'row');
|
95
|
+
});
|
96
|
+
});
|
97
|
+
it('can render table in stacked layout', async () => {
|
98
|
+
renderTable({
|
99
|
+
layout: 'stacked'
|
100
|
+
});
|
101
|
+
const stackedTable = _react2.screen.getByRole('table');
|
102
|
+
expect(stackedTable).toBeInTheDocument();
|
103
|
+
expect(stackedTable).toHaveTextContent('RowHeader');
|
104
|
+
expect(stackedTable).toHaveTextContent('Cell');
|
105
|
+
expect(stackedTable).not.toHaveTextContent('ColHeader');
|
106
|
+
});
|
107
|
+
it('can handle non-existent head in stacked layout', async () => {
|
108
|
+
(0, _react2.render)(_Table || (_Table = /*#__PURE__*/_react.default.createElement(_index.Table, {
|
109
|
+
caption: "Test table",
|
110
|
+
layout: "stacked"
|
111
|
+
}, /*#__PURE__*/_react.default.createElement(_index.Table.Body, null))));
|
112
|
+
const stackedTable = _react2.screen.getByRole('table');
|
113
|
+
expect(stackedTable).toBeInTheDocument();
|
114
|
+
});
|
115
|
+
it('can handle empty head in stacked layout', async () => {
|
116
|
+
(0, _react2.render)(_Table2 || (_Table2 = /*#__PURE__*/_react.default.createElement(_index.Table, {
|
117
|
+
caption: "Test table",
|
118
|
+
layout: "stacked"
|
119
|
+
}, /*#__PURE__*/_react.default.createElement(_index.Table.Head, null))));
|
120
|
+
const stackedTable = _react2.screen.getByRole('table');
|
121
|
+
expect(stackedTable).toBeInTheDocument();
|
122
|
+
});
|
123
|
+
it('can handle invalid header in stacked layout', async () => {
|
124
|
+
(0, _react2.render)(_Table3 || (_Table3 = /*#__PURE__*/_react.default.createElement(_index.Table, {
|
125
|
+
caption: "Test table",
|
126
|
+
layout: "stacked"
|
127
|
+
}, /*#__PURE__*/_react.default.createElement(_index.Table.Head, null, /*#__PURE__*/_react.default.createElement(_index.Table.Row, null, /*#__PURE__*/_react.default.createElement(_index.Table.Cell, null, "Foo"))))));
|
128
|
+
const stackedTable = _react2.screen.getByRole('table');
|
129
|
+
expect(stackedTable).toBeInTheDocument();
|
130
|
+
expect(stackedTable).not.toHaveTextContent('Foo');
|
131
|
+
});
|
132
|
+
describe('when table is sortable', async () => {
|
133
|
+
const renderSortableTable = (props, handlers = {}, layout = 'auto') => (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Table, {
|
134
|
+
caption: "Sortable table",
|
135
|
+
layout: layout
|
136
|
+
}, /*#__PURE__*/_react.default.createElement(_index.Table.Head, null, /*#__PURE__*/_react.default.createElement(_index.Table.Row, null, /*#__PURE__*/_react.default.createElement(_index.Table.ColHeader, Object.assign({
|
137
|
+
id: "foo"
|
138
|
+
}, props, handlers), "Foo"), /*#__PURE__*/_react.default.createElement(_index.Table.ColHeader, Object.assign({
|
139
|
+
id: "bar"
|
140
|
+
}, handlers), "Bar"))), _Table$Body2 || (_Table$Body2 = /*#__PURE__*/_react.default.createElement(_index.Table.Body, null, /*#__PURE__*/_react.default.createElement(_index.Table.Row, null), /*#__PURE__*/_react.default.createElement(_index.Table.Row, null)))));
|
141
|
+
it('can render up arrow for ascending order', async () => {
|
142
|
+
const _renderSortableTable = renderSortableTable({
|
143
|
+
id: 'id',
|
144
|
+
sortDirection: 'ascending'
|
145
|
+
}),
|
146
|
+
container = _renderSortableTable.container;
|
147
|
+
const arrow = container.querySelector('svg');
|
148
|
+
expect(arrow).toHaveAttribute('name', 'IconMiniArrowUp');
|
149
|
+
});
|
150
|
+
it('can render down arrow for descending order', async () => {
|
151
|
+
const _renderSortableTable2 = renderSortableTable({
|
152
|
+
id: 'id',
|
153
|
+
sortDirection: 'descending'
|
154
|
+
}),
|
155
|
+
container = _renderSortableTable2.container;
|
156
|
+
const arrow = container.querySelector('svg');
|
157
|
+
expect(arrow).toHaveAttribute('name', 'IconMiniArrowDown');
|
158
|
+
});
|
159
|
+
it('calls onRequestSort when column header is clicked', async () => {
|
160
|
+
const onRequestSort = _vitest.vi.fn();
|
161
|
+
renderSortableTable({
|
162
|
+
id: 'id'
|
163
|
+
}, {
|
164
|
+
onRequestSort
|
165
|
+
});
|
166
|
+
const button = _react2.screen.getByRole('button', {
|
167
|
+
name: 'Foo'
|
168
|
+
});
|
169
|
+
_userEvent.userEvent.click(button);
|
170
|
+
await (0, _react2.waitFor)(() => {
|
171
|
+
expect(onRequestSort).toHaveBeenCalledTimes(1);
|
172
|
+
});
|
173
|
+
});
|
174
|
+
it('can display custom label in the select in stacked layout', async () => {
|
175
|
+
renderSortableTable({
|
176
|
+
id: 'id',
|
177
|
+
stackedSortByLabel: 'Custom Text'
|
178
|
+
}, {
|
179
|
+
onRequestSort: _vitest.vi.fn()
|
180
|
+
}, 'stacked');
|
181
|
+
const input = _react2.screen.getByRole('combobox');
|
182
|
+
_userEvent.userEvent.click(input);
|
183
|
+
await (0, _react2.waitFor)(async () => {
|
184
|
+
const options = _react2.screen.getAllByRole('option');
|
185
|
+
expect(options[0]).toHaveTextContent('Custom Text');
|
186
|
+
expect(options[1]).toHaveTextContent('bar');
|
187
|
+
});
|
188
|
+
});
|
189
|
+
it('can render check mark for sorted column in stacked layout', async () => {
|
190
|
+
const _renderSortableTable3 = renderSortableTable({
|
191
|
+
id: 'id',
|
192
|
+
sortDirection: 'ascending'
|
193
|
+
}, {
|
194
|
+
onRequestSort: _vitest.vi.fn()
|
195
|
+
}, 'stacked'),
|
196
|
+
container = _renderSortableTable3.container;
|
197
|
+
const icon = container.querySelector('svg');
|
198
|
+
expect(icon).toHaveAttribute('name', 'IconCheck');
|
199
|
+
});
|
200
|
+
it('creates proper aria-sort attributes (ascending)', async () => {
|
201
|
+
renderSortableTable({
|
202
|
+
id: 'id',
|
203
|
+
sortDirection: 'ascending'
|
204
|
+
});
|
205
|
+
const header = _react2.screen.getByRole('columnheader', {
|
206
|
+
name: 'Foo'
|
207
|
+
});
|
208
|
+
expect(header).toHaveAttribute('aria-sort', 'ascending');
|
209
|
+
});
|
210
|
+
it('creates proper aria-sort attributes (descending)', async () => {
|
211
|
+
renderSortableTable({
|
212
|
+
id: 'id',
|
213
|
+
sortDirection: 'descending'
|
214
|
+
});
|
215
|
+
const header = _react2.screen.getByRole('columnheader', {
|
216
|
+
name: 'Foo'
|
217
|
+
});
|
218
|
+
expect(header).toHaveAttribute('aria-sort', 'descending');
|
219
|
+
});
|
220
|
+
});
|
221
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-table",
|
3
|
-
"version": "9.5.0",
|
3
|
+
"version": "9.5.1-snapshot-0",
|
4
4
|
"description": "A styled HTML table component",
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
6
6
|
"module": "./es/index.js",
|
@@ -23,24 +23,29 @@
|
|
23
23
|
},
|
24
24
|
"license": "MIT",
|
25
25
|
"devDependencies": {
|
26
|
-
"@instructure/ui-
|
27
|
-
"@instructure/ui-
|
28
|
-
"@instructure/ui-
|
29
|
-
"@instructure/ui-
|
26
|
+
"@instructure/ui-axe-check": "9.5.1-snapshot-0",
|
27
|
+
"@instructure/ui-babel-preset": "9.5.1-snapshot-0",
|
28
|
+
"@instructure/ui-color-utils": "9.5.1-snapshot-0",
|
29
|
+
"@instructure/ui-test-utils": "9.5.1-snapshot-0",
|
30
|
+
"@instructure/ui-themes": "9.5.1-snapshot-0",
|
31
|
+
"@testing-library/jest-dom": "^6.4.6",
|
32
|
+
"@testing-library/react": "^15.0.7",
|
33
|
+
"@testing-library/user-event": "^14.5.2",
|
34
|
+
"vitest": "^2.0.2"
|
30
35
|
},
|
31
36
|
"dependencies": {
|
32
37
|
"@babel/runtime": "^7.24.5",
|
33
|
-
"@instructure/console": "9.5.0",
|
34
|
-
"@instructure/emotion": "9.5.0",
|
35
|
-
"@instructure/shared-types": "9.5.0",
|
36
|
-
"@instructure/ui-a11y-content": "9.5.0",
|
37
|
-
"@instructure/ui-icons": "9.5.0",
|
38
|
-
"@instructure/ui-prop-types": "9.5.0",
|
39
|
-
"@instructure/ui-react-utils": "9.5.0",
|
40
|
-
"@instructure/ui-simple-select": "9.5.0",
|
41
|
-
"@instructure/ui-testable": "9.5.0",
|
42
|
-
"@instructure/ui-utils": "9.5.0",
|
43
|
-
"@instructure/ui-view": "9.5.0",
|
38
|
+
"@instructure/console": "9.5.1-snapshot-0",
|
39
|
+
"@instructure/emotion": "9.5.1-snapshot-0",
|
40
|
+
"@instructure/shared-types": "9.5.1-snapshot-0",
|
41
|
+
"@instructure/ui-a11y-content": "9.5.1-snapshot-0",
|
42
|
+
"@instructure/ui-icons": "9.5.1-snapshot-0",
|
43
|
+
"@instructure/ui-prop-types": "9.5.1-snapshot-0",
|
44
|
+
"@instructure/ui-react-utils": "9.5.1-snapshot-0",
|
45
|
+
"@instructure/ui-simple-select": "9.5.1-snapshot-0",
|
46
|
+
"@instructure/ui-testable": "9.5.1-snapshot-0",
|
47
|
+
"@instructure/ui-utils": "9.5.1-snapshot-0",
|
48
|
+
"@instructure/ui-view": "9.5.1-snapshot-0",
|
44
49
|
"prop-types": "^15.8.1"
|
45
50
|
},
|
46
51
|
"peerDependencies": {
|