@transferwise/components 0.0.0-experimental-756c861 → 0.0.0-experimental-a4db2ca
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/README.md +1 -1
- package/build/index.js +31 -84
- package/build/index.js.map +1 -1
- package/build/index.mjs +28 -80
- package/build/index.mjs.map +1 -1
- package/build/types/card/Card.d.ts +17 -20
- package/build/types/card/Card.d.ts.map +1 -1
- package/build/types/card/index.d.ts +2 -1
- package/build/types/card/index.d.ts.map +1 -1
- package/build/types/drawer/Drawer.d.ts +19 -36
- package/build/types/drawer/Drawer.d.ts.map +1 -1
- package/build/types/drawer/index.d.ts +2 -1
- package/build/types/drawer/index.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/accordion/Accordion.spec.js +5 -5
- package/src/accordion/AccordionItem/AccordionItem.spec.js +2 -2
- package/src/actionButton/ActionButton.spec.tsx +4 -4
- package/src/alert/Alert.spec.tsx +4 -4
- package/src/button/Button.spec.js +4 -4
- package/src/card/{Card.spec.js → Card.spec.tsx} +4 -4
- package/src/card/{Card.story.js → Card.story.tsx} +6 -15
- package/src/card/{Card.js → Card.tsx} +23 -34
- package/src/card/index.ts +2 -0
- package/src/carousel/Carousel.spec.tsx +17 -17
- package/src/circularButton/CircularButton.spec.tsx +4 -4
- package/src/common/RadioButton/RadioButton.spec.tsx +2 -2
- package/src/dateLookup/DateLookup.rtl.spec.tsx +16 -18
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +43 -47
- package/src/dimmer/Dimmer.rtl.spec.js +10 -10
- package/src/drawer/{Drawer.rtl.spec.js → Drawer.rtl.spec.tsx} +6 -4
- package/src/drawer/{Drawer.story.js → Drawer.story.tsx} +20 -28
- package/src/drawer/{Drawer.js → Drawer.tsx} +26 -31
- package/src/drawer/index.ts +2 -0
- package/src/field/Field.spec.tsx +2 -2
- package/src/header/Header.spec.tsx +6 -6
- package/src/index.ts +2 -0
- package/src/inputs/SelectInput.spec.tsx +47 -26
- package/src/moneyInput/MoneyInput.rtl.spec.tsx +2 -2
- package/src/popover/Popover.spec.tsx +10 -10
- package/src/section/Section.story.tsx +0 -2
- package/src/segmentedControl/SegmentedControl.spec.tsx +10 -10
- package/src/select/Select.spec.js +71 -71
- package/src/test-utils/index.js +1 -1
- package/src/tooltip/Tooltip.spec.tsx +16 -15
- package/src/uploadInput/UploadInput.spec.tsx +10 -9
- package/src/uploadInput/uploadButton/UploadButton.spec.tsx +4 -4
- package/src/uploadInput/uploadItem/UploadItem.spec.tsx +4 -4
- package/src/card/index.js +0 -1
- package/src/drawer/index.js +0 -1
- /package/src/drawer/__snapshots__/{Drawer.rtl.spec.js.snap → Drawer.rtl.spec.tsx.snap} +0 -0
|
@@ -42,16 +42,16 @@ describe('Select', () => {
|
|
|
42
42
|
global.requestAnimationFrame = originalRAF;
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
const openSelect =
|
|
45
|
+
const openSelect = (container) => {
|
|
46
46
|
const button = screen.getByRole('button');
|
|
47
|
-
|
|
47
|
+
userEvent.click(button);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
describe('search property', () => {
|
|
51
51
|
it('should focus input when dropdown is open', async () => {
|
|
52
52
|
const { container } = render(<Select {...props} search />);
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
openSelect(container);
|
|
55
55
|
const input = screen.getByPlaceholderText('Search...');
|
|
56
56
|
|
|
57
57
|
expect(input).toHaveFocus();
|
|
@@ -60,7 +60,7 @@ describe('Select', () => {
|
|
|
60
60
|
it('should pass id to search box', async () => {
|
|
61
61
|
const { container } = render(<Select {...props} search id="dummy" />);
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
openSelect(container);
|
|
64
64
|
const input = screen.getByPlaceholderText('Search...');
|
|
65
65
|
|
|
66
66
|
expect(input).toHaveAttribute('id', 'dummy-searchbox');
|
|
@@ -69,9 +69,9 @@ describe('Select', () => {
|
|
|
69
69
|
it('should filter the options with the default filter function', async () => {
|
|
70
70
|
const { container } = render(<Select {...props} search />);
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
openSelect(container);
|
|
73
73
|
const input = screen.getByPlaceholderText('Search...');
|
|
74
|
-
|
|
74
|
+
userEvent.type(input, 'yo');
|
|
75
75
|
|
|
76
76
|
// Not ideal, this higlights accessibility issues.
|
|
77
77
|
expect(container.querySelector('.np-dropdown-item.np-dropdown-item--focused')).toStrictEqual(
|
|
@@ -113,14 +113,14 @@ describe('Select', () => {
|
|
|
113
113
|
beforeEach(async () => {
|
|
114
114
|
const { container } = render(<Select {...props} options={searchableOptions} search />);
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
openSelect(container);
|
|
117
117
|
|
|
118
118
|
input = screen.getByPlaceholderText('Search...');
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
describe('when searching by label', () => {
|
|
122
|
-
it('should display the search result',
|
|
123
|
-
|
|
122
|
+
it('should display the search result', () => {
|
|
123
|
+
userEvent.type(input, 'second_label');
|
|
124
124
|
|
|
125
125
|
expect(screen.queryByText('first_label')).not.toBeInTheDocument();
|
|
126
126
|
expect(screen.getByText('second_label')).toBeInTheDocument();
|
|
@@ -129,8 +129,8 @@ describe('Select', () => {
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
describe('when searching by note', () => {
|
|
132
|
-
it('should display the search result',
|
|
133
|
-
|
|
132
|
+
it('should display the search result', () => {
|
|
133
|
+
userEvent.type(input, 'third_note');
|
|
134
134
|
|
|
135
135
|
expect(screen.queryByText('first_label')).not.toBeInTheDocument();
|
|
136
136
|
expect(screen.queryByText('second_label')).not.toBeInTheDocument();
|
|
@@ -139,8 +139,8 @@ describe('Select', () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
describe('when searching by secondary', () => {
|
|
142
|
-
it('should display the search result',
|
|
143
|
-
|
|
142
|
+
it('should display the search result', () => {
|
|
143
|
+
userEvent.type(input, 'first_secondary');
|
|
144
144
|
|
|
145
145
|
expect(screen.getByText('first_label')).toBeInTheDocument();
|
|
146
146
|
expect(screen.queryByText('second_label')).not.toBeInTheDocument();
|
|
@@ -149,8 +149,8 @@ describe('Select', () => {
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
describe('when searching by currency', () => {
|
|
152
|
-
it('should display the search result',
|
|
153
|
-
|
|
152
|
+
it('should display the search result', () => {
|
|
153
|
+
userEvent.type(input, 'usd');
|
|
154
154
|
|
|
155
155
|
expect(screen.queryByText('first_label')).not.toBeInTheDocument();
|
|
156
156
|
expect(screen.getByText('second_label')).toBeInTheDocument();
|
|
@@ -159,8 +159,8 @@ describe('Select', () => {
|
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
describe('when searching by searchStrings', () => {
|
|
162
|
-
it('should display the search result',
|
|
163
|
-
|
|
162
|
+
it('should display the search result', () => {
|
|
163
|
+
userEvent.type(input, 'third_search_string');
|
|
164
164
|
|
|
165
165
|
expect(screen.queryByText('first_label')).not.toBeInTheDocument();
|
|
166
166
|
expect(screen.queryByText('second_label')).not.toBeInTheDocument();
|
|
@@ -169,7 +169,7 @@ describe('Select', () => {
|
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
it('should be able to search disabled options',
|
|
172
|
+
it('should be able to search disabled options', () => {
|
|
173
173
|
const { container } = render(
|
|
174
174
|
<Select
|
|
175
175
|
{...props}
|
|
@@ -180,9 +180,9 @@ describe('Select', () => {
|
|
|
180
180
|
]}
|
|
181
181
|
/>,
|
|
182
182
|
);
|
|
183
|
-
|
|
183
|
+
openSelect(container);
|
|
184
184
|
const input = screen.getByPlaceholderText('Search...');
|
|
185
|
-
|
|
185
|
+
userEvent.type(input, 'Disabled');
|
|
186
186
|
expect(screen.queryByText('Enabled Option')).not.toBeInTheDocument();
|
|
187
187
|
expect(screen.getByText('Disabled Option')).toBeInTheDocument();
|
|
188
188
|
});
|
|
@@ -199,9 +199,9 @@ describe('Select', () => {
|
|
|
199
199
|
/>,
|
|
200
200
|
);
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
openSelect(container);
|
|
203
203
|
const input = screen.getByPlaceholderText('Search...');
|
|
204
|
-
|
|
204
|
+
userEvent.type(input, 'HUF');
|
|
205
205
|
|
|
206
206
|
expect(container.querySelector('.np-dropdown-item.np-dropdown-item--focused')).toStrictEqual(
|
|
207
207
|
container.querySelector('.np-dropdown-item'),
|
|
@@ -224,9 +224,9 @@ describe('Select', () => {
|
|
|
224
224
|
/>,
|
|
225
225
|
);
|
|
226
226
|
|
|
227
|
-
|
|
227
|
+
openSelect(container);
|
|
228
228
|
const input = screen.getByPlaceholderText('Search...');
|
|
229
|
-
|
|
229
|
+
userEvent.type(input, 'Tallinn');
|
|
230
230
|
|
|
231
231
|
expect(container.querySelector('.np-dropdown-item.np-dropdown-item--focused')).toStrictEqual(
|
|
232
232
|
container.querySelector('.np-dropdown-item'),
|
|
@@ -239,9 +239,9 @@ describe('Select', () => {
|
|
|
239
239
|
it('should filter the options with a custom search function', async () => {
|
|
240
240
|
const searchFunction = jest.fn();
|
|
241
241
|
const { container } = render(<Select {...props} search={searchFunction} />);
|
|
242
|
-
|
|
242
|
+
openSelect(container);
|
|
243
243
|
const input = screen.getByPlaceholderText('Search...');
|
|
244
|
-
|
|
244
|
+
userEvent.type(input, 'o');
|
|
245
245
|
|
|
246
246
|
expect(searchFunction).toHaveBeenCalledTimes(3);
|
|
247
247
|
});
|
|
@@ -249,10 +249,10 @@ describe('Select', () => {
|
|
|
249
249
|
it('should filter the options with a custom search function with 3 results', async () => {
|
|
250
250
|
const searchFunction = (option, searchValue) => option.label.includes(searchValue);
|
|
251
251
|
const { container } = render(<Select {...props} search={searchFunction} />);
|
|
252
|
-
|
|
252
|
+
openSelect(container);
|
|
253
253
|
|
|
254
254
|
const input = screen.getByPlaceholderText('Search...');
|
|
255
|
-
|
|
255
|
+
userEvent.type(input, 'o');
|
|
256
256
|
|
|
257
257
|
expect(screen.getByRole('listbox').children).toHaveLength(3);
|
|
258
258
|
});
|
|
@@ -260,7 +260,7 @@ describe('Select', () => {
|
|
|
260
260
|
|
|
261
261
|
it('show list of options in dropdown (Panel) on desktop', async () => {
|
|
262
262
|
const { container } = render(<Select {...props} />);
|
|
263
|
-
|
|
263
|
+
openSelect(container);
|
|
264
264
|
|
|
265
265
|
const drawer = document.querySelector('.np-panel');
|
|
266
266
|
expect(drawer).toBeInTheDocument();
|
|
@@ -269,7 +269,7 @@ describe('Select', () => {
|
|
|
269
269
|
it('show list of options in Bottom Sheet when on mobile', async () => {
|
|
270
270
|
enableMobileScreen();
|
|
271
271
|
const { container } = render(<Select {...props} />);
|
|
272
|
-
|
|
272
|
+
openSelect(container);
|
|
273
273
|
|
|
274
274
|
const bottomSheet = await screen.findByRole('dialog');
|
|
275
275
|
|
|
@@ -279,7 +279,7 @@ describe('Select', () => {
|
|
|
279
279
|
it('show list of options in Drawer when on mobile and search in enabled', async () => {
|
|
280
280
|
enableMobileScreen();
|
|
281
281
|
const { container } = render(<Select {...props} search />);
|
|
282
|
-
|
|
282
|
+
openSelect(container);
|
|
283
283
|
|
|
284
284
|
await waitFor(() => {
|
|
285
285
|
const drawer = document.querySelector('.np-drawer');
|
|
@@ -289,7 +289,7 @@ describe('Select', () => {
|
|
|
289
289
|
|
|
290
290
|
it('focuses dropdown options when clicked', async () => {
|
|
291
291
|
const { container } = render(<Select {...props} />);
|
|
292
|
-
|
|
292
|
+
openSelect(container);
|
|
293
293
|
|
|
294
294
|
const dropdown = screen.getByRole('listbox');
|
|
295
295
|
expect(dropdown).toHaveFocus();
|
|
@@ -299,7 +299,7 @@ describe('Select', () => {
|
|
|
299
299
|
enableMobileScreen();
|
|
300
300
|
const { container } = render(<Select {...props} onSearchChange={jest.fn()} />);
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
openSelect(container);
|
|
303
303
|
const input = await screen.findByPlaceholderText('Search...');
|
|
304
304
|
|
|
305
305
|
expect(input).not.toHaveFocus();
|
|
@@ -308,7 +308,7 @@ describe('Select', () => {
|
|
|
308
308
|
it('on not touch device focuses on the search box once opened', async () => {
|
|
309
309
|
const { container } = render(<Select {...props} search onSearchChange={jest.fn()} />);
|
|
310
310
|
|
|
311
|
-
|
|
311
|
+
openSelect(container);
|
|
312
312
|
const input = screen.getByPlaceholderText('Search...');
|
|
313
313
|
|
|
314
314
|
expect(input).toHaveFocus();
|
|
@@ -316,7 +316,7 @@ describe('Select', () => {
|
|
|
316
316
|
|
|
317
317
|
it('renders controls with fallback id', async () => {
|
|
318
318
|
const { container } = render(<Select {...props} />);
|
|
319
|
-
|
|
319
|
+
openSelect(container);
|
|
320
320
|
|
|
321
321
|
const button = screen.getByRole('button');
|
|
322
322
|
const options = screen.getByRole('listbox');
|
|
@@ -327,7 +327,7 @@ describe('Select', () => {
|
|
|
327
327
|
|
|
328
328
|
it('renders controls with passed id', async () => {
|
|
329
329
|
const { container } = render(<Select id="my-select-component" {...props} />);
|
|
330
|
-
|
|
330
|
+
openSelect(container);
|
|
331
331
|
|
|
332
332
|
const button = screen.getByRole('button');
|
|
333
333
|
const options = screen.getByRole('listbox');
|
|
@@ -338,7 +338,7 @@ describe('Select', () => {
|
|
|
338
338
|
|
|
339
339
|
it('renders button with correct aria-controls attribute', async () => {
|
|
340
340
|
const { container } = render(<Select {...props} search onSearchChange={jest.fn()} />);
|
|
341
|
-
|
|
341
|
+
openSelect(container);
|
|
342
342
|
|
|
343
343
|
const button = screen.getByRole('button');
|
|
344
344
|
const options = screen.getByRole('listbox');
|
|
@@ -353,11 +353,11 @@ describe('Select', () => {
|
|
|
353
353
|
it('navigates to the next item', async () => {
|
|
354
354
|
const { container } = render(<Select {...props} />);
|
|
355
355
|
|
|
356
|
-
|
|
356
|
+
openSelect(container);
|
|
357
357
|
|
|
358
358
|
expect(screen.queryByRole('listbox')).toHaveFocus();
|
|
359
359
|
|
|
360
|
-
|
|
360
|
+
userEvent.keyboard('[ArrowDown]');
|
|
361
361
|
|
|
362
362
|
await waitFor(() => {
|
|
363
363
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
@@ -372,17 +372,17 @@ describe('Select', () => {
|
|
|
372
372
|
/>,
|
|
373
373
|
);
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
openSelect(container);
|
|
376
376
|
|
|
377
377
|
expect(screen.queryByRole('listbox')).toHaveFocus();
|
|
378
378
|
|
|
379
|
-
|
|
379
|
+
userEvent.keyboard('[ArrowDown]');
|
|
380
380
|
|
|
381
381
|
await waitFor(() => {
|
|
382
382
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
383
383
|
});
|
|
384
384
|
|
|
385
|
-
|
|
385
|
+
userEvent.keyboard('[ArrowDown]');
|
|
386
386
|
|
|
387
387
|
await waitFor(() => {
|
|
388
388
|
expect(screen.queryByRole('option', { name: 'boi' })).toHaveFocus();
|
|
@@ -392,17 +392,17 @@ describe('Select', () => {
|
|
|
392
392
|
it('cannot navigate past the first list item', async () => {
|
|
393
393
|
const { container } = render(<Select {...props} />);
|
|
394
394
|
|
|
395
|
-
|
|
395
|
+
openSelect(container);
|
|
396
396
|
|
|
397
397
|
expect(screen.queryByRole('listbox')).toHaveFocus();
|
|
398
398
|
|
|
399
|
-
|
|
399
|
+
userEvent.keyboard('[ArrowUp]');
|
|
400
400
|
|
|
401
401
|
await waitFor(() => {
|
|
402
402
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
-
|
|
405
|
+
userEvent.keyboard('[ArrowUp]');
|
|
406
406
|
|
|
407
407
|
await waitFor(() => {
|
|
408
408
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
@@ -412,29 +412,29 @@ describe('Select', () => {
|
|
|
412
412
|
it('cannot navigate past the last list item', async () => {
|
|
413
413
|
const { container } = render(<Select {...props} />);
|
|
414
414
|
|
|
415
|
-
|
|
415
|
+
openSelect(container);
|
|
416
416
|
|
|
417
417
|
expect(screen.queryByRole('listbox')).toHaveFocus();
|
|
418
418
|
|
|
419
|
-
|
|
419
|
+
userEvent.keyboard('[ArrowDown]');
|
|
420
420
|
|
|
421
421
|
await waitFor(() => {
|
|
422
422
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
423
423
|
});
|
|
424
424
|
|
|
425
|
-
|
|
425
|
+
userEvent.keyboard('[ArrowDown]');
|
|
426
426
|
|
|
427
427
|
await waitFor(() => {
|
|
428
428
|
expect(screen.queryByRole('option', { name: 'dawg' })).toHaveFocus();
|
|
429
429
|
});
|
|
430
430
|
|
|
431
|
-
|
|
431
|
+
userEvent.keyboard('[ArrowDown]');
|
|
432
432
|
|
|
433
433
|
await waitFor(() => {
|
|
434
434
|
expect(screen.queryByRole('option', { name: 'boi' })).toHaveFocus();
|
|
435
435
|
});
|
|
436
436
|
|
|
437
|
-
|
|
437
|
+
userEvent.keyboard('[ArrowDown]');
|
|
438
438
|
|
|
439
439
|
await waitFor(() => {
|
|
440
440
|
expect(screen.queryByRole('option', { name: 'boi' })).toHaveFocus();
|
|
@@ -445,11 +445,11 @@ describe('Select', () => {
|
|
|
445
445
|
it('maintains focus on search but visually indicates which item is focused with keyboard navigation and selects it on enter', async () => {
|
|
446
446
|
const { container } = render(<Select {...props} search />);
|
|
447
447
|
|
|
448
|
-
|
|
448
|
+
openSelect(container);
|
|
449
449
|
|
|
450
450
|
expect(screen.queryByPlaceholderText('Search...')).toHaveFocus();
|
|
451
451
|
|
|
452
|
-
|
|
452
|
+
userEvent.keyboard('[ArrowDown]');
|
|
453
453
|
|
|
454
454
|
await waitFor(() => {
|
|
455
455
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveClass(
|
|
@@ -460,7 +460,7 @@ describe('Select', () => {
|
|
|
460
460
|
|
|
461
461
|
expect(screen.queryByPlaceholderText('Search...')).toHaveFocus();
|
|
462
462
|
|
|
463
|
-
|
|
463
|
+
userEvent.keyboard('[ArrowDown]');
|
|
464
464
|
|
|
465
465
|
await waitFor(() => {
|
|
466
466
|
expect(screen.queryByRole('option', { name: 'dawg' })).toHaveClass(
|
|
@@ -471,7 +471,7 @@ describe('Select', () => {
|
|
|
471
471
|
|
|
472
472
|
expect(screen.queryByPlaceholderText('Search...')).toHaveFocus();
|
|
473
473
|
|
|
474
|
-
|
|
474
|
+
userEvent.keyboard('[Enter]');
|
|
475
475
|
|
|
476
476
|
expect(props.onChange).toHaveBeenCalledWith({ label: 'dawg', value: 1 });
|
|
477
477
|
});
|
|
@@ -486,11 +486,11 @@ describe('Select', () => {
|
|
|
486
486
|
it('navigates to the next item', async () => {
|
|
487
487
|
const { container } = render(<Select {...props} />);
|
|
488
488
|
|
|
489
|
-
|
|
489
|
+
openSelect(container);
|
|
490
490
|
|
|
491
491
|
await expect(screen.findByRole('dialog')).resolves.toBeInTheDocument();
|
|
492
492
|
|
|
493
|
-
|
|
493
|
+
userEvent.keyboard('[ArrowDown]');
|
|
494
494
|
|
|
495
495
|
await waitFor(() => {
|
|
496
496
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
@@ -505,17 +505,17 @@ describe('Select', () => {
|
|
|
505
505
|
/>,
|
|
506
506
|
);
|
|
507
507
|
|
|
508
|
-
|
|
508
|
+
openSelect(container);
|
|
509
509
|
|
|
510
510
|
await expect(screen.findByRole('dialog')).resolves.toBeInTheDocument();
|
|
511
511
|
|
|
512
|
-
|
|
512
|
+
userEvent.keyboard('[ArrowDown]');
|
|
513
513
|
|
|
514
514
|
await waitFor(() => {
|
|
515
515
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
516
516
|
});
|
|
517
517
|
|
|
518
|
-
|
|
518
|
+
userEvent.keyboard('[ArrowDown]');
|
|
519
519
|
|
|
520
520
|
await waitFor(() => {
|
|
521
521
|
expect(screen.queryByRole('option', { name: 'boi' })).toHaveFocus();
|
|
@@ -525,17 +525,17 @@ describe('Select', () => {
|
|
|
525
525
|
it('cannot navigate past the first list item', async () => {
|
|
526
526
|
const { container } = render(<Select {...props} />);
|
|
527
527
|
|
|
528
|
-
|
|
528
|
+
openSelect(container);
|
|
529
529
|
|
|
530
530
|
await expect(screen.findByRole('dialog')).resolves.toBeInTheDocument();
|
|
531
531
|
|
|
532
|
-
|
|
532
|
+
userEvent.keyboard('[ArrowUp]');
|
|
533
533
|
|
|
534
534
|
await waitFor(() => {
|
|
535
535
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
536
536
|
});
|
|
537
537
|
|
|
538
|
-
|
|
538
|
+
userEvent.keyboard('[ArrowUp]');
|
|
539
539
|
|
|
540
540
|
await waitFor(() => {
|
|
541
541
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
@@ -545,29 +545,29 @@ describe('Select', () => {
|
|
|
545
545
|
it('cannot navigate past the last list item', async () => {
|
|
546
546
|
const { container } = render(<Select {...props} />);
|
|
547
547
|
|
|
548
|
-
|
|
548
|
+
openSelect(container);
|
|
549
549
|
|
|
550
550
|
await expect(screen.findByRole('dialog')).resolves.toBeInTheDocument();
|
|
551
551
|
|
|
552
|
-
|
|
552
|
+
userEvent.keyboard('[ArrowDown]');
|
|
553
553
|
|
|
554
554
|
await waitFor(() => {
|
|
555
555
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveFocus();
|
|
556
556
|
});
|
|
557
557
|
|
|
558
|
-
|
|
558
|
+
userEvent.keyboard('[ArrowDown]');
|
|
559
559
|
|
|
560
560
|
await waitFor(() => {
|
|
561
561
|
expect(screen.queryByRole('option', { name: 'dawg' })).toHaveFocus();
|
|
562
562
|
});
|
|
563
563
|
|
|
564
|
-
|
|
564
|
+
userEvent.keyboard('[ArrowDown]');
|
|
565
565
|
|
|
566
566
|
await waitFor(() => {
|
|
567
567
|
expect(screen.queryByRole('option', { name: 'boi' })).toHaveFocus();
|
|
568
568
|
});
|
|
569
569
|
|
|
570
|
-
|
|
570
|
+
userEvent.keyboard('[ArrowDown]');
|
|
571
571
|
|
|
572
572
|
await waitFor(() => {
|
|
573
573
|
expect(screen.queryByRole('option', { name: 'boi' })).toHaveFocus();
|
|
@@ -582,13 +582,13 @@ describe('Select', () => {
|
|
|
582
582
|
it('visually indicates which item is focused with keyboard navigation and selects it on enter', async () => {
|
|
583
583
|
const { container } = render(<Select {...props} search />);
|
|
584
584
|
|
|
585
|
-
|
|
585
|
+
openSelect(container);
|
|
586
586
|
|
|
587
587
|
await waitFor(() => {
|
|
588
588
|
expect(screen.queryByPlaceholderText('Search...')).not.toHaveFocus();
|
|
589
589
|
});
|
|
590
590
|
|
|
591
|
-
|
|
591
|
+
userEvent.keyboard('[ArrowDown]');
|
|
592
592
|
|
|
593
593
|
await waitFor(() => {
|
|
594
594
|
expect(screen.queryByRole('option', { name: 'yo' })).toHaveClass(
|
|
@@ -599,7 +599,7 @@ describe('Select', () => {
|
|
|
599
599
|
|
|
600
600
|
expect(screen.queryByPlaceholderText('Search...')).not.toHaveFocus();
|
|
601
601
|
|
|
602
|
-
|
|
602
|
+
userEvent.keyboard('[ArrowDown]');
|
|
603
603
|
|
|
604
604
|
await waitFor(() => {
|
|
605
605
|
expect(screen.queryByRole('option', { name: 'dawg' })).toHaveClass(
|
|
@@ -610,7 +610,7 @@ describe('Select', () => {
|
|
|
610
610
|
|
|
611
611
|
expect(screen.queryByPlaceholderText('Search...')).not.toHaveFocus();
|
|
612
612
|
|
|
613
|
-
|
|
613
|
+
userEvent.keyboard('[Enter]');
|
|
614
614
|
|
|
615
615
|
expect(props.onChange).toHaveBeenCalledWith({ label: 'dawg', value: 1 });
|
|
616
616
|
});
|
package/src/test-utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { render, screen } from '@testing-library/react';
|
|
2
|
-
import
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
3
4
|
|
|
4
5
|
import Tooltip from '.';
|
|
5
6
|
|
|
@@ -25,7 +26,7 @@ describe('Tooltip Component', () => {
|
|
|
25
26
|
expect(tooltip).toHaveAttribute('aria-hidden', 'true');
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
it('should render the tooltip label when closed',
|
|
29
|
+
it('should render the tooltip label when closed', () => {
|
|
29
30
|
render(
|
|
30
31
|
<Tooltip label="Test Tooltip">
|
|
31
32
|
<span>Hover me</span>
|
|
@@ -35,11 +36,11 @@ describe('Tooltip Component', () => {
|
|
|
35
36
|
const tooltip = screen.getByRole('tooltip', { hidden: true });
|
|
36
37
|
expect(tooltip).toHaveAttribute('aria-hidden', 'true');
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
userEvent.hover(triggerElement);
|
|
39
40
|
expect(tooltip).toHaveAttribute('aria-hidden', 'false');
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
it('should display the tooltip on mouse hover',
|
|
43
|
+
it('should display the tooltip on mouse hover', () => {
|
|
43
44
|
render(
|
|
44
45
|
<Tooltip label="Test Tooltip">
|
|
45
46
|
<span>Hover over me!</span>
|
|
@@ -47,13 +48,13 @@ describe('Tooltip Component', () => {
|
|
|
47
48
|
);
|
|
48
49
|
const triggerElement = screen.getByText('Hover over me!');
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
userEvent.hover(triggerElement);
|
|
51
52
|
|
|
52
53
|
const tooltipElement = screen.queryByText('Test Tooltip');
|
|
53
54
|
expect(tooltipElement).toBeVisible();
|
|
54
55
|
});
|
|
55
56
|
|
|
56
|
-
it('should hide the tooltip on mouse out',
|
|
57
|
+
it('should hide the tooltip on mouse out', () => {
|
|
57
58
|
render(
|
|
58
59
|
<Tooltip label="Test Tooltip">
|
|
59
60
|
<span>Hover me</span>
|
|
@@ -61,16 +62,16 @@ describe('Tooltip Component', () => {
|
|
|
61
62
|
);
|
|
62
63
|
const triggerElement = screen.getByText('Hover me');
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
userEvent.hover(triggerElement);
|
|
65
66
|
let tooltipElement = screen.getByText('Test Tooltip');
|
|
66
67
|
expect(tooltipElement).toBeVisible();
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
userEvent.unhover(triggerElement);
|
|
69
70
|
tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
70
71
|
expect(tooltipElement).toHaveAttribute('aria-hidden', 'true');
|
|
71
72
|
});
|
|
72
73
|
|
|
73
|
-
it('should display the tooltip on focus',
|
|
74
|
+
it('should display the tooltip on focus', () => {
|
|
74
75
|
render(
|
|
75
76
|
<Tooltip label="Test Tooltip">
|
|
76
77
|
<span>Focus me</span>
|
|
@@ -78,12 +79,12 @@ describe('Tooltip Component', () => {
|
|
|
78
79
|
);
|
|
79
80
|
const triggerElement = screen.getByText('Focus me');
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
userEvent.tab();
|
|
82
83
|
const tooltipElement = screen.getByText('Test Tooltip');
|
|
83
84
|
expect(tooltipElement).toBeVisible();
|
|
84
85
|
});
|
|
85
86
|
|
|
86
|
-
it('should hide the tooltip on blur',
|
|
87
|
+
it('should hide the tooltip on blur', () => {
|
|
87
88
|
render(
|
|
88
89
|
<Tooltip label="Test Tooltip">
|
|
89
90
|
<span>Focus me</span>
|
|
@@ -91,16 +92,16 @@ describe('Tooltip Component', () => {
|
|
|
91
92
|
);
|
|
92
93
|
const triggerElement = screen.getByText('Focus me');
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
userEvent.tab();
|
|
95
96
|
let tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
96
97
|
expect(tooltipElement).toBeVisible();
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
userEvent.tab({ shift: true }); // Blur the element
|
|
99
100
|
tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
100
101
|
expect(tooltipElement).toHaveAttribute('aria-hidden', 'true');
|
|
101
102
|
});
|
|
102
103
|
|
|
103
|
-
it('should display the tooltip when the "children" prop is a React element',
|
|
104
|
+
it('should display the tooltip when the "children" prop is a React element', () => {
|
|
104
105
|
render(
|
|
105
106
|
<Tooltip label="Test Tooltip">
|
|
106
107
|
<button type="button">Click me</button>
|
|
@@ -108,7 +109,7 @@ describe('Tooltip Component', () => {
|
|
|
108
109
|
);
|
|
109
110
|
const triggerElement = screen.getByText('Click me');
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
userEvent.hover(triggerElement);
|
|
112
113
|
const tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
113
114
|
expect(tooltipElement).toBeVisible();
|
|
114
115
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { within } from '@testing-library/react';
|
|
2
|
-
import
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
3
|
|
|
4
4
|
import { Status } from '../common';
|
|
5
5
|
import { mockMatchMedia, render, screen, waitFor, waitForElementToBeRemoved } from '../test-utils';
|
|
@@ -9,8 +9,6 @@ import { TEST_IDS as UPLOAD_BUTTON_TEST_IDS } from './uploadButton/UploadButton'
|
|
|
9
9
|
import { TEST_IDS as UPLOAD_ITEM_TEST_IDS } from './uploadItem/UploadItem';
|
|
10
10
|
import { act } from 'react';
|
|
11
11
|
|
|
12
|
-
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTimeAsync });
|
|
13
|
-
|
|
14
12
|
mockMatchMedia();
|
|
15
13
|
|
|
16
14
|
describe('UploadInput', () => {
|
|
@@ -60,7 +58,10 @@ describe('UploadInput', () => {
|
|
|
60
58
|
renderComponent({ ...props, onFilesChange });
|
|
61
59
|
|
|
62
60
|
const input = screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput);
|
|
63
|
-
|
|
61
|
+
userEvent.upload(input, [pngFile, jpgFile]);
|
|
62
|
+
await act(async () => {
|
|
63
|
+
await jest.runOnlyPendingTimersAsync();
|
|
64
|
+
});
|
|
64
65
|
|
|
65
66
|
expect(props.onUploadFile).toHaveBeenCalledTimes(1);
|
|
66
67
|
expect(onFilesChange).toHaveBeenCalledTimes(2);
|
|
@@ -115,7 +116,7 @@ describe('UploadInput', () => {
|
|
|
115
116
|
expect(screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput)).toHaveAttribute('multiple');
|
|
116
117
|
|
|
117
118
|
const input = screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput);
|
|
118
|
-
|
|
119
|
+
userEvent.upload(input, [pngFile, jpgFile]);
|
|
119
120
|
|
|
120
121
|
await waitFor(() => {
|
|
121
122
|
expect(props.onUploadFile).toHaveBeenCalledTimes(2);
|
|
@@ -243,11 +244,11 @@ describe('UploadInput', () => {
|
|
|
243
244
|
});
|
|
244
245
|
|
|
245
246
|
const input = screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput);
|
|
246
|
-
|
|
247
|
+
userEvent.upload(input, [pngFile, jpgFile]);
|
|
247
248
|
|
|
248
249
|
const pngFile2 = new File(['foo2'], 'foo2.png', { type: 'image/png' });
|
|
249
250
|
const jpgFile2 = new File(['foo2'], 'foo2.jpg', { type: 'image/jpeg' });
|
|
250
|
-
|
|
251
|
+
userEvent.upload(input, [pngFile2, jpgFile2]);
|
|
251
252
|
|
|
252
253
|
await waitFor(() => {
|
|
253
254
|
expect(screen.getByText(maxFilesReachedMessage)).toBeInTheDocument();
|
|
@@ -273,7 +274,7 @@ describe('UploadInput', () => {
|
|
|
273
274
|
const input = screen.getByTestId(UPLOAD_BUTTON_TEST_IDS.uploadInput);
|
|
274
275
|
const pngFile2 = new File(['foo2'], 'foo2.png', { type: 'image/png' });
|
|
275
276
|
|
|
276
|
-
|
|
277
|
+
userEvent.upload(input, [pngFile, jpgFile, pngFile2]);
|
|
277
278
|
|
|
278
279
|
await waitFor(() => {
|
|
279
280
|
expect(screen.getByText(defaultMaxFilesReachedMessage)).toBeInTheDocument();
|
|
@@ -304,7 +305,7 @@ describe('UploadInput', () => {
|
|
|
304
305
|
const overSizedFile = new File([''], 'testFile.png', { type: 'image/png' });
|
|
305
306
|
Object.defineProperty(overSizedFile, 'size', { value: twoKbInBytes });
|
|
306
307
|
|
|
307
|
-
|
|
308
|
+
userEvent.upload(input, [overSizedFile]);
|
|
308
309
|
await waitFor(() => {
|
|
309
310
|
expect(screen.getByText(sizeLimitErrorMessage)).toBeInTheDocument();
|
|
310
311
|
});
|