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