@instructure/ui-select 10.19.2-snapshot-2 → 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.
@@ -1,968 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
- var _react = require("react");
6
- var _react2 = require("@testing-library/react");
7
- var _vitest = require("vitest");
8
- var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
9
- require("@testing-library/jest-dom");
10
- var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
11
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
12
- var _index = _interopRequireDefault(require("../index"));
13
- var _Select8 = _interopRequireDefault(require("../__examples__/Select.examples"));
14
- var utils = _interopRequireWildcard(require("@instructure/ui-utils"));
15
- var _IconAddLine = require("@instructure/ui-icons/lib/IconAddLine.js");
16
- var _IconCheckSolid = require("@instructure/ui-icons/lib/IconCheckSolid.js");
17
- var _IconDownloadSolid = require("@instructure/ui-icons/lib/IconDownloadSolid.js");
18
- var _IconEyeSolid = require("@instructure/ui-icons/lib/IconEyeSolid.js");
19
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
20
- var _react3 = require("@emotion/react");
21
- var _Select$Option, _Select, _Select2, _Select3, _Select4, _Select5, _Select6, _Select7;
22
- /*
23
- * The MIT License (MIT)
24
- *
25
- * Copyright (c) 2015 - present Instructure, Inc.
26
- *
27
- * Permission is hereby granted, free of charge, to any person obtaining a copy
28
- * of this software and associated documentation files (the "Software"), to deal
29
- * in the Software without restriction, including without limitation the rights
30
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
- * copies of the Software, and to permit persons to whom the Software is
32
- * furnished to do so, subject to the following conditions:
33
- *
34
- * The above copyright notice and this permission notice shall be included in all
35
- * copies or substantial portions of the Software.
36
- *
37
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
- * SOFTWARE.
44
- */
45
- // eslint-disable-next-line no-restricted-imports
46
- const defaultOptions = ['foo', 'bar', 'baz'];
47
- const getOptions = (highlighted, selected, disabled) => defaultOptions.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
48
- id: opt,
49
- value: opt,
50
- isHighlighted: opt === highlighted,
51
- isSelected: opt === selected,
52
- isDisabled: opt === disabled,
53
- children: opt
54
- }, opt));
55
- const optionsWithBeforeContent = [{
56
- id: 'opt1',
57
- label: 'Text',
58
- renderBeforeLabel: 'XY'
59
- }, {
60
- id: 'opt2',
61
- label: 'Icon',
62
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
63
- }, {
64
- id: 'opt3',
65
- label: 'Colored Icon',
66
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
67
- }];
68
- const groupOptionsWithBeforeContent = {
69
- Options1: [{
70
- id: 'opt1',
71
- label: 'Text1',
72
- renderBeforeLabel: 'XY'
73
- }, {
74
- id: 'opt2',
75
- label: 'Icon1',
76
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
77
- }, {
78
- id: 'opt3',
79
- label: 'Colored Icon1',
80
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
81
- }],
82
- Options2: [{
83
- id: 'opt4',
84
- label: 'Text2',
85
- renderBeforeLabel: 'AB'
86
- }, {
87
- id: 'opt5',
88
- label: 'Icon2',
89
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconAddLine.IconAddLine, {})
90
- }, {
91
- id: 'opt6',
92
- label: 'Colored Icon2',
93
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconDownloadSolid.IconDownloadSolid, {})
94
- }]
95
- };
96
- const optionsWithAfterContent = [{
97
- id: 'opt1',
98
- label: 'Text',
99
- renderAfterLabel: 'XY'
100
- }, {
101
- id: 'opt2',
102
- label: 'Icon',
103
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
104
- }, {
105
- id: 'opt3',
106
- label: 'Colored Icon',
107
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
108
- }];
109
- const groupOptionsWithAfterContent = {
110
- Options1: [{
111
- id: 'opt1',
112
- label: 'Text1',
113
- renderAfterLabel: 'XY'
114
- }, {
115
- id: 'opt2',
116
- label: 'Icon1',
117
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
118
- }, {
119
- id: 'opt3',
120
- label: 'Colored Icon1',
121
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
122
- }],
123
- Options2: [{
124
- id: 'opt4',
125
- label: 'Text2',
126
- renderAfterLabel: 'AB'
127
- }, {
128
- id: 'opt5',
129
- label: 'Icon2',
130
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconAddLine.IconAddLine, {})
131
- }, {
132
- id: 'opt6',
133
- label: 'Colored Icon2',
134
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconDownloadSolid.IconDownloadSolid, {})
135
- }]
136
- };
137
- const optionsWithBeforeAndAfterContent = [{
138
- id: 'opt1',
139
- label: 'Text',
140
- renderBeforeLabel: 'XY',
141
- renderAfterLabel: 'ZZ'
142
- }, {
143
- id: 'opt2',
144
- label: 'Icon',
145
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {}),
146
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
147
- }, {
148
- id: 'opt3',
149
- label: 'Colored Icon',
150
- renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {}),
151
- renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
152
- }];
153
- const getOptionsWithBeforeContent = selected => optionsWithBeforeContent.map(opt => (0, _react3.createElement)(_index.default.Option, {
154
- ...opt,
155
- key: opt.id,
156
- isSelected: opt.id === selected
157
- }));
158
- const getGroupOptionsWithBeforeContent = selected => {
159
- return Object.keys(groupOptionsWithBeforeContent).map((key, index) => {
160
- return (0, _jsxRuntime.jsx)(_index.default.Group, {
161
- renderLabel: key,
162
- children: groupOptionsWithBeforeContent[key].map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
163
- id: opt.id,
164
- value: opt.label,
165
- renderBeforeLabel: opt.renderBeforeLabel,
166
- isSelected: opt.id === selected
167
- }, opt.id))
168
- }, index);
169
- });
170
- };
171
- const getOptionsWithAfterContent = selected => optionsWithAfterContent.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
172
- id: opt.id,
173
- value: opt.label,
174
- renderAfterLabel: opt.renderAfterLabel,
175
- isSelected: opt.id === selected
176
- }, opt.id));
177
- const getGroupOptionsWithAfterContent = selected => {
178
- return Object.keys(groupOptionsWithAfterContent).map((key, index) => {
179
- return (0, _jsxRuntime.jsx)(_index.default.Group, {
180
- renderLabel: key,
181
- children: groupOptionsWithAfterContent[key].map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
182
- id: opt.id,
183
- value: opt.label,
184
- renderAfterLabel: opt.renderAfterLabel,
185
- isSelected: opt.id === selected
186
- }, opt.id))
187
- }, index);
188
- });
189
- };
190
- const getOptionsWithBeforeAndAfterContent = selected => optionsWithBeforeAndAfterContent.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
191
- id: opt.id,
192
- value: opt.label,
193
- renderBeforeLabel: opt.renderBeforeLabel,
194
- renderAfterLabel: opt.renderAfterLabel,
195
- isSelected: opt.id === selected
196
- }, opt.id));
197
- _vitest.vi.mock('@instructure/ui-utils', async importOriginal => {
198
- const originalModule = await importOriginal();
199
- return {
200
- __esModule: true,
201
- ...originalModule,
202
- isSafari: _vitest.vi.fn(() => true)
203
- };
204
- });
205
- const mockUtils = utils;
206
- describe('<Select />', () => {
207
- let consoleErrorMock;
208
- beforeEach(() => {
209
- // Mocking console to prevent test output pollution and expect for messages
210
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
211
- });
212
- afterEach(() => {
213
- consoleErrorMock.mockRestore();
214
- });
215
- it('should not crash for weird option ids', async () => {
216
- const weirdID = 'some_`w@ei:r|!@#$%^&*(()|\\.l/d"id';
217
- _vitest.vi.useFakeTimers();
218
- const _render = (0, _react2.render)((0, _jsxRuntime.jsxs)(_index.default, {
219
- renderLabel: "Choose an option",
220
- scrollToHighlightedOption: true,
221
- isShowingOptions: true,
222
- children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
223
- id: weirdID,
224
- value: "2",
225
- isHighlighted: true,
226
- children: "op1"
227
- }, "1"), _Select$Option || (_Select$Option = (0, _jsxRuntime.jsx)(_index.default.Option, {
228
- id: "sdfsdfsd",
229
- value: "2",
230
- children: "op2"
231
- }, "2"))]
232
- })),
233
- container = _render.container;
234
- _vitest.vi.advanceTimersToNextFrame();
235
- _vitest.vi.useRealTimers();
236
- const input = container.querySelector('input');
237
- expect(input).toBeInTheDocument();
238
- });
239
- it('should have role button in Safari without onInputChange', async () => {
240
- const _render2 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
241
- renderLabel: "Choose an option",
242
- children: getOptions()
243
- })),
244
- container = _render2.container;
245
- const input = container.querySelector('input');
246
- expect(input).toHaveAttribute('role', 'button');
247
- });
248
- it('should have role combobox in different browsers than Safari without onInputChange', async () => {
249
- mockUtils.isSafari = _vitest.vi.fn(() => false);
250
- const _render3 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
251
- renderLabel: "Choose an option",
252
- children: getOptions()
253
- })),
254
- container = _render3.container;
255
- const input = container.querySelector('input');
256
- expect(input).toHaveAttribute('role', 'combobox');
257
- });
258
- it('should have role combobox with onInputChange', async () => {
259
- const _render4 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
260
- renderLabel: "Choose an option",
261
- onInputChange: () => {},
262
- children: getOptions()
263
- })),
264
- container = _render4.container;
265
- const input = container.querySelector('input');
266
- expect(input).toHaveAttribute('role', 'combobox');
267
- });
268
- it('should render an input and a list', async () => {
269
- const _render5 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
270
- renderLabel: "Choose an option",
271
- isShowingOptions: true,
272
- "data-testid": "subidubi",
273
- children: getOptions()
274
- })),
275
- container = _render5.container;
276
- const select = container.querySelector('span[class$="-select"]');
277
- const label = _react2.screen.getByLabelText('Choose an option');
278
- const input = container.querySelector('input[id^="Select_"]');
279
- const list = _react2.screen.getByRole('listbox');
280
- const options = _react2.screen.getAllByRole('option');
281
- const optionsCount = defaultOptions.length;
282
- expect(select).toBeInTheDocument();
283
- expect(label).toBeInTheDocument();
284
- expect(input).toBeInTheDocument();
285
- expect(list).toBeInTheDocument();
286
- expect(options.length).toBe(optionsCount);
287
- expect(options[0]).toHaveTextContent(defaultOptions[0]);
288
- expect(options[1]).toHaveTextContent(defaultOptions[1]);
289
- expect(options[2]).toHaveTextContent(defaultOptions[2]);
290
- });
291
- it('should render groups', async () => {
292
- (0, _react2.render)(_Select || (_Select = (0, _jsxRuntime.jsxs)(_index.default, {
293
- renderLabel: "Choose an option",
294
- isShowingOptions: true,
295
- children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
296
- id: "0",
297
- children: "ungrouped option one"
298
- }), (0, _jsxRuntime.jsx)(_index.default.Group, {
299
- renderLabel: "Group one",
300
- children: (0, _jsxRuntime.jsx)(_index.default.Option, {
301
- id: "1",
302
- children: "grouped option one"
303
- })
304
- }), (0, _jsxRuntime.jsx)(_index.default.Group, {
305
- renderLabel: "Group two",
306
- children: (0, _jsxRuntime.jsx)(_index.default.Option, {
307
- id: "2",
308
- children: "grouped option two"
309
- })
310
- }), (0, _jsxRuntime.jsx)(_index.default.Option, {
311
- id: "3",
312
- children: "ungrouped option two"
313
- })]
314
- })));
315
- const groups = _react2.screen.getAllByRole('group');
316
- const groupLabel = _react2.screen.getByText('Group one');
317
- expect(groupLabel).toHaveAttribute('role', 'presentation');
318
- expect(groups[0].getAttribute('aria-labelledby')).toEqual(groupLabel.getAttribute('id'));
319
- expect(groups.length).toBe(2);
320
- });
321
- it('should ignore invalid children', async () => {
322
- (0, _react2.render)(_Select2 || (_Select2 = (0, _jsxRuntime.jsxs)(_index.default, {
323
- renderLabel: "Choose an option",
324
- isShowingOptions: true,
325
- children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
326
- id: "0",
327
- children: "valid"
328
- }), (0, _jsxRuntime.jsx)("div", {
329
- children: "invalid"
330
- })]
331
- })));
332
- const invalidChild = _react2.screen.queryByText('invalid');
333
- expect(invalidChild).not.toBeInTheDocument();
334
- const expectedErrorMessage = 'Expected one of Group, Option';
335
- expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining(expectedErrorMessage), expect.any(String));
336
- });
337
- it('should provide a focus method', async () => {
338
- var _ref$current;
339
- const ref = /*#__PURE__*/(0, _react.createRef)();
340
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
341
- renderLabel: "Choose an option",
342
- ref: ref,
343
- children: getOptions()
344
- }));
345
- const input = _react2.screen.getByLabelText('Choose an option');
346
- (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
347
- await (0, _react2.waitFor)(() => {
348
- expect(document.activeElement).toBe(input);
349
- });
350
- });
351
- it('should provide a focused getter', async () => {
352
- var _ref$current2, _ref$current3;
353
- const ref = /*#__PURE__*/(0, _react.createRef)();
354
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
355
- renderLabel: "Choose an option",
356
- ref: ref,
357
- children: getOptions()
358
- }));
359
- expect((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focused).toBe(false);
360
- (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.focus();
361
- await (0, _react2.waitFor)(() => {
362
- var _ref$current4;
363
- expect((_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.focused).toBe(true);
364
- });
365
- });
366
- describe('input', () => {
367
- it('should render with a generated id by default', () => {
368
- const _render6 = (0, _react2.render)(_Select3 || (_Select3 = (0, _jsxRuntime.jsx)(_index.default, {
369
- renderLabel: "Choose an option"
370
- }))),
371
- container = _render6.container;
372
- const input = container.querySelector('input[id^="Select_"]');
373
- expect(input).toBeInTheDocument();
374
- expect(input).toHaveAttribute('id', expect.stringContaining('Select_'));
375
- });
376
- it('should render with a custom id if given', () => {
377
- const _render7 = (0, _react2.render)(_Select4 || (_Select4 = (0, _jsxRuntime.jsx)(_index.default, {
378
- renderLabel: "Choose an option",
379
- id: "customSelect"
380
- }))),
381
- container = _render7.container;
382
- const input = container.querySelector('input[id^="customSelect"]');
383
- expect(input).toBeInTheDocument();
384
- expect(input.getAttribute('id')).toEqual('customSelect');
385
- });
386
- it('should render readonly when interaction="enabled" with no onInputChange', () => {
387
- (0, _react2.render)(_Select5 || (_Select5 = (0, _jsxRuntime.jsx)(_index.default, {
388
- renderLabel: "Choose an option"
389
- })));
390
- const input = _react2.screen.getByLabelText('Choose an option');
391
- expect(input).toHaveAttribute('readonly');
392
- expect(input).not.toHaveAttribute('disabled');
393
- });
394
- it('should not render readonly when interaction="enabled" with onInputChange', () => {
395
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
396
- renderLabel: "Choose an option",
397
- onInputChange: () => {}
398
- }));
399
- const input = _react2.screen.getByLabelText('Choose an option');
400
- expect(input).not.toHaveAttribute('readonly');
401
- expect(input).not.toHaveAttribute('disabled');
402
- });
403
- it('should render readonly when interaction="readonly"', () => {
404
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
405
- renderLabel: "Choose an option",
406
- interaction: "readonly",
407
- onInputChange: () => {}
408
- }));
409
- const input = _react2.screen.getByLabelText('Choose an option');
410
- expect(input).toHaveAttribute('readonly');
411
- expect(input).not.toHaveAttribute('disabled');
412
- });
413
- it('should render disabled when interaction="disabled"', () => {
414
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
415
- renderLabel: "Choose an option",
416
- interaction: "disabled",
417
- onInputChange: () => {}
418
- }));
419
- const input = _react2.screen.getByLabelText('Choose an option');
420
- expect(input).toHaveAttribute('disabled');
421
- expect(input).not.toHaveAttribute('readonly');
422
- });
423
- it('should not render readonly when disabled', () => {
424
- (0, _react2.render)(_Select6 || (_Select6 = (0, _jsxRuntime.jsx)(_index.default, {
425
- renderLabel: "Choose an option",
426
- interaction: "disabled"
427
- })));
428
- const input = _react2.screen.getByLabelText('Choose an option');
429
- expect(input).toHaveAttribute('disabled');
430
- expect(input).not.toHaveAttribute('readonly');
431
- });
432
- it('should render required when isRequired={true}', () => {
433
- (0, _react2.render)(_Select7 || (_Select7 = (0, _jsxRuntime.jsx)(_index.default, {
434
- renderLabel: "Choose an option",
435
- isRequired: true
436
- })));
437
- const input = _react2.screen.getByLabelText('Choose an option *');
438
- expect(input).toHaveAttribute('required');
439
- });
440
- it('should render with inputValue', () => {
441
- const val = 'hello world';
442
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
443
- renderLabel: "Choose an option",
444
- inputValue: val
445
- }));
446
- const input = _react2.screen.getByLabelText('Choose an option');
447
- expect(input).toHaveAttribute('value', val);
448
- });
449
- it('should set aria-activedescendant based on the highlighted option', () => {
450
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
451
- renderLabel: "Choose an option",
452
- isShowingOptions: true,
453
- children: getOptions(defaultOptions[1])
454
- }));
455
- const input = _react2.screen.getByLabelText('Choose an option');
456
- expect(input).toHaveAttribute('aria-activedescendant', defaultOptions[1]);
457
- });
458
- it('should not set aria-activedescendant when not showing options', () => {
459
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
460
- renderLabel: "Choose an option",
461
- children: getOptions(defaultOptions[1])
462
- }));
463
- const input = _react2.screen.getByLabelText('Choose an option');
464
- expect(input).not.toHaveAttribute('aria-activedescendant');
465
- });
466
- it('should allow assistive text', () => {
467
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
468
- renderLabel: "Choose an option",
469
- assistiveText: "hello world",
470
- children: getOptions()
471
- }));
472
- const input = _react2.screen.getByLabelText('Choose an option');
473
- const assistiveText = _react2.screen.getByText('hello world');
474
- const assistiveTextId = assistiveText.getAttribute('id');
475
- expect(input).toHaveAttribute('aria-describedby', assistiveTextId);
476
- });
477
- it('should allow custom props to pass through', () => {
478
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
479
- renderLabel: "Choose an option",
480
- "data-custom-attr": "true",
481
- children: getOptions()
482
- }));
483
- const input = _react2.screen.getByLabelText('Choose an option');
484
- expect(input).toHaveAttribute('data-custom-attr', 'true');
485
- });
486
- it('should allow override of autoComplete prop', () => {
487
- const _render8 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
488
- renderLabel: "Choose an option",
489
- children: getOptions()
490
- })),
491
- rerender = _render8.rerender;
492
- const input = _react2.screen.getByLabelText('Choose an option');
493
- expect(input).toHaveAttribute('autocomplete', 'off');
494
- rerender((0, _jsxRuntime.jsx)(_index.default, {
495
- renderLabel: "Choose an option",
496
- autoComplete: "false",
497
- children: getOptions()
498
- }));
499
- expect(input).toHaveAttribute('autocomplete', 'false');
500
- });
501
- it('should provide a ref to the input element', async () => {
502
- const inputRef = _vitest.vi.fn();
503
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
504
- renderLabel: "Choose an option",
505
- inputRef: inputRef,
506
- children: getOptions()
507
- }));
508
- const input = _react2.screen.getByLabelText('Choose an option');
509
- await (0, _react2.waitFor)(() => {
510
- expect(inputRef).toHaveBeenCalledWith(input);
511
- });
512
- });
513
- it("should not render option's before content in input field when isOptionContentAppliedToInput is set to false", async () => {
514
- const _render9 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
515
- renderLabel: "Choose an option",
516
- isOptionContentAppliedToInput: false,
517
- inputValue: optionsWithBeforeContent[0].label,
518
- children: getOptionsWithBeforeContent('opt1')
519
- })),
520
- container = _render9.container;
521
- const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
522
- expect(beforeContent).not.toHaveTextContent('XY');
523
- });
524
- it('should render arrow in input field when isOptionContentAppliedToInput is set to false', async () => {
525
- const _render10 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
526
- renderLabel: "Choose an option",
527
- isOptionContentAppliedToInput: false,
528
- inputValue: optionsWithBeforeContent[0].label,
529
- children: getOptionsWithBeforeContent('opt1')
530
- })),
531
- container = _render10.container;
532
- const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
533
- const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
534
- expect(svgElement).toBeInTheDocument();
535
- });
536
- it("should render option's before content in input field when isOptionContentAppliedToInput is set to true", async () => {
537
- const _render11 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
538
- renderLabel: "Choose an option",
539
- isOptionContentAppliedToInput: true,
540
- inputValue: optionsWithBeforeContent[0].label,
541
- children: getOptionsWithBeforeContent('opt1')
542
- })),
543
- container = _render11.container;
544
- const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
545
- expect(beforeContent).toHaveTextContent('XY');
546
- });
547
- it('should render arrow icon when isOptionContentAppliedToInput is set to true with before content', async () => {
548
- const _render12 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
549
- renderLabel: "Choose an option",
550
- isOptionContentAppliedToInput: true,
551
- inputValue: optionsWithBeforeContent[0].label,
552
- children: getOptionsWithBeforeContent('opt1')
553
- })),
554
- container = _render12.container;
555
- const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
556
- const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
557
- expect(svgElement).toBeInTheDocument();
558
- });
559
- it("should render option's after content in input field when isOptionContentAppliedToInput is set to true", async () => {
560
- const _render13 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
561
- renderLabel: "Choose an option",
562
- isOptionContentAppliedToInput: true,
563
- inputValue: optionsWithAfterContent[0].label,
564
- children: getOptionsWithAfterContent('opt1')
565
- })),
566
- container = _render13.container;
567
- const beforeContent = container.querySelector('span[class$="-textInput__afterElement"]');
568
- expect(beforeContent).toHaveTextContent('XY');
569
- });
570
- it("should render option's before content in input field when isOptionContentAppliedToInput is set to true but renderBeforeInput is also set", async () => {
571
- const _render14 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
572
- renderLabel: "Choose an option",
573
- isOptionContentAppliedToInput: true,
574
- inputValue: optionsWithBeforeContent[0].label,
575
- renderBeforeInput: "ZZ",
576
- children: getOptionsWithBeforeContent('opt1')
577
- })),
578
- container = _render14.container;
579
- const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
580
- expect(beforeContent).toHaveTextContent('XY');
581
- });
582
- it("should render option's after content in input field when isOptionContentAppliedToInput is set to true but renderAfterInput is also set", async () => {
583
- const _render15 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
584
- renderLabel: "Choose an option",
585
- isOptionContentAppliedToInput: true,
586
- inputValue: optionsWithAfterContent[0].label,
587
- renderAfterInput: "ZZ",
588
- children: getOptionsWithAfterContent('opt1')
589
- })),
590
- container = _render15.container;
591
- const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
592
- expect(afterContent).toHaveTextContent('XY');
593
- });
594
- it("should not render option's before content in input field when isOptionContentAppliedToInput is set to true but inputValue is not set", async () => {
595
- const _render16 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
596
- renderLabel: "Choose an option",
597
- isOptionContentAppliedToInput: true,
598
- children: getOptionsWithBeforeContent('opt1')
599
- })),
600
- container = _render16.container;
601
- const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
602
- expect(beforeContent).not.toHaveTextContent('XY');
603
- });
604
- it("should render option's before content in input field when isOptionContentAppliedToInput is set to true and both optionBeforeContent and optionAfterContent are provided", async () => {
605
- const _render17 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
606
- renderLabel: "Choose an option",
607
- isOptionContentAppliedToInput: true,
608
- inputValue: optionsWithBeforeAndAfterContent[0].label,
609
- children: getOptionsWithBeforeAndAfterContent('opt1')
610
- })),
611
- container = _render17.container;
612
- const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
613
- expect(beforeContent).toHaveTextContent('XY');
614
- });
615
- it("should render option's after content in input field when isOptionContentAppliedToInput is set to true and both optionBeforeContent and optionAfterContent are provided", async () => {
616
- const _render18 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
617
- renderLabel: "Choose an option",
618
- isOptionContentAppliedToInput: true,
619
- inputValue: optionsWithBeforeAndAfterContent[0].label,
620
- children: getOptionsWithBeforeAndAfterContent('opt1')
621
- })),
622
- container = _render18.container;
623
- const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
624
- expect(afterContent).toHaveTextContent('ZZ');
625
- });
626
- it('should render arrow in input field when isOptionContentAppliedToInput is set to true but inputValue is not set', async () => {
627
- const _render19 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
628
- renderLabel: "Choose an option",
629
- isOptionContentAppliedToInput: true,
630
- children: getOptionsWithBeforeContent('opt1')
631
- })),
632
- container = _render19.container;
633
- const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
634
- const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
635
- expect(svgElement).toBeInTheDocument();
636
- });
637
- it("should not render option's after content in input field when isOptionContentAppliedToInput is set to true but inputValue is not set", async () => {
638
- const _render20 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
639
- renderLabel: "Choose an option",
640
- isOptionContentAppliedToInput: true,
641
- children: getOptionsWithBeforeContent('opt1')
642
- })),
643
- container = _render20.container;
644
- const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
645
- expect(afterContent).not.toHaveTextContent('XY');
646
- });
647
- it("should render option's before content input field when isOptionContentAppliedToInput is set to true with group options", async () => {
648
- const _render21 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
649
- renderLabel: "Choose an option",
650
- isOptionContentAppliedToInput: true,
651
- inputValue: groupOptionsWithBeforeContent.Options1[0].label,
652
- children: getGroupOptionsWithBeforeContent('opt1')
653
- })),
654
- container = _render21.container;
655
- const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
656
- expect(beforeContent).toHaveTextContent('XY');
657
- });
658
- it('should render arrow icon when isOptionContentAppliedToInput is set to true with before content and group options', async () => {
659
- const _render22 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
660
- renderLabel: "Choose an option",
661
- isOptionContentAppliedToInput: true,
662
- inputValue: groupOptionsWithBeforeContent.Options1[0].label,
663
- children: getGroupOptionsWithBeforeContent('opt1')
664
- })),
665
- container = _render22.container;
666
- const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
667
- const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
668
- expect(svgElement).toBeInTheDocument();
669
- });
670
- it("should render option's after content input field when isOptionContentAppliedToInput is set to true with group options", async () => {
671
- const _render23 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
672
- renderLabel: "Choose an option",
673
- isOptionContentAppliedToInput: true,
674
- inputValue: groupOptionsWithAfterContent.Options2[0].label,
675
- children: getGroupOptionsWithAfterContent('opt4')
676
- })),
677
- container = _render23.container;
678
- const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
679
- expect(afterContent).toHaveTextContent('AB');
680
- });
681
- });
682
- describe('list', () => {
683
- it('should set aria-selected on options with isSelected={true}', () => {
684
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
685
- renderLabel: "Choose an option",
686
- isShowingOptions: true,
687
- children: getOptions(void 0, defaultOptions[1])
688
- }));
689
- const options = _react2.screen.getAllByRole('option');
690
- expect(options[1].getAttribute('aria-selected')).toEqual('true');
691
- });
692
- it('should set aria-disabled on options when isDisabled={true}', () => {
693
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
694
- renderLabel: "Choose an option",
695
- isShowingOptions: true,
696
- children: getOptions(void 0, void 0, defaultOptions[2])
697
- }));
698
- const options = _react2.screen.getAllByRole('option');
699
- expect(options[0]).not.toHaveAttribute('aria-disabled');
700
- expect(options[2]).toHaveAttribute('aria-disabled', 'true');
701
- });
702
- it('should set list element role to "listbox"', async () => {
703
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
704
- renderLabel: "Choose an option",
705
- isShowingOptions: true,
706
- children: getOptions()
707
- }));
708
- const listbox = _react2.screen.getByRole('listbox');
709
- expect(listbox).toBeInTheDocument();
710
- expect(listbox.tagName).toBe('UL');
711
- });
712
- it('should provide a ref to the list element', async () => {
713
- const listRef = _vitest.vi.fn();
714
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
715
- renderLabel: "Choose an option",
716
- isShowingOptions: true,
717
- listRef: listRef,
718
- children: getOptions()
719
- }));
720
- const listbox = _react2.screen.getByRole('listbox');
721
- await (0, _react2.waitFor)(() => {
722
- expect(listRef).toHaveBeenCalledWith(listbox);
723
- });
724
- });
725
- });
726
- describe('with callbacks', () => {
727
- describe('should fire onRequestShowOptions', () => {
728
- it('when root is clicked', async () => {
729
- const onRequestShowOptions = _vitest.vi.fn();
730
- const _render24 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
731
- renderLabel: "Choose an option",
732
- onRequestShowOptions: onRequestShowOptions,
733
- children: getOptions()
734
- })),
735
- container = _render24.container,
736
- rerender = _render24.rerender;
737
- const icon = container.querySelector('svg[name="IconArrowOpenDown"]');
738
- const label = _react2.screen.getByText('Choose an option');
739
- expect(icon).toBeInTheDocument();
740
- expect(label).toBeInTheDocument();
741
- await _userEvent.default.click(label);
742
- await (0, _react2.waitFor)(() => {
743
- expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
744
- });
745
- await _userEvent.default.click(icon);
746
- await (0, _react2.waitFor)(() => {
747
- expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
748
- });
749
- rerender((0, _jsxRuntime.jsx)(_index.default, {
750
- renderLabel: "Choose an option",
751
- onRequestShowOptions: onRequestShowOptions,
752
- isShowingOptions: true,
753
- children: getOptions()
754
- }));
755
- await _userEvent.default.click(label);
756
- await (0, _react2.waitFor)(() => {
757
- expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
758
- });
759
- });
760
- it('when input is clicked', async () => {
761
- const onRequestShowOptions = _vitest.vi.fn();
762
- const _render25 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
763
- renderLabel: "Choose an option",
764
- onRequestShowOptions: onRequestShowOptions,
765
- children: getOptions()
766
- })),
767
- rerender = _render25.rerender;
768
- const input = _react2.screen.getByLabelText('Choose an option');
769
- await _userEvent.default.click(input);
770
- await (0, _react2.waitFor)(() => {
771
- expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
772
- });
773
- rerender((0, _jsxRuntime.jsx)(_index.default, {
774
- renderLabel: "Choose an option",
775
- onRequestShowOptions: onRequestShowOptions,
776
- isShowingOptions: true,
777
- children: getOptions()
778
- }));
779
- await _userEvent.default.click(input);
780
- await (0, _react2.waitFor)(() => {
781
- expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
782
- });
783
- });
784
- it('when up/down arrows are pressed', async () => {
785
- const onRequestShowOptions = _vitest.vi.fn();
786
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
787
- renderLabel: "Choose an option",
788
- onRequestShowOptions: onRequestShowOptions,
789
- children: getOptions()
790
- }));
791
- const input = _react2.screen.getByLabelText('Choose an option');
792
- await _userEvent.default.type(input, '{arrowdown}');
793
- await (0, _react2.waitFor)(() => {
794
- expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
795
- });
796
- await _userEvent.default.type(input, '{arrowup}');
797
- await (0, _react2.waitFor)(() => {
798
- expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
799
- });
800
- });
801
- it('when space is pressed', async () => {
802
- const onRequestShowOptions = _vitest.vi.fn();
803
- const _render26 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
804
- renderLabel: "Choose an option",
805
- onRequestShowOptions: onRequestShowOptions,
806
- children: getOptions()
807
- })),
808
- rerender = _render26.rerender;
809
- const input = _react2.screen.getByLabelText('Choose an option');
810
- await _userEvent.default.type(input, '{space}');
811
- await (0, _react2.waitFor)(() => {
812
- expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
813
- });
814
- rerender((0, _jsxRuntime.jsx)(_index.default, {
815
- renderLabel: "Choose an option",
816
- onRequestShowOptions: onRequestShowOptions,
817
- isShowingOptions: true,
818
- children: getOptions()
819
- }));
820
- await _userEvent.default.type(input, '{space}');
821
- await (0, _react2.waitFor)(() => {
822
- expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
823
- });
824
- });
825
- });
826
- describe('should fire onRequestHideOptions', () => {
827
- it('when root is clicked and isShowingOptions is true', async () => {
828
- const onRequestHideOptions = _vitest.vi.fn();
829
- const _render27 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
830
- renderLabel: "Choose an option",
831
- isShowingOptions: true,
832
- onRequestHideOptions: onRequestHideOptions,
833
- children: getOptions()
834
- })),
835
- container = _render27.container;
836
- const icon = container.querySelector('svg[name="IconArrowOpenUp"]');
837
- const label = _react2.screen.getByText('Choose an option');
838
- expect(icon).toBeInTheDocument();
839
- expect(label).toBeInTheDocument();
840
- await _userEvent.default.click(label);
841
- await (0, _react2.waitFor)(() => {
842
- expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
843
- });
844
- await _userEvent.default.click(icon);
845
- await (0, _react2.waitFor)(() => {
846
- expect(onRequestHideOptions).toHaveBeenCalledTimes(2);
847
- });
848
- });
849
- it('when root is clicked and isShowingOptions is false should NOT fire onRequestHideOptions', async () => {
850
- const onRequestHideOptions = _vitest.vi.fn();
851
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
852
- renderLabel: "Choose an option",
853
- isShowingOptions: false,
854
- onRequestHideOptions: onRequestHideOptions,
855
- children: getOptions()
856
- }));
857
- const label = _react2.screen.getByText('Choose an option');
858
- expect(label).toBeInTheDocument();
859
- await _userEvent.default.click(label);
860
- await (0, _react2.waitFor)(() => {
861
- expect(onRequestHideOptions).not.toHaveBeenCalled();
862
- });
863
- });
864
- it('when input is clicked', async () => {
865
- const onRequestHideOptions = _vitest.vi.fn();
866
- const _render28 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
867
- renderLabel: "Choose an option",
868
- isShowingOptions: true,
869
- onRequestHideOptions: onRequestHideOptions,
870
- children: getOptions()
871
- })),
872
- rerender = _render28.rerender;
873
- const input = _react2.screen.getByLabelText('Choose an option');
874
- await _userEvent.default.click(input);
875
- await (0, _react2.waitFor)(() => {
876
- expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
877
- });
878
- rerender((0, _jsxRuntime.jsx)(_index.default, {
879
- renderLabel: "Choose an option",
880
- isShowingOptions: false,
881
- onRequestHideOptions: onRequestHideOptions,
882
- children: getOptions()
883
- }));
884
- await _userEvent.default.click(input);
885
- await (0, _react2.waitFor)(() => {
886
- expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
887
- });
888
- });
889
- it('when escape is pressed', async () => {
890
- const onRequestHideOptions = _vitest.vi.fn();
891
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
892
- renderLabel: "Choose an option",
893
- isShowingOptions: true,
894
- onRequestHideOptions: onRequestHideOptions,
895
- children: getOptions()
896
- }));
897
- const input = _react2.screen.getByLabelText('Choose an option');
898
- await _userEvent.default.type(input, '{esc}');
899
- await (0, _react2.waitFor)(() => {
900
- expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
901
- });
902
- });
903
- });
904
- describe('should fire onRequestHighlightOption', () => {
905
- it('when options are hovered', async () => {
906
- const onRequestHighlightOption = _vitest.vi.fn();
907
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
908
- renderLabel: "Choose an option",
909
- isShowingOptions: true,
910
- onRequestHighlightOption: onRequestHighlightOption,
911
- children: getOptions()
912
- }));
913
- const options = _react2.screen.getAllByRole('option');
914
- await _userEvent.default.hover(options[0]);
915
- await (0, _react2.waitFor)(() => {
916
- expect(onRequestHighlightOption).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
917
- id: defaultOptions[0]
918
- }));
919
- });
920
- await _userEvent.default.hover(options[1]);
921
- await (0, _react2.waitFor)(() => {
922
- expect(onRequestHighlightOption).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
923
- id: defaultOptions[1]
924
- }));
925
- });
926
- });
927
- });
928
- describe('input callbacks', () => {
929
- it('should fire onInputChange when input is typed in', async () => {
930
- const onInputChange = _vitest.vi.fn();
931
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
932
- renderLabel: "Choose an option",
933
- onInputChange: onInputChange,
934
- children: getOptions()
935
- }));
936
- const input = _react2.screen.getByLabelText('Choose an option');
937
- await _userEvent.default.type(input, 'h');
938
- await (0, _react2.waitFor)(() => {
939
- expect(onInputChange).toHaveBeenCalled();
940
- });
941
- });
942
- it('should fire onFocus when input gains focus', async () => {
943
- const onFocus = _vitest.vi.fn();
944
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
945
- renderLabel: "Choose an option",
946
- onFocus: onFocus,
947
- children: getOptions()
948
- }));
949
- const input = _react2.screen.getByLabelText('Choose an option');
950
- input.focus();
951
- await (0, _react2.waitFor)(() => {
952
- expect(onFocus).toHaveBeenCalled();
953
- });
954
- });
955
- });
956
- });
957
- describe('with generated examples', () => {
958
- const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.default, _Select8.default);
959
- it.each(generatedComponents)('should be accessible with example: $description', async ({
960
- content
961
- }) => {
962
- const _render29 = (0, _react2.render)(content),
963
- container = _render29.container;
964
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
965
- expect(axeCheck).toBe(true);
966
- });
967
- });
968
- });