@loadsmart/loadsmart-ui 5.11.0 → 5.11.1

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.
Files changed (56) hide show
  1. package/dist/index.js +490 -340
  2. package/dist/index.js.map +1 -1
  3. package/dist/testing/SelectEvent/SelectEvent.d.ts +2 -0
  4. package/dist/testing/index.js +1 -1
  5. package/dist/testing/index.js.map +1 -1
  6. package/package.json +8 -7
  7. package/src/common/CloseButton/CloseButton.tsx +11 -7
  8. package/src/common/SelectionWrapper.tsx +7 -7
  9. package/src/components/Accordion/Accordion.tsx +28 -22
  10. package/src/components/Banner/Banner.tsx +2 -2
  11. package/src/components/Breadcrumbs/Breadcrumb.tsx +3 -2
  12. package/src/components/Breadcrumbs/Breadcrumbs.tsx +1 -1
  13. package/src/components/Button/Button.tsx +20 -17
  14. package/src/components/Calendar/Calendar.tsx +8 -4
  15. package/src/components/Calendar/PickerModeToggle.tsx +6 -3
  16. package/src/components/Calendar/Pickers/DayPicker.tsx +1 -1
  17. package/src/components/Calendar/Pickers/MonthPicker.tsx +1 -1
  18. package/src/components/Calendar/Pickers/PickerButton.tsx +39 -29
  19. package/src/components/Calendar/Pickers/YearPicker.tsx +1 -1
  20. package/src/components/Card/Card.tsx +9 -6
  21. package/src/components/Card/CardTitle.tsx +3 -4
  22. package/src/components/Checkbox/Checkbox.tsx +26 -14
  23. package/src/components/Dialog/Dialog.tsx +5 -5
  24. package/src/components/DragDropFile/styles.tsx +11 -6
  25. package/src/components/Drawer/Drawer.tsx +6 -6
  26. package/src/components/Dropdown/DropdownMenu.tsx +28 -15
  27. package/src/components/Dropdown/DropdownTrigger.tsx +34 -24
  28. package/src/components/HighlightMatch/HighlightMatch.tsx +1 -2
  29. package/src/components/Label/Label.tsx +3 -3
  30. package/src/components/Link/Link.tsx +13 -9
  31. package/src/components/Loaders/LoadingBar.tsx +2 -2
  32. package/src/components/Modal/Modal.tsx +12 -7
  33. package/src/components/ProgressBar/ProgressBar.tsx +6 -4
  34. package/src/components/Radio/Radio.tsx +19 -11
  35. package/src/components/Section/Section.tsx +8 -6
  36. package/src/components/Select/Select.test.tsx +161 -161
  37. package/src/components/Select/SelectEmpty.tsx +5 -4
  38. package/src/components/Select/SelectTrigger.tsx +11 -6
  39. package/src/components/SideNavigation/Menu/Menu.tsx +3 -3
  40. package/src/components/SideNavigation/Menu/MenuBaseItem.tsx +5 -4
  41. package/src/components/SideNavigation/Menu/MenuExpandable.tsx +3 -2
  42. package/src/components/Steps/ProgressSteps/ProgressStep.tsx +39 -31
  43. package/src/components/Switch/Switch.tsx +18 -6
  44. package/src/components/Table/Table.tsx +2 -2
  45. package/src/components/Tabs/Tabs.tsx +32 -26
  46. package/src/components/Tag/Tag.tsx +44 -35
  47. package/src/components/TextField/TextField.tsx +22 -15
  48. package/src/components/Textarea/Textarea.tsx +22 -17
  49. package/src/components/Toast/Toast.tsx +3 -3
  50. package/src/components/ToggleGroup/Toggle.tsx +7 -7
  51. package/src/components/ToggleGroup/ToggleGroup.stories.tsx +14 -12
  52. package/src/components/Tooltip/Tooltip.tsx +22 -20
  53. package/src/components/TopNavigation/Menu/MenuItemDropdown.tsx +1 -1
  54. package/src/components/TopNavigation/OpenSideNavButton/OpenSideNavButton.tsx +1 -1
  55. package/src/styles/font.tsx +3 -3
  56. package/src/testing/SelectEvent/SelectEvent.ts +87 -45
