@instructure/ui-simple-select 10.3.1-snapshot-8 → 10.3.1-snapshot-9
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/es/SimpleSelect/__new-tests__/SimpleSelect.test.js +241 -36
- package/lib/SimpleSelect/__new-tests__/SimpleSelect.test.js +240 -38
- package/package.json +16 -15
- package/src/SimpleSelect/__new-tests__/SimpleSelect.test.tsx +312 -38
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/SimpleSelect/__new-tests__/SimpleSelect.test.d.ts.map +1 -1
- package/es/SimpleSelect/SimpleSelectLocator.js +0 -38
- package/es/SimpleSelect/locator.js +0 -26
- package/lib/SimpleSelect/SimpleSelectLocator.js +0 -44
- package/lib/SimpleSelect/locator.js +0 -37
- package/src/SimpleSelect/SimpleSelectLocator.ts +0 -39
- package/src/SimpleSelect/locator.ts +0 -27
- package/types/SimpleSelect/SimpleSelectLocator.d.ts +0 -325
- package/types/SimpleSelect/SimpleSelectLocator.d.ts.map +0 -1
- package/types/SimpleSelect/locator.d.ts +0 -4
- package/types/SimpleSelect/locator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@
|
|
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
|
-
## [10.3.1-snapshot-
|
6
|
+
## [10.3.1-snapshot-9](https://github.com/instructure/instructure-ui/compare/v10.3.0...v10.3.1-snapshot-9) (2024-10-11)
|
7
7
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-simple-select
|
9
9
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
var _SimpleSelect, _SimpleSelect2, _SimpleSelect3, _SimpleSelect4, _SimpleSelect5, _SimpleSelect6, _IconCheckSolid;
|
1
3
|
/*
|
2
4
|
* The MIT License (MIT)
|
3
5
|
*
|
@@ -22,46 +24,249 @@
|
|
22
24
|
* SOFTWARE.
|
23
25
|
*/
|
24
26
|
import React from 'react';
|
25
|
-
import {
|
26
|
-
import { vi } from 'vitest';
|
27
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
28
|
+
import { vi, it } from 'vitest';
|
29
|
+
import userEvent from '@testing-library/user-event';
|
27
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';
|
28
37
|
import SimpleSelect from '../index';
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
};
|
37
|
-
});
|
38
|
-
const mockUtils = utils;
|
38
|
+
const defaultOptions = ['foo', 'bar', 'baz'];
|
39
|
+
const getOptions = disabled => defaultOptions.map(opt => /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
40
|
+
id: opt,
|
41
|
+
key: opt,
|
42
|
+
value: opt,
|
43
|
+
isDisabled: opt === disabled
|
44
|
+
}, opt));
|
39
45
|
describe('<SimpleSelect />', () => {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
let consoleErrorMock;
|
47
|
+
beforeEach(() => {
|
48
|
+
// Mocking console to prevent test output pollution and expect for messages
|
49
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
50
|
+
});
|
51
|
+
afterEach(() => {
|
52
|
+
consoleErrorMock.mockRestore();
|
53
|
+
});
|
54
|
+
it('should render an input and a list', async () => {
|
55
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
56
|
+
renderLabel: "Choose an option"
|
57
|
+
}, getOptions()));
|
58
|
+
const input = screen.getByLabelText('Choose an option');
|
59
|
+
const listInitial = screen.queryByRole('listbox');
|
60
|
+
expect(listInitial).not.toBeInTheDocument();
|
61
|
+
expect(input).toBeInTheDocument();
|
62
|
+
await userEvent.click(input);
|
63
|
+
await waitFor(() => {
|
64
|
+
const list = screen.queryByRole('listbox');
|
65
|
+
expect(list).toBeInTheDocument();
|
66
|
+
});
|
67
|
+
});
|
68
|
+
it('should render groups', async () => {
|
69
|
+
render(_SimpleSelect || (_SimpleSelect = /*#__PURE__*/React.createElement(SimpleSelect, {
|
70
|
+
renderLabel: "Choose an option"
|
71
|
+
}, /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
72
|
+
id: "0",
|
73
|
+
value: "0"
|
74
|
+
}, "ungrouped option one"), /*#__PURE__*/React.createElement(SimpleSelect.Group, {
|
75
|
+
renderLabel: "Group one"
|
76
|
+
}, /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
77
|
+
id: "1",
|
78
|
+
value: "1"
|
79
|
+
}, "grouped option one")), /*#__PURE__*/React.createElement(SimpleSelect.Group, {
|
80
|
+
renderLabel: "Group two"
|
81
|
+
}, /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
82
|
+
id: "2",
|
83
|
+
value: "2"
|
84
|
+
}, "grouped option two")), /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
85
|
+
id: "3",
|
86
|
+
value: "3"
|
87
|
+
}, "ungrouped option two"))));
|
88
|
+
const input = screen.getByLabelText('Choose an option');
|
89
|
+
await userEvent.click(input);
|
90
|
+
await waitFor(() => {
|
91
|
+
const groups = screen.getAllByRole('group');
|
92
|
+
const labelOne = screen.getByText('Group one');
|
93
|
+
const labelOneID = labelOne.getAttribute('id');
|
94
|
+
expect(groups.length).toBe(2);
|
95
|
+
expect(groups[0]).toHaveAttribute('aria-labelledby', labelOneID);
|
96
|
+
expect(labelOne).toHaveAttribute('role', 'presentation');
|
97
|
+
});
|
98
|
+
});
|
99
|
+
it('should ignore invalid children', async () => {
|
100
|
+
render(_SimpleSelect2 || (_SimpleSelect2 = /*#__PURE__*/React.createElement(SimpleSelect, {
|
101
|
+
renderLabel: "Choose an option"
|
102
|
+
}, /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
103
|
+
id: "0",
|
104
|
+
value: 0
|
105
|
+
}, "valid"), /*#__PURE__*/React.createElement("div", null, "invalid"))));
|
106
|
+
const input = screen.getByLabelText('Choose an option');
|
107
|
+
await userEvent.click(input);
|
108
|
+
await waitFor(() => {
|
109
|
+
const invalidChild = screen.queryByText('invalid');
|
110
|
+
expect(invalidChild).not.toBeInTheDocument();
|
111
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining('Expected one of Group, Option'), expect.any(String));
|
112
|
+
});
|
113
|
+
});
|
114
|
+
it('should fire onFocus when input gains focus', async () => {
|
115
|
+
const onFocus = vi.fn();
|
116
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
117
|
+
renderLabel: "Choose an option",
|
118
|
+
onFocus: onFocus
|
119
|
+
}, getOptions()));
|
120
|
+
const input = screen.getByLabelText('Choose an option');
|
121
|
+
input.focus();
|
122
|
+
await waitFor(() => {
|
123
|
+
expect(onFocus).toHaveBeenCalled();
|
124
|
+
});
|
125
|
+
});
|
126
|
+
describe('input', () => {
|
127
|
+
it('should render with a custom id if given', async () => {
|
128
|
+
render(_SimpleSelect3 || (_SimpleSelect3 = /*#__PURE__*/React.createElement(SimpleSelect, {
|
129
|
+
renderLabel: "Choose an option",
|
130
|
+
id: "customSelect"
|
131
|
+
})));
|
132
|
+
const input = screen.getByLabelText('Choose an option');
|
133
|
+
expect(input).toHaveAttribute('id', 'customSelect');
|
134
|
+
});
|
135
|
+
it('should always render readonly', async () => {
|
136
|
+
render(_SimpleSelect4 || (_SimpleSelect4 = /*#__PURE__*/React.createElement(SimpleSelect, {
|
137
|
+
renderLabel: "Choose an option",
|
138
|
+
interaction: "enabled"
|
139
|
+
})));
|
140
|
+
const input = screen.getByLabelText('Choose an option');
|
141
|
+
expect(input).toHaveAttribute('readonly');
|
142
|
+
expect(input).not.toHaveAttribute('disabled');
|
143
|
+
});
|
144
|
+
it('should render disabled when interaction="disabled"', async () => {
|
145
|
+
render(_SimpleSelect5 || (_SimpleSelect5 = /*#__PURE__*/React.createElement(SimpleSelect, {
|
146
|
+
renderLabel: "Choose an option",
|
147
|
+
interaction: "disabled"
|
148
|
+
})));
|
149
|
+
const input = screen.getByLabelText('Choose an option');
|
150
|
+
expect(input).toHaveAttribute('disabled');
|
151
|
+
expect(input).not.toHaveAttribute('readonly');
|
152
|
+
});
|
153
|
+
it('should render required when isRequired={true}', async () => {
|
154
|
+
render(_SimpleSelect6 || (_SimpleSelect6 = /*#__PURE__*/React.createElement(SimpleSelect, {
|
155
|
+
renderLabel: "Choose an option",
|
156
|
+
isRequired: true
|
157
|
+
})));
|
158
|
+
const input = screen.getByLabelText('Choose an option');
|
159
|
+
expect(input).toHaveAttribute('required');
|
160
|
+
});
|
161
|
+
it('should allow assistive text', async () => {
|
162
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
163
|
+
renderLabel: "Choose an option",
|
164
|
+
assistiveText: "hello world"
|
165
|
+
}, getOptions()));
|
166
|
+
const input = screen.getByLabelText('Choose an option');
|
167
|
+
const assistiveText = screen.getByText('hello world');
|
168
|
+
const assistiveTextID = assistiveText.getAttribute('id');
|
169
|
+
expect(input).toHaveAttribute('aria-describedby', assistiveTextID);
|
170
|
+
});
|
171
|
+
it('should allow custom props to pass through', async () => {
|
172
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
173
|
+
renderLabel: "Choose an option",
|
174
|
+
"data-custom-attr": "true"
|
175
|
+
}, getOptions()));
|
176
|
+
const input = screen.getByLabelText('Choose an option');
|
177
|
+
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
178
|
+
});
|
179
|
+
it('should provide a ref to the input element', async () => {
|
180
|
+
const inputRef = vi.fn();
|
181
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
182
|
+
renderLabel: "Choose an option",
|
183
|
+
inputRef: inputRef
|
184
|
+
}, getOptions()));
|
185
|
+
const input = screen.getByLabelText('Choose an option');
|
186
|
+
expect(inputRef).toHaveBeenCalledWith(input);
|
187
|
+
});
|
188
|
+
});
|
189
|
+
it('should render icons before option and call renderBeforeLabel callback with necessary props', async () => {
|
190
|
+
const renderBeforeLabel = vi.fn(() => _IconCheckSolid || (_IconCheckSolid = /*#__PURE__*/React.createElement(IconCheckSolid, {
|
191
|
+
"data-testid": "option-icon"
|
192
|
+
})));
|
193
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
194
|
+
renderLabel: "Choose an option"
|
195
|
+
}, /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
196
|
+
id: "option-1",
|
197
|
+
value: "1",
|
198
|
+
isDisabled: true,
|
199
|
+
renderBeforeLabel: renderBeforeLabel
|
200
|
+
}, "option one"), /*#__PURE__*/React.createElement(SimpleSelect.Option, {
|
201
|
+
id: "option-2",
|
202
|
+
value: "2",
|
203
|
+
renderBeforeLabel: renderBeforeLabel
|
204
|
+
}, "option two")));
|
205
|
+
const input = screen.getByLabelText('Choose an option');
|
206
|
+
await userEvent.click(input);
|
207
|
+
await waitFor(() => {
|
208
|
+
const optionIcons = screen.getAllByTestId('option-icon');
|
209
|
+
expect(optionIcons.length).toBe(2);
|
210
|
+
expect(renderBeforeLabel).toHaveBeenCalledTimes(2);
|
211
|
+
const _ref = renderBeforeLabel.mock.calls,
|
212
|
+
_ref2 = _slicedToArray(_ref, 2),
|
213
|
+
_ref2$ = _slicedToArray(_ref2[0], 1),
|
214
|
+
argsOption1 = _ref2$[0],
|
215
|
+
_ref2$2 = _slicedToArray(_ref2[1], 1),
|
216
|
+
argsOption2 = _ref2$2[0];
|
217
|
+
expect(argsOption1).toMatchObject({
|
218
|
+
id: 'option-1',
|
219
|
+
isDisabled: true,
|
220
|
+
isSelected: true,
|
221
|
+
isHighlighted: true,
|
222
|
+
children: 'option one'
|
223
|
+
});
|
224
|
+
expect(argsOption2).toMatchObject({
|
225
|
+
id: 'option-2',
|
226
|
+
isDisabled: false,
|
227
|
+
isSelected: false,
|
228
|
+
isHighlighted: false,
|
229
|
+
children: 'option two'
|
230
|
+
});
|
231
|
+
});
|
232
|
+
});
|
233
|
+
describe('list', () => {
|
234
|
+
it('should set aria-disabled on options when isDisabled={true}', async () => {
|
235
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
60
236
|
renderLabel: "Choose an option"
|
61
|
-
}, getOptions()))
|
62
|
-
|
63
|
-
|
64
|
-
|
237
|
+
}, getOptions(defaultOptions[2])));
|
238
|
+
const input = screen.getByLabelText('Choose an option');
|
239
|
+
await userEvent.click(input);
|
240
|
+
await waitFor(() => {
|
241
|
+
const options = screen.getAllByRole('option');
|
242
|
+
expect(options[0]).not.toHaveAttribute('aria-disabled');
|
243
|
+
expect(options[2]).toHaveAttribute('aria-disabled', 'true');
|
244
|
+
});
|
245
|
+
});
|
246
|
+
it('should provide a ref to the list element', async () => {
|
247
|
+
const listRef = vi.fn();
|
248
|
+
render(/*#__PURE__*/React.createElement(SimpleSelect, {
|
249
|
+
renderLabel: "Choose an option",
|
250
|
+
listRef: listRef
|
251
|
+
}, getOptions()));
|
252
|
+
const input = screen.getByLabelText('Choose an option');
|
253
|
+
await userEvent.click(input);
|
254
|
+
await waitFor(() => {
|
255
|
+
const listbox = screen.getByRole('listbox');
|
256
|
+
expect(listRef).toHaveBeenCalledWith(listbox);
|
257
|
+
});
|
258
|
+
});
|
259
|
+
});
|
260
|
+
describe('with generated examples', () => {
|
261
|
+
const generatedComponents = generateA11yTests(SimpleSelect, SimpleSelectExamples);
|
262
|
+
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
263
|
+
content
|
264
|
+
}) => {
|
265
|
+
const _render = render(content),
|
266
|
+
container = _render.container;
|
267
|
+
const axeCheck = await runAxeCheck(container);
|
268
|
+
expect(axeCheck).toBe(true);
|
269
|
+
});
|
65
270
|
});
|
66
271
|
describe('children', () => {
|
67
272
|
const initialOptions = ['foo', 'bar'];
|
@@ -1,13 +1,18 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
5
5
|
var _react = _interopRequireDefault(require("react"));
|
6
6
|
var _react2 = require("@testing-library/react");
|
7
7
|
var _vitest = require("vitest");
|
8
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
8
9
|
require("@testing-library/jest-dom");
|
10
|
+
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
11
|
+
var _IconCheckSolid2 = require("@instructure/ui-icons/lib/IconCheckSolid.js");
|
12
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
13
|
+
var _SimpleSelect7 = _interopRequireDefault(require("../__examples__/SimpleSelect.examples"));
|
9
14
|
var _index = _interopRequireDefault(require("../index"));
|
10
|
-
var
|
15
|
+
var _SimpleSelect, _SimpleSelect2, _SimpleSelect3, _SimpleSelect4, _SimpleSelect5, _SimpleSelect6, _IconCheckSolid;
|
11
16
|
/*
|
12
17
|
* The MIT License (MIT)
|
13
18
|
*
|
@@ -31,42 +36,239 @@ var utils = _interopRequireWildcard(require("@instructure/ui-utils"));
|
|
31
36
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
32
37
|
* SOFTWARE.
|
33
38
|
*/
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
});
|
43
|
-
const mockUtils = utils;
|
39
|
+
// eslint-disable-next-line no-restricted-imports
|
40
|
+
const defaultOptions = ['foo', 'bar', 'baz'];
|
41
|
+
const getOptions = disabled => defaultOptions.map(opt => /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
42
|
+
id: opt,
|
43
|
+
key: opt,
|
44
|
+
value: opt,
|
45
|
+
isDisabled: opt === disabled
|
46
|
+
}, opt));
|
44
47
|
describe('<SimpleSelect />', () => {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
58
|
+
renderLabel: "Choose an option"
|
59
|
+
}, getOptions()));
|
60
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
61
|
+
const listInitial = _react2.screen.queryByRole('listbox');
|
62
|
+
expect(listInitial).not.toBeInTheDocument();
|
63
|
+
expect(input).toBeInTheDocument();
|
64
|
+
await _userEvent.default.click(input);
|
65
|
+
await (0, _react2.waitFor)(() => {
|
66
|
+
const list = _react2.screen.queryByRole('listbox');
|
67
|
+
expect(list).toBeInTheDocument();
|
68
|
+
});
|
69
|
+
});
|
70
|
+
(0, _vitest.it)('should render groups', async () => {
|
71
|
+
(0, _react2.render)(_SimpleSelect || (_SimpleSelect = /*#__PURE__*/_react.default.createElement(_index.default, {
|
72
|
+
renderLabel: "Choose an option"
|
73
|
+
}, /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
74
|
+
id: "0",
|
75
|
+
value: "0"
|
76
|
+
}, "ungrouped option one"), /*#__PURE__*/_react.default.createElement(_index.default.Group, {
|
77
|
+
renderLabel: "Group one"
|
78
|
+
}, /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
79
|
+
id: "1",
|
80
|
+
value: "1"
|
81
|
+
}, "grouped option one")), /*#__PURE__*/_react.default.createElement(_index.default.Group, {
|
82
|
+
renderLabel: "Group two"
|
83
|
+
}, /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
84
|
+
id: "2",
|
85
|
+
value: "2"
|
86
|
+
}, "grouped option two")), /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
87
|
+
id: "3",
|
88
|
+
value: "3"
|
89
|
+
}, "ungrouped option two"))));
|
90
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
91
|
+
await _userEvent.default.click(input);
|
92
|
+
await (0, _react2.waitFor)(() => {
|
93
|
+
const groups = _react2.screen.getAllByRole('group');
|
94
|
+
const labelOne = _react2.screen.getByText('Group one');
|
95
|
+
const labelOneID = labelOne.getAttribute('id');
|
96
|
+
expect(groups.length).toBe(2);
|
97
|
+
expect(groups[0]).toHaveAttribute('aria-labelledby', labelOneID);
|
98
|
+
expect(labelOne).toHaveAttribute('role', 'presentation');
|
99
|
+
});
|
100
|
+
});
|
101
|
+
(0, _vitest.it)('should ignore invalid children', async () => {
|
102
|
+
(0, _react2.render)(_SimpleSelect2 || (_SimpleSelect2 = /*#__PURE__*/_react.default.createElement(_index.default, {
|
103
|
+
renderLabel: "Choose an option"
|
104
|
+
}, /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
105
|
+
id: "0",
|
106
|
+
value: 0
|
107
|
+
}, "valid"), /*#__PURE__*/_react.default.createElement("div", null, "invalid"))));
|
108
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
109
|
+
await _userEvent.default.click(input);
|
110
|
+
await (0, _react2.waitFor)(() => {
|
111
|
+
const invalidChild = _react2.screen.queryByText('invalid');
|
112
|
+
expect(invalidChild).not.toBeInTheDocument();
|
113
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining('Expected one of Group, Option'), expect.any(String));
|
114
|
+
});
|
115
|
+
});
|
116
|
+
(0, _vitest.it)('should fire onFocus when input gains focus', async () => {
|
117
|
+
const onFocus = _vitest.vi.fn();
|
118
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
119
|
+
renderLabel: "Choose an option",
|
120
|
+
onFocus: onFocus
|
121
|
+
}, getOptions()));
|
122
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
123
|
+
input.focus();
|
124
|
+
await (0, _react2.waitFor)(() => {
|
125
|
+
expect(onFocus).toHaveBeenCalled();
|
126
|
+
});
|
127
|
+
});
|
128
|
+
describe('input', () => {
|
129
|
+
(0, _vitest.it)('should render with a custom id if given', async () => {
|
130
|
+
(0, _react2.render)(_SimpleSelect3 || (_SimpleSelect3 = /*#__PURE__*/_react.default.createElement(_index.default, {
|
131
|
+
renderLabel: "Choose an option",
|
132
|
+
id: "customSelect"
|
133
|
+
})));
|
134
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
135
|
+
expect(input).toHaveAttribute('id', 'customSelect');
|
136
|
+
});
|
137
|
+
(0, _vitest.it)('should always render readonly', async () => {
|
138
|
+
(0, _react2.render)(_SimpleSelect4 || (_SimpleSelect4 = /*#__PURE__*/_react.default.createElement(_index.default, {
|
139
|
+
renderLabel: "Choose an option",
|
140
|
+
interaction: "enabled"
|
141
|
+
})));
|
142
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
143
|
+
expect(input).toHaveAttribute('readonly');
|
144
|
+
expect(input).not.toHaveAttribute('disabled');
|
145
|
+
});
|
146
|
+
(0, _vitest.it)('should render disabled when interaction="disabled"', async () => {
|
147
|
+
(0, _react2.render)(_SimpleSelect5 || (_SimpleSelect5 = /*#__PURE__*/_react.default.createElement(_index.default, {
|
148
|
+
renderLabel: "Choose an option",
|
149
|
+
interaction: "disabled"
|
150
|
+
})));
|
151
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
152
|
+
expect(input).toHaveAttribute('disabled');
|
153
|
+
expect(input).not.toHaveAttribute('readonly');
|
154
|
+
});
|
155
|
+
(0, _vitest.it)('should render required when isRequired={true}', async () => {
|
156
|
+
(0, _react2.render)(_SimpleSelect6 || (_SimpleSelect6 = /*#__PURE__*/_react.default.createElement(_index.default, {
|
157
|
+
renderLabel: "Choose an option",
|
158
|
+
isRequired: true
|
159
|
+
})));
|
160
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
161
|
+
expect(input).toHaveAttribute('required');
|
162
|
+
});
|
163
|
+
(0, _vitest.it)('should allow assistive text', async () => {
|
164
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
165
|
+
renderLabel: "Choose an option",
|
166
|
+
assistiveText: "hello world"
|
167
|
+
}, getOptions()));
|
168
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
169
|
+
const assistiveText = _react2.screen.getByText('hello world');
|
170
|
+
const assistiveTextID = assistiveText.getAttribute('id');
|
171
|
+
expect(input).toHaveAttribute('aria-describedby', assistiveTextID);
|
172
|
+
});
|
173
|
+
(0, _vitest.it)('should allow custom props to pass through', async () => {
|
174
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
175
|
+
renderLabel: "Choose an option",
|
176
|
+
"data-custom-attr": "true"
|
177
|
+
}, getOptions()));
|
178
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
179
|
+
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
180
|
+
});
|
181
|
+
(0, _vitest.it)('should provide a ref to the input element', async () => {
|
182
|
+
const inputRef = _vitest.vi.fn();
|
183
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
184
|
+
renderLabel: "Choose an option",
|
185
|
+
inputRef: inputRef
|
186
|
+
}, getOptions()));
|
187
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
188
|
+
expect(inputRef).toHaveBeenCalledWith(input);
|
189
|
+
});
|
190
|
+
});
|
191
|
+
(0, _vitest.it)('should render icons before option and call renderBeforeLabel callback with necessary props', async () => {
|
192
|
+
const renderBeforeLabel = _vitest.vi.fn(() => _IconCheckSolid || (_IconCheckSolid = /*#__PURE__*/_react.default.createElement(_IconCheckSolid2.IconCheckSolid, {
|
193
|
+
"data-testid": "option-icon"
|
194
|
+
})));
|
195
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
196
|
+
renderLabel: "Choose an option"
|
197
|
+
}, /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
198
|
+
id: "option-1",
|
199
|
+
value: "1",
|
200
|
+
isDisabled: true,
|
201
|
+
renderBeforeLabel: renderBeforeLabel
|
202
|
+
}, "option one"), /*#__PURE__*/_react.default.createElement(_index.default.Option, {
|
203
|
+
id: "option-2",
|
204
|
+
value: "2",
|
205
|
+
renderBeforeLabel: renderBeforeLabel
|
206
|
+
}, "option two")));
|
207
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
208
|
+
await _userEvent.default.click(input);
|
209
|
+
await (0, _react2.waitFor)(() => {
|
210
|
+
const optionIcons = _react2.screen.getAllByTestId('option-icon');
|
211
|
+
expect(optionIcons.length).toBe(2);
|
212
|
+
expect(renderBeforeLabel).toHaveBeenCalledTimes(2);
|
213
|
+
const _ref = renderBeforeLabel.mock.calls,
|
214
|
+
_ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
215
|
+
_ref2$ = (0, _slicedToArray2.default)(_ref2[0], 1),
|
216
|
+
argsOption1 = _ref2$[0],
|
217
|
+
_ref2$2 = (0, _slicedToArray2.default)(_ref2[1], 1),
|
218
|
+
argsOption2 = _ref2$2[0];
|
219
|
+
expect(argsOption1).toMatchObject({
|
220
|
+
id: 'option-1',
|
221
|
+
isDisabled: true,
|
222
|
+
isSelected: true,
|
223
|
+
isHighlighted: true,
|
224
|
+
children: 'option one'
|
225
|
+
});
|
226
|
+
expect(argsOption2).toMatchObject({
|
227
|
+
id: 'option-2',
|
228
|
+
isDisabled: false,
|
229
|
+
isSelected: false,
|
230
|
+
isHighlighted: false,
|
231
|
+
children: 'option two'
|
232
|
+
});
|
233
|
+
});
|
234
|
+
});
|
235
|
+
describe('list', () => {
|
236
|
+
(0, _vitest.it)('should set aria-disabled on options when isDisabled={true}', async () => {
|
237
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
65
238
|
renderLabel: "Choose an option"
|
66
|
-
}, getOptions()))
|
67
|
-
|
68
|
-
|
69
|
-
|
239
|
+
}, getOptions(defaultOptions[2])));
|
240
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
241
|
+
await _userEvent.default.click(input);
|
242
|
+
await (0, _react2.waitFor)(() => {
|
243
|
+
const options = _react2.screen.getAllByRole('option');
|
244
|
+
expect(options[0]).not.toHaveAttribute('aria-disabled');
|
245
|
+
expect(options[2]).toHaveAttribute('aria-disabled', 'true');
|
246
|
+
});
|
247
|
+
});
|
248
|
+
(0, _vitest.it)('should provide a ref to the list element', async () => {
|
249
|
+
const listRef = _vitest.vi.fn();
|
250
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.default, {
|
251
|
+
renderLabel: "Choose an option",
|
252
|
+
listRef: listRef
|
253
|
+
}, getOptions()));
|
254
|
+
const input = _react2.screen.getByLabelText('Choose an option');
|
255
|
+
await _userEvent.default.click(input);
|
256
|
+
await (0, _react2.waitFor)(() => {
|
257
|
+
const listbox = _react2.screen.getByRole('listbox');
|
258
|
+
expect(listRef).toHaveBeenCalledWith(listbox);
|
259
|
+
});
|
260
|
+
});
|
261
|
+
});
|
262
|
+
describe('with generated examples', () => {
|
263
|
+
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.default, _SimpleSelect7.default);
|
264
|
+
_vitest.it.each(generatedComponents)('should be accessible with example: $description', async ({
|
265
|
+
content
|
266
|
+
}) => {
|
267
|
+
const _render = (0, _react2.render)(content),
|
268
|
+
container = _render.container;
|
269
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
270
|
+
expect(axeCheck).toBe(true);
|
271
|
+
});
|
70
272
|
});
|
71
273
|
describe('children', () => {
|
72
274
|
const initialOptions = ['foo', 'bar'];
|
@@ -81,7 +283,7 @@ describe('<SimpleSelect />', () => {
|
|
81
283
|
renderLabel: "Choose an option"
|
82
284
|
}, getOptions(options)));
|
83
285
|
};
|
84
|
-
it('should clear selection if selected option does not exist in updated options', () => {
|
286
|
+
(0, _vitest.it)('should clear selection if selected option does not exist in updated options', () => {
|
85
287
|
const _renderSimpleSelect = renderSimpleSelect(initialOptions),
|
86
288
|
rerender = _renderSimpleSelect.rerender;
|
87
289
|
const input = _react2.screen.getByRole('combobox', {
|
@@ -98,7 +300,7 @@ describe('<SimpleSelect />', () => {
|
|
98
300
|
}, getOptions(updatedOptions)));
|
99
301
|
expect(input).toHaveValue('');
|
100
302
|
});
|
101
|
-
it('should persist selected option if it exists in updated options', () => {
|
303
|
+
(0, _vitest.it)('should persist selected option if it exists in updated options', () => {
|
102
304
|
const _renderSimpleSelect2 = renderSimpleSelect(initialOptions),
|
103
305
|
rerender = _renderSimpleSelect2.rerender;
|
104
306
|
const input = _react2.screen.getByRole('combobox', {
|