@instructure/ui-drilldown 10.2.0 → 10.2.1-snapshot-0

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 (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +573 -0
  3. package/es/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +595 -0
  4. package/es/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +299 -0
  5. package/es/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +56 -0
  6. package/es/Drilldown/__new-tests__/Drilldown.test.js +818 -0
  7. package/lib/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +575 -0
  8. package/lib/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +598 -0
  9. package/lib/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +301 -0
  10. package/lib/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +58 -0
  11. package/lib/Drilldown/__new-tests__/Drilldown.test.js +819 -0
  12. package/package.json +25 -20
  13. package/src/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.tsx +634 -0
  14. package/src/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.tsx +774 -0
  15. package/src/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.tsx +352 -0
  16. package/src/Drilldown/{locator.ts → DrilldownSeparator/__new-tests__/DrilldownSeparator.test.tsx} +35 -3
  17. package/src/Drilldown/__new-tests__/Drilldown.test.tsx +979 -0
  18. package/tsconfig.build.json +3 -2
  19. package/tsconfig.build.tsbuildinfo +1 -1
  20. package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts +2 -0
  21. package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts.map +1 -0
  22. package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts +2 -0
  23. package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts.map +1 -0
  24. package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts +2 -0
  25. package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts.map +1 -0
  26. package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts +2 -0
  27. package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts.map +1 -0
  28. package/types/Drilldown/__new-tests__/Drilldown.test.d.ts +2 -0
  29. package/types/Drilldown/__new-tests__/Drilldown.test.d.ts.map +1 -0
  30. package/es/Drilldown/DrilldownLocator.js +0 -99
  31. package/es/Drilldown/locator.js +0 -27
  32. package/lib/Drilldown/DrilldownLocator.js +0 -106
  33. package/lib/Drilldown/locator.js +0 -37
  34. package/src/Drilldown/DrilldownLocator.ts +0 -104
  35. package/types/Drilldown/DrilldownLocator.d.ts +0 -7484
  36. package/types/Drilldown/DrilldownLocator.d.ts.map +0 -1
  37. package/types/Drilldown/locator.d.ts +0 -4
  38. package/types/Drilldown/locator.d.ts.map +0 -1
@@ -0,0 +1,774 @@
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
+ import React from 'react'
25
+ import { render, screen, waitFor } from '@testing-library/react'
26
+ import { vi } from 'vitest'
27
+ import userEvent from '@testing-library/user-event'
28
+ import '@testing-library/jest-dom'
29
+
30
+ import { IconCheckSolid } from '@instructure/ui-icons'
31
+
32
+ import { Drilldown } from '../../index'
33
+
34
+ describe('<Drilldown.Option />', () => {
35
+ let consoleWarningMock: ReturnType<typeof vi.spyOn>
36
+ let consoleErrorMock: ReturnType<typeof vi.spyOn>
37
+
38
+ beforeEach(() => {
39
+ // Mocking console to prevent test output pollution and expect for messages
40
+ consoleWarningMock = vi
41
+ .spyOn(console, 'warn')
42
+ .mockImplementation(() => {}) as any
43
+ consoleErrorMock = vi
44
+ .spyOn(console, 'error')
45
+ .mockImplementation(() => {}) as any
46
+ })
47
+
48
+ afterEach(() => {
49
+ consoleWarningMock.mockRestore()
50
+ consoleErrorMock.mockRestore()
51
+ })
52
+
53
+ it('should allow setting "selected" property on Options', async () => {
54
+ render(
55
+ <Drilldown rootPageId="page0">
56
+ <Drilldown.Page id="page0">
57
+ <Drilldown.Group id="group0">
58
+ <Drilldown.Option id="groupOption01">Option - 1</Drilldown.Option>
59
+ <Drilldown.Option selected id="groupOption02">
60
+ Option - 2
61
+ </Drilldown.Option>
62
+ <Drilldown.Option id="groupOption03">Option - 3</Drilldown.Option>
63
+ <Drilldown.Option id="groupOption04">Option - 4</Drilldown.Option>
64
+ </Drilldown.Group>
65
+ </Drilldown.Page>
66
+ </Drilldown>
67
+ )
68
+ const selectedOption = screen.getByLabelText('Option - 2')
69
+
70
+ expect(selectedOption).toBeInTheDocument()
71
+ expect(selectedOption).toHaveAttribute('id', 'groupOption02')
72
+ expect(selectedOption).toHaveAttribute('aria-checked', 'true')
73
+ })
74
+
75
+ describe('id prop', () => {
76
+ it('should throw warning the id is not provided', async () => {
77
+ render(
78
+ <Drilldown rootPageId="page0">
79
+ <Drilldown.Page id="page0">
80
+ {/* @ts-expect-error: Testing behavior when `id` is missing */}
81
+ <Drilldown.Option>Option1</Drilldown.Option>
82
+ </Drilldown.Page>
83
+ </Drilldown>
84
+ )
85
+ const expectedErrorMessage =
86
+ "Warning: Drilldown.Option without id won't be rendered. It is needed to internally track the options."
87
+
88
+ expect(consoleWarningMock).toHaveBeenCalledWith(
89
+ expect.stringContaining(expectedErrorMessage),
90
+ expect.any(String)
91
+ )
92
+ })
93
+
94
+ it('should throw warning the id is duplicated', async () => {
95
+ render(
96
+ <Drilldown rootPageId="page0">
97
+ <Drilldown.Page id="page0">
98
+ <Drilldown.Option id="option1">Option1</Drilldown.Option>
99
+ <Drilldown.Option id="option1">Option2</Drilldown.Option>
100
+ </Drilldown.Page>
101
+ </Drilldown>
102
+ )
103
+ const expectedErrorMessage =
104
+ 'Warning: Duplicate id: "option1"! Make sure all options have unique ids, otherwise they won\'t be rendered.'
105
+
106
+ expect(consoleWarningMock).toHaveBeenCalledWith(
107
+ expect.stringContaining(expectedErrorMessage),
108
+ expect.any(String)
109
+ )
110
+ })
111
+
112
+ it('should not render the options with duplicated id', async () => {
113
+ render(
114
+ <Drilldown rootPageId="page0">
115
+ <Drilldown.Page id="page0">
116
+ <Drilldown.Option id="option1">Option1</Drilldown.Option>
117
+ <Drilldown.Option id="option1">Option2</Drilldown.Option>
118
+ <Drilldown.Option id="option1">Option3</Drilldown.Option>
119
+ </Drilldown.Page>
120
+ </Drilldown>
121
+ )
122
+ const menuitems = screen.queryAllByRole('menuitem')
123
+ const option = screen.queryByText('Option2')
124
+
125
+ expect(menuitems.length).toBe(0)
126
+ expect(option).not.toBeInTheDocument()
127
+ })
128
+ })
129
+
130
+ describe('children function prop', () => {
131
+ it('should throw warning if it returns nothing', async () => {
132
+ render(
133
+ <Drilldown rootPageId="page0">
134
+ <Drilldown.Page id="page0">
135
+ <Drilldown.Option id="option1">{() => null}</Drilldown.Option>
136
+ </Drilldown.Page>
137
+ </Drilldown>
138
+ )
139
+ const expectedErrorMessage =
140
+ 'Warning: There are no "children" prop provided for option with id: "option1", so it won\'t be rendered.'
141
+
142
+ expect(consoleWarningMock).toHaveBeenCalledWith(
143
+ expect.stringContaining(expectedErrorMessage),
144
+ expect.any(String)
145
+ )
146
+ })
147
+
148
+ it('should provide props as parameters', async () => {
149
+ const childrenFunction = vi.fn(() => 'Option')
150
+
151
+ render(
152
+ <Drilldown rootPageId="page0">
153
+ <Drilldown.Page id="page0">
154
+ <Drilldown.Option id="option1">{childrenFunction}</Drilldown.Option>
155
+ </Drilldown.Page>
156
+ </Drilldown>
157
+ )
158
+
159
+ expect(childrenFunction).toHaveBeenCalledWith({
160
+ id: 'option1',
161
+ variant: 'default',
162
+ isSelected: false
163
+ })
164
+ })
165
+ })
166
+
167
+ describe('elementRef prop', () => {
168
+ it('should give back to ref for the option wrapper (Options.Item)', async () => {
169
+ const elementRef = vi.fn()
170
+ const { container } = render(
171
+ <Drilldown rootPageId="page0">
172
+ <Drilldown.Page id="page0">
173
+ <Drilldown.Option id="option1" elementRef={elementRef}>
174
+ Option
175
+ </Drilldown.Option>
176
+ </Drilldown.Page>
177
+ </Drilldown>
178
+ )
179
+ const option = container.querySelector('li')
180
+
181
+ expect(elementRef).toHaveBeenCalledWith(option)
182
+ })
183
+ })
184
+
185
+ describe('subPageId prop', () => {
186
+ it('should display arrow icon', async () => {
187
+ const { container } = render(
188
+ <Drilldown rootPageId="page0">
189
+ <Drilldown.Page id="page0">
190
+ <Drilldown.Option id="option1" subPageId="page1">
191
+ Option
192
+ </Drilldown.Option>
193
+ </Drilldown.Page>
194
+ </Drilldown>
195
+ )
196
+ const icon = container.querySelector('svg')
197
+
198
+ expect(icon).toBeInTheDocument()
199
+ expect(icon).toHaveAttribute('name', 'IconArrowOpenEnd')
200
+ })
201
+
202
+ it('should indicate subpage fo SR', async () => {
203
+ render(
204
+ <Drilldown rootPageId="page0">
205
+ <Drilldown.Page id="page0">
206
+ <Drilldown.Option id="option1" subPageId="page1">
207
+ Option
208
+ </Drilldown.Option>
209
+ </Drilldown.Page>
210
+ </Drilldown>
211
+ )
212
+ const option = screen.getByLabelText('Option')
213
+
214
+ expect(option).toHaveAttribute('role', 'button')
215
+ expect(option).toHaveAttribute('aria-haspopup', 'true')
216
+ })
217
+ })
218
+
219
+ describe('disabled prop', () => {
220
+ it('should mark option as disabled for SR', async () => {
221
+ render(
222
+ <Drilldown rootPageId="page0">
223
+ <Drilldown.Page id="page0">
224
+ <Drilldown.Option id="option1" disabled>
225
+ Option
226
+ </Drilldown.Option>
227
+ </Drilldown.Page>
228
+ </Drilldown>
229
+ )
230
+ const option = screen.getByLabelText('Option')
231
+
232
+ expect(option).toHaveAttribute('aria-disabled', 'true')
233
+ })
234
+ })
235
+
236
+ describe('href prop', () => {
237
+ it('should display option as link', async () => {
238
+ render(
239
+ <Drilldown rootPageId="page0">
240
+ <Drilldown.Page id="page0">
241
+ <Drilldown.Option id="option1" href="/helloWorld">
242
+ Option
243
+ </Drilldown.Option>
244
+ </Drilldown.Page>
245
+ </Drilldown>
246
+ )
247
+ const option = screen.getByLabelText('Option')
248
+
249
+ expect(option.tagName).toBe('A')
250
+ expect(option).toHaveAttribute('href', '/helloWorld')
251
+ })
252
+
253
+ it('should throw warning if subPageId is provided too', async () => {
254
+ render(
255
+ <Drilldown rootPageId="page0">
256
+ <Drilldown.Page id="page0">
257
+ <Drilldown.Option id="option1" href="/helloWorld" subPageId="page1">
258
+ Option
259
+ </Drilldown.Option>
260
+ </Drilldown.Page>
261
+ </Drilldown>
262
+ )
263
+ const option = screen.getByLabelText('Option')
264
+ const expectedErrorMessage =
265
+ 'Warning: Drilldown.Option with id "option1" has subPageId, so it will ignore the "href" property.'
266
+
267
+ expect(consoleWarningMock).toHaveBeenCalledWith(
268
+ expect.stringContaining(expectedErrorMessage),
269
+ expect.any(String)
270
+ )
271
+
272
+ expect(option.tagName).not.toBe('A')
273
+ expect(option).not.toHaveAttribute('href')
274
+ })
275
+
276
+ it('should throw warning if option is in selectable group', async () => {
277
+ render(
278
+ <Drilldown rootPageId="page0">
279
+ <Drilldown.Page id="page0">
280
+ <Drilldown.Group id="group0" selectableType="multiple">
281
+ <Drilldown.Option id="groupOption01" href="/helloWorld">
282
+ Option
283
+ </Drilldown.Option>
284
+ </Drilldown.Group>
285
+ </Drilldown.Page>
286
+ </Drilldown>
287
+ )
288
+ const option = screen.getByLabelText('Option')
289
+ const expectedErrorMessage =
290
+ 'Warning: Drilldown.Option with id "groupOption01" is in a selectable group, so it will ignore the "href" property.'
291
+
292
+ expect(consoleWarningMock).toHaveBeenCalledWith(
293
+ expect.stringContaining(expectedErrorMessage),
294
+ expect.any(String)
295
+ )
296
+
297
+ expect(option.tagName).not.toBe('A')
298
+ expect(option).not.toHaveAttribute('href')
299
+ })
300
+ })
301
+
302
+ describe('as prop', () => {
303
+ it('should render option as `li` by default', async () => {
304
+ render(
305
+ <Drilldown rootPageId="page0">
306
+ <Drilldown.Page id="page0">
307
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
308
+ </Drilldown.Page>
309
+ </Drilldown>
310
+ )
311
+ const option = screen.getByLabelText('Option')
312
+ const wrapper = option.parentElement
313
+
314
+ expect(option).toHaveAttribute('id', 'option1')
315
+ expect(wrapper?.tagName).toBe('LI')
316
+ })
317
+
318
+ it('should force option to be `li` while the parent is "ul" or "ol"', async () => {
319
+ render(
320
+ <Drilldown rootPageId="page0" as="ol">
321
+ <Drilldown.Page id="page0">
322
+ <Drilldown.Option id="option1" as="div">
323
+ Option
324
+ </Drilldown.Option>
325
+ </Drilldown.Page>
326
+ </Drilldown>
327
+ )
328
+ const option = screen.getByLabelText('Option')
329
+ const wrapper = option.parentElement
330
+
331
+ expect(option).toHaveAttribute('id', 'option1')
332
+ expect(wrapper?.tagName).toBe('LI')
333
+ })
334
+
335
+ it('should render option as specified html element, when the parent in non-list element', async () => {
336
+ render(
337
+ <Drilldown rootPageId="page0" as="div">
338
+ <Drilldown.Page id="page0">
339
+ <Drilldown.Option id="option1" as="div">
340
+ Option
341
+ </Drilldown.Option>
342
+ </Drilldown.Page>
343
+ </Drilldown>
344
+ )
345
+ const option = screen.getByLabelText('Option')
346
+ const wrapper = option.parentElement
347
+
348
+ expect(option).toHaveAttribute('id', 'option1')
349
+ expect(wrapper?.tagName).toBe('DIV')
350
+ })
351
+ })
352
+
353
+ describe('role prop', () => {
354
+ it('should be "menuitem" by default', async () => {
355
+ render(
356
+ <Drilldown rootPageId="page0">
357
+ <Drilldown.Page id="page0">
358
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
359
+ </Drilldown.Page>
360
+ </Drilldown>
361
+ )
362
+ const option = screen.getByLabelText('Option')
363
+
364
+ expect(option).toHaveAttribute('role', 'menuitem')
365
+ })
366
+
367
+ it('should be applied on prop', async () => {
368
+ render(
369
+ <Drilldown rootPageId="page0">
370
+ <Drilldown.Page id="page0">
371
+ <Drilldown.Option id="option1" role="presentation">
372
+ Option
373
+ </Drilldown.Option>
374
+ </Drilldown.Page>
375
+ </Drilldown>
376
+ )
377
+ const option = screen.getByLabelText('Option')
378
+
379
+ expect(option).toHaveAttribute('role', 'presentation')
380
+ })
381
+ })
382
+
383
+ describe('renderLabelInfo prop', () => {
384
+ it('should display tag next to the label', async () => {
385
+ const { container } = render(
386
+ <Drilldown rootPageId="page0">
387
+ <Drilldown.Page id="page0">
388
+ <Drilldown.Option id="option1" renderLabelInfo="Info">
389
+ Option
390
+ </Drilldown.Option>
391
+ </Drilldown.Page>
392
+ </Drilldown>
393
+ )
394
+ const tag = container.querySelector('[class$="optionLabelInfo"]')
395
+
396
+ expect(tag).toBeInTheDocument()
397
+ expect(tag).toHaveTextContent('Info')
398
+ })
399
+
400
+ it('as function should have option props as params', async () => {
401
+ const infoFunction = vi.fn(() => 'Info')
402
+ render(
403
+ <Drilldown rootPageId="page0">
404
+ <Drilldown.Page id="page0">
405
+ <Drilldown.Option id="option1" renderLabelInfo={infoFunction}>
406
+ Option
407
+ </Drilldown.Option>
408
+ </Drilldown.Page>
409
+ </Drilldown>
410
+ )
411
+
412
+ expect(infoFunction).toHaveBeenCalledWith({
413
+ variant: 'default',
414
+ vAlign: 'start',
415
+ as: 'li',
416
+ role: 'menuitem',
417
+ isSelected: false
418
+ })
419
+ })
420
+ })
421
+
422
+ describe('renderBeforeLabel prop', () => {
423
+ it('should display icon before the label', async () => {
424
+ const { container } = render(
425
+ <Drilldown rootPageId="page0">
426
+ <Drilldown.Page id="page0">
427
+ <Drilldown.Option
428
+ id="option1"
429
+ renderBeforeLabel={<IconCheckSolid />}
430
+ >
431
+ Option
432
+ </Drilldown.Option>
433
+ </Drilldown.Page>
434
+ </Drilldown>
435
+ )
436
+ const icon = container.querySelector('svg')
437
+
438
+ expect(icon).toBeInTheDocument()
439
+ expect(icon).toHaveAttribute('name', 'IconCheck')
440
+ })
441
+
442
+ it('as function should have option props as params', async () => {
443
+ const beforeLabelFunction = vi.fn(() => <IconCheckSolid />)
444
+ render(
445
+ <Drilldown rootPageId="page0">
446
+ <Drilldown.Page id="page0">
447
+ <Drilldown.Option
448
+ id="option1"
449
+ renderBeforeLabel={beforeLabelFunction}
450
+ >
451
+ Option
452
+ </Drilldown.Option>
453
+ </Drilldown.Page>
454
+ </Drilldown>
455
+ )
456
+
457
+ expect(beforeLabelFunction).toHaveBeenCalledWith(
458
+ expect.objectContaining({
459
+ variant: 'default',
460
+ vAlign: 'start',
461
+ as: 'li',
462
+ role: 'menuitem',
463
+ isSelected: false
464
+ }),
465
+ expect.any(Object)
466
+ )
467
+ })
468
+
469
+ it('should throw warning if it is in selectable group', async () => {
470
+ render(
471
+ <Drilldown rootPageId="page0">
472
+ <Drilldown.Page id="page0">
473
+ <Drilldown.Group id="group1" selectableType="multiple">
474
+ <Drilldown.Option id="groupOption1" renderBeforeLabel="Before">
475
+ Option
476
+ </Drilldown.Option>
477
+ </Drilldown.Group>
478
+ </Drilldown.Page>
479
+ </Drilldown>
480
+ )
481
+ const expectedErrorMessage =
482
+ 'Warning: The prop "renderBeforeLabel" is reserved on item with id: "groupOption1". When this option is a selectable member of a Drilldown.Group, selection indicator will render before the label.'
483
+
484
+ expect(consoleWarningMock).toHaveBeenCalledWith(
485
+ expect.stringContaining(expectedErrorMessage),
486
+ expect.any(String)
487
+ )
488
+ })
489
+ })
490
+
491
+ describe('renderAfterLabel prop', () => {
492
+ it('should display icon before the label', async () => {
493
+ const { container } = render(
494
+ <Drilldown rootPageId="page0">
495
+ <Drilldown.Page id="page0">
496
+ <Drilldown.Option
497
+ id="option1"
498
+ renderAfterLabel={<IconCheckSolid />}
499
+ >
500
+ Option
501
+ </Drilldown.Option>
502
+ </Drilldown.Page>
503
+ </Drilldown>
504
+ )
505
+ const icon = container.querySelector('svg')
506
+
507
+ expect(icon).toBeInTheDocument()
508
+ expect(icon).toHaveAttribute('name', 'IconCheck')
509
+ })
510
+
511
+ it('as function should have option props as params', async () => {
512
+ const beforeLabelFunction = vi.fn(() => <IconCheckSolid />)
513
+ render(
514
+ <Drilldown rootPageId="page0">
515
+ <Drilldown.Page id="page0">
516
+ <Drilldown.Option
517
+ id="option1"
518
+ renderAfterLabel={beforeLabelFunction}
519
+ >
520
+ Option
521
+ </Drilldown.Option>
522
+ </Drilldown.Page>
523
+ </Drilldown>
524
+ )
525
+
526
+ expect(beforeLabelFunction).toHaveBeenCalledWith(
527
+ expect.objectContaining({
528
+ variant: 'default',
529
+ vAlign: 'start',
530
+ as: 'li',
531
+ role: 'menuitem',
532
+ isSelected: false
533
+ }),
534
+ expect.any(Object)
535
+ )
536
+ })
537
+
538
+ it('should throw warning if it has subPageId', async () => {
539
+ render(
540
+ <Drilldown rootPageId="page0">
541
+ <Drilldown.Page id="page0">
542
+ <Drilldown.Option
543
+ id="option1"
544
+ subPageId="page1"
545
+ renderAfterLabel="after"
546
+ >
547
+ Option
548
+ </Drilldown.Option>
549
+ </Drilldown.Page>
550
+ </Drilldown>
551
+ )
552
+ const expectedErrorMessage =
553
+ 'Warning: The prop "renderAfterLabel" is reserved on item with id: "option1". When it has "subPageId" provided, a navigation arrow will render after the label.'
554
+
555
+ expect(consoleWarningMock).toHaveBeenCalledWith(
556
+ expect.stringContaining(expectedErrorMessage),
557
+ expect.any(String)
558
+ )
559
+ })
560
+ })
561
+
562
+ describe('description prop', () => {
563
+ it('should display description under the option', async () => {
564
+ render(
565
+ <Drilldown rootPageId="page0">
566
+ <Drilldown.Page id="page0">
567
+ <Drilldown.Option id="option1" description="This is a description.">
568
+ Option
569
+ </Drilldown.Option>
570
+ </Drilldown.Page>
571
+ </Drilldown>
572
+ )
573
+ const description = screen.getByText('This is a description.')
574
+
575
+ expect(description).toBeInTheDocument()
576
+ })
577
+
578
+ it('as a function should display description under the option', async () => {
579
+ render(
580
+ <Drilldown rootPageId="page0">
581
+ <Drilldown.Page id="page0">
582
+ <Drilldown.Option
583
+ id="option1"
584
+ description={() => 'This is a description.'}
585
+ >
586
+ Option
587
+ </Drilldown.Option>
588
+ </Drilldown.Page>
589
+ </Drilldown>
590
+ )
591
+ const description = screen.getByText('This is a description.')
592
+
593
+ expect(description).toBeInTheDocument()
594
+ })
595
+ })
596
+
597
+ describe('descriptionRole prop', () => {
598
+ it('should set the role of description', async () => {
599
+ render(
600
+ <Drilldown rootPageId="page0">
601
+ <Drilldown.Page id="page0">
602
+ <Drilldown.Option
603
+ id="option1"
604
+ description="This is a description."
605
+ descriptionRole="button"
606
+ >
607
+ Option
608
+ </Drilldown.Option>
609
+ </Drilldown.Page>
610
+ </Drilldown>
611
+ )
612
+ const description = screen.getByText('This is a description.')
613
+
614
+ expect(description).toHaveAttribute('role', 'button')
615
+ })
616
+ })
617
+
618
+ describe('onOptionClick callback', () => {
619
+ it('should fire on click with correct params', async () => {
620
+ const onOptionClick = vi.fn()
621
+ render(
622
+ <Drilldown rootPageId="page0">
623
+ <Drilldown.Page id="page0">
624
+ <Drilldown.Option id="option1" onOptionClick={onOptionClick}>
625
+ Option
626
+ </Drilldown.Option>
627
+ </Drilldown.Page>
628
+ </Drilldown>
629
+ )
630
+ const option = screen.getByText('Option')
631
+
632
+ await userEvent.click(option)
633
+
634
+ await waitFor(() => {
635
+ expect(onOptionClick).toHaveBeenCalledTimes(1)
636
+
637
+ const args = onOptionClick.mock.calls[0][1]
638
+
639
+ expect(args).toHaveProperty('optionId', 'option1')
640
+ expect(args).toHaveProperty('pageHistory', ['page0'])
641
+
642
+ expect(args.drilldown).toBeInstanceOf(Object)
643
+ expect(args.drilldown.props).toHaveProperty('role', 'menu')
644
+
645
+ expect(args.goToPage).toBeInstanceOf(Function)
646
+ expect(args.goToPreviousPage).toBeInstanceOf(Function)
647
+ })
648
+ })
649
+
650
+ it('should provide goToPreviousPage method that throws a warning, if there is no previous page', async () => {
651
+ render(
652
+ <Drilldown rootPageId="page0">
653
+ <Drilldown.Page id="page0">
654
+ <Drilldown.Option
655
+ id="option01"
656
+ onOptionClick={(_e, { goToPreviousPage }) => {
657
+ goToPreviousPage()
658
+ }}
659
+ >
660
+ Option
661
+ </Drilldown.Option>
662
+ </Drilldown.Page>
663
+ </Drilldown>
664
+ )
665
+ const option = screen.getByText('Option')
666
+
667
+ await userEvent.click(option)
668
+
669
+ await waitFor(() => {
670
+ const expectedErrorMessage =
671
+ 'Warning: There is no previous page to go to. The current page history is: [page0].'
672
+
673
+ expect(consoleWarningMock).toHaveBeenCalledWith(
674
+ expect.stringContaining(expectedErrorMessage),
675
+ expect.any(String)
676
+ )
677
+ })
678
+ })
679
+
680
+ describe('provide goToPage method', () => {
681
+ it("should throws warning if page doesn't exist", async () => {
682
+ render(
683
+ <Drilldown rootPageId="page0">
684
+ <Drilldown.Page id="page0">
685
+ <Drilldown.Option
686
+ id="option01"
687
+ onOptionClick={(_e, { goToPage }) => {
688
+ goToPage('page1')
689
+ }}
690
+ >
691
+ Option
692
+ </Drilldown.Option>
693
+ </Drilldown.Page>
694
+ </Drilldown>
695
+ )
696
+ const option = screen.getByText('Option')
697
+
698
+ await userEvent.click(option)
699
+
700
+ await waitFor(() => {
701
+ const expectedErrorMessage =
702
+ 'Warning: Cannot go to page because page with id: "page1" doesn\'t exist.'
703
+
704
+ expect(consoleWarningMock).toHaveBeenCalledWith(
705
+ expect.stringContaining(expectedErrorMessage),
706
+ expect.any(String)
707
+ )
708
+ })
709
+ })
710
+
711
+ it('should throws warning if if no page id is provided', async () => {
712
+ render(
713
+ <Drilldown rootPageId="page0">
714
+ <Drilldown.Page id="page0">
715
+ <Drilldown.Option
716
+ id="option01"
717
+ onOptionClick={(_e, { goToPage }) => {
718
+ // @ts-expect-error we want this to fail
719
+ goToPage()
720
+ }}
721
+ >
722
+ Option
723
+ </Drilldown.Option>
724
+ </Drilldown.Page>
725
+ </Drilldown>
726
+ )
727
+ const option = screen.getByText('Option')
728
+
729
+ await userEvent.click(option)
730
+
731
+ await waitFor(() => {
732
+ const expectedErrorMessage =
733
+ 'Warning: Cannot go to page because there was no page id provided.'
734
+
735
+ expect(consoleWarningMock).toHaveBeenCalledWith(
736
+ expect.stringContaining(expectedErrorMessage),
737
+ expect.any(String)
738
+ )
739
+ })
740
+ })
741
+
742
+ it('should throws warning if parameter is not string', async () => {
743
+ render(
744
+ <Drilldown rootPageId="page0">
745
+ <Drilldown.Page id="page0">
746
+ <Drilldown.Option
747
+ id="option01"
748
+ onOptionClick={(_e, { goToPage }) => {
749
+ // @ts-expect-error we want this to fail
750
+ goToPage({ page: 'page1' })
751
+ }}
752
+ >
753
+ Option
754
+ </Drilldown.Option>
755
+ </Drilldown.Page>
756
+ </Drilldown>
757
+ )
758
+ const option = screen.getByText('Option')
759
+
760
+ await userEvent.click(option)
761
+
762
+ await waitFor(() => {
763
+ const expectedErrorMessage =
764
+ 'Warning: Cannot go to page because parameter newPageId has to be string (valid page id). Current newPageId is "object".'
765
+
766
+ expect(consoleWarningMock).toHaveBeenCalledWith(
767
+ expect.stringContaining(expectedErrorMessage),
768
+ expect.any(String)
769
+ )
770
+ })
771
+ })
772
+ })
773
+ })
774
+ })