@instructure/ui-drilldown 10.19.2-snapshot-2 → 10.19.2-snapshot-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +21 -21
  3. package/tsconfig.build.tsbuildinfo +1 -1
  4. package/es/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +0 -696
  5. package/es/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +0 -708
  6. package/es/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +0 -353
  7. package/es/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +0 -61
  8. package/es/Drilldown/__new-tests__/Drilldown.test.js +0 -1021
  9. package/lib/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +0 -698
  10. package/lib/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +0 -710
  11. package/lib/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +0 -355
  12. package/lib/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +0 -62
  13. package/lib/Drilldown/__new-tests__/Drilldown.test.js +0 -1022
  14. package/src/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.tsx +0 -633
  15. package/src/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.tsx +0 -774
  16. package/src/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.tsx +0 -351
  17. package/src/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.tsx +0 -59
  18. package/src/Drilldown/__new-tests__/Drilldown.test.tsx +0 -1005
  19. package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts +0 -2
  20. package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts.map +0 -1
  21. package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts +0 -2
  22. package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts.map +0 -1
  23. package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts +0 -2
  24. package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts.map +0 -1
  25. package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts +0 -2
  26. package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts.map +0 -1
  27. package/types/Drilldown/__new-tests__/Drilldown.test.d.ts +0 -2
  28. package/types/Drilldown/__new-tests__/Drilldown.test.d.ts.map +0 -1
