@instructure/ui-simple-select 10.19.2-snapshot-3 → 10.19.2-snapshot-4
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 +15 -15
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/SimpleSelect/__new-tests__/SimpleSelect.test.js +0 -344
- package/lib/SimpleSelect/__new-tests__/SimpleSelect.test.js +0 -345
- package/src/SimpleSelect/__new-tests__/SimpleSelect.test.tsx +0 -410
- package/types/SimpleSelect/__new-tests__/SimpleSelect.test.d.ts +0 -2
- package/types/SimpleSelect/__new-tests__/SimpleSelect.test.d.ts.map +0 -1
@@ -1,344 +0,0 @@
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
-
var _SimpleSelect, _SimpleSelect2, _SimpleSelect3, _SimpleSelect4, _SimpleSelect5, _SimpleSelect6, _IconCheckSolid;
|
3
|
-
/*
|
4
|
-
* The MIT License (MIT)
|
5
|
-
*
|
6
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
7
|
-
*
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
13
|
-
* furnished to do so, subject to the following conditions:
|
14
|
-
*
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
16
|
-
* copies or substantial portions of the Software.
|
17
|
-
*
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
-
* SOFTWARE.
|
25
|
-
*/
|
26
|
-
|
27
|
-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
28
|
-
import { vi, it } from 'vitest';
|
29
|
-
import userEvent from '@testing-library/user-event';
|
30
|
-
import '@testing-library/jest-dom';
|
31
|
-
|
32
|
-
// eslint-disable-next-line no-restricted-imports
|
33
|
-
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
34
|
-
import { IconCheckSolid } from '@instructure/ui-icons';
|
35
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
36
|
-
import SimpleSelectExamples from '../__examples__/SimpleSelect.examples';
|
37
|
-
import SimpleSelect from '../index';
|
38
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
39
|
-
const defaultOptions = ['foo', 'bar', 'baz'];
|
40
|
-
const getOptions = disabled => defaultOptions.map(opt => _jsx(SimpleSelect.Option, {
|
41
|
-
id: opt,
|
42
|
-
value: opt,
|
43
|
-
isDisabled: opt === disabled,
|
44
|
-
children: opt
|
45
|
-
}, opt));
|
46
|
-
describe('<SimpleSelect />', () => {
|
47
|
-
let consoleErrorMock;
|
48
|
-
beforeEach(() => {
|
49
|
-
// Mocking console to prevent test output pollution and expect for messages
|
50
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
51
|
-
});
|
52
|
-
afterEach(() => {
|
53
|
-
consoleErrorMock.mockRestore();
|
54
|
-
});
|
55
|
-
it('should render an input and a list', async () => {
|
56
|
-
render(_jsx(SimpleSelect, {
|
57
|
-
renderLabel: "Choose an option",
|
58
|
-
children: getOptions()
|
59
|
-
}));
|
60
|
-
const input = screen.getByLabelText('Choose an option');
|
61
|
-
const listInitial = screen.queryByRole('listbox');
|
62
|
-
expect(listInitial).not.toBeInTheDocument();
|
63
|
-
expect(input).toBeInTheDocument();
|
64
|
-
await userEvent.click(input);
|
65
|
-
await waitFor(() => {
|
66
|
-
const list = screen.queryByRole('listbox');
|
67
|
-
expect(list).toBeInTheDocument();
|
68
|
-
});
|
69
|
-
});
|
70
|
-
it('should render groups', async () => {
|
71
|
-
render(_SimpleSelect || (_SimpleSelect = _jsxs(SimpleSelect, {
|
72
|
-
renderLabel: "Choose an option",
|
73
|
-
children: [_jsx(SimpleSelect.Option, {
|
74
|
-
id: "0",
|
75
|
-
value: "0",
|
76
|
-
children: "ungrouped option one"
|
77
|
-
}), _jsx(SimpleSelect.Group, {
|
78
|
-
renderLabel: "Group one",
|
79
|
-
children: _jsx(SimpleSelect.Option, {
|
80
|
-
id: "1",
|
81
|
-
value: "1",
|
82
|
-
children: "grouped option one"
|
83
|
-
})
|
84
|
-
}), _jsx(SimpleSelect.Group, {
|
85
|
-
renderLabel: "Group two",
|
86
|
-
children: _jsx(SimpleSelect.Option, {
|
87
|
-
id: "2",
|
88
|
-
value: "2",
|
89
|
-
children: "grouped option two"
|
90
|
-
})
|
91
|
-
}), _jsx(SimpleSelect.Option, {
|
92
|
-
id: "3",
|
93
|
-
value: "3",
|
94
|
-
children: "ungrouped option two"
|
95
|
-
})]
|
96
|
-
})));
|
97
|
-
const input = screen.getByLabelText('Choose an option');
|
98
|
-
await userEvent.click(input);
|
99
|
-
await waitFor(() => {
|
100
|
-
const groups = screen.getAllByRole('group');
|
101
|
-
const labelOne = screen.getByText('Group one');
|
102
|
-
const labelOneID = labelOne.getAttribute('id');
|
103
|
-
expect(groups.length).toBe(2);
|
104
|
-
expect(groups[0]).toHaveAttribute('aria-labelledby', labelOneID);
|
105
|
-
expect(labelOne).toHaveAttribute('role', 'presentation');
|
106
|
-
});
|
107
|
-
});
|
108
|
-
it('should ignore invalid children', async () => {
|
109
|
-
render(_SimpleSelect2 || (_SimpleSelect2 = _jsxs(SimpleSelect, {
|
110
|
-
renderLabel: "Choose an option",
|
111
|
-
children: [_jsx(SimpleSelect.Option, {
|
112
|
-
id: "0",
|
113
|
-
value: 0,
|
114
|
-
children: "valid"
|
115
|
-
}), _jsx("div", {
|
116
|
-
children: "invalid"
|
117
|
-
})]
|
118
|
-
})));
|
119
|
-
const input = screen.getByLabelText('Choose an option');
|
120
|
-
await userEvent.click(input);
|
121
|
-
await waitFor(() => {
|
122
|
-
const invalidChild = screen.queryByText('invalid');
|
123
|
-
expect(invalidChild).not.toBeInTheDocument();
|
124
|
-
expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining('Expected one of Group, Option'), expect.any(String));
|
125
|
-
});
|
126
|
-
});
|
127
|
-
it('should fire onFocus when input gains focus', async () => {
|
128
|
-
const onFocus = vi.fn();
|
129
|
-
render(_jsx(SimpleSelect, {
|
130
|
-
renderLabel: "Choose an option",
|
131
|
-
onFocus: onFocus,
|
132
|
-
children: getOptions()
|
133
|
-
}));
|
134
|
-
const input = screen.getByLabelText('Choose an option');
|
135
|
-
input.focus();
|
136
|
-
await waitFor(() => {
|
137
|
-
expect(onFocus).toHaveBeenCalled();
|
138
|
-
});
|
139
|
-
});
|
140
|
-
describe('input', () => {
|
141
|
-
it('should render with a custom id if given', async () => {
|
142
|
-
render(_SimpleSelect3 || (_SimpleSelect3 = _jsx(SimpleSelect, {
|
143
|
-
renderLabel: "Choose an option",
|
144
|
-
id: "customSelect"
|
145
|
-
})));
|
146
|
-
const input = screen.getByLabelText('Choose an option');
|
147
|
-
expect(input).toHaveAttribute('id', 'customSelect');
|
148
|
-
});
|
149
|
-
it('should always render readonly', async () => {
|
150
|
-
render(_SimpleSelect4 || (_SimpleSelect4 = _jsx(SimpleSelect, {
|
151
|
-
renderLabel: "Choose an option",
|
152
|
-
interaction: "enabled"
|
153
|
-
})));
|
154
|
-
const input = screen.getByLabelText('Choose an option');
|
155
|
-
expect(input).toHaveAttribute('readonly');
|
156
|
-
expect(input).not.toHaveAttribute('disabled');
|
157
|
-
});
|
158
|
-
it('should render disabled when interaction="disabled"', async () => {
|
159
|
-
render(_SimpleSelect5 || (_SimpleSelect5 = _jsx(SimpleSelect, {
|
160
|
-
renderLabel: "Choose an option",
|
161
|
-
interaction: "disabled"
|
162
|
-
})));
|
163
|
-
const input = screen.getByLabelText('Choose an option');
|
164
|
-
expect(input).toHaveAttribute('disabled');
|
165
|
-
expect(input).not.toHaveAttribute('readonly');
|
166
|
-
});
|
167
|
-
it('should render required when isRequired={true}', async () => {
|
168
|
-
render(_SimpleSelect6 || (_SimpleSelect6 = _jsx(SimpleSelect, {
|
169
|
-
renderLabel: "Choose an option",
|
170
|
-
isRequired: true
|
171
|
-
})));
|
172
|
-
const input = screen.getByLabelText('Choose an option *');
|
173
|
-
expect(input).toHaveAttribute('required');
|
174
|
-
});
|
175
|
-
it('should allow assistive text', async () => {
|
176
|
-
render(_jsx(SimpleSelect, {
|
177
|
-
renderLabel: "Choose an option",
|
178
|
-
assistiveText: "hello world",
|
179
|
-
children: getOptions()
|
180
|
-
}));
|
181
|
-
const input = screen.getByLabelText('Choose an option');
|
182
|
-
const assistiveText = screen.getByText('hello world');
|
183
|
-
const assistiveTextID = assistiveText.getAttribute('id');
|
184
|
-
expect(input).toHaveAttribute('aria-describedby', assistiveTextID);
|
185
|
-
});
|
186
|
-
it('should allow custom props to pass through', async () => {
|
187
|
-
render(_jsx(SimpleSelect, {
|
188
|
-
renderLabel: "Choose an option",
|
189
|
-
"data-custom-attr": "true",
|
190
|
-
children: getOptions()
|
191
|
-
}));
|
192
|
-
const input = screen.getByLabelText('Choose an option');
|
193
|
-
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
194
|
-
});
|
195
|
-
it('should provide a ref to the input element', async () => {
|
196
|
-
const inputRef = vi.fn();
|
197
|
-
render(_jsx(SimpleSelect, {
|
198
|
-
renderLabel: "Choose an option",
|
199
|
-
inputRef: inputRef,
|
200
|
-
children: getOptions()
|
201
|
-
}));
|
202
|
-
const input = screen.getByLabelText('Choose an option');
|
203
|
-
expect(inputRef).toHaveBeenCalledWith(input);
|
204
|
-
});
|
205
|
-
});
|
206
|
-
it('should render icons before option and call renderBeforeLabel callback with necessary props', async () => {
|
207
|
-
const renderBeforeLabel = vi.fn(() => _IconCheckSolid || (_IconCheckSolid = _jsx(IconCheckSolid, {
|
208
|
-
"data-testid": "option-icon"
|
209
|
-
})));
|
210
|
-
render(_jsxs(SimpleSelect, {
|
211
|
-
renderLabel: "Choose an option",
|
212
|
-
children: [_jsx(SimpleSelect.Option, {
|
213
|
-
id: "option-1",
|
214
|
-
value: "1",
|
215
|
-
isDisabled: true,
|
216
|
-
renderBeforeLabel: renderBeforeLabel,
|
217
|
-
children: "option one"
|
218
|
-
}), _jsx(SimpleSelect.Option, {
|
219
|
-
id: "option-2",
|
220
|
-
value: "2",
|
221
|
-
renderBeforeLabel: renderBeforeLabel,
|
222
|
-
children: "option two"
|
223
|
-
})]
|
224
|
-
}));
|
225
|
-
const input = screen.getByLabelText('Choose an option');
|
226
|
-
await userEvent.click(input);
|
227
|
-
await waitFor(() => {
|
228
|
-
const optionIcons = screen.getAllByTestId('option-icon');
|
229
|
-
expect(optionIcons.length).toBe(2);
|
230
|
-
expect(renderBeforeLabel).toHaveBeenCalledTimes(2);
|
231
|
-
const _ref = renderBeforeLabel.mock.calls,
|
232
|
-
_ref2 = _slicedToArray(_ref, 2),
|
233
|
-
_ref2$ = _slicedToArray(_ref2[0], 1),
|
234
|
-
argsOption1 = _ref2$[0],
|
235
|
-
_ref2$2 = _slicedToArray(_ref2[1], 1),
|
236
|
-
argsOption2 = _ref2$2[0];
|
237
|
-
expect(argsOption1).toMatchObject({
|
238
|
-
id: 'option-1',
|
239
|
-
isDisabled: true,
|
240
|
-
isSelected: true,
|
241
|
-
isHighlighted: true,
|
242
|
-
children: 'option one'
|
243
|
-
});
|
244
|
-
expect(argsOption2).toMatchObject({
|
245
|
-
id: 'option-2',
|
246
|
-
isDisabled: false,
|
247
|
-
isSelected: false,
|
248
|
-
isHighlighted: false,
|
249
|
-
children: 'option two'
|
250
|
-
});
|
251
|
-
});
|
252
|
-
});
|
253
|
-
describe('list', () => {
|
254
|
-
it('should set aria-disabled on options when isDisabled={true}', async () => {
|
255
|
-
render(_jsx(SimpleSelect, {
|
256
|
-
renderLabel: "Choose an option",
|
257
|
-
children: getOptions(defaultOptions[2])
|
258
|
-
}));
|
259
|
-
const input = screen.getByLabelText('Choose an option');
|
260
|
-
await userEvent.click(input);
|
261
|
-
await waitFor(() => {
|
262
|
-
const options = screen.getAllByRole('option');
|
263
|
-
expect(options[0]).not.toHaveAttribute('aria-disabled');
|
264
|
-
expect(options[2]).toHaveAttribute('aria-disabled', 'true');
|
265
|
-
});
|
266
|
-
});
|
267
|
-
it('should provide a ref to the list element', async () => {
|
268
|
-
const listRef = vi.fn();
|
269
|
-
render(_jsx(SimpleSelect, {
|
270
|
-
renderLabel: "Choose an option",
|
271
|
-
listRef: listRef,
|
272
|
-
children: getOptions()
|
273
|
-
}));
|
274
|
-
const input = screen.getByLabelText('Choose an option');
|
275
|
-
await userEvent.click(input);
|
276
|
-
await waitFor(() => {
|
277
|
-
const listbox = screen.getByRole('listbox');
|
278
|
-
expect(listRef).toHaveBeenCalledWith(listbox);
|
279
|
-
});
|
280
|
-
});
|
281
|
-
});
|
282
|
-
describe('with generated examples', () => {
|
283
|
-
const generatedComponents = generateA11yTests(SimpleSelect, SimpleSelectExamples);
|
284
|
-
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
285
|
-
content
|
286
|
-
}) => {
|
287
|
-
const _render = render(content),
|
288
|
-
container = _render.container;
|
289
|
-
const axeCheck = await runAxeCheck(container);
|
290
|
-
expect(axeCheck).toBe(true);
|
291
|
-
});
|
292
|
-
});
|
293
|
-
describe('children', () => {
|
294
|
-
const initialOptions = ['foo', 'bar'];
|
295
|
-
const updatedOptions = ['bar', 'baz'];
|
296
|
-
const getOptions = options => options.map(opt => _jsx(SimpleSelect.Option, {
|
297
|
-
id: opt,
|
298
|
-
value: opt,
|
299
|
-
children: opt
|
300
|
-
}, opt));
|
301
|
-
const renderSimpleSelect = options => {
|
302
|
-
return render(_jsx(SimpleSelect, {
|
303
|
-
renderLabel: "Choose an option",
|
304
|
-
children: getOptions(options)
|
305
|
-
}));
|
306
|
-
};
|
307
|
-
it('should clear selection if selected option does not exist in updated options', () => {
|
308
|
-
const _renderSimpleSelect = renderSimpleSelect(initialOptions),
|
309
|
-
rerender = _renderSimpleSelect.rerender;
|
310
|
-
const input = screen.getByRole('combobox', {
|
311
|
-
name: 'Choose an option'
|
312
|
-
});
|
313
|
-
fireEvent.click(input);
|
314
|
-
const fooOption = screen.getByRole('option', {
|
315
|
-
name: 'foo'
|
316
|
-
});
|
317
|
-
fireEvent.click(fooOption);
|
318
|
-
expect(input).toHaveValue('foo');
|
319
|
-
rerender(_jsx(SimpleSelect, {
|
320
|
-
renderLabel: "Choose an option",
|
321
|
-
children: getOptions(updatedOptions)
|
322
|
-
}));
|
323
|
-
expect(input).toHaveValue('');
|
324
|
-
});
|
325
|
-
it('should persist selected option if it exists in updated options', () => {
|
326
|
-
const _renderSimpleSelect2 = renderSimpleSelect(initialOptions),
|
327
|
-
rerender = _renderSimpleSelect2.rerender;
|
328
|
-
const input = screen.getByRole('combobox', {
|
329
|
-
name: 'Choose an option'
|
330
|
-
});
|
331
|
-
fireEvent.click(input);
|
332
|
-
const barOption = screen.getByRole('option', {
|
333
|
-
name: 'bar'
|
334
|
-
});
|
335
|
-
fireEvent.click(barOption);
|
336
|
-
expect(input).toHaveValue('bar');
|
337
|
-
rerender(_jsx(SimpleSelect, {
|
338
|
-
renderLabel: "Choose an option",
|
339
|
-
children: getOptions(updatedOptions)
|
340
|
-
}));
|
341
|
-
expect(input).toHaveValue('bar');
|
342
|
-
});
|
343
|
-
});
|
344
|
-
});
|
@@ -1,345 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
5
|
-
var _react = require("@testing-library/react");
|
6
|
-
var _vitest = require("vitest");
|
7
|
-
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
8
|
-
require("@testing-library/jest-dom");
|
9
|
-
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
10
|
-
var _IconCheckSolid2 = require("@instructure/ui-icons/lib/IconCheckSolid.js");
|
11
|
-
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
12
|
-
var _SimpleSelect7 = _interopRequireDefault(require("../__examples__/SimpleSelect.examples"));
|
13
|
-
var _index = _interopRequireDefault(require("../index"));
|
14
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
15
|
-
var _SimpleSelect, _SimpleSelect2, _SimpleSelect3, _SimpleSelect4, _SimpleSelect5, _SimpleSelect6, _IconCheckSolid;
|
16
|
-
/*
|
17
|
-
* The MIT License (MIT)
|
18
|
-
*
|
19
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
20
|
-
*
|
21
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
22
|
-
* of this software and associated documentation files (the "Software"), to deal
|
23
|
-
* in the Software without restriction, including without limitation the rights
|
24
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
25
|
-
* copies of the Software, and to permit persons to whom the Software is
|
26
|
-
* furnished to do so, subject to the following conditions:
|
27
|
-
*
|
28
|
-
* The above copyright notice and this permission notice shall be included in all
|
29
|
-
* copies or substantial portions of the Software.
|
30
|
-
*
|
31
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
32
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
33
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
34
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
35
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
36
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
37
|
-
* SOFTWARE.
|
38
|
-
*/
|
39
|
-
// eslint-disable-next-line no-restricted-imports
|
40
|
-
const defaultOptions = ['foo', 'bar', 'baz'];
|
41
|
-
const getOptions = disabled => defaultOptions.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
42
|
-
id: opt,
|
43
|
-
value: opt,
|
44
|
-
isDisabled: opt === disabled,
|
45
|
-
children: opt
|
46
|
-
}, opt));
|
47
|
-
describe('<SimpleSelect />', () => {
|
48
|
-
let consoleErrorMock;
|
49
|
-
beforeEach(() => {
|
50
|
-
// Mocking console to prevent test output pollution and expect for messages
|
51
|
-
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
52
|
-
});
|
53
|
-
afterEach(() => {
|
54
|
-
consoleErrorMock.mockRestore();
|
55
|
-
});
|
56
|
-
(0, _vitest.it)('should render an input and a list', async () => {
|
57
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
58
|
-
renderLabel: "Choose an option",
|
59
|
-
children: getOptions()
|
60
|
-
}));
|
61
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
62
|
-
const listInitial = _react.screen.queryByRole('listbox');
|
63
|
-
expect(listInitial).not.toBeInTheDocument();
|
64
|
-
expect(input).toBeInTheDocument();
|
65
|
-
await _userEvent.default.click(input);
|
66
|
-
await (0, _react.waitFor)(() => {
|
67
|
-
const list = _react.screen.queryByRole('listbox');
|
68
|
-
expect(list).toBeInTheDocument();
|
69
|
-
});
|
70
|
-
});
|
71
|
-
(0, _vitest.it)('should render groups', async () => {
|
72
|
-
(0, _react.render)(_SimpleSelect || (_SimpleSelect = (0, _jsxRuntime.jsxs)(_index.default, {
|
73
|
-
renderLabel: "Choose an option",
|
74
|
-
children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
|
75
|
-
id: "0",
|
76
|
-
value: "0",
|
77
|
-
children: "ungrouped option one"
|
78
|
-
}), (0, _jsxRuntime.jsx)(_index.default.Group, {
|
79
|
-
renderLabel: "Group one",
|
80
|
-
children: (0, _jsxRuntime.jsx)(_index.default.Option, {
|
81
|
-
id: "1",
|
82
|
-
value: "1",
|
83
|
-
children: "grouped option one"
|
84
|
-
})
|
85
|
-
}), (0, _jsxRuntime.jsx)(_index.default.Group, {
|
86
|
-
renderLabel: "Group two",
|
87
|
-
children: (0, _jsxRuntime.jsx)(_index.default.Option, {
|
88
|
-
id: "2",
|
89
|
-
value: "2",
|
90
|
-
children: "grouped option two"
|
91
|
-
})
|
92
|
-
}), (0, _jsxRuntime.jsx)(_index.default.Option, {
|
93
|
-
id: "3",
|
94
|
-
value: "3",
|
95
|
-
children: "ungrouped option two"
|
96
|
-
})]
|
97
|
-
})));
|
98
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
99
|
-
await _userEvent.default.click(input);
|
100
|
-
await (0, _react.waitFor)(() => {
|
101
|
-
const groups = _react.screen.getAllByRole('group');
|
102
|
-
const labelOne = _react.screen.getByText('Group one');
|
103
|
-
const labelOneID = labelOne.getAttribute('id');
|
104
|
-
expect(groups.length).toBe(2);
|
105
|
-
expect(groups[0]).toHaveAttribute('aria-labelledby', labelOneID);
|
106
|
-
expect(labelOne).toHaveAttribute('role', 'presentation');
|
107
|
-
});
|
108
|
-
});
|
109
|
-
(0, _vitest.it)('should ignore invalid children', async () => {
|
110
|
-
(0, _react.render)(_SimpleSelect2 || (_SimpleSelect2 = (0, _jsxRuntime.jsxs)(_index.default, {
|
111
|
-
renderLabel: "Choose an option",
|
112
|
-
children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
|
113
|
-
id: "0",
|
114
|
-
value: 0,
|
115
|
-
children: "valid"
|
116
|
-
}), (0, _jsxRuntime.jsx)("div", {
|
117
|
-
children: "invalid"
|
118
|
-
})]
|
119
|
-
})));
|
120
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
121
|
-
await _userEvent.default.click(input);
|
122
|
-
await (0, _react.waitFor)(() => {
|
123
|
-
const invalidChild = _react.screen.queryByText('invalid');
|
124
|
-
expect(invalidChild).not.toBeInTheDocument();
|
125
|
-
expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining('Expected one of Group, Option'), expect.any(String));
|
126
|
-
});
|
127
|
-
});
|
128
|
-
(0, _vitest.it)('should fire onFocus when input gains focus', async () => {
|
129
|
-
const onFocus = _vitest.vi.fn();
|
130
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
131
|
-
renderLabel: "Choose an option",
|
132
|
-
onFocus: onFocus,
|
133
|
-
children: getOptions()
|
134
|
-
}));
|
135
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
136
|
-
input.focus();
|
137
|
-
await (0, _react.waitFor)(() => {
|
138
|
-
expect(onFocus).toHaveBeenCalled();
|
139
|
-
});
|
140
|
-
});
|
141
|
-
describe('input', () => {
|
142
|
-
(0, _vitest.it)('should render with a custom id if given', async () => {
|
143
|
-
(0, _react.render)(_SimpleSelect3 || (_SimpleSelect3 = (0, _jsxRuntime.jsx)(_index.default, {
|
144
|
-
renderLabel: "Choose an option",
|
145
|
-
id: "customSelect"
|
146
|
-
})));
|
147
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
148
|
-
expect(input).toHaveAttribute('id', 'customSelect');
|
149
|
-
});
|
150
|
-
(0, _vitest.it)('should always render readonly', async () => {
|
151
|
-
(0, _react.render)(_SimpleSelect4 || (_SimpleSelect4 = (0, _jsxRuntime.jsx)(_index.default, {
|
152
|
-
renderLabel: "Choose an option",
|
153
|
-
interaction: "enabled"
|
154
|
-
})));
|
155
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
156
|
-
expect(input).toHaveAttribute('readonly');
|
157
|
-
expect(input).not.toHaveAttribute('disabled');
|
158
|
-
});
|
159
|
-
(0, _vitest.it)('should render disabled when interaction="disabled"', async () => {
|
160
|
-
(0, _react.render)(_SimpleSelect5 || (_SimpleSelect5 = (0, _jsxRuntime.jsx)(_index.default, {
|
161
|
-
renderLabel: "Choose an option",
|
162
|
-
interaction: "disabled"
|
163
|
-
})));
|
164
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
165
|
-
expect(input).toHaveAttribute('disabled');
|
166
|
-
expect(input).not.toHaveAttribute('readonly');
|
167
|
-
});
|
168
|
-
(0, _vitest.it)('should render required when isRequired={true}', async () => {
|
169
|
-
(0, _react.render)(_SimpleSelect6 || (_SimpleSelect6 = (0, _jsxRuntime.jsx)(_index.default, {
|
170
|
-
renderLabel: "Choose an option",
|
171
|
-
isRequired: true
|
172
|
-
})));
|
173
|
-
const input = _react.screen.getByLabelText('Choose an option *');
|
174
|
-
expect(input).toHaveAttribute('required');
|
175
|
-
});
|
176
|
-
(0, _vitest.it)('should allow assistive text', async () => {
|
177
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
178
|
-
renderLabel: "Choose an option",
|
179
|
-
assistiveText: "hello world",
|
180
|
-
children: getOptions()
|
181
|
-
}));
|
182
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
183
|
-
const assistiveText = _react.screen.getByText('hello world');
|
184
|
-
const assistiveTextID = assistiveText.getAttribute('id');
|
185
|
-
expect(input).toHaveAttribute('aria-describedby', assistiveTextID);
|
186
|
-
});
|
187
|
-
(0, _vitest.it)('should allow custom props to pass through', async () => {
|
188
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
189
|
-
renderLabel: "Choose an option",
|
190
|
-
"data-custom-attr": "true",
|
191
|
-
children: getOptions()
|
192
|
-
}));
|
193
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
194
|
-
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
195
|
-
});
|
196
|
-
(0, _vitest.it)('should provide a ref to the input element', async () => {
|
197
|
-
const inputRef = _vitest.vi.fn();
|
198
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
199
|
-
renderLabel: "Choose an option",
|
200
|
-
inputRef: inputRef,
|
201
|
-
children: getOptions()
|
202
|
-
}));
|
203
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
204
|
-
expect(inputRef).toHaveBeenCalledWith(input);
|
205
|
-
});
|
206
|
-
});
|
207
|
-
(0, _vitest.it)('should render icons before option and call renderBeforeLabel callback with necessary props', async () => {
|
208
|
-
const renderBeforeLabel = _vitest.vi.fn(() => _IconCheckSolid || (_IconCheckSolid = (0, _jsxRuntime.jsx)(_IconCheckSolid2.IconCheckSolid, {
|
209
|
-
"data-testid": "option-icon"
|
210
|
-
})));
|
211
|
-
(0, _react.render)((0, _jsxRuntime.jsxs)(_index.default, {
|
212
|
-
renderLabel: "Choose an option",
|
213
|
-
children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
|
214
|
-
id: "option-1",
|
215
|
-
value: "1",
|
216
|
-
isDisabled: true,
|
217
|
-
renderBeforeLabel: renderBeforeLabel,
|
218
|
-
children: "option one"
|
219
|
-
}), (0, _jsxRuntime.jsx)(_index.default.Option, {
|
220
|
-
id: "option-2",
|
221
|
-
value: "2",
|
222
|
-
renderBeforeLabel: renderBeforeLabel,
|
223
|
-
children: "option two"
|
224
|
-
})]
|
225
|
-
}));
|
226
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
227
|
-
await _userEvent.default.click(input);
|
228
|
-
await (0, _react.waitFor)(() => {
|
229
|
-
const optionIcons = _react.screen.getAllByTestId('option-icon');
|
230
|
-
expect(optionIcons.length).toBe(2);
|
231
|
-
expect(renderBeforeLabel).toHaveBeenCalledTimes(2);
|
232
|
-
const _ref = renderBeforeLabel.mock.calls,
|
233
|
-
_ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
234
|
-
_ref2$ = (0, _slicedToArray2.default)(_ref2[0], 1),
|
235
|
-
argsOption1 = _ref2$[0],
|
236
|
-
_ref2$2 = (0, _slicedToArray2.default)(_ref2[1], 1),
|
237
|
-
argsOption2 = _ref2$2[0];
|
238
|
-
expect(argsOption1).toMatchObject({
|
239
|
-
id: 'option-1',
|
240
|
-
isDisabled: true,
|
241
|
-
isSelected: true,
|
242
|
-
isHighlighted: true,
|
243
|
-
children: 'option one'
|
244
|
-
});
|
245
|
-
expect(argsOption2).toMatchObject({
|
246
|
-
id: 'option-2',
|
247
|
-
isDisabled: false,
|
248
|
-
isSelected: false,
|
249
|
-
isHighlighted: false,
|
250
|
-
children: 'option two'
|
251
|
-
});
|
252
|
-
});
|
253
|
-
});
|
254
|
-
describe('list', () => {
|
255
|
-
(0, _vitest.it)('should set aria-disabled on options when isDisabled={true}', async () => {
|
256
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
257
|
-
renderLabel: "Choose an option",
|
258
|
-
children: getOptions(defaultOptions[2])
|
259
|
-
}));
|
260
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
261
|
-
await _userEvent.default.click(input);
|
262
|
-
await (0, _react.waitFor)(() => {
|
263
|
-
const options = _react.screen.getAllByRole('option');
|
264
|
-
expect(options[0]).not.toHaveAttribute('aria-disabled');
|
265
|
-
expect(options[2]).toHaveAttribute('aria-disabled', 'true');
|
266
|
-
});
|
267
|
-
});
|
268
|
-
(0, _vitest.it)('should provide a ref to the list element', async () => {
|
269
|
-
const listRef = _vitest.vi.fn();
|
270
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
271
|
-
renderLabel: "Choose an option",
|
272
|
-
listRef: listRef,
|
273
|
-
children: getOptions()
|
274
|
-
}));
|
275
|
-
const input = _react.screen.getByLabelText('Choose an option');
|
276
|
-
await _userEvent.default.click(input);
|
277
|
-
await (0, _react.waitFor)(() => {
|
278
|
-
const listbox = _react.screen.getByRole('listbox');
|
279
|
-
expect(listRef).toHaveBeenCalledWith(listbox);
|
280
|
-
});
|
281
|
-
});
|
282
|
-
});
|
283
|
-
describe('with generated examples', () => {
|
284
|
-
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.default, _SimpleSelect7.default);
|
285
|
-
_vitest.it.each(generatedComponents)('should be accessible with example: $description', async ({
|
286
|
-
content
|
287
|
-
}) => {
|
288
|
-
const _render = (0, _react.render)(content),
|
289
|
-
container = _render.container;
|
290
|
-
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
291
|
-
expect(axeCheck).toBe(true);
|
292
|
-
});
|
293
|
-
});
|
294
|
-
describe('children', () => {
|
295
|
-
const initialOptions = ['foo', 'bar'];
|
296
|
-
const updatedOptions = ['bar', 'baz'];
|
297
|
-
const getOptions = options => options.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
298
|
-
id: opt,
|
299
|
-
value: opt,
|
300
|
-
children: opt
|
301
|
-
}, opt));
|
302
|
-
const renderSimpleSelect = options => {
|
303
|
-
return (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
304
|
-
renderLabel: "Choose an option",
|
305
|
-
children: getOptions(options)
|
306
|
-
}));
|
307
|
-
};
|
308
|
-
(0, _vitest.it)('should clear selection if selected option does not exist in updated options', () => {
|
309
|
-
const _renderSimpleSelect = renderSimpleSelect(initialOptions),
|
310
|
-
rerender = _renderSimpleSelect.rerender;
|
311
|
-
const input = _react.screen.getByRole('combobox', {
|
312
|
-
name: 'Choose an option'
|
313
|
-
});
|
314
|
-
_react.fireEvent.click(input);
|
315
|
-
const fooOption = _react.screen.getByRole('option', {
|
316
|
-
name: 'foo'
|
317
|
-
});
|
318
|
-
_react.fireEvent.click(fooOption);
|
319
|
-
expect(input).toHaveValue('foo');
|
320
|
-
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
321
|
-
renderLabel: "Choose an option",
|
322
|
-
children: getOptions(updatedOptions)
|
323
|
-
}));
|
324
|
-
expect(input).toHaveValue('');
|
325
|
-
});
|
326
|
-
(0, _vitest.it)('should persist selected option if it exists in updated options', () => {
|
327
|
-
const _renderSimpleSelect2 = renderSimpleSelect(initialOptions),
|
328
|
-
rerender = _renderSimpleSelect2.rerender;
|
329
|
-
const input = _react.screen.getByRole('combobox', {
|
330
|
-
name: 'Choose an option'
|
331
|
-
});
|
332
|
-
_react.fireEvent.click(input);
|
333
|
-
const barOption = _react.screen.getByRole('option', {
|
334
|
-
name: 'bar'
|
335
|
-
});
|
336
|
-
_react.fireEvent.click(barOption);
|
337
|
-
expect(input).toHaveValue('bar');
|
338
|
-
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
339
|
-
renderLabel: "Choose an option",
|
340
|
-
children: getOptions(updatedOptions)
|
341
|
-
}));
|
342
|
-
expect(input).toHaveValue('bar');
|
343
|
-
});
|
344
|
-
});
|
345
|
-
});
|