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