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