@instructure/ui-select 9.0.2-snapshot-7 → 9.0.2-snapshot-10
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/Select/__new-tests__/Select.test.js +517 -8
- package/lib/Select/__new-tests__/Select.test.js +516 -9
- package/package.json +26 -23
- package/src/Select/__new-tests__/Select.test.tsx +709 -14
- package/tsconfig.build.json +2 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Select/__new-tests__/Select.test.d.ts.map +1 -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
|
-
## [9.0.2-snapshot-
|
|
6
|
+
## [9.0.2-snapshot-10](https://github.com/instructure/instructure-ui/compare/v9.0.1...v9.0.2-snapshot-10) (2024-06-11)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-select
|
|
9
9
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _Select, _Select2, _Select3, _Select4, _Select5, _Select6, _Select7;
|
|
1
2
|
/*
|
|
2
3
|
* The MIT License (MIT)
|
|
3
4
|
*
|
|
@@ -22,10 +23,25 @@
|
|
|
22
23
|
* SOFTWARE.
|
|
23
24
|
*/
|
|
24
25
|
import React from 'react';
|
|
25
|
-
import { render } from '@testing-library/react';
|
|
26
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
27
|
+
import userEvent from '@testing-library/user-event';
|
|
26
28
|
import '@testing-library/jest-dom';
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line no-restricted-imports
|
|
31
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
27
33
|
import Select from '../index';
|
|
34
|
+
import SelectExamples from '../__examples__/Select.examples';
|
|
28
35
|
import * as utils from '@instructure/ui-utils';
|
|
36
|
+
const defaultOptions = ['foo', 'bar', 'baz'];
|
|
37
|
+
const getOptions = (highlighted, selected, disabled) => defaultOptions.map(opt => /*#__PURE__*/React.createElement(Select.Option, {
|
|
38
|
+
id: opt,
|
|
39
|
+
key: opt,
|
|
40
|
+
value: opt,
|
|
41
|
+
isHighlighted: opt === highlighted,
|
|
42
|
+
isSelected: opt === selected,
|
|
43
|
+
isDisabled: opt === disabled
|
|
44
|
+
}, opt));
|
|
29
45
|
jest.mock('@instructure/ui-utils', () => {
|
|
30
46
|
const originalModule = jest.requireActual('@instructure/ui-utils');
|
|
31
47
|
return {
|
|
@@ -36,13 +52,14 @@ jest.mock('@instructure/ui-utils', () => {
|
|
|
36
52
|
});
|
|
37
53
|
const mockUtils = utils;
|
|
38
54
|
describe('<Select />', () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
let consoleErrorMock;
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
58
|
+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
59
|
+
});
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
consoleErrorMock.mockRestore();
|
|
62
|
+
});
|
|
46
63
|
it('should have role button in Safari without onInputChange', async () => {
|
|
47
64
|
const _render = render( /*#__PURE__*/React.createElement(Select, {
|
|
48
65
|
renderLabel: "Choose an option"
|
|
@@ -71,4 +88,496 @@ describe('<Select />', () => {
|
|
|
71
88
|
const input = container.querySelector('input');
|
|
72
89
|
expect(input).toHaveAttribute('role', 'combobox');
|
|
73
90
|
});
|
|
91
|
+
it('should render an input and a list', async () => {
|
|
92
|
+
const _render4 = render( /*#__PURE__*/React.createElement(Select, {
|
|
93
|
+
renderLabel: "Choose an option",
|
|
94
|
+
isShowingOptions: true,
|
|
95
|
+
"data-testid": "subidubi"
|
|
96
|
+
}, getOptions())),
|
|
97
|
+
container = _render4.container;
|
|
98
|
+
const select = container.querySelector('span[class$="-select"]');
|
|
99
|
+
const label = screen.getByLabelText('Choose an option');
|
|
100
|
+
const input = container.querySelector('input[id^="Select_"]');
|
|
101
|
+
const list = screen.getByRole('listbox');
|
|
102
|
+
const options = screen.getAllByRole('option');
|
|
103
|
+
const optionsCount = defaultOptions.length;
|
|
104
|
+
expect(select).toBeInTheDocument();
|
|
105
|
+
expect(label).toBeInTheDocument();
|
|
106
|
+
expect(input).toBeInTheDocument();
|
|
107
|
+
expect(list).toBeInTheDocument();
|
|
108
|
+
expect(options.length).toBe(optionsCount);
|
|
109
|
+
expect(options[0]).toHaveTextContent(defaultOptions[0]);
|
|
110
|
+
expect(options[1]).toHaveTextContent(defaultOptions[1]);
|
|
111
|
+
expect(options[2]).toHaveTextContent(defaultOptions[2]);
|
|
112
|
+
});
|
|
113
|
+
it('should render groups', async () => {
|
|
114
|
+
render(_Select || (_Select = /*#__PURE__*/React.createElement(Select, {
|
|
115
|
+
renderLabel: "Choose an option",
|
|
116
|
+
isShowingOptions: true
|
|
117
|
+
}, /*#__PURE__*/React.createElement(Select.Option, {
|
|
118
|
+
id: "0"
|
|
119
|
+
}, "ungrouped option one"), /*#__PURE__*/React.createElement(Select.Group, {
|
|
120
|
+
renderLabel: "Group one"
|
|
121
|
+
}, /*#__PURE__*/React.createElement(Select.Option, {
|
|
122
|
+
id: "1"
|
|
123
|
+
}, "grouped option one")), /*#__PURE__*/React.createElement(Select.Group, {
|
|
124
|
+
renderLabel: "Group two"
|
|
125
|
+
}, /*#__PURE__*/React.createElement(Select.Option, {
|
|
126
|
+
id: "2"
|
|
127
|
+
}, "grouped option two")), /*#__PURE__*/React.createElement(Select.Option, {
|
|
128
|
+
id: "3"
|
|
129
|
+
}, "ungrouped option two"))));
|
|
130
|
+
const groups = screen.getAllByRole('group');
|
|
131
|
+
const groupLabel = screen.getByText('Group one');
|
|
132
|
+
expect(groupLabel).toHaveAttribute('role', 'presentation');
|
|
133
|
+
expect(groups[0].getAttribute('aria-labelledby')).toEqual(groupLabel.getAttribute('id'));
|
|
134
|
+
expect(groups.length).toBe(2);
|
|
135
|
+
});
|
|
136
|
+
it('should ignore invalid children', async () => {
|
|
137
|
+
render(_Select2 || (_Select2 = /*#__PURE__*/React.createElement(Select, {
|
|
138
|
+
renderLabel: "Choose an option",
|
|
139
|
+
isShowingOptions: true
|
|
140
|
+
}, /*#__PURE__*/React.createElement(Select.Option, {
|
|
141
|
+
id: "0"
|
|
142
|
+
}, "valid"), /*#__PURE__*/React.createElement("div", null, "invalid"))));
|
|
143
|
+
const invalidChild = screen.queryByText('invalid');
|
|
144
|
+
expect(invalidChild).not.toBeInTheDocument();
|
|
145
|
+
const expectedErrorMessage = 'Expected one of Group, Option';
|
|
146
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
147
|
+
});
|
|
148
|
+
it('should provide a focus method', async () => {
|
|
149
|
+
var _ref$current;
|
|
150
|
+
const ref = /*#__PURE__*/React.createRef();
|
|
151
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
152
|
+
renderLabel: "Choose an option",
|
|
153
|
+
ref: ref
|
|
154
|
+
}, getOptions()));
|
|
155
|
+
const input = screen.getByLabelText('Choose an option');
|
|
156
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
|
157
|
+
await waitFor(() => {
|
|
158
|
+
expect(document.activeElement).toBe(input);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
it('should provide a focused getter', async () => {
|
|
162
|
+
var _ref$current2, _ref$current3;
|
|
163
|
+
const ref = /*#__PURE__*/React.createRef();
|
|
164
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
165
|
+
renderLabel: "Choose an option",
|
|
166
|
+
ref: ref
|
|
167
|
+
}, getOptions()));
|
|
168
|
+
expect((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focused).toBe(false);
|
|
169
|
+
(_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.focus();
|
|
170
|
+
await waitFor(() => {
|
|
171
|
+
var _ref$current4;
|
|
172
|
+
expect((_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.focused).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe('input', () => {
|
|
176
|
+
it('should render with a generated id by default', () => {
|
|
177
|
+
const _render5 = render(_Select3 || (_Select3 = /*#__PURE__*/React.createElement(Select, {
|
|
178
|
+
renderLabel: "Choose an option"
|
|
179
|
+
}))),
|
|
180
|
+
container = _render5.container;
|
|
181
|
+
const input = container.querySelector('input[id^="Select_"]');
|
|
182
|
+
expect(input).toBeInTheDocument();
|
|
183
|
+
expect(input).toHaveAttribute('id', expect.stringContaining('Select_'));
|
|
184
|
+
});
|
|
185
|
+
it('should render with a custom id if given', () => {
|
|
186
|
+
const _render6 = render(_Select4 || (_Select4 = /*#__PURE__*/React.createElement(Select, {
|
|
187
|
+
renderLabel: "Choose an option",
|
|
188
|
+
id: "customSelect"
|
|
189
|
+
}))),
|
|
190
|
+
container = _render6.container;
|
|
191
|
+
const input = container.querySelector('input[id^="customSelect"]');
|
|
192
|
+
expect(input).toBeInTheDocument();
|
|
193
|
+
expect(input.getAttribute('id')).toEqual('customSelect');
|
|
194
|
+
});
|
|
195
|
+
it('should render readonly when interaction="enabled" with no onInputChange', () => {
|
|
196
|
+
render(_Select5 || (_Select5 = /*#__PURE__*/React.createElement(Select, {
|
|
197
|
+
renderLabel: "Choose an option"
|
|
198
|
+
})));
|
|
199
|
+
const input = screen.getByLabelText('Choose an option');
|
|
200
|
+
expect(input).toHaveAttribute('readonly');
|
|
201
|
+
expect(input).not.toHaveAttribute('disabled');
|
|
202
|
+
});
|
|
203
|
+
it('should not render readonly when interaction="enabled" with onInputChange', () => {
|
|
204
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
205
|
+
renderLabel: "Choose an option",
|
|
206
|
+
onInputChange: () => {}
|
|
207
|
+
}));
|
|
208
|
+
const input = screen.getByLabelText('Choose an option');
|
|
209
|
+
expect(input).not.toHaveAttribute('readonly');
|
|
210
|
+
expect(input).not.toHaveAttribute('disabled');
|
|
211
|
+
});
|
|
212
|
+
it('should render readonly when interaction="readonly"', () => {
|
|
213
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
214
|
+
renderLabel: "Choose an option",
|
|
215
|
+
interaction: "readonly",
|
|
216
|
+
onInputChange: () => {}
|
|
217
|
+
}));
|
|
218
|
+
const input = screen.getByLabelText('Choose an option');
|
|
219
|
+
expect(input).toHaveAttribute('readonly');
|
|
220
|
+
expect(input).not.toHaveAttribute('disabled');
|
|
221
|
+
});
|
|
222
|
+
it('should render disabled when interaction="disabled"', () => {
|
|
223
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
224
|
+
renderLabel: "Choose an option",
|
|
225
|
+
interaction: "disabled",
|
|
226
|
+
onInputChange: () => {}
|
|
227
|
+
}));
|
|
228
|
+
const input = screen.getByLabelText('Choose an option');
|
|
229
|
+
expect(input).toHaveAttribute('disabled');
|
|
230
|
+
expect(input).not.toHaveAttribute('readonly');
|
|
231
|
+
});
|
|
232
|
+
it('should not render readonly when disabled', () => {
|
|
233
|
+
render(_Select6 || (_Select6 = /*#__PURE__*/React.createElement(Select, {
|
|
234
|
+
renderLabel: "Choose an option",
|
|
235
|
+
interaction: "disabled"
|
|
236
|
+
})));
|
|
237
|
+
const input = screen.getByLabelText('Choose an option');
|
|
238
|
+
expect(input).toHaveAttribute('disabled');
|
|
239
|
+
expect(input).not.toHaveAttribute('readonly');
|
|
240
|
+
});
|
|
241
|
+
it('should render required when isRequired={true}', () => {
|
|
242
|
+
render(_Select7 || (_Select7 = /*#__PURE__*/React.createElement(Select, {
|
|
243
|
+
renderLabel: "Choose an option",
|
|
244
|
+
isRequired: true
|
|
245
|
+
})));
|
|
246
|
+
const input = screen.getByLabelText('Choose an option');
|
|
247
|
+
expect(input).toHaveAttribute('required');
|
|
248
|
+
});
|
|
249
|
+
it('should render with inputValue', () => {
|
|
250
|
+
const val = 'hello world';
|
|
251
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
252
|
+
renderLabel: "Choose an option",
|
|
253
|
+
inputValue: val
|
|
254
|
+
}));
|
|
255
|
+
const input = screen.getByLabelText('Choose an option');
|
|
256
|
+
expect(input).toHaveAttribute('value', val);
|
|
257
|
+
});
|
|
258
|
+
it('should set aria-activedescendant based on the highlighted option', () => {
|
|
259
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
260
|
+
renderLabel: "Choose an option",
|
|
261
|
+
isShowingOptions: true
|
|
262
|
+
}, getOptions(defaultOptions[1])));
|
|
263
|
+
const input = screen.getByLabelText('Choose an option');
|
|
264
|
+
expect(input).toHaveAttribute('aria-activedescendant', defaultOptions[1]);
|
|
265
|
+
});
|
|
266
|
+
it('should not set aria-activedescendant when not showing options', () => {
|
|
267
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
268
|
+
renderLabel: "Choose an option"
|
|
269
|
+
}, getOptions(defaultOptions[1])));
|
|
270
|
+
const input = screen.getByLabelText('Choose an option');
|
|
271
|
+
expect(input).not.toHaveAttribute('aria-activedescendant');
|
|
272
|
+
});
|
|
273
|
+
it('should allow assistive text', () => {
|
|
274
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
275
|
+
renderLabel: "Choose an option",
|
|
276
|
+
assistiveText: "hello world"
|
|
277
|
+
}, getOptions()));
|
|
278
|
+
const input = screen.getByLabelText('Choose an option');
|
|
279
|
+
const assistiveText = screen.getByText('hello world');
|
|
280
|
+
const assistiveTextId = assistiveText.getAttribute('id');
|
|
281
|
+
expect(input).toHaveAttribute('aria-describedby', assistiveTextId);
|
|
282
|
+
});
|
|
283
|
+
it('should allow custom props to pass through', () => {
|
|
284
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
285
|
+
renderLabel: "Choose an option",
|
|
286
|
+
"data-custom-attr": "true"
|
|
287
|
+
}, getOptions()));
|
|
288
|
+
const input = screen.getByLabelText('Choose an option');
|
|
289
|
+
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
|
290
|
+
});
|
|
291
|
+
it('should allow override of autoComplete prop', () => {
|
|
292
|
+
const _render7 = render( /*#__PURE__*/React.createElement(Select, {
|
|
293
|
+
renderLabel: "Choose an option"
|
|
294
|
+
}, getOptions())),
|
|
295
|
+
rerender = _render7.rerender;
|
|
296
|
+
const input = screen.getByLabelText('Choose an option');
|
|
297
|
+
expect(input).toHaveAttribute('autocomplete', 'off');
|
|
298
|
+
rerender( /*#__PURE__*/React.createElement(Select, {
|
|
299
|
+
renderLabel: "Choose an option",
|
|
300
|
+
autoComplete: "false"
|
|
301
|
+
}, getOptions()));
|
|
302
|
+
expect(input).toHaveAttribute('autocomplete', 'false');
|
|
303
|
+
});
|
|
304
|
+
it('should provide a ref to the input element', async () => {
|
|
305
|
+
const inputRef = jest.fn();
|
|
306
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
307
|
+
renderLabel: "Choose an option",
|
|
308
|
+
inputRef: inputRef
|
|
309
|
+
}, getOptions()));
|
|
310
|
+
const input = screen.getByLabelText('Choose an option');
|
|
311
|
+
await waitFor(() => {
|
|
312
|
+
expect(inputRef).toHaveBeenCalledWith(input);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe('list', () => {
|
|
317
|
+
it('should set aria-selected on options with isSelected={true}', () => {
|
|
318
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
319
|
+
renderLabel: "Choose an option",
|
|
320
|
+
isShowingOptions: true
|
|
321
|
+
}, getOptions(void 0, defaultOptions[1])));
|
|
322
|
+
const options = screen.getAllByRole('option');
|
|
323
|
+
expect(options[1].getAttribute('aria-selected')).toEqual('true');
|
|
324
|
+
});
|
|
325
|
+
it('should set aria-disabled on options when isDisabled={true}', () => {
|
|
326
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
327
|
+
renderLabel: "Choose an option",
|
|
328
|
+
isShowingOptions: true
|
|
329
|
+
}, getOptions(void 0, void 0, defaultOptions[2])));
|
|
330
|
+
const options = screen.getAllByRole('option');
|
|
331
|
+
expect(options[0]).not.toHaveAttribute('aria-disabled');
|
|
332
|
+
expect(options[2]).toHaveAttribute('aria-disabled', 'true');
|
|
333
|
+
});
|
|
334
|
+
it('should set list element role to "listbox"', async () => {
|
|
335
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
336
|
+
renderLabel: "Choose an option",
|
|
337
|
+
isShowingOptions: true
|
|
338
|
+
}, getOptions()));
|
|
339
|
+
const listbox = screen.getByRole('listbox');
|
|
340
|
+
expect(listbox).toBeInTheDocument();
|
|
341
|
+
expect(listbox.tagName).toBe('UL');
|
|
342
|
+
});
|
|
343
|
+
it('should provide a ref to the list element', async () => {
|
|
344
|
+
const listRef = jest.fn();
|
|
345
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
346
|
+
renderLabel: "Choose an option",
|
|
347
|
+
isShowingOptions: true,
|
|
348
|
+
listRef: listRef
|
|
349
|
+
}, getOptions()));
|
|
350
|
+
const listbox = screen.getByRole('listbox');
|
|
351
|
+
await waitFor(() => {
|
|
352
|
+
expect(listRef).toHaveBeenCalledWith(listbox);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
describe('with callbacks', () => {
|
|
357
|
+
describe('should fire onRequestShowOptions', () => {
|
|
358
|
+
it('when root is clicked', async () => {
|
|
359
|
+
const onRequestShowOptions = jest.fn();
|
|
360
|
+
const _render8 = render( /*#__PURE__*/React.createElement(Select, {
|
|
361
|
+
renderLabel: "Choose an option",
|
|
362
|
+
onRequestShowOptions: onRequestShowOptions
|
|
363
|
+
}, getOptions())),
|
|
364
|
+
container = _render8.container,
|
|
365
|
+
rerender = _render8.rerender;
|
|
366
|
+
const icon = container.querySelector('svg[name="IconArrowOpenDown"]');
|
|
367
|
+
const label = screen.getByText('Choose an option');
|
|
368
|
+
expect(icon).toBeInTheDocument();
|
|
369
|
+
expect(label).toBeInTheDocument();
|
|
370
|
+
await userEvent.click(label);
|
|
371
|
+
await waitFor(() => {
|
|
372
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
373
|
+
});
|
|
374
|
+
await userEvent.click(icon);
|
|
375
|
+
await waitFor(() => {
|
|
376
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
|
|
377
|
+
});
|
|
378
|
+
rerender( /*#__PURE__*/React.createElement(Select, {
|
|
379
|
+
renderLabel: "Choose an option",
|
|
380
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
381
|
+
isShowingOptions: true
|
|
382
|
+
}, getOptions()));
|
|
383
|
+
await userEvent.click(label);
|
|
384
|
+
await waitFor(() => {
|
|
385
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
it('when input is clicked', async () => {
|
|
389
|
+
const onRequestShowOptions = jest.fn();
|
|
390
|
+
const _render9 = render( /*#__PURE__*/React.createElement(Select, {
|
|
391
|
+
renderLabel: "Choose an option",
|
|
392
|
+
onRequestShowOptions: onRequestShowOptions
|
|
393
|
+
}, getOptions())),
|
|
394
|
+
rerender = _render9.rerender;
|
|
395
|
+
const input = screen.getByLabelText('Choose an option');
|
|
396
|
+
await userEvent.click(input);
|
|
397
|
+
await waitFor(() => {
|
|
398
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
399
|
+
});
|
|
400
|
+
rerender( /*#__PURE__*/React.createElement(Select, {
|
|
401
|
+
renderLabel: "Choose an option",
|
|
402
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
403
|
+
isShowingOptions: true
|
|
404
|
+
}, getOptions()));
|
|
405
|
+
await userEvent.click(input);
|
|
406
|
+
await waitFor(() => {
|
|
407
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
it('when up/down arrows are pressed', async () => {
|
|
411
|
+
const onRequestShowOptions = jest.fn();
|
|
412
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
413
|
+
renderLabel: "Choose an option",
|
|
414
|
+
onRequestShowOptions: onRequestShowOptions
|
|
415
|
+
}, getOptions()));
|
|
416
|
+
const input = screen.getByLabelText('Choose an option');
|
|
417
|
+
await userEvent.type(input, '{arrowdown}');
|
|
418
|
+
await waitFor(() => {
|
|
419
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
420
|
+
});
|
|
421
|
+
await userEvent.type(input, '{arrowup}');
|
|
422
|
+
await waitFor(() => {
|
|
423
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
it('when space is pressed', async () => {
|
|
427
|
+
const onRequestShowOptions = jest.fn();
|
|
428
|
+
const _render10 = render( /*#__PURE__*/React.createElement(Select, {
|
|
429
|
+
renderLabel: "Choose an option",
|
|
430
|
+
onRequestShowOptions: onRequestShowOptions
|
|
431
|
+
}, getOptions())),
|
|
432
|
+
rerender = _render10.rerender;
|
|
433
|
+
const input = screen.getByLabelText('Choose an option');
|
|
434
|
+
await userEvent.type(input, '{space}');
|
|
435
|
+
await waitFor(() => {
|
|
436
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
437
|
+
});
|
|
438
|
+
rerender( /*#__PURE__*/React.createElement(Select, {
|
|
439
|
+
renderLabel: "Choose an option",
|
|
440
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
441
|
+
isShowingOptions: true
|
|
442
|
+
}, getOptions()));
|
|
443
|
+
await userEvent.type(input, '{space}');
|
|
444
|
+
await waitFor(() => {
|
|
445
|
+
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
describe('should fire onRequestHideOptions', () => {
|
|
450
|
+
it('when root is clicked and isShowingOptions is true', async () => {
|
|
451
|
+
const onRequestHideOptions = jest.fn();
|
|
452
|
+
const _render11 = render( /*#__PURE__*/React.createElement(Select, {
|
|
453
|
+
renderLabel: "Choose an option",
|
|
454
|
+
isShowingOptions: true,
|
|
455
|
+
onRequestHideOptions: onRequestHideOptions
|
|
456
|
+
}, getOptions())),
|
|
457
|
+
container = _render11.container;
|
|
458
|
+
const icon = container.querySelector('svg[name="IconArrowOpenUp"]');
|
|
459
|
+
const label = screen.getByText('Choose an option');
|
|
460
|
+
expect(icon).toBeInTheDocument();
|
|
461
|
+
expect(label).toBeInTheDocument();
|
|
462
|
+
await userEvent.click(label);
|
|
463
|
+
await waitFor(() => {
|
|
464
|
+
expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
|
|
465
|
+
});
|
|
466
|
+
await userEvent.click(icon);
|
|
467
|
+
await waitFor(() => {
|
|
468
|
+
expect(onRequestHideOptions).toHaveBeenCalledTimes(2);
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
it('when root is clicked and isShowingOptions is false should NOT fire onRequestHideOptions', async () => {
|
|
472
|
+
const onRequestHideOptions = jest.fn();
|
|
473
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
474
|
+
renderLabel: "Choose an option",
|
|
475
|
+
isShowingOptions: false,
|
|
476
|
+
onRequestHideOptions: onRequestHideOptions
|
|
477
|
+
}, getOptions()));
|
|
478
|
+
const label = screen.getByText('Choose an option');
|
|
479
|
+
expect(label).toBeInTheDocument();
|
|
480
|
+
await userEvent.click(label);
|
|
481
|
+
await waitFor(() => {
|
|
482
|
+
expect(onRequestHideOptions).not.toHaveBeenCalled();
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
it('when input is clicked', async () => {
|
|
486
|
+
const onRequestHideOptions = jest.fn();
|
|
487
|
+
const _render12 = render( /*#__PURE__*/React.createElement(Select, {
|
|
488
|
+
renderLabel: "Choose an option",
|
|
489
|
+
isShowingOptions: true,
|
|
490
|
+
onRequestHideOptions: onRequestHideOptions
|
|
491
|
+
}, getOptions())),
|
|
492
|
+
rerender = _render12.rerender;
|
|
493
|
+
const input = screen.getByLabelText('Choose an option');
|
|
494
|
+
await userEvent.click(input);
|
|
495
|
+
await waitFor(() => {
|
|
496
|
+
expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
|
|
497
|
+
});
|
|
498
|
+
rerender( /*#__PURE__*/React.createElement(Select, {
|
|
499
|
+
renderLabel: "Choose an option",
|
|
500
|
+
isShowingOptions: false,
|
|
501
|
+
onRequestHideOptions: onRequestHideOptions
|
|
502
|
+
}, getOptions()));
|
|
503
|
+
await userEvent.click(input);
|
|
504
|
+
await waitFor(() => {
|
|
505
|
+
expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
it('when escape is pressed', async () => {
|
|
509
|
+
const onRequestHideOptions = jest.fn();
|
|
510
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
511
|
+
renderLabel: "Choose an option",
|
|
512
|
+
isShowingOptions: true,
|
|
513
|
+
onRequestHideOptions: onRequestHideOptions
|
|
514
|
+
}, getOptions()));
|
|
515
|
+
const input = screen.getByLabelText('Choose an option');
|
|
516
|
+
await userEvent.type(input, '{esc}');
|
|
517
|
+
await waitFor(() => {
|
|
518
|
+
expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
describe('should fire onRequestHighlightOption', () => {
|
|
523
|
+
it('when options are hovered', async () => {
|
|
524
|
+
const onRequestHighlightOption = jest.fn();
|
|
525
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
526
|
+
renderLabel: "Choose an option",
|
|
527
|
+
isShowingOptions: true,
|
|
528
|
+
onRequestHighlightOption: onRequestHighlightOption
|
|
529
|
+
}, getOptions()));
|
|
530
|
+
const options = screen.getAllByRole('option');
|
|
531
|
+
await userEvent.hover(options[0]);
|
|
532
|
+
await waitFor(() => {
|
|
533
|
+
expect(onRequestHighlightOption).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
534
|
+
id: defaultOptions[0]
|
|
535
|
+
}));
|
|
536
|
+
});
|
|
537
|
+
await userEvent.hover(options[1]);
|
|
538
|
+
await waitFor(() => {
|
|
539
|
+
expect(onRequestHighlightOption).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
540
|
+
id: defaultOptions[1]
|
|
541
|
+
}));
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
describe('input callbacks', () => {
|
|
546
|
+
it('should fire onInputChange when input is typed in', async () => {
|
|
547
|
+
const onInputChange = jest.fn();
|
|
548
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
549
|
+
renderLabel: "Choose an option",
|
|
550
|
+
onInputChange: onInputChange
|
|
551
|
+
}, getOptions()));
|
|
552
|
+
const input = screen.getByLabelText('Choose an option');
|
|
553
|
+
await userEvent.type(input, 'h');
|
|
554
|
+
await waitFor(() => {
|
|
555
|
+
expect(onInputChange).toHaveBeenCalled();
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
it('should fire onFocus when input gains focus', async () => {
|
|
559
|
+
const onFocus = jest.fn();
|
|
560
|
+
render( /*#__PURE__*/React.createElement(Select, {
|
|
561
|
+
renderLabel: "Choose an option",
|
|
562
|
+
onFocus: onFocus
|
|
563
|
+
}, getOptions()));
|
|
564
|
+
const input = screen.getByLabelText('Choose an option');
|
|
565
|
+
input.focus();
|
|
566
|
+
await waitFor(() => {
|
|
567
|
+
expect(onFocus).toHaveBeenCalled();
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
describe('with generated examples', () => {
|
|
573
|
+
const generatedComponents = generateA11yTests(Select, SelectExamples);
|
|
574
|
+
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
|
575
|
+
content
|
|
576
|
+
}) => {
|
|
577
|
+
const _render13 = render(content),
|
|
578
|
+
container = _render13.container;
|
|
579
|
+
const axeCheck = await runAxeCheck(container);
|
|
580
|
+
expect(axeCheck).toBe(true);
|
|
581
|
+
});
|
|
582
|
+
});
|
|
74
583
|
});
|