@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,1021 +0,0 @@
1
- var _Drilldown, _Drilldown2, _Drilldown3, _Drilldown4, _Drilldown5, _Drilldown6, _Drilldown7, _Drilldown8, _Drilldown9, _Drilldown$Page, _button, _Drilldown$Page2, _button2, _Drilldown$Page3, _Drilldown$Page4, _button3, _Drilldown$Page5, _button4, _Drilldown$Page6, _Drilldown$Page7, _button5, _Drilldown$Page8, _button6, _Drilldown$Page9, _Drilldown10, _button7, _Drilldown$Page10, _Drilldown11, _button8, _Drilldown$Page11, _button9, _Drilldown$Page12, _button10, _Drilldown$Page13, _Drilldown12, _button11, _Drilldown$Page14, _Drilldown13, _button12, _Drilldown$Page15, _button13, _Drilldown$Page16, _button14, _Drilldown$Page17, _button15, _Drilldown$Page18, _button16, _Drilldown$Page19, _button17, _Drilldown$Page20, _button18, _Drilldown$Page21, _button19, _Drilldown$Page22, _Drilldown14, _Drilldown15;
2
- /*
3
- * The MIT License (MIT)
4
- *
5
- * Copyright (c) 2015 - present Instructure, Inc.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
-
26
- import { render, screen, waitFor } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import userEvent from '@testing-library/user-event';
29
- import '@testing-library/jest-dom';
30
-
31
- // eslint-disable-next-line no-restricted-imports
32
- import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
33
- import { runAxeCheck } from '@instructure/ui-axe-check';
34
- import { IconCheckSolid } from '@instructure/ui-icons';
35
- import { Drilldown } from '../index';
36
- import DrilldownExamples from '../__examples__/Drilldown.examples';
37
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
38
- const data = Array(5).fill(0).map((_v, ind) => ({
39
- label: `option ${ind}`,
40
- id: `opt_${ind}`
41
- }));
42
- describe('<Drilldown />', () => {
43
- let consoleWarningMock;
44
- let consoleErrorMock;
45
- beforeEach(() => {
46
- // Mocking console to prevent test output pollution and expect for messages
47
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
48
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
49
- });
50
- afterEach(() => {
51
- consoleWarningMock.mockRestore();
52
- consoleErrorMock.mockRestore();
53
- });
54
- describe('rootPageId prop', () => {
55
- it('should set the initial page and render it', async () => {
56
- render(_Drilldown || (_Drilldown = _jsxs(Drilldown, {
57
- rootPageId: "page1",
58
- children: [_jsx(Drilldown.Page, {
59
- id: "page0",
60
- children: _jsx(Drilldown.Option, {
61
- id: "option01",
62
- children: "Option-01"
63
- })
64
- }), _jsx(Drilldown.Page, {
65
- id: "page1",
66
- children: _jsx(Drilldown.Option, {
67
- id: "option11",
68
- children: "Option-11"
69
- })
70
- })]
71
- })));
72
- const drilldown = screen.getByRole('menu');
73
- const options = screen.getAllByRole('menuitem');
74
- const rootlessOption = screen.queryByText('Option-01');
75
- expect(drilldown).toBeInTheDocument();
76
- expect(rootlessOption).not.toBeInTheDocument();
77
- expect(options.length).toBe(1);
78
- expect(options[0]).toHaveTextContent('Option-11');
79
- expect(options[0]).toHaveAttribute('id', 'option11');
80
- });
81
- });
82
- describe('children prop', () => {
83
- it('should not allow non-DrilldownPage children', async () => {
84
- render(_Drilldown2 || (_Drilldown2 = _jsx(Drilldown, {
85
- rootPageId: "page0",
86
- children: _jsx("div", {
87
- id: "testDiv",
88
- children: "DIV-child"
89
- })
90
- })));
91
- const drilldown = screen.queryByRole('menu');
92
- const options = screen.queryAllByRole('menuitem');
93
- const notAllowedChild = screen.queryByText('DIV-child');
94
- expect(drilldown).not.toBeInTheDocument();
95
- expect(options.length).toBe(0);
96
- expect(notAllowedChild).not.toBeInTheDocument();
97
- });
98
- it('should not crash for weird option ids', async () => {
99
- const onSelect = vi.fn();
100
- const weirdID = 'some"_weird!@#$%^&*()\\|`id';
101
- render(_jsx(Drilldown, {
102
- rootPageId: "page0",
103
- onSelect: onSelect,
104
- children: _jsx(Drilldown.Page, {
105
- id: "page0",
106
- children: data.map(option => _jsx(Drilldown.Option, {
107
- id: weirdID + option.id,
108
- value: weirdID + option.id,
109
- "data-testid": weirdID + option.id,
110
- children: option.label
111
- }, weirdID + option.id))
112
- })
113
- }));
114
- const option_1 = screen.getByTestId(weirdID + 'opt_1');
115
- await userEvent.click(option_1);
116
- await waitFor(() => {
117
- expect(onSelect).toHaveBeenCalled();
118
- });
119
- });
120
- });
121
- describe('id prop', () => {
122
- it('should put id attr on the drilldown', async () => {
123
- render(_Drilldown3 || (_Drilldown3 = _jsx(Drilldown, {
124
- rootPageId: "page0",
125
- id: "testId",
126
- children: _jsx(Drilldown.Page, {
127
- id: "page0",
128
- children: _jsx(Drilldown.Option, {
129
- id: "option01",
130
- children: "Option"
131
- })
132
- })
133
- })));
134
- const drilldown = screen.getByRole('menu');
135
- expect(drilldown).toBeInTheDocument();
136
- expect(drilldown).toHaveAttribute('id', 'testId');
137
- });
138
- });
139
- describe('label prop', () => {
140
- it('should be added as aria-label', async () => {
141
- render(_Drilldown4 || (_Drilldown4 = _jsx(Drilldown, {
142
- rootPageId: "page0",
143
- label: "testLabel",
144
- children: _jsx(Drilldown.Page, {
145
- id: "page0",
146
- children: _jsx(Drilldown.Option, {
147
- id: "option01",
148
- children: "Option"
149
- })
150
- })
151
- })));
152
- const drilldown = screen.getByRole('menu');
153
- expect(drilldown).toBeInTheDocument();
154
- expect(drilldown).toHaveAttribute('aria-label', 'testLabel');
155
- });
156
- });
157
- describe('disabled prop', () => {
158
- it('should disable all options', async () => {
159
- render(_Drilldown5 || (_Drilldown5 = _jsx(Drilldown, {
160
- rootPageId: "page0",
161
- disabled: true,
162
- children: _jsxs(Drilldown.Page, {
163
- id: "page0",
164
- renderActionLabel: "Action",
165
- children: [_jsx(Drilldown.Option, {
166
- id: "option01",
167
- children: "Option"
168
- }), _jsx(Drilldown.Option, {
169
- id: "option02",
170
- children: "Option"
171
- }), _jsx(Drilldown.Option, {
172
- id: "option03",
173
- children: "Option"
174
- })]
175
- })
176
- })));
177
- const options = screen.getAllByRole('menuitem');
178
- expect(options.length).toBe(4); // header action + 3 options
179
-
180
- options.forEach(option => {
181
- expect(option).toHaveAttribute('aria-disabled', 'true');
182
- });
183
- });
184
- });
185
- describe('as prop', () => {
186
- it('should be "ul" by default', async () => {
187
- const _render = render(_Drilldown6 || (_Drilldown6 = _jsx(Drilldown, {
188
- rootPageId: "page0",
189
- children: _jsx(Drilldown.Page, {
190
- id: "page0",
191
- children: _jsx(Drilldown.Option, {
192
- id: "option01",
193
- children: "Option"
194
- })
195
- })
196
- }))),
197
- container = _render.container;
198
- const drilldownList = container.querySelector('[class$="-options__list"]');
199
- expect(drilldownList === null || drilldownList === void 0 ? void 0 : drilldownList.tagName).toBe('UL');
200
- });
201
- it('should render as passed element', async () => {
202
- const _render2 = render(_Drilldown7 || (_Drilldown7 = _jsx(Drilldown, {
203
- rootPageId: "page0",
204
- as: "ol",
205
- children: _jsx(Drilldown.Page, {
206
- id: "page0",
207
- children: _jsx(Drilldown.Option, {
208
- id: "option01",
209
- children: "Option"
210
- })
211
- })
212
- }))),
213
- container = _render2.container;
214
- const drilldownList = container.querySelector('[class$="-options__list"]');
215
- expect(drilldownList === null || drilldownList === void 0 ? void 0 : drilldownList.tagName).toBe('OL');
216
- });
217
- });
218
- describe('role prop', () => {
219
- it('should be "menu" by default', async () => {
220
- const _render3 = render(_Drilldown8 || (_Drilldown8 = _jsx(Drilldown, {
221
- rootPageId: "page0",
222
- children: _jsx(Drilldown.Page, {
223
- id: "page0",
224
- children: _jsx(Drilldown.Option, {
225
- id: "option01",
226
- children: "Option"
227
- })
228
- })
229
- }))),
230
- container = _render3.container;
231
- const drilldown = container.querySelector('div[id^="Drilldown_"]');
232
- expect(drilldown).toHaveAttribute('role', 'menu');
233
- });
234
- it('should apply passed role', async () => {
235
- const _render4 = render(_Drilldown9 || (_Drilldown9 = _jsx(Drilldown, {
236
- rootPageId: "page0",
237
- role: "list",
238
- children: _jsx(Drilldown.Page, {
239
- id: "page0",
240
- children: _jsx(Drilldown.Option, {
241
- id: "option01",
242
- children: "Option"
243
- })
244
- })
245
- }))),
246
- container = _render4.container;
247
- const drilldown = container.querySelector('div[id^="Drilldown_"]');
248
- expect(drilldown).toHaveAttribute('role', 'list');
249
- });
250
- });
251
- describe('elementRef prop (and ref static prop)', () => {
252
- it('should give back the drilldown element when there is no trigger', async () => {
253
- const elementRef = vi.fn();
254
- render(_jsx(Drilldown, {
255
- rootPageId: "page0",
256
- elementRef: elementRef,
257
- children: _Drilldown$Page || (_Drilldown$Page = _jsx(Drilldown.Page, {
258
- id: "page0",
259
- children: _jsx(Drilldown.Option, {
260
- id: "option01",
261
- children: "Option"
262
- })
263
- }))
264
- }));
265
- const drilldown = screen.getByRole('menu');
266
- expect(drilldown).toBeInTheDocument();
267
- expect(elementRef).toHaveBeenCalledWith(drilldown);
268
- });
269
- it('should give back the Popover root when drilldown has trigger and is closed', async () => {
270
- const elementRef = vi.fn();
271
- const _render5 = render(_jsx(Drilldown, {
272
- rootPageId: "page0",
273
- elementRef: elementRef,
274
- trigger: _button || (_button = _jsx("button", {
275
- children: "Toggle"
276
- })),
277
- children: _Drilldown$Page2 || (_Drilldown$Page2 = _jsx(Drilldown.Page, {
278
- id: "page0",
279
- children: _jsx(Drilldown.Option, {
280
- id: "option01",
281
- children: "Option"
282
- })
283
- }))
284
- })),
285
- container = _render5.container;
286
- const trigger = screen.getByText('Toggle');
287
- const positionId = trigger.getAttribute('data-position-target');
288
- const drilldownRoot = container.querySelector(`span[data-position="${positionId}"]`);
289
- expect(drilldownRoot).toBeInTheDocument();
290
- expect(elementRef).toHaveBeenCalledWith(drilldownRoot);
291
- });
292
- it('should give back the the Popover root when drilldown has trigger and is open', async () => {
293
- const elementRef = vi.fn();
294
- const _render6 = render(_jsx(Drilldown, {
295
- rootPageId: "page0",
296
- elementRef: elementRef,
297
- trigger: _button2 || (_button2 = _jsx("button", {
298
- children: "Toggle"
299
- })),
300
- defaultShow: true,
301
- children: _Drilldown$Page3 || (_Drilldown$Page3 = _jsx(Drilldown.Page, {
302
- id: "page0",
303
- children: _jsx(Drilldown.Option, {
304
- id: "option01",
305
- children: "Option"
306
- })
307
- }))
308
- })),
309
- container = _render6.container;
310
- const trigger = screen.getByText('Toggle');
311
- const positionId = trigger.getAttribute('data-position-target');
312
- const drilldownRoot = container.querySelector(`span[data-position="${positionId}"]`);
313
- expect(drilldownRoot).toBeInTheDocument();
314
- expect(elementRef).toHaveBeenCalledWith(drilldownRoot);
315
- });
316
- });
317
- describe('drilldownRef prop', () => {
318
- it('should give back the drilldown element when there is no trigger', async () => {
319
- const drilldownRef = vi.fn();
320
- render(_jsx(Drilldown, {
321
- rootPageId: "page0",
322
- drilldownRef: drilldownRef,
323
- children: _Drilldown$Page4 || (_Drilldown$Page4 = _jsx(Drilldown.Page, {
324
- id: "page0",
325
- children: _jsx(Drilldown.Option, {
326
- id: "option01",
327
- children: "Option"
328
- })
329
- }))
330
- }));
331
- const drilldown = screen.getByRole('menu');
332
- expect(drilldownRef).toHaveBeenCalledWith(drilldown);
333
- });
334
- it("shouldn't be called when drilldown has trigger and is closed", async () => {
335
- const drilldownRef = vi.fn();
336
- render(_jsx(Drilldown, {
337
- rootPageId: "page0",
338
- drilldownRef: drilldownRef,
339
- trigger: _button3 || (_button3 = _jsx("button", {
340
- children: "Toggle"
341
- })),
342
- children: _Drilldown$Page5 || (_Drilldown$Page5 = _jsx(Drilldown.Page, {
343
- id: "page0",
344
- children: _jsx(Drilldown.Option, {
345
- id: "option01",
346
- children: "Option"
347
- })
348
- }))
349
- }));
350
- expect(drilldownRef).not.toHaveBeenCalled();
351
- });
352
- it('should give back the drilldown element when drilldown has trigger and is open', async () => {
353
- const drilldownRef = vi.fn();
354
- render(_jsx(Drilldown, {
355
- rootPageId: "page0",
356
- drilldownRef: drilldownRef,
357
- trigger: _button4 || (_button4 = _jsx("button", {
358
- children: "Toggle"
359
- })),
360
- defaultShow: true,
361
- children: _Drilldown$Page6 || (_Drilldown$Page6 = _jsx(Drilldown.Page, {
362
- id: "page0",
363
- children: _jsx(Drilldown.Option, {
364
- id: "option01",
365
- children: "Option"
366
- })
367
- }))
368
- }));
369
- const drilldown = screen.getByRole('menu');
370
- expect(drilldownRef).toHaveBeenCalledWith(drilldown);
371
- });
372
- });
373
- describe('popoverRef prop', () => {
374
- it('should not be called when there is no trigger', async () => {
375
- const popoverRef = vi.fn();
376
- render(_jsx(Drilldown, {
377
- rootPageId: "page0",
378
- popoverRef: popoverRef,
379
- children: _Drilldown$Page7 || (_Drilldown$Page7 = _jsx(Drilldown.Page, {
380
- id: "page0",
381
- children: _jsx(Drilldown.Option, {
382
- id: "option01",
383
- children: "Option"
384
- })
385
- }))
386
- }));
387
- expect(popoverRef).not.toHaveBeenCalled();
388
- });
389
- it('should give back the Popover component when drilldown has trigger and is closed', async () => {
390
- const popoverRef = vi.fn();
391
- const _render7 = render(_jsx(Drilldown, {
392
- rootPageId: "page0",
393
- popoverRef: popoverRef,
394
- trigger: _button5 || (_button5 = _jsx("button", {
395
- children: "Toggle"
396
- })),
397
- children: _Drilldown$Page8 || (_Drilldown$Page8 = _jsx(Drilldown.Page, {
398
- id: "page0",
399
- children: _jsx(Drilldown.Option, {
400
- id: "option01",
401
- children: "Option"
402
- })
403
- }))
404
- })),
405
- container = _render7.container;
406
- const trigger = screen.getByText('Toggle');
407
- const positionId = trigger.getAttribute('data-position-target');
408
- const popoverRoot = container.querySelector(`span[data-position="${positionId}"]`);
409
- expect(popoverRoot).toBeInTheDocument();
410
- expect(popoverRef).toHaveBeenCalled();
411
-
412
- // Popover component's public ref prop
413
- expect(popoverRef.mock.calls[0][0].ref).toBe(popoverRoot);
414
- });
415
- it('should give back the Popover component when drilldown has trigger and is open', async () => {
416
- const popoverRef = vi.fn();
417
- const _render8 = render(_jsx(Drilldown, {
418
- rootPageId: "page0",
419
- popoverRef: popoverRef,
420
- trigger: _button6 || (_button6 = _jsx("button", {
421
- children: "Toggle"
422
- })),
423
- defaultShow: true,
424
- children: _Drilldown$Page9 || (_Drilldown$Page9 = _jsx(Drilldown.Page, {
425
- id: "page0",
426
- children: _jsx(Drilldown.Option, {
427
- id: "option01",
428
- children: "Option"
429
- })
430
- }))
431
- })),
432
- container = _render8.container;
433
- const trigger = screen.getByText('Toggle');
434
- const positionId = trigger.getAttribute('data-position-target');
435
- const popoverRoot = container.querySelector(`span[data-position="${positionId}"]`);
436
- expect(popoverRoot).toBeInTheDocument();
437
- expect(popoverRef).toHaveBeenCalled();
438
-
439
- // Popover component's public ref prop
440
- expect(popoverRef.mock.calls[0][0].ref).toBe(popoverRoot);
441
- });
442
- });
443
- describe('onSelect prop', () => {
444
- it('should fire when option is selected', async () => {
445
- const onSelect = vi.fn();
446
- render(_jsx(Drilldown, {
447
- rootPageId: "page0",
448
- onSelect: onSelect,
449
- children: _jsx(Drilldown.Page, {
450
- id: "page0",
451
- children: data.map(option => _jsx(Drilldown.Option, {
452
- id: option.id,
453
- value: option.id,
454
- "data-testid": option.id,
455
- children: option.label
456
- }, option.id))
457
- })
458
- }));
459
- const option_1 = screen.getByTestId('opt_1');
460
- await userEvent.click(option_1);
461
- await waitFor(() => {
462
- expect(onSelect).toHaveBeenCalled();
463
- const args = onSelect.mock.calls[0][1];
464
- const event = onSelect.mock.calls[0][0];
465
- expect(args.value).toBe('opt_1');
466
- expect(args.isSelected).toBe(true);
467
- expect(args.selectedOption.props).toHaveProperty('id', 'opt_1');
468
- expect(args.selectedOption.props).toHaveProperty('role', 'menuitem');
469
- expect(args.selectedOption.props).toHaveProperty('value', 'opt_1');
470
- expect(args.drilldown.props).toHaveProperty('role', 'menu');
471
- expect(args.drilldown.hide).toBeInstanceOf(Function);
472
- expect(event.target).toBe(option_1);
473
- });
474
- });
475
- it('should not fire when drilldown is disabled', async () => {
476
- const onSelect = vi.fn();
477
- render(_jsx(Drilldown, {
478
- rootPageId: "page0",
479
- onSelect: onSelect,
480
- disabled: true,
481
- children: _jsx(Drilldown.Page, {
482
- id: "page0",
483
- children: data.map(option => _jsx(Drilldown.Option, {
484
- id: option.id,
485
- "data-testid": option.id,
486
- children: option.label
487
- }, option.id))
488
- })
489
- }));
490
- const option_1 = screen.getByTestId('opt_1');
491
- await userEvent.click(option_1);
492
- await waitFor(() => {
493
- expect(onSelect).not.toHaveBeenCalled();
494
- });
495
- });
496
- });
497
- describe('with a trigger', () => {
498
- it('should not show content by default', async () => {
499
- render(_Drilldown10 || (_Drilldown10 = _jsx(Drilldown, {
500
- rootPageId: "page0",
501
- trigger: _jsx("button", {
502
- children: "click me"
503
- }),
504
- children: _jsx(Drilldown.Page, {
505
- id: "page0",
506
- children: _jsx(Drilldown.Option, {
507
- id: "option0",
508
- children: "Option 0"
509
- })
510
- })
511
- })));
512
- const option_0 = screen.queryByText('Option 0');
513
- expect(option_0).not.toBeInTheDocument();
514
- });
515
- it('should render into a mountNode', async () => {
516
- const container = document.createElement('div');
517
- container.setAttribute('data-testid', 'container');
518
- document.body.appendChild(container);
519
- render(_jsx(Drilldown, {
520
- rootPageId: "page0",
521
- mountNode: container,
522
- trigger: _button7 || (_button7 = _jsx("button", {
523
- children: "Options"
524
- })),
525
- children: _Drilldown$Page10 || (_Drilldown$Page10 = _jsx(Drilldown.Page, {
526
- id: "page0",
527
- children: _jsx(Drilldown.Option, {
528
- id: "option0",
529
- children: "Option 0"
530
- })
531
- }))
532
- }));
533
- const optionsContainer = screen.getByTestId('container');
534
- const trigger = screen.getByRole('button');
535
- expect(optionsContainer).not.toHaveTextContent('Option 0');
536
- await userEvent.click(trigger);
537
- await waitFor(() => {
538
- const updatedOptionsContainer = screen.getByTestId('container');
539
- expect(updatedOptionsContainer).toHaveTextContent('Option 0');
540
- });
541
- });
542
- it('should have an aria-haspopup attribute', async () => {
543
- render(_Drilldown11 || (_Drilldown11 = _jsx(Drilldown, {
544
- rootPageId: "page0",
545
- trigger: _jsx("button", {
546
- children: "Options"
547
- }),
548
- children: _jsx(Drilldown.Page, {
549
- id: "page0",
550
- children: _jsx(Drilldown.Option, {
551
- id: "option0",
552
- children: "Option 0"
553
- })
554
- })
555
- })));
556
- const trigger = screen.getByRole('button');
557
- expect(trigger).toHaveAttribute('aria-haspopup');
558
- });
559
- it('should call onToggle when Drilldown is opened', async () => {
560
- const onToggle = vi.fn();
561
- render(_jsx(Drilldown, {
562
- rootPageId: "page0",
563
- trigger: _button8 || (_button8 = _jsx("button", {
564
- children: "Options"
565
- })),
566
- onToggle: onToggle,
567
- "data-testid": "drilldown",
568
- children: _Drilldown$Page11 || (_Drilldown$Page11 = _jsx(Drilldown.Page, {
569
- id: "page0",
570
- children: _jsx(Drilldown.Option, {
571
- id: "option0",
572
- children: "Option 0"
573
- })
574
- }))
575
- }));
576
- const trigger = screen.getByRole('button');
577
- await userEvent.click(trigger);
578
- await waitFor(() => {
579
- expect(onToggle).toHaveBeenCalled();
580
- const args = onToggle.mock.calls[0][1];
581
- expect(args).toHaveProperty('shown', true);
582
- expect(args).toHaveProperty('pageHistory', ['page0']);
583
- expect(args.goToPage).toBeInstanceOf(Function);
584
- expect(args.goToPreviousPage).toBeInstanceOf(Function);
585
- expect(args.drilldown.props).toHaveProperty('role', 'menu');
586
- expect(args.drilldown.props).toHaveProperty('data-testid', 'drilldown');
587
- });
588
- });
589
- it('should call onToggle when Drilldown is closed', async () => {
590
- const onToggle = vi.fn();
591
- render(_jsx(Drilldown, {
592
- rootPageId: "page0",
593
- trigger: _button9 || (_button9 = _jsx("button", {
594
- children: "Options"
595
- })),
596
- onToggle: onToggle,
597
- defaultShow: true,
598
- children: _Drilldown$Page12 || (_Drilldown$Page12 = _jsx(Drilldown.Page, {
599
- id: "page0",
600
- children: _jsx(Drilldown.Option, {
601
- id: "option0",
602
- children: "Option 0"
603
- })
604
- }))
605
- }));
606
- const trigger = screen.getByRole('button');
607
- await userEvent.click(trigger);
608
- await waitFor(() => {
609
- expect(onToggle).toHaveBeenCalled();
610
- const args = onToggle.mock.calls[0][1];
611
- expect(args).toHaveProperty('shown', false);
612
- expect(args).toHaveProperty('pageHistory', ['page0']);
613
- expect(args).toHaveProperty('drilldown');
614
- expect(args.goToPage).toBeInstanceOf(Function);
615
- expect(args.goToPreviousPage).toBeInstanceOf(Function);
616
- });
617
- });
618
- });
619
- describe('placement prop', () => {
620
- it('should be passed to Popover', async () => {
621
- let popoverRef = null;
622
- render(_jsx(Drilldown, {
623
- rootPageId: "page0",
624
- trigger: _button10 || (_button10 = _jsx("button", {
625
- children: "Toggle"
626
- })),
627
- defaultShow: true,
628
- popoverRef: e => {
629
- popoverRef = e;
630
- },
631
- placement: 'top start',
632
- children: _Drilldown$Page13 || (_Drilldown$Page13 = _jsx(Drilldown.Page, {
633
- id: "page0",
634
- children: _jsx(Drilldown.Option, {
635
- id: "option01",
636
- children: "Option"
637
- })
638
- }))
639
- }));
640
- const popoverProps = popoverRef.props;
641
- expect(popoverProps.placement).toBe('top start');
642
- });
643
- });
644
- describe('defaultShow prop', () => {
645
- it('should display Popover on render', async () => {
646
- render(_Drilldown12 || (_Drilldown12 = _jsx(Drilldown, {
647
- rootPageId: "page0",
648
- trigger: _jsx("button", {
649
- children: "Toggle"
650
- }),
651
- defaultShow: true,
652
- children: _jsx(Drilldown.Page, {
653
- id: "page0",
654
- children: _jsx(Drilldown.Option, {
655
- id: "option01",
656
- children: "Option"
657
- })
658
- })
659
- })));
660
- const popoverContent = screen.getByText('Option');
661
- expect(popoverContent).toBeVisible();
662
- });
663
- });
664
- describe('show prop', () => {
665
- it('should display popover', async () => {
666
- const onToggle = vi.fn();
667
- render(_jsx(Drilldown, {
668
- rootPageId: "page0",
669
- trigger: _button11 || (_button11 = _jsx("button", {
670
- children: "Toggle"
671
- })),
672
- show: true,
673
- onToggle: onToggle,
674
- children: _Drilldown$Page14 || (_Drilldown$Page14 = _jsx(Drilldown.Page, {
675
- id: "page0",
676
- children: _jsx(Drilldown.Option, {
677
- id: "option01",
678
- children: "Option"
679
- })
680
- }))
681
- }));
682
- const popoverContent = screen.getByText('Option');
683
- expect(popoverContent).toBeVisible();
684
- });
685
- it('should give error if onToggle is not provided (controllable)', async () => {
686
- render(_Drilldown13 || (_Drilldown13 = _jsx(Drilldown, {
687
- rootPageId: "page0",
688
- trigger: _jsx("button", {
689
- children: "Toggle"
690
- }),
691
- show: true,
692
- children: _jsx(Drilldown.Page, {
693
- id: "page0",
694
- children: _jsx(Drilldown.Option, {
695
- id: "option01",
696
- children: "Option"
697
- })
698
- })
699
- })));
700
- const popoverContent = screen.getByText('Option');
701
- expect(popoverContent).toBeVisible();
702
- expect(popoverContent).toBeVisible();
703
- expect(consoleErrorMock).toHaveBeenCalled();
704
- });
705
- });
706
- describe('onFocus prop', () => {
707
- it('should be passed to Popover', async () => {
708
- let popoverRef = null;
709
- const onFocus = vi.fn();
710
- render(_jsx(Drilldown, {
711
- rootPageId: "page0",
712
- trigger: _button12 || (_button12 = _jsx("button", {
713
- children: "Toggle"
714
- })),
715
- popoverRef: e => {
716
- popoverRef = e;
717
- },
718
- onFocus: onFocus,
719
- children: _Drilldown$Page15 || (_Drilldown$Page15 = _jsx(Drilldown.Page, {
720
- id: "page0",
721
- children: _jsx(Drilldown.Option, {
722
- id: "option01",
723
- children: "Option"
724
- })
725
- }))
726
- }));
727
- const popoverProps = popoverRef.props;
728
- expect(popoverProps.onFocus).toEqual(onFocus);
729
- });
730
- });
731
- describe('onMouseOver prop', () => {
732
- it('should be passed to Popover', async () => {
733
- let popoverRef = null;
734
- const onMouseOver = vi.fn();
735
- render(_jsx(Drilldown, {
736
- rootPageId: "page0",
737
- trigger: _button13 || (_button13 = _jsx("button", {
738
- children: "Toggle"
739
- })),
740
- popoverRef: e => {
741
- popoverRef = e;
742
- },
743
- onMouseOver: onMouseOver,
744
- children: _Drilldown$Page16 || (_Drilldown$Page16 = _jsx(Drilldown.Page, {
745
- id: "page0",
746
- children: _jsx(Drilldown.Option, {
747
- id: "option01",
748
- children: "Option"
749
- })
750
- }))
751
- }));
752
- const popoverProps = popoverRef.props;
753
- expect(popoverProps.onMouseOver).toEqual(onMouseOver);
754
- });
755
- });
756
- describe('shouldContainFocus prop', () => {
757
- it('should be passed to Popover', async () => {
758
- let popoverRef = null;
759
- render(_jsx(Drilldown, {
760
- rootPageId: "page0",
761
- trigger: _button14 || (_button14 = _jsx("button", {
762
- children: "Toggle"
763
- })),
764
- popoverRef: e => {
765
- popoverRef = e;
766
- },
767
- shouldContainFocus: true,
768
- children: _Drilldown$Page17 || (_Drilldown$Page17 = _jsx(Drilldown.Page, {
769
- id: "page0",
770
- children: _jsx(Drilldown.Option, {
771
- id: "option01",
772
- children: "Option"
773
- })
774
- }))
775
- }));
776
- const popoverProps = popoverRef.props;
777
- expect(popoverProps.shouldContainFocus).toEqual(true);
778
- });
779
- });
780
- describe('shouldReturnFocus prop', () => {
781
- it('should be passed to Popover', async () => {
782
- let popoverRef = null;
783
- render(_jsx(Drilldown, {
784
- rootPageId: "page0",
785
- trigger: _button15 || (_button15 = _jsx("button", {
786
- children: "Toggle"
787
- })),
788
- popoverRef: e => {
789
- popoverRef = e;
790
- },
791
- shouldReturnFocus: false,
792
- children: _Drilldown$Page18 || (_Drilldown$Page18 = _jsx(Drilldown.Page, {
793
- id: "page0",
794
- children: _jsx(Drilldown.Option, {
795
- id: "option01",
796
- children: "Option"
797
- })
798
- }))
799
- }));
800
- const popoverProps = popoverRef.props;
801
- expect(popoverProps.shouldReturnFocus).toEqual(false);
802
- });
803
- });
804
- describe('withArrow prop', () => {
805
- it('should be passed to Popover', async () => {
806
- let popoverRef = null;
807
- render(_jsx(Drilldown, {
808
- rootPageId: "page0",
809
- trigger: _button16 || (_button16 = _jsx("button", {
810
- children: "Toggle"
811
- })),
812
- popoverRef: e => {
813
- popoverRef = e;
814
- },
815
- withArrow: false,
816
- children: _Drilldown$Page19 || (_Drilldown$Page19 = _jsx(Drilldown.Page, {
817
- id: "page0",
818
- children: _jsx(Drilldown.Option, {
819
- id: "option01",
820
- children: "Option"
821
- })
822
- }))
823
- }));
824
- const popoverProps = popoverRef.props;
825
- expect(popoverProps.withArrow).toEqual(false);
826
- });
827
- });
828
- describe('offsetX prop', () => {
829
- it('should be passed to Popover', async () => {
830
- let popoverRef = null;
831
- render(_jsx(Drilldown, {
832
- rootPageId: "page0",
833
- trigger: _button17 || (_button17 = _jsx("button", {
834
- children: "Toggle"
835
- })),
836
- popoverRef: e => {
837
- popoverRef = e;
838
- },
839
- offsetX: '2rem',
840
- children: _Drilldown$Page20 || (_Drilldown$Page20 = _jsx(Drilldown.Page, {
841
- id: "page0",
842
- children: _jsx(Drilldown.Option, {
843
- id: "option01",
844
- children: "Option"
845
- })
846
- }))
847
- }));
848
- const popoverProps = popoverRef.props;
849
- expect(popoverProps.offsetX).toEqual('2rem');
850
- });
851
- });
852
- describe('offsetY prop', () => {
853
- it('should be passed to Popover', async () => {
854
- let popoverRef = null;
855
- render(_jsx(Drilldown, {
856
- rootPageId: "page0",
857
- trigger: _button18 || (_button18 = _jsx("button", {
858
- children: "Toggle"
859
- })),
860
- popoverRef: e => {
861
- popoverRef = e;
862
- },
863
- offsetY: '2rem',
864
- children: _Drilldown$Page21 || (_Drilldown$Page21 = _jsx(Drilldown.Page, {
865
- id: "page0",
866
- children: _jsx(Drilldown.Option, {
867
- id: "option01",
868
- children: "Option"
869
- })
870
- }))
871
- }));
872
- const popoverProps = popoverRef.props;
873
- expect(popoverProps.offsetY).toEqual('2rem');
874
- });
875
- });
876
- describe('positionContainerDisplay prop', () => {
877
- it('should be passed to Popover', async () => {
878
- let popoverRef = null;
879
- render(_jsx(Drilldown, {
880
- rootPageId: "page0",
881
- trigger: _button19 || (_button19 = _jsx("button", {
882
- children: "Toggle"
883
- })),
884
- popoverRef: e => {
885
- popoverRef = e;
886
- },
887
- positionContainerDisplay: "block",
888
- children: _Drilldown$Page22 || (_Drilldown$Page22 = _jsx(Drilldown.Page, {
889
- id: "page0",
890
- children: _jsx(Drilldown.Option, {
891
- id: "option01",
892
- children: "Option"
893
- })
894
- }))
895
- }));
896
- const popoverProps = popoverRef.props;
897
- expect(popoverProps.positionContainerDisplay).toEqual('block');
898
- });
899
- });
900
- describe('for a11y', () => {
901
- it('should be accessible', async () => {
902
- const _render9 = render(_Drilldown14 || (_Drilldown14 = _jsxs(Drilldown, {
903
- rootPageId: "page0",
904
- children: [_jsxs(Drilldown.Page, {
905
- id: "page0",
906
- renderTitle: "Page Title",
907
- renderActionLabel: "Action Label",
908
- children: [_jsx(Drilldown.Option, {
909
- id: "item01",
910
- children: "Item1"
911
- }), _jsx(Drilldown.Option, {
912
- id: "item02",
913
- subPageId: "page1",
914
- children: "Item2"
915
- }), _jsx(Drilldown.Option, {
916
- id: "item03",
917
- description: "This is a description",
918
- children: "Item3"
919
- }), _jsx(Drilldown.Option, {
920
- id: "item04",
921
- renderLabelInfo: "After",
922
- children: "Item4"
923
- }), _jsx(Drilldown.Option, {
924
- id: "item05",
925
- disabled: true,
926
- children: "Item5"
927
- }), _jsx(Drilldown.Option, {
928
- id: "item06",
929
- href: "/",
930
- children: "Item6"
931
- }), _jsx(Drilldown.Option, {
932
- id: "item07",
933
- renderBeforeLabel: _jsx(IconCheckSolid, {}),
934
- children: "Item7"
935
- }), _jsx(Drilldown.Option, {
936
- id: "item08",
937
- renderAfterLabel: _jsx(IconCheckSolid, {}),
938
- children: "Item8"
939
- }), _jsx(Drilldown.Separator, {
940
- id: "sep1"
941
- }), _jsxs(Drilldown.Group, {
942
- id: "group1",
943
- renderGroupTitle: "Multi-select group",
944
- selectableType: "multiple",
945
- children: [_jsx(Drilldown.Option, {
946
- id: "groupItem11",
947
- children: "GroupItem"
948
- }), _jsx(Drilldown.Option, {
949
- id: "groupItem12",
950
- children: "GroupItem"
951
- }), _jsx(Drilldown.Option, {
952
- id: "groupItem13",
953
- children: "GroupItem"
954
- })]
955
- }), _jsxs(Drilldown.Group, {
956
- id: "group2",
957
- renderGroupTitle: "Single-select group",
958
- selectableType: "single",
959
- children: [_jsx(Drilldown.Option, {
960
- id: "groupItem21",
961
- children: "GroupItem"
962
- }), _jsx(Drilldown.Option, {
963
- id: "groupItem22",
964
- children: "GroupItem"
965
- }), _jsx(Drilldown.Option, {
966
- id: "groupItem23",
967
- children: "GroupItem"
968
- })]
969
- })]
970
- }), _jsx(Drilldown.Page, {
971
- id: "page1",
972
- children: _jsx(Drilldown.Option, {
973
- id: "item11",
974
- children: "Item1"
975
- })
976
- })]
977
- }))),
978
- container = _render9.container;
979
-
980
- // axe-check is more strict now, and expects "list" role to have "listitem" children, but we use "role='none'" children. After discussing it with the A11y team, we agreed to ignore this error because the screen readers can read the component perfectly.
981
- // TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
982
- // https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
983
- const axeCheck = await runAxeCheck(container, {
984
- ignores: ['aria-required-children']
985
- });
986
- expect(axeCheck).toBe(true);
987
- });
988
- it('should meet a11y standarts when drilldown is open', async () => {
989
- const _render10 = render(_Drilldown15 || (_Drilldown15 = _jsx(Drilldown, {
990
- defaultShow: true,
991
- rootPageId: "page0",
992
- children: _jsx(Drilldown.Page, {
993
- id: "page0",
994
- children: _jsx(Drilldown.Option, {
995
- id: "option0",
996
- children: "Option 0"
997
- })
998
- })
999
- }))),
1000
- container = _render10.container;
1001
- const axeCheck = await runAxeCheck(container);
1002
- expect(axeCheck).toBe(true);
1003
- });
1004
- });
1005
- describe('with generated examples', () => {
1006
- const generatedComponents = generateA11yTests(Drilldown, DrilldownExamples);
1007
- it.each(generatedComponents)('should be accessible with example: $description', async ({
1008
- content
1009
- }) => {
1010
- const _render11 = render(content),
1011
- container = _render11.container;
1012
- const axeCheck = await runAxeCheck(container, {
1013
- // axe-check is more strict now, and expects "list" role to have "listitem" children, but we use "role='none'" children. After discussing it with the A11y team, we agreed to ignore this error because the screen readers can read the component perfectly.
1014
- // TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
1015
- // https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
1016
- ignores: ['aria-required-children']
1017
- });
1018
- expect(axeCheck).toBe(true);
1019
- });
1020
- });
1021
- });