@@ -6,7 +6,7 @@ import { render } from '@testing-library/react'
6
6
  import { SelectableKeyTypeOptions, Fruit, FRUITS, USERS } from './Select.fixtures'
7
7
  import * as stories from './Select.stories'
8
8
  import generator from '../../tests/generator'
9
- import renderer, { screen, fire, waitFor } from '../../tests/renderer'
9
+ import renderer, { act, screen, fire, waitFor } from '../../tests/renderer'
10
10
  import selectEvent from '../../testing/SelectEvent'
11
11
 
12
12
  import type { SelectProps, Option } from './Select.types'
@@ -22,24 +22,6 @@ const {
22
22
  CreatableAsync,
23
23
  } = composeStories(stories)
24
24
 
25
- async function expandSelect(waitForOptionsToBeAvailable = false) {
26
- await waitFor(() => {
27
- expect(screen.getByTestId('select-trigger-handle')).toBeEnabled()
28
- })
29
-
30
- fire.click(screen.getByTestId('select-trigger-handle'))
31
-
32
- await waitFor(() => {
33
- screen.queryByRole('listbox')
34
- })
35
-
36
- if (waitForOptionsToBeAvailable) {
37
- await waitFor(() => {
38
- screen.getAllByRole('option')
39
- })
40
- }
41
- }
42
-
43
25
  describe('Select', () => {
44
26
  describe('Generic', () => {
45
27
  const setup = (overrides: Partial<SelectProps>) =>
@@ -55,23 +37,28 @@ describe('Select', () => {
55
37
  it('does not expand with the available options when search input is clicked', () => {
56
38
  setup({ disabled: true })
57
39
 
58
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
59
- expect(screen.getByTestId('select-trigger-search-field')).toBeDisabled()
40
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
60
41
 
61
- fire.click(screen.getByTestId('select-trigger-search-field'))
42
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
43
+ expect(searchInput).toBeDisabled()
62
44
 
63
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
45
+ fire.click(searchInput)
46
+
47
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
64
48
  })
65
49
 
66
50
  it('does not expand with the available options when trigger handle is clicked', () => {
67
51
  setup({ disabled: true })
68
52
 
69
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
70
- expect(screen.getByTestId('select-trigger-handle')).toBeDisabled()
53
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
54
+ const triggerHandle = screen.getByTestId('select-trigger-handle')
71
55
 
72
- fire.click(screen.getByTestId('select-trigger-handle'))
56
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
57
+ expect(triggerHandle).toBeDisabled()
73
58
 
74
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
59
+ fire.click(triggerHandle)
60
+
61
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
75
62
  })
76
63
  })
77
64
 
@@ -79,40 +66,38 @@ describe('Select', () => {
79
66
  it('expands with the available options when search input is clicked', async () => {
80
67
  setup({})
81
68
 
82
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
83
-
84
69
  await waitFor(() => {
85
70
  expect(screen.getByTestId('select-trigger-handle')).toBeEnabled()
86
71
  })
87
72
 
88
- fire.click(screen.getByTestId('select-trigger-search-field'))
73
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
89
74
 
90
- expect(await screen.findByRole('listbox')).toBeInTheDocument()
75
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
91
76
 
92
- await waitFor(() => {
93
- screen.getAllByRole('option')
94
- })
77
+ fire.click(searchInput)
95
78
 
96
- const items = screen.getAllByRole('option')
79
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(true)
80
+
81
+ const options = await selectEvent.getOptions(searchInput)
97
82
 
98
83
  for (let i = 0; i < FRUITS.length; i++) {
99
- expect(items[i]).toHaveTextContent(FRUITS[i].label)
84
+ expect(options[i]).toHaveTextContent(FRUITS[i].label)
100
85
  }
101
86
  })
102
87
 
103
88
  it('expands with the available options when trigger handle is clicked', async () => {
104
89
  setup({})
105
90
 
106
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
91
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
107
92
 
108
- await expandSelect(true)
93
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
109
94
 
110
- expect(screen.getByRole('listbox')).toBeInTheDocument()
95
+ await selectEvent.expand(searchInput)
111
96
 
112
- const items = screen.getAllByRole('option')
97
+ const options = await selectEvent.getOptions(searchInput)
113
98
 
114
99
  for (let i = 0; i < FRUITS.length; i++) {
115
- expect(items[i]).toHaveTextContent(FRUITS[i].label)
100
+ expect(options[i]).toHaveTextContent(FRUITS[i].label)
116
101
  }
117
102
  })
118
103
 
@@ -120,17 +105,19 @@ describe('Select', () => {
120
105
  render(<Playground options={undefined} />)
121
106
 
122
107
  const searchInput = screen.getByLabelText('Select your favorite fruit')
108
+ const triggerHandle = screen.getByTestId('select-trigger-handle')
123
109
 
124
- expect(screen.getByTestId('select-trigger-handle')).toBeDisabled()
125
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
110
+ expect(triggerHandle).toBeDisabled()
111
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
126
112
 
127
113
  userEvent.type(searchInput, generator.word())
128
114
 
129
115
  await selectEvent.expand(searchInput)
130
116
 
117
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(true)
118
+
131
119
  await waitFor(() => {
132
- expect(screen.getByTestId('select-trigger-handle')).toBeEnabled()
133
- expect(screen.queryByRole('listbox')).toBeInTheDocument()
120
+ expect(triggerHandle).toBeEnabled()
134
121
  })
135
122
  })
136
123
 
@@ -157,33 +144,32 @@ describe('Select', () => {
157
144
  }
158
145
  })
159
146
 
160
- it('expands when user enters a search string', async () => {
147
+ it('expands when user enters a search string', () => {
161
148
  setup({})
162
149
 
163
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
150
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
151
+
152
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
164
153
 
165
- fire.change(screen.getByTestId('select-trigger-search-field'), { target: { value: 'foo' } })
154
+ fire.change(searchInput, { target: { value: 'foo' } })
166
155
 
167
- await waitFor(() => expect(screen.queryByRole('listbox')).toBeInTheDocument())
156
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(true)
168
157
  })
169
158
 
170
159
  it('filters the available options when user enters a search string', async () => {
171
160
  setup({})
172
161
 
173
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
162
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
163
+ const searchedFruit = generator.pickone([...FRUITS])
174
164
 
175
- const indexToSearch = generator.natural({ min: 0, max: FRUITS.length - 1 })
176
- fire.change(screen.getByTestId('select-trigger-search-field'), {
177
- target: { value: FRUITS[indexToSearch].label },
165
+ fire.change(searchInput, {
166
+ target: { value: searchedFruit.label },
178
167
  })
179
168
 
180
- let items = [] as HTMLElement[]
181
- await waitFor(() => {
182
- items = screen.getAllByRole('option')
183
- })
169
+ const options = await selectEvent.getOptions(searchInput)
184
170
 
185
- expect(items.length).toBeGreaterThanOrEqual(1)
186
- expect(items[0]).toHaveTextContent(FRUITS[indexToSearch].label)
171
+ expect(options.length).toBeGreaterThanOrEqual(1)
172
+ expect(options[0]).toHaveTextContent(searchedFruit.label)
187
173
  })
188
174
 
189
175
  it('calls blur when focus is lost', async () => {
@@ -242,10 +228,11 @@ describe('Select', () => {
242
228
  })
243
229
 
244
230
  it('updates selected item after the initially selected item changes', async () => {
245
- const selectedFruit = generator.pickone([...FRUITS])
231
+ const [selectedFruit, newSelectedFruit] = generator.pickset([...FRUITS], 2)
246
232
  const props = {
247
233
  value: selectedFruit as Option,
248
234
  }
235
+
249
236
  const { rerender } = render(<Playground {...props} />)
250
237
 
251
238
  const searchInput = screen.getByLabelText('Select your favorite fruit')
@@ -256,7 +243,6 @@ describe('Select', () => {
256
243
 
257
244
  expect(selectedOptions[0]).toHaveTextContent(selectedFruit.label)
258
245
 
259
- const newSelectedFruit = generator.pickone([...FRUITS])
260
246
  const newProps = {
261
247
  value: newSelectedFruit as Option,
262
248
  }
@@ -316,22 +302,18 @@ describe('Select', () => {
316
302
 
317
303
  describe('Multi selection', () => {
318
304
  it('selects multiple options', async () => {
319
- const [firstOption, secondOption] = FRUITS
305
+ const [firstOption, secondOption] = generator.pickset([...FRUITS], 2)
306
+
320
307
  setup({ multiple: true })
321
308
 
322
309
  const searchInput = screen.getByLabelText('Select your favorite fruit')
323
310
  await selectEvent.select(firstOption.label, searchInput)
324
311
 
325
- await waitFor(() => {
326
- expect(screen.getByTestId('select-trigger-clear-counter')).toHaveTextContent('1')
327
- })
328
-
329
- expect(screen.getByTitle('1 selected option')).toBeInTheDocument()
312
+ expect(screen.getByTitle('1 selected option')).toHaveTextContent('1')
330
313
 
331
314
  await selectEvent.select(secondOption.label, searchInput)
332
315
 
333
- expect(screen.getByTestId('select-trigger-clear-counter')).toHaveTextContent('2')
334
- expect(screen.getByTitle('2 selected options')).toBeInTheDocument()
316
+ expect(screen.getByTitle('2 selected options')).toHaveTextContent('2')
335
317
 
336
318
  const selectedOptions = await selectEvent.getSelectedOptions(searchInput)
337
319
  expect(selectedOptions).toHaveLength(2)
@@ -343,15 +325,14 @@ describe('Select', () => {
343
325
  })
344
326
 
345
327
  it('unselects a selected option keeping selected the others', async () => {
346
- const [firstOption, secondOption, thirdOption] = FRUITS
328
+ const [firstOption, secondOption, thirdOption] = generator.pickset([...FRUITS], 3)
329
+
347
330
  setup({ multiple: true, value: [firstOption, secondOption, thirdOption] as Option[] })
348
331
 
349
332
  const searchInput = screen.getByLabelText('Select your favorite fruit')
350
333
  expect(await selectEvent.getSelectedOptions(searchInput)).toHaveLength(3)
351
334
 
352
- await waitFor(() => {
353
- expect(screen.getByTestId('select-trigger-clear-counter')).toHaveTextContent('3')
354
- })
335
+ expect(screen.getByTitle('3 selected options')).toHaveTextContent('3')
355
336
 
356
337
  await selectEvent.unselect(secondOption.label, searchInput)
357
338
 
@@ -365,21 +346,19 @@ describe('Select', () => {
365
346
  })
366
347
 
367
348
  it('clears all selections when clicking the counter close button', async () => {
368
- const [firstOption, secondOption, thirdOption] = FRUITS
349
+ const [firstOption, secondOption, thirdOption] = generator.pickset([...FRUITS], 3)
369
350
  setup({ multiple: true, value: [firstOption, secondOption, thirdOption] as Option[] })
370
351
 
371
352
  const searchInput = screen.getByLabelText('Select your favorite fruit')
372
353
  expect(await selectEvent.getSelectedOptions(searchInput)).toHaveLength(3)
373
354
 
374
- await waitFor(() => {
375
- expect(screen.getByTestId('select-trigger-clear-counter')).toHaveTextContent('3')
376
- })
355
+ expect(screen.getByTitle('3 selected options')).toHaveTextContent('3')
377
356
 
378
357
  await selectEvent.clear(searchInput)
379
358
 
380
359
  expect(screen.queryByTestId('select-trigger-clear-counter')).not.toBeInTheDocument()
381
360
 
382
- expect(screen.queryByRole('option', { selected: true })).not.toBeInTheDocument()
361
+ expect(await selectEvent.getSelectedOptions(searchInput)).toHaveLength(0)
383
362
  })
384
363
  })
385
364
  })
@@ -391,59 +370,59 @@ describe('Select', () => {
391
370
  it('expands with the available options when search input is clicked', async () => {
392
371
  setup({})
393
372
 
394
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
373
+ await waitFor(() => {
374
+ expect(screen.getByTestId('select-trigger-handle')).toBeEnabled()
375
+ })
395
376
 
396
- await expandSelect(true)
377
+ const searchInput = screen.getByLabelText('Select the project manager')
397
378
 
398
- expect(screen.getByRole('listbox')).toBeInTheDocument()
379
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
399
380
 
400
- const items = screen.getAllByRole('option')
381
+ fire.click(searchInput)
382
+
383
+ await waitFor(() => {
384
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(true)
385
+ })
386
+
387
+ const options = await selectEvent.getOptions(searchInput)
401
388
 
402
389
  for (let i = 0; i < USERS.length; i++) {
403
- expect(items[i]).toHaveTextContent(USERS[i].name)
390
+ expect(options[i]).toHaveTextContent(USERS[i].name)
404
391
  }
405
392
  })
406
393
 
407
394
  it('expands with the available options when trigger handle is clicked', async () => {
408
395
  setup({})
409
396
 
410
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
397
+ const searchInput = screen.getByLabelText('Select the project manager')
398
+
399
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
411
400
 
412
- await expandSelect(true)
401
+ await selectEvent.expand(searchInput)
413
402
 
414
- expect(screen.getByRole('listbox')).toBeInTheDocument()
403
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(true)
415
404
 
416
- const items = screen.getAllByRole('option')
405
+ const options = await selectEvent.getOptions(searchInput)
417
406
 
418
407
  for (let i = 0; i < USERS.length; i++) {
419
- expect(items[i]).toHaveTextContent(USERS[i].name)
408
+ expect(options[i]).toHaveTextContent(USERS[i].name)
420
409
  }
421
410
  })
422
411
 
423
412
  it('filters the available options when user enters a search string', async () => {
424
413
  setup({})
425
414
 
426
- expect(screen.queryByRole('listbox')).not.toBeInTheDocument()
415
+ const searchInput = screen.getByLabelText('Select the project manager')
416
+ const searchedUser = generator.pickone([...USERS])
427
417
 
428
- const indexToSearch = generator.natural({ min: 0, max: USERS.length - 1 })
429
- fire.change(screen.getByTestId('select-trigger-search-field'), {
430
- target: { value: USERS[indexToSearch].name },
418
+ fire.change(searchInput, {
419
+ target: { value: searchedUser.name },
431
420
  })
432
421
 
433
- await waitFor(() => screen.findByTestId('select-trigger-loading'))
422
+ const options = await selectEvent.getOptions(searchInput)
434
423
 
435
- let items = [] as HTMLElement[]
436
- await waitFor(
437
- () => {
438
- items = screen.getAllByRole('option')
439
- },
440
- {
441
- timeout: 2500,
442
- }
443
- )
444
-
445
- expect(items.length).toBe(1)
446
- expect(items[0]).toHaveTextContent(USERS[indexToSearch].name)
424
+ expect(options.length).toBe(1)
425
+ expect(options[0]).toHaveTextContent(searchedUser.name)
447
426
  })
448
427
  })
449
428
 
@@ -462,7 +441,8 @@ describe('Select', () => {
462
441
  async (props) => {
463
442
  setup(props)
464
443
 
465
- await expandSelect(true)
444
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
445
+ await selectEvent.expand(searchInput)
466
446
 
467
447
  const items = screen.getAllByTestId('custom-option')
468
448
  expect(items).toHaveLength(FRUITS.length)
@@ -474,28 +454,28 @@ describe('Select', () => {
474
454
  )
475
455
 
476
456
  it('overrides the option component with initial value', async () => {
477
- const [firstOption, secondOption] = FRUITS
478
- setup({ multiple: true, value: [firstOption, secondOption] as Option[] })
457
+ const selectedFruit = generator.pickone([...FRUITS])
479
458
 
480
- await expandSelect(true)
459
+ setup({ value: selectedFruit as Option })
460
+
461
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
462
+ await selectEvent.expand(searchInput)
481
463
 
482
- expect(screen.getAllByTestId('custom-option')).toHaveLength(2)
464
+ const customOptions = screen.getAllByTestId('custom-option')
465
+ expect(customOptions).toHaveLength(FRUITS.length)
483
466
 
484
- await waitFor(() => {
485
- expect(screen.getAllByTestId('custom-option')).toHaveLength(FRUITS.length)
486
- })
467
+ const selectedOptions = await selectEvent.getSelectedOptions(searchInput)
487
468
 
488
- const items = screen.getAllByTestId('custom-option')
489
- for (let i = 0; i < FRUITS.length; i++) {
490
- expect(items[i]).toHaveTextContent(getOptionText(FRUITS[i]))
491
- }
469
+ expect(selectedOptions).toHaveLength(1)
470
+ expect(selectedOptions[0]).toHaveTextContent(selectedFruit.label)
492
471
  })
493
472
 
494
473
  it('selects custom item clicked', async () => {
474
+ const selectedFruit = generator.pickone<Fruit>([...FRUITS])
475
+
495
476
  setup({})
496
477
 
497
478
  const searchInput = screen.getByLabelText('Select your favorite fruit')
498
- const selectedFruit = generator.pickone<Fruit>([...FRUITS])
499
479
  const optionText = getOptionText(selectedFruit)
500
480
 
501
481
  await selectEvent.select(optionText, searchInput)
@@ -507,11 +487,12 @@ describe('Select', () => {
507
487
  })
508
488
 
509
489
  it('selects multiple clicked custom items', async () => {
490
+ const SELECTED_OPTIONS_AMOUNT = 2
491
+ const options = generator.pickset([...FRUITS], SELECTED_OPTIONS_AMOUNT)
492
+
510
493
  setup({ multiple: true })
511
494
 
512
- const SELECTED_OPTIONS_AMOUNT = 2
513
495
  const searchInput = screen.getByLabelText('Select your favorite fruit')
514
- const options = generator.pickset([...FRUITS], SELECTED_OPTIONS_AMOUNT)
515
496
 
516
497
  for await (const option of options) {
517
498
  const optionText = getOptionText(option)
@@ -576,12 +557,17 @@ describe('Select', () => {
576
557
  })
577
558
 
578
559
  const searchInput = screen.getByLabelText('Select your favorite fruit')
579
- fire.change(searchInput, {
580
- target: { value: 'foo' },
560
+
561
+ await act(async () => {
562
+ fire.change(searchInput, {
563
+ target: { value: 'foo' },
564
+ })
565
+
566
+ const creatableOption = await screen.findByTestId('custom-creatable')
567
+
568
+ fire.click(creatableOption)
581
569
  })
582
570
 
583
- const creatableOption = await screen.findByTestId('custom-creatable')
584
- fire.click(creatableOption)
585
571
  expect(onCreate).toBeCalledWith('foo')
586
572
  }
587
573
  )
@@ -590,13 +576,11 @@ describe('Select', () => {
590
576
  describe('Creatable sync', () => {
591
577
  const setup = (overrides: Partial<SelectProps>) =>
592
578
  renderer(<CreatableSync {...overrides} />).render()
593
-
594
579
  it.each([[{ multiple: false }], [{ multiple: true }]])(
595
580
  'does not render the creatable option when onCreate callback is not provided - %s',
596
581
  async (args) => {
597
582
  setup({ onCreate: (null as unknown) as undefined, ...args })
598
583
 
599
- await expandSelect(true)
600
584
  const searchInput = screen.getByLabelText('Select your favorite fruit')
601
585
  fire.change(searchInput, {
602
586
  target: { value: 'foo' },
@@ -613,12 +597,10 @@ describe('Select', () => {
613
597
  'renders creatable option when onCreate callback is provided - %s',
614
598
  async (args) => {
615
599
  setup({ ...args })
616
-
617
600
  const searchInput = screen.getByLabelText('Select your favorite fruit')
618
601
  fire.change(searchInput, {
619
602
  target: { value: 'foo' },
620
603
  })
621
-
622
604
  await waitFor(() => {
623
605
  expect(screen.getByText('Add "foo"')).toBeInTheDocument()
624
606
  })
@@ -631,8 +613,8 @@ describe('Select', () => {
631
613
  setup({ ...args })
632
614
  const { label: availableOption } = generator.pickone([...FRUITS])
633
615
  const query = availableOption.slice(0, availableOption.length - 1)
634
-
635
616
  const searchInput = screen.getByLabelText('Select your favorite fruit')
617
+
636
618
  fire.change(searchInput, {
637
619
  target: { value: query },
638
620
  })
@@ -653,8 +635,8 @@ describe('Select', () => {
653
635
  })
654
636
  const { label: availableOption } = generator.pickone([...FRUITS])
655
637
  const query = availableOption.slice(0, availableOption.length - 1)
656
-
657
638
  const searchInput = screen.getByLabelText('Select your favorite fruit')
639
+
658
640
  fire.change(searchInput, {
659
641
  target: { value: query },
660
642
  })
@@ -673,8 +655,8 @@ describe('Select', () => {
673
655
  ...args,
674
656
  })
675
657
  const { label: availableOption } = generator.pickone([...FRUITS])
676
-
677
658
  const searchInput = screen.getByLabelText('Select your favorite fruit')
659
+
678
660
  fire.change(searchInput, {
679
661
  target: { value: availableOption },
680
662
  })
@@ -693,8 +675,9 @@ describe('Select', () => {
693
675
  ...args,
694
676
  })
695
677
  const { label: availableOption } = generator.pickone([...FRUITS])
678
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
696
679
 
697
- await expandSelect()
680
+ await selectEvent.expand(searchInput)
698
681
 
699
682
  await screen.findByLabelText(availableOption)
700
683
  await waitFor(() => {
@@ -708,14 +691,18 @@ describe('Select', () => {
708
691
  async (args) => {
709
692
  const onCreate = jest.fn()
710
693
  setup({ onCreate, ...args })
711
-
712
694
  const searchInput = screen.getByLabelText('Select your favorite fruit')
713
- fire.change(searchInput, {
714
- target: { value: 'foo' },
695
+
696
+ await act(async () => {
697
+ fire.change(searchInput, {
698
+ target: { value: 'foo' },
699
+ })
700
+
701
+ const creatableOption = await screen.findByText('Add "foo"')
702
+
703
+ fire.click(creatableOption)
715
704
  })
716
705
 
717
- const creatableOption = await screen.findByText('Add "foo"')
718
- fire.click(creatableOption)
719
706
  expect(onCreate).toBeCalledWith('foo')
720
707
  }
721
708
  )
@@ -732,11 +719,16 @@ describe('Select', () => {
732
719
  setup({ onCreate, onChange, ...args })
733
720
 
734
721
  const searchInput = screen.getByLabelText('Select your favorite fruit')
735
- fire.change(searchInput, {
736
- target: { value: query },
722
+
723
+ await act(async () => {
724
+ fire.change(searchInput, {
725
+ target: { value: query },
726
+ })
727
+
728
+ const creatableOption = await screen.findByText(`Add "${query}"`)
729
+
730
+ fire.click(creatableOption)
737
731
  })
738
- const creatableOption = await screen.findByText(`Add "${query}"`)
739
- fire.click(creatableOption)
740
732
 
741
733
  expect(onChange).toBeCalledWith({
742
734
  target: {
@@ -758,11 +750,16 @@ describe('Select', () => {
758
750
  setup({ onCreate, onChange, ...args })
759
751
 
760
752
  const searchInput = screen.getByLabelText('Select your favorite fruit')
761
- fire.change(searchInput, {
762
- target: { value: query },
753
+
754
+ await act(async () => {
755
+ fire.change(searchInput, {
756
+ target: { value: query },
757
+ })
758
+
759
+ const creatableOption = await screen.findByText(`Add "${query}"`)
760
+
761
+ fire.click(creatableOption)
763
762
  })
764
- const creatableOption = await screen.findByText(`Add "${query}"`)
765
- fire.click(creatableOption)
766
763
 
767
764
  expect(onChange).not.toBeCalled()
768
765
  }
@@ -783,13 +780,17 @@ describe('Select', () => {
783
780
  }),
784
781
  ]
785
782
  setup({ datasources, ...args })
786
-
787
783
  const searchInput = screen.getByLabelText('Select your favorite fruit')
788
- fire.change(searchInput, {
789
- target: { value: 'foo' },
784
+
785
+ await act(async () => {
786
+ fire.change(searchInput, {
787
+ target: { value: 'foo' },
788
+ })
789
+
790
+ const creatableOption = await screen.findByText('Add "foo"')
791
+
792
+ fire.click(creatableOption)
790
793
  })
791
- const creatableOption = await screen.findByText('Add "foo"')
792
- fire.click(creatableOption)
793
794
 
794
795
  await waitFor(() => {
795
796
  expect(dsFetch).toBeCalledTimes(2)
@@ -803,7 +804,8 @@ describe('Select', () => {
803
804
  async (args) => {
804
805
  setup({ ...args, isValidNewOption: true })
805
806
 
806
- await expandSelect(false)
807
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
808
+ await selectEvent.expand(searchInput)
807
809
 
808
810
  await waitFor(() => {
809
811
  expect(screen.getByText(/add ""/i)).toBeInTheDocument()
@@ -816,12 +818,12 @@ describe('Select', () => {
816
818
  async (args) => {
817
819
  setup({ ...args, isValidNewOption: true, createOptionPosition: 'first' })
818
820
 
819
- await expandSelect(true)
821
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
822
+ await selectEvent.expand(searchInput)
820
823
 
821
824
  await waitFor(() => {
822
825
  expect(screen.getByText(/add ""/i)).toBeInTheDocument()
823
826
  })
824
-
825
827
  expect(screen.getAllByTestId('dropdown-menu-item')[0]).toHaveTextContent(/add ""/i)
826
828
  }
827
829
  )
@@ -831,14 +833,13 @@ describe('Select', () => {
831
833
  async (args) => {
832
834
  setup({ ...args, isValidNewOption: true, createOptionPosition: 'last' })
833
835
 
834
- await expandSelect(true)
836
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
837
+ await selectEvent.expand(searchInput)
835
838
 
836
839
  await waitFor(() => {
837
840
  expect(screen.getByText(/add ""/i)).toBeInTheDocument()
838
841
  })
839
-
840
842
  const options = screen.getAllByTestId('dropdown-menu-item')
841
-
842
843
  expect(options[options.length - 1]).toHaveTextContent(/add ""/i)
843
844
  }
844
845
  )
@@ -851,9 +852,7 @@ describe('Select', () => {
851
852
  <Select.CreatableOption data-testid="custom-creatable">Add item</Select.CreatableOption>
852
853
  )
853
854
  }
854
-
855
855
  const value = generator.pickone([...FRUITS]) as Selectable
856
-
857
856
  setup({
858
857
  ...args,
859
858
  isValidNewOption: true,
@@ -864,7 +863,8 @@ describe('Select', () => {
864
863
  },
865
864
  })
866
865
 
867
- await expandSelect(true)
866
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
867
+ await selectEvent.expand(searchInput)
868
868
  expect(await screen.findByText(/add item/i)).toBeVisible()
869
869
  }
870
870
  )
@@ -875,7 +875,6 @@ describe('Select', () => {
875
875
  const CreatableOption = () => {
876
876
  return <Select.CreatableOption>Add item</Select.CreatableOption>
877
877
  }
878
-
879
878
  setup({
880
879
  ...args,
881
880
  isValidNewOption: true,
@@ -886,7 +885,8 @@ describe('Select', () => {
886
885
  },
887
886
  })
888
887
 
889
- await expandSelect(true)
888
+ const searchInput = screen.getByLabelText('Select your favorite fruit')
889
+ await selectEvent.expand(searchInput)
890
890
  expect(await screen.findByText(/add item/i)).toBeVisible()
891
891
  }
892
892
  )