@@ -1,633 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { render, screen, waitFor } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
-
28
- import userEvent from '@testing-library/user-event'
29
- import '@testing-library/jest-dom'
30
-
31
- import { Drilldown } from '../../index'
32
-
33
- describe('<Drilldown.Group />', () => {
34
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
35
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
36
-
37
- beforeEach(() => {
38
- // Mocking console to prevent test output pollution and expect for messages
39
- consoleWarningMock = vi
40
- .spyOn(console, 'warn')
41
- .mockImplementation(() => {}) as any
42
- consoleErrorMock = vi
43
- .spyOn(console, 'error')
44
- .mockImplementation(() => {}) as any
45
- })
46
-
47
- afterEach(() => {
48
- consoleWarningMock.mockRestore()
49
- consoleErrorMock.mockRestore()
50
- })
51
-
52
- it('should not allow de-selecting an option when selectableType = "single"', async () => {
53
- const options = ['one', 'two', 'three']
54
- const Example = ({ opts }: { opts: typeof options }) => {
55
- return (
56
- <Drilldown rootPageId="page0">
57
- <Drilldown.Page id="page0">
58
- <Drilldown.Group id="group0" selectableType="single">
59
- {opts.map((opt) => {
60
- return (
61
- <Drilldown.Option
62
- key={opt}
63
- value={opt}
64
- name={opt}
65
- id={opt}
66
- defaultSelected={opt === 'three'}
67
- data-testid={opt}
68
- >
69
- {opt}
70
- </Drilldown.Option>
71
- )
72
- })}
73
- </Drilldown.Group>
74
- </Drilldown.Page>
75
- </Drilldown>
76
- )
77
- }
78
-
79
- render(<Example opts={options} />)
80
-
81
- const selectedOption = screen.getByTestId('three')
82
-
83
- expect(selectedOption).toHaveAttribute('aria-checked', 'true')
84
-
85
- await userEvent.click(selectedOption)
86
-
87
- await waitFor(() => {
88
- const updatedSelectedOption = screen.getByTestId('three')
89
-
90
- expect(updatedSelectedOption).toHaveAttribute('aria-checked', 'true')
91
- })
92
- })
93
-
94
- it("shouldn't render non-DrilldownGroup children", async () => {
95
- render(
96
- <Drilldown rootPageId="page0">
97
- <Drilldown.Page id="page0">
98
- <Drilldown.Group id="group0">
99
- <div data-testid="testDiv">Div</div>
100
- </Drilldown.Group>
101
- </Drilldown.Page>
102
- </Drilldown>
103
- )
104
- const nonGroupChild = screen.queryByTestId('testDiv')
105
- const childText = screen.queryByText('Div')
106
-
107
- expect(nonGroupChild).not.toBeInTheDocument()
108
- expect(childText).not.toBeInTheDocument()
109
- })
110
-
111
- it('elementRef should return ref to the group', async () => {
112
- const elementRef = vi.fn()
113
- const { container } = render(
114
- <Drilldown rootPageId="page0">
115
- <Drilldown.Page id="page0">
116
- <Drilldown.Group id="group0" elementRef={elementRef}>
117
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
118
- </Drilldown.Group>
119
- </Drilldown.Page>
120
- </Drilldown>
121
- )
122
- const group = container.querySelector('#group0')
123
-
124
- expect(elementRef).toHaveBeenCalledWith(group)
125
- })
126
-
127
- describe('renderGroupTitle', () => {
128
- it('should display', async () => {
129
- render(
130
- <Drilldown rootPageId="page0">
131
- <Drilldown.Page id="page0">
132
- <Drilldown.Group id="group0" renderGroupTitle="Group Title">
133
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
134
- </Drilldown.Group>
135
- </Drilldown.Page>
136
- </Drilldown>
137
- )
138
- const title = screen.getByText('Group Title')
139
-
140
- expect(title).toBeInTheDocument()
141
- })
142
-
143
- it('should display, if function is provided', async () => {
144
- render(
145
- <Drilldown rootPageId="page0">
146
- <Drilldown.Page id="page0">
147
- <Drilldown.Group id="group0" renderGroupTitle={() => 'Group Title'}>
148
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
149
- </Drilldown.Group>
150
- </Drilldown.Page>
151
- </Drilldown>
152
- )
153
- const title = screen.getByText('Group Title')
154
-
155
- expect(title).toBeInTheDocument()
156
- })
157
- })
158
-
159
- describe('separators', () => {
160
- it("shouldn't display, when group is first and/or last item", async () => {
161
- const { container } = render(
162
- <Drilldown rootPageId="page0">
163
- <Drilldown.Page id="page0">
164
- <Drilldown.Group id="group0">
165
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
166
- </Drilldown.Group>
167
- </Drilldown.Page>
168
- </Drilldown>
169
- )
170
- const separators = container.querySelectorAll('[class$="-separator"]')
171
-
172
- expect(separators.length).toBe(0)
173
- })
174
-
175
- it('should display by default, if group is between other items', async () => {
176
- const { container } = render(
177
- <Drilldown rootPageId="page0">
178
- <Drilldown.Page id="page0">
179
- <Drilldown.Option id="option1">Option</Drilldown.Option>
180
- <Drilldown.Group id="group0">
181
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
182
- </Drilldown.Group>
183
- <Drilldown.Option id="option2">Option</Drilldown.Option>
184
- </Drilldown.Page>
185
- </Drilldown>
186
- )
187
- const separators = container.querySelectorAll('[class$="-separator"]')
188
-
189
- expect(separators.length).toBe(2)
190
- })
191
-
192
- it("shouldn't display extra separator between groups", async () => {
193
- const { container } = render(
194
- <Drilldown rootPageId="page0">
195
- <Drilldown.Page id="page0">
196
- <Drilldown.Option id="option1">Option</Drilldown.Option>
197
- <Drilldown.Group id="group0">
198
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
199
- </Drilldown.Group>
200
- <Drilldown.Group id="group1">
201
- <Drilldown.Option id="groupOption11">Option</Drilldown.Option>
202
- </Drilldown.Group>
203
- <Drilldown.Option id="option2">Option</Drilldown.Option>
204
- </Drilldown.Page>
205
- </Drilldown>
206
- )
207
- const separators = container.querySelectorAll('[class$="-separator"]')
208
-
209
- expect(separators.length).toBe(3)
210
- })
211
- })
212
-
213
- describe('disabled prop', () => {
214
- it('should disable all items in the group', async () => {
215
- const { container } = render(
216
- <Drilldown rootPageId="page0">
217
- <Drilldown.Page id="page0">
218
- <Drilldown.Option id="option1">Option</Drilldown.Option>
219
- <Drilldown.Group id="group0" disabled>
220
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
221
- <Drilldown.Option id="groupOption02">Option</Drilldown.Option>
222
- </Drilldown.Group>
223
- <Drilldown.Option id="option2">Option</Drilldown.Option>
224
- </Drilldown.Page>
225
- </Drilldown>
226
- )
227
- const disabledOption_1 = container.querySelector('#groupOption01')
228
- const disabledOption_2 = container.querySelector('#groupOption02')
229
- const option_1 = container.querySelector('#option1')
230
- const option_2 = container.querySelector('#option2')
231
-
232
- expect(disabledOption_1).toHaveAttribute('aria-disabled', 'true')
233
- expect(disabledOption_2).toHaveAttribute('aria-disabled', 'true')
234
- expect(option_1).not.toHaveAttribute('aria-disabled')
235
- expect(option_2).not.toHaveAttribute('aria-disabled')
236
- })
237
- })
238
-
239
- describe('role prop', () => {
240
- it('should be "group" by default', async () => {
241
- const { container } = render(
242
- <Drilldown rootPageId="page0">
243
- <Drilldown.Page id="page0">
244
- <Drilldown.Group id="group0">
245
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
246
- <Drilldown.Option id="groupOption02">Option</Drilldown.Option>
247
- </Drilldown.Group>
248
- </Drilldown.Page>
249
- </Drilldown>
250
- )
251
- const group = container.querySelector('#group0')
252
-
253
- expect(group).toHaveAttribute('role', 'group')
254
- })
255
-
256
- it('should render the group with passed role', async () => {
257
- const { container } = render(
258
- <Drilldown rootPageId="page0">
259
- <Drilldown.Page id="page0">
260
- <Drilldown.Group id="group0" role="menu">
261
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
262
- <Drilldown.Option id="groupOption02">Option</Drilldown.Option>
263
- </Drilldown.Group>
264
- </Drilldown.Page>
265
- </Drilldown>
266
- )
267
- const group = container.querySelector('#group0')
268
-
269
- expect(group).toHaveAttribute('role', 'menu')
270
- })
271
- })
272
-
273
- describe('as prop', () => {
274
- it('should inherit Drilldown\'s "ul" by default', async () => {
275
- const { container } = render(
276
- <Drilldown rootPageId="page0">
277
- <Drilldown.Page id="page0">
278
- <Drilldown.Group id="group0">
279
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
280
- <Drilldown.Option id="groupOption02">Option</Drilldown.Option>
281
- </Drilldown.Group>
282
- </Drilldown.Page>
283
- </Drilldown>
284
- )
285
- const drilldownContainer = container.querySelector(
286
- '[id^=Selectable_][id$=-list]'
287
- )!
288
- const group = container.querySelector('#group0')!
289
-
290
- expect(drilldownContainer.tagName).toBe('UL')
291
- expect(group.tagName).toBe('UL')
292
- })
293
-
294
- it('should inherit Drilldown\'s "as" prop', async () => {
295
- const { container } = render(
296
- <Drilldown rootPageId="page0" as="ol">
297
- <Drilldown.Page id="page0">
298
- <Drilldown.Group id="group0">
299
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
300
- <Drilldown.Option id="groupOption02">Option</Drilldown.Option>
301
- </Drilldown.Group>
302
- </Drilldown.Page>
303
- </Drilldown>
304
- )
305
- const drilldownContainer = container.querySelector(
306
- '[id^=Selectable_][id$=-list]'
307
- )!
308
- const group = container.querySelector('#group0')!
309
-
310
- expect(drilldownContainer.tagName).toBe('OL')
311
- expect(group.tagName).toBe('OL')
312
- })
313
-
314
- it('should render the group as other element', async () => {
315
- const { container } = render(
316
- <Drilldown rootPageId="page0">
317
- <Drilldown.Page id="page0">
318
- <Drilldown.Group id="group0" as="ol">
319
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
320
- <Drilldown.Option id="groupOption02">Option</Drilldown.Option>
321
- </Drilldown.Group>
322
- </Drilldown.Page>
323
- </Drilldown>
324
- )
325
- const drilldownContainer = container.querySelector(
326
- '[id^=Selectable_][id$=-list]'
327
- )!
328
- const group = container.querySelector('#group0')!
329
-
330
- expect(drilldownContainer.tagName).toBe('UL')
331
- expect(group.tagName).toBe('OL')
332
- })
333
- })
334
-
335
- describe('selectableType', () => {
336
- it('if not set, should render role="menuitem" options without icon by default', async () => {
337
- const { container } = render(
338
- <Drilldown rootPageId="page0">
339
- <Drilldown.Page id="page0">
340
- <Drilldown.Group id="group0">
341
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
342
- </Drilldown.Group>
343
- </Drilldown.Page>
344
- </Drilldown>
345
- )
346
- const icon = container.querySelector('svg[name="IconCheck"]')
347
- const groupOption = container.querySelector('#groupOption01')
348
-
349
- expect(icon).not.toBeInTheDocument()
350
- expect(groupOption).toHaveAttribute('role', 'menuitem')
351
- })
352
-
353
- it('value "single" should render role="menuitemradio" options with icon', async () => {
354
- const { container } = render(
355
- <Drilldown rootPageId="page0">
356
- <Drilldown.Page id="page0">
357
- <Drilldown.Group id="group0" selectableType="single">
358
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
359
- </Drilldown.Group>
360
- </Drilldown.Page>
361
- </Drilldown>
362
- )
363
- const icon = container.querySelector('svg[name="IconCheck"]')
364
- const groupOption = container.querySelector('#groupOption01')
365
-
366
- expect(icon).toBeInTheDocument()
367
- expect(groupOption).toHaveAttribute('role', 'menuitemradio')
368
- })
369
-
370
- it('value "multiple" should render role="menuitemcheckbox" options with icon', async () => {
371
- const { container } = render(
372
- <Drilldown rootPageId="page0">
373
- <Drilldown.Page id="page0">
374
- <Drilldown.Group id="group0" selectableType="multiple">
375
- <Drilldown.Option id="groupOption01">Option</Drilldown.Option>
376
- </Drilldown.Group>
377
- </Drilldown.Page>
378
- </Drilldown>
379
- )
380
- const icon = container.querySelector('svg[name="IconCheck"]')
381
- const groupOption = container.querySelector('#groupOption01')
382
-
383
- expect(icon).toBeInTheDocument()
384
- expect(groupOption).toHaveAttribute('role', 'menuitemcheckbox')
385
- })
386
- })
387
-
388
- describe('defaultSelected', () => {
389
- describe('if not provided', () => {
390
- it('all group options has to be unselected', async () => {
391
- render(
392
- <Drilldown rootPageId="page0">
393
- <Drilldown.Page id="page0">
394
- <Drilldown.Group id="group0" selectableType="multiple">
395
- <Drilldown.Option id="groupOption01" value={1}>
396
- Option
397
- </Drilldown.Option>
398
- <Drilldown.Option id="groupOption02" value={2}>
399
- Option
400
- </Drilldown.Option>
401
- <Drilldown.Option id="groupOption03" value={3}>
402
- Option
403
- </Drilldown.Option>
404
- </Drilldown.Group>
405
- </Drilldown.Page>
406
- </Drilldown>
407
- )
408
- const options = screen.getAllByRole('menuitemcheckbox')
409
- expect(options.length).toBe(3)
410
-
411
- options.forEach((option) => {
412
- expect(option).toHaveAttribute('aria-checked', 'false')
413
- })
414
- })
415
-
416
- it('all checkboxes should not be visible', async () => {
417
- const { container } = render(
418
- <Drilldown rootPageId="page0">
419
- <Drilldown.Page id="page0">
420
- <Drilldown.Group id="group0" selectableType="multiple">
421
- <Drilldown.Option id="groupOption01" value={1}>
422
- Option
423
- </Drilldown.Option>
424
- <Drilldown.Option id="groupOption02" value={2}>
425
- Option
426
- </Drilldown.Option>
427
- <Drilldown.Option id="groupOption03" value={3}>
428
- Option
429
- </Drilldown.Option>
430
- </Drilldown.Group>
431
- </Drilldown.Page>
432
- </Drilldown>
433
- )
434
- const icons = container.querySelectorAll('svg[name="IconCheck"]')
435
-
436
- expect(icons.length).toBe(3)
437
-
438
- icons.forEach((icon) => {
439
- expect(icon).not.toBeVisible()
440
- })
441
- })
442
- })
443
-
444
- describe('if provided', () => {
445
- it('all selected checkboxes should be visible', async () => {
446
- const selectedValues = ['item1', 'item3']
447
- const { container } = render(
448
- <Drilldown rootPageId="page0">
449
- <Drilldown.Page id="page0">
450
- <Drilldown.Group
451
- id="group0"
452
- selectableType="multiple"
453
- defaultSelected={selectedValues}
454
- >
455
- <Drilldown.Option id="groupOption01" value="item1">
456
- Option
457
- </Drilldown.Option>
458
- <Drilldown.Option id="groupOption02" value="item2">
459
- Option
460
- </Drilldown.Option>
461
- <Drilldown.Option id="groupOption03" value="item3">
462
- Option
463
- </Drilldown.Option>
464
- </Drilldown.Group>
465
- </Drilldown.Page>
466
- </Drilldown>
467
- )
468
- const options = screen.getAllByRole('menuitemcheckbox')
469
- const icons = container.querySelectorAll('svg')
470
-
471
- expect(options[0]).toHaveAttribute('aria-checked', 'true')
472
- expect(options[1]).toHaveAttribute('aria-checked', 'false')
473
- expect(options[2]).toHaveAttribute('aria-checked', 'true')
474
-
475
- expect(icons[0]).toBeVisible()
476
- expect(icons[1]).not.toBeVisible()
477
- expect(icons[2]).toBeVisible()
478
- })
479
-
480
- it("should be overridden by the Option's own defaultSelected", async () => {
481
- const selectedValues = ['item1', 'item3']
482
- render(
483
- <Drilldown rootPageId="page0">
484
- <Drilldown.Page id="page0">
485
- <Drilldown.Group
486
- id="group0"
487
- selectableType="multiple"
488
- defaultSelected={selectedValues}
489
- >
490
- <Drilldown.Option id="groupOption01" value="item1">
491
- Option
492
- </Drilldown.Option>
493
- <Drilldown.Option
494
- id="groupOption02"
495
- value="item2"
496
- defaultSelected={true}
497
- >
498
- Option
499
- </Drilldown.Option>
500
- <Drilldown.Option
501
- id="groupOption03"
502
- value="item3"
503
- defaultSelected={false}
504
- >
505
- Option
506
- </Drilldown.Option>
507
- </Drilldown.Group>
508
- </Drilldown.Page>
509
- </Drilldown>
510
- )
511
- const options = screen.getAllByRole('menuitemcheckbox')
512
-
513
- expect(options[0]).toHaveAttribute('aria-checked', 'true') // from the group,
514
- expect(options[1]).toHaveAttribute('aria-checked', 'true') // from own prop,
515
- expect(options[2]).toHaveAttribute('aria-checked', 'false') // override group's
516
- })
517
-
518
- describe('for "single" selectableType', () => {
519
- it('the selected option should be checked', async () => {
520
- const selectedValues = ['item2']
521
- render(
522
- <Drilldown rootPageId="page0">
523
- <Drilldown.Page id="page0">
524
- <Drilldown.Group
525
- id="group0"
526
- selectableType="single"
527
- defaultSelected={selectedValues}
528
- >
529
- <Drilldown.Option id="groupOption01" value="item1">
530
- Option
531
- </Drilldown.Option>
532
- <Drilldown.Option id="groupOption02" value="item2">
533
- Option
534
- </Drilldown.Option>
535
- <Drilldown.Option id="groupOption03" value="item3">
536
- Option
537
- </Drilldown.Option>
538
- </Drilldown.Group>
539
- </Drilldown.Page>
540
- </Drilldown>
541
- )
542
- const options = screen.getAllByRole('menuitemradio')
543
-
544
- expect(options[0]).toHaveAttribute('aria-checked', 'false')
545
- expect(options[1]).toHaveAttribute('aria-checked', 'true')
546
- expect(options[2]).toHaveAttribute('aria-checked', 'false')
547
- })
548
-
549
- it("should throw error if multiple items are selected, and shouldn't select any item", async () => {
550
- const selectedValues = ['item1', 'item3']
551
- render(
552
- <Drilldown rootPageId="page0">
553
- <Drilldown.Page id="page0">
554
- <Drilldown.Group
555
- id="group0"
556
- selectableType="single"
557
- defaultSelected={selectedValues}
558
- >
559
- <Drilldown.Option id="groupOption01" value="item1">
560
- Option
561
- </Drilldown.Option>
562
- <Drilldown.Option id="groupOption02" value="item2">
563
- Option
564
- </Drilldown.Option>
565
- <Drilldown.Option id="groupOption03" value="item3">
566
- Option
567
- </Drilldown.Option>
568
- </Drilldown.Group>
569
- </Drilldown.Page>
570
- </Drilldown>
571
- )
572
- const options = screen.getAllByRole('menuitemradio')
573
-
574
- expect(options[0]).toHaveAttribute('aria-checked', 'false')
575
- expect(options[1]).toHaveAttribute('aria-checked', 'false')
576
- expect(options[2]).toHaveAttribute('aria-checked', 'false')
577
-
578
- expect(consoleErrorMock).toHaveBeenCalled()
579
- })
580
- })
581
- })
582
- })
583
-
584
- describe('selection', () => {
585
- it('should fire "onSelect" callback', async () => {
586
- const onSelect = vi.fn()
587
- render(
588
- <Drilldown rootPageId="page0">
589
- <Drilldown.Page id="page0">
590
- <Drilldown.Group
591
- id="group0"
592
- selectableType="multiple"
593
- onSelect={onSelect}
594
- >
595
- <Drilldown.Option id="groupOption01" value="item1">
596
- Option 1
597
- </Drilldown.Option>
598
- <Drilldown.Option id="groupOption02" value="item2">
599
- Option 2
600
- </Drilldown.Option>
601
- <Drilldown.Option id="groupOption03" value="item3">
602
- Option 3
603
- </Drilldown.Option>
604
- </Drilldown.Group>
605
- </Drilldown.Page>
606
- </Drilldown>
607
- )
608
- const option2 = screen.getByText('Option 2')
609
-
610
- await userEvent.click(option2)
611
-
612
- await waitFor(() => {
613
- expect(onSelect).toHaveBeenCalledTimes(1)
614
-
615
- const args = onSelect.mock.calls[0][1]
616
- const event = onSelect.mock.calls[0][0]
617
-
618
- expect(args).toHaveProperty('value', ['item2'])
619
- expect(args).toHaveProperty('isSelected', true)
620
-
621
- expect(args.selectedOption).toBeInstanceOf(Object)
622
- expect(args.selectedOption.props).toHaveProperty('id', 'groupOption02')
623
- expect(args.selectedOption.props).toHaveProperty('value', 'item2')
624
-
625
- expect(args.drilldown).toBeInstanceOf(Object)
626
- expect(args.drilldown.props).toHaveProperty('role', 'menu')
627
- expect(args.drilldown.hide).toBeInstanceOf(Function)
628
-
629
- expect(event.target).toBe(option2)
630
- })
631
- })
632
- })
633
- })