@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.
- package/CHANGELOG.md +8 -0
- package/es/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +573 -0
- package/es/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +595 -0
- package/es/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +299 -0
- package/es/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +56 -0
- package/es/Drilldown/__new-tests__/Drilldown.test.js +818 -0
- package/lib/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +575 -0
- package/lib/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +598 -0
- package/lib/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +301 -0
- package/lib/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +58 -0
- package/lib/Drilldown/__new-tests__/Drilldown.test.js +819 -0
- package/package.json +25 -20
- package/src/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.tsx +634 -0
- package/src/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.tsx +774 -0
- package/src/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.tsx +352 -0
- package/src/Drilldown/{locator.ts → DrilldownSeparator/__new-tests__/DrilldownSeparator.test.tsx} +35 -3
- package/src/Drilldown/__new-tests__/Drilldown.test.tsx +979 -0
- package/tsconfig.build.json +3 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts +2 -0
- package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts.map +1 -0
- package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts +2 -0
- package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts.map +1 -0
- package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts +2 -0
- package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts.map +1 -0
- package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts +2 -0
- package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts.map +1 -0
- package/types/Drilldown/__new-tests__/Drilldown.test.d.ts +2 -0
- package/types/Drilldown/__new-tests__/Drilldown.test.d.ts.map +1 -0
- package/es/Drilldown/DrilldownLocator.js +0 -99
- package/es/Drilldown/locator.js +0 -27
- package/lib/Drilldown/DrilldownLocator.js +0 -106
- package/lib/Drilldown/locator.js +0 -37
- package/src/Drilldown/DrilldownLocator.ts +0 -104
- package/types/Drilldown/DrilldownLocator.d.ts +0 -7484
- package/types/Drilldown/DrilldownLocator.d.ts.map +0 -1
- package/types/Drilldown/locator.d.ts +0 -4
- package/types/Drilldown/locator.d.ts.map +0 -1
|
@@ -0,0 +1,818 @@
|
|
|
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 React from 'react';
|
|
27
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
29
|
+
import userEvent from '@testing-library/user-event';
|
|
30
|
+
import '@testing-library/jest-dom';
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line no-restricted-imports
|
|
33
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
34
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
35
|
+
import { IconCheckSolid } from '@instructure/ui-icons';
|
|
36
|
+
import { Drilldown } from '../index';
|
|
37
|
+
import DrilldownExamples from '../__examples__/Drilldown.examples';
|
|
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 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
57
|
+
rootPageId: "page1"
|
|
58
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
59
|
+
id: "page0"
|
|
60
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
61
|
+
id: "option01"
|
|
62
|
+
}, "Option-01")), /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
63
|
+
id: "page1"
|
|
64
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
65
|
+
id: "option11"
|
|
66
|
+
}, "Option-11")))));
|
|
67
|
+
const drilldown = screen.getByRole('menu');
|
|
68
|
+
const options = screen.getAllByRole('menuitem');
|
|
69
|
+
const rootlessOption = screen.queryByText('Option-01');
|
|
70
|
+
expect(drilldown).toBeInTheDocument();
|
|
71
|
+
expect(rootlessOption).not.toBeInTheDocument();
|
|
72
|
+
expect(options.length).toBe(1);
|
|
73
|
+
expect(options[0]).toHaveTextContent('Option-11');
|
|
74
|
+
expect(options[0]).toHaveAttribute('id', 'option11');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('children prop', () => {
|
|
78
|
+
it('should not allow non-DrilldownPage children', async () => {
|
|
79
|
+
render(_Drilldown2 || (_Drilldown2 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
80
|
+
rootPageId: "page0"
|
|
81
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
id: "testDiv"
|
|
83
|
+
}, "DIV-child"))));
|
|
84
|
+
const drilldown = screen.queryByRole('menu');
|
|
85
|
+
const options = screen.queryAllByRole('menuitem');
|
|
86
|
+
const notAllowedChild = screen.queryByText('DIV-child');
|
|
87
|
+
expect(drilldown).not.toBeInTheDocument();
|
|
88
|
+
expect(options.length).toBe(0);
|
|
89
|
+
expect(notAllowedChild).not.toBeInTheDocument();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe('id prop', () => {
|
|
93
|
+
it('should put id attr on the drilldown', async () => {
|
|
94
|
+
render(_Drilldown3 || (_Drilldown3 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
95
|
+
rootPageId: "page0",
|
|
96
|
+
id: "testId"
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
98
|
+
id: "page0"
|
|
99
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
100
|
+
id: "option01"
|
|
101
|
+
}, "Option")))));
|
|
102
|
+
const drilldown = screen.getByRole('menu');
|
|
103
|
+
expect(drilldown).toBeInTheDocument();
|
|
104
|
+
expect(drilldown).toHaveAttribute('id', 'testId');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('label prop', () => {
|
|
108
|
+
it('should be added as aria-label', async () => {
|
|
109
|
+
render(_Drilldown4 || (_Drilldown4 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
110
|
+
rootPageId: "page0",
|
|
111
|
+
label: "testLabel"
|
|
112
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
113
|
+
id: "page0"
|
|
114
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
115
|
+
id: "option01"
|
|
116
|
+
}, "Option")))));
|
|
117
|
+
const drilldown = screen.getByRole('menu');
|
|
118
|
+
expect(drilldown).toBeInTheDocument();
|
|
119
|
+
expect(drilldown).toHaveAttribute('aria-label', 'testLabel');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe('disabled prop', () => {
|
|
123
|
+
it('should disable all options', async () => {
|
|
124
|
+
render(_Drilldown5 || (_Drilldown5 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
125
|
+
rootPageId: "page0",
|
|
126
|
+
disabled: true
|
|
127
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
128
|
+
id: "page0",
|
|
129
|
+
renderActionLabel: "Action"
|
|
130
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
131
|
+
id: "option01"
|
|
132
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
133
|
+
id: "option02"
|
|
134
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
135
|
+
id: "option03"
|
|
136
|
+
}, "Option")))));
|
|
137
|
+
const options = screen.getAllByRole('menuitem');
|
|
138
|
+
expect(options.length).toBe(4); // header action + 3 options
|
|
139
|
+
|
|
140
|
+
options.forEach(option => {
|
|
141
|
+
expect(option).toHaveAttribute('aria-disabled', 'true');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe('as prop', () => {
|
|
146
|
+
it('should be "ul" by default', async () => {
|
|
147
|
+
const _render = render(_Drilldown6 || (_Drilldown6 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
148
|
+
rootPageId: "page0"
|
|
149
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
150
|
+
id: "page0"
|
|
151
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
152
|
+
id: "option01"
|
|
153
|
+
}, "Option"))))),
|
|
154
|
+
container = _render.container;
|
|
155
|
+
const drilldownList = container.querySelector('[class$="-options__list"]');
|
|
156
|
+
expect(drilldownList === null || drilldownList === void 0 ? void 0 : drilldownList.tagName).toBe('UL');
|
|
157
|
+
});
|
|
158
|
+
it('should render as passed element', async () => {
|
|
159
|
+
const _render2 = render(_Drilldown7 || (_Drilldown7 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
160
|
+
rootPageId: "page0",
|
|
161
|
+
as: "ol"
|
|
162
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
163
|
+
id: "page0"
|
|
164
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
165
|
+
id: "option01"
|
|
166
|
+
}, "Option"))))),
|
|
167
|
+
container = _render2.container;
|
|
168
|
+
const drilldownList = container.querySelector('[class$="-options__list"]');
|
|
169
|
+
expect(drilldownList === null || drilldownList === void 0 ? void 0 : drilldownList.tagName).toBe('OL');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe('role prop', () => {
|
|
173
|
+
it('should be "menu" by default', async () => {
|
|
174
|
+
const _render3 = render(_Drilldown8 || (_Drilldown8 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
175
|
+
rootPageId: "page0"
|
|
176
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
177
|
+
id: "page0"
|
|
178
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
179
|
+
id: "option01"
|
|
180
|
+
}, "Option"))))),
|
|
181
|
+
container = _render3.container;
|
|
182
|
+
const drilldown = container.querySelector('div[id^="Drilldown_"]');
|
|
183
|
+
expect(drilldown).toHaveAttribute('role', 'menu');
|
|
184
|
+
});
|
|
185
|
+
it('should apply passed role', async () => {
|
|
186
|
+
const _render4 = render(_Drilldown9 || (_Drilldown9 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
187
|
+
rootPageId: "page0",
|
|
188
|
+
role: "list"
|
|
189
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
190
|
+
id: "page0"
|
|
191
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
192
|
+
id: "option01"
|
|
193
|
+
}, "Option"))))),
|
|
194
|
+
container = _render4.container;
|
|
195
|
+
const drilldown = container.querySelector('div[id^="Drilldown_"]');
|
|
196
|
+
expect(drilldown).toHaveAttribute('role', 'list');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
describe('elementRef prop (and ref static prop)', () => {
|
|
200
|
+
it('should give back the drilldown element when there is no trigger', async () => {
|
|
201
|
+
const elementRef = vi.fn();
|
|
202
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
203
|
+
rootPageId: "page0",
|
|
204
|
+
elementRef: elementRef
|
|
205
|
+
}, _Drilldown$Page || (_Drilldown$Page = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
206
|
+
id: "page0"
|
|
207
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
208
|
+
id: "option01"
|
|
209
|
+
}, "Option")))));
|
|
210
|
+
const drilldown = screen.getByRole('menu');
|
|
211
|
+
expect(drilldown).toBeInTheDocument();
|
|
212
|
+
expect(elementRef).toHaveBeenCalledWith(drilldown);
|
|
213
|
+
});
|
|
214
|
+
it('should give back the Popover root when drilldown has trigger and is closed', async () => {
|
|
215
|
+
const elementRef = vi.fn();
|
|
216
|
+
const _render5 = render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
217
|
+
rootPageId: "page0",
|
|
218
|
+
elementRef: elementRef,
|
|
219
|
+
trigger: _button || (_button = /*#__PURE__*/React.createElement("button", null, "Toggle"))
|
|
220
|
+
}, _Drilldown$Page2 || (_Drilldown$Page2 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
221
|
+
id: "page0"
|
|
222
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
223
|
+
id: "option01"
|
|
224
|
+
}, "Option"))))),
|
|
225
|
+
container = _render5.container;
|
|
226
|
+
const trigger = screen.getByText('Toggle');
|
|
227
|
+
const positionId = trigger.getAttribute('data-position-target');
|
|
228
|
+
const drilldownRoot = container.querySelector(`span[data-position="${positionId}"]`);
|
|
229
|
+
expect(drilldownRoot).toBeInTheDocument();
|
|
230
|
+
expect(elementRef).toHaveBeenCalledWith(drilldownRoot);
|
|
231
|
+
});
|
|
232
|
+
it('should give back the the Popover root when drilldown has trigger and is open', async () => {
|
|
233
|
+
const elementRef = vi.fn();
|
|
234
|
+
const _render6 = render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
235
|
+
rootPageId: "page0",
|
|
236
|
+
elementRef: elementRef,
|
|
237
|
+
trigger: _button2 || (_button2 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
238
|
+
defaultShow: true
|
|
239
|
+
}, _Drilldown$Page3 || (_Drilldown$Page3 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
240
|
+
id: "page0"
|
|
241
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
242
|
+
id: "option01"
|
|
243
|
+
}, "Option"))))),
|
|
244
|
+
container = _render6.container;
|
|
245
|
+
const trigger = screen.getByText('Toggle');
|
|
246
|
+
const positionId = trigger.getAttribute('data-position-target');
|
|
247
|
+
const drilldownRoot = container.querySelector(`span[data-position="${positionId}"]`);
|
|
248
|
+
expect(drilldownRoot).toBeInTheDocument();
|
|
249
|
+
expect(elementRef).toHaveBeenCalledWith(drilldownRoot);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
describe('drilldownRef prop', () => {
|
|
253
|
+
it('should give back the drilldown element when there is no trigger', async () => {
|
|
254
|
+
const drilldownRef = vi.fn();
|
|
255
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
256
|
+
rootPageId: "page0",
|
|
257
|
+
drilldownRef: drilldownRef
|
|
258
|
+
}, _Drilldown$Page4 || (_Drilldown$Page4 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
259
|
+
id: "page0"
|
|
260
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
261
|
+
id: "option01"
|
|
262
|
+
}, "Option")))));
|
|
263
|
+
const drilldown = screen.getByRole('menu');
|
|
264
|
+
expect(drilldownRef).toHaveBeenCalledWith(drilldown);
|
|
265
|
+
});
|
|
266
|
+
it("shouldn't be called when drilldown has trigger and is closed", async () => {
|
|
267
|
+
const drilldownRef = vi.fn();
|
|
268
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
269
|
+
rootPageId: "page0",
|
|
270
|
+
drilldownRef: drilldownRef,
|
|
271
|
+
trigger: _button3 || (_button3 = /*#__PURE__*/React.createElement("button", null, "Toggle"))
|
|
272
|
+
}, _Drilldown$Page5 || (_Drilldown$Page5 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
273
|
+
id: "page0"
|
|
274
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
275
|
+
id: "option01"
|
|
276
|
+
}, "Option")))));
|
|
277
|
+
expect(drilldownRef).not.toHaveBeenCalled();
|
|
278
|
+
});
|
|
279
|
+
it('should give back the drilldown element when drilldown has trigger and is open', async () => {
|
|
280
|
+
const drilldownRef = vi.fn();
|
|
281
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
282
|
+
rootPageId: "page0",
|
|
283
|
+
drilldownRef: drilldownRef,
|
|
284
|
+
trigger: _button4 || (_button4 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
285
|
+
defaultShow: true
|
|
286
|
+
}, _Drilldown$Page6 || (_Drilldown$Page6 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
287
|
+
id: "page0"
|
|
288
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
289
|
+
id: "option01"
|
|
290
|
+
}, "Option")))));
|
|
291
|
+
const drilldown = screen.getByRole('menu');
|
|
292
|
+
expect(drilldownRef).toHaveBeenCalledWith(drilldown);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
describe('popoverRef prop', () => {
|
|
296
|
+
it('should not be called when there is no trigger', async () => {
|
|
297
|
+
const popoverRef = vi.fn();
|
|
298
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
299
|
+
rootPageId: "page0",
|
|
300
|
+
popoverRef: popoverRef
|
|
301
|
+
}, _Drilldown$Page7 || (_Drilldown$Page7 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
302
|
+
id: "page0"
|
|
303
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
304
|
+
id: "option01"
|
|
305
|
+
}, "Option")))));
|
|
306
|
+
expect(popoverRef).not.toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
it('should give back the Popover component when drilldown has trigger and is closed', async () => {
|
|
309
|
+
const popoverRef = vi.fn();
|
|
310
|
+
const _render7 = render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
311
|
+
rootPageId: "page0",
|
|
312
|
+
popoverRef: popoverRef,
|
|
313
|
+
trigger: _button5 || (_button5 = /*#__PURE__*/React.createElement("button", null, "Toggle"))
|
|
314
|
+
}, _Drilldown$Page8 || (_Drilldown$Page8 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
315
|
+
id: "page0"
|
|
316
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
317
|
+
id: "option01"
|
|
318
|
+
}, "Option"))))),
|
|
319
|
+
container = _render7.container;
|
|
320
|
+
const trigger = screen.getByText('Toggle');
|
|
321
|
+
const positionId = trigger.getAttribute('data-position-target');
|
|
322
|
+
const popoverRoot = container.querySelector(`span[data-position="${positionId}"]`);
|
|
323
|
+
expect(popoverRoot).toBeInTheDocument();
|
|
324
|
+
expect(popoverRef).toHaveBeenCalled();
|
|
325
|
+
|
|
326
|
+
// Popover component's public ref prop
|
|
327
|
+
expect(popoverRef.mock.calls[0][0].ref).toBe(popoverRoot);
|
|
328
|
+
});
|
|
329
|
+
it('should give back the Popover component when drilldown has trigger and is open', async () => {
|
|
330
|
+
const popoverRef = vi.fn();
|
|
331
|
+
const _render8 = render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
332
|
+
rootPageId: "page0",
|
|
333
|
+
popoverRef: popoverRef,
|
|
334
|
+
trigger: _button6 || (_button6 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
335
|
+
defaultShow: true
|
|
336
|
+
}, _Drilldown$Page9 || (_Drilldown$Page9 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
337
|
+
id: "page0"
|
|
338
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
339
|
+
id: "option01"
|
|
340
|
+
}, "Option"))))),
|
|
341
|
+
container = _render8.container;
|
|
342
|
+
const trigger = screen.getByText('Toggle');
|
|
343
|
+
const positionId = trigger.getAttribute('data-position-target');
|
|
344
|
+
const popoverRoot = container.querySelector(`span[data-position="${positionId}"]`);
|
|
345
|
+
expect(popoverRoot).toBeInTheDocument();
|
|
346
|
+
expect(popoverRef).toHaveBeenCalled();
|
|
347
|
+
|
|
348
|
+
// Popover component's public ref prop
|
|
349
|
+
expect(popoverRef.mock.calls[0][0].ref).toBe(popoverRoot);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
describe('onSelect prop', () => {
|
|
353
|
+
it('should fire when option is selected', async () => {
|
|
354
|
+
const onSelect = vi.fn();
|
|
355
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
356
|
+
rootPageId: "page0",
|
|
357
|
+
onSelect: onSelect
|
|
358
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
359
|
+
id: "page0"
|
|
360
|
+
}, data.map(option => /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
361
|
+
id: option.id,
|
|
362
|
+
value: option.id,
|
|
363
|
+
key: option.id,
|
|
364
|
+
"data-testid": option.id
|
|
365
|
+
}, option.label)))));
|
|
366
|
+
const option_1 = screen.getByTestId('opt_1');
|
|
367
|
+
await userEvent.click(option_1);
|
|
368
|
+
await waitFor(() => {
|
|
369
|
+
expect(onSelect).toHaveBeenCalled();
|
|
370
|
+
const args = onSelect.mock.calls[0][1];
|
|
371
|
+
const event = onSelect.mock.calls[0][0];
|
|
372
|
+
expect(args.value).toBe('opt_1');
|
|
373
|
+
expect(args.isSelected).toBe(true);
|
|
374
|
+
expect(args.selectedOption.props).toHaveProperty('id', 'opt_1');
|
|
375
|
+
expect(args.selectedOption.props).toHaveProperty('role', 'menuitem');
|
|
376
|
+
expect(args.selectedOption.props).toHaveProperty('value', 'opt_1');
|
|
377
|
+
expect(args.drilldown.props).toHaveProperty('role', 'menu');
|
|
378
|
+
expect(args.drilldown.hide).toBeInstanceOf(Function);
|
|
379
|
+
expect(event.target).toBe(option_1);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
it('should not fire when drilldown is disabled', async () => {
|
|
383
|
+
const onSelect = vi.fn();
|
|
384
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
385
|
+
rootPageId: "page0",
|
|
386
|
+
onSelect: onSelect,
|
|
387
|
+
disabled: true
|
|
388
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
389
|
+
id: "page0"
|
|
390
|
+
}, data.map(option => /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
391
|
+
id: option.id,
|
|
392
|
+
key: option.id,
|
|
393
|
+
"data-testid": option.id
|
|
394
|
+
}, option.label)))));
|
|
395
|
+
const option_1 = screen.getByTestId('opt_1');
|
|
396
|
+
await userEvent.click(option_1);
|
|
397
|
+
await waitFor(() => {
|
|
398
|
+
expect(onSelect).not.toHaveBeenCalled();
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
describe('with a trigger', () => {
|
|
403
|
+
it('should not show content by default', async () => {
|
|
404
|
+
render(_Drilldown10 || (_Drilldown10 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
405
|
+
rootPageId: "page0",
|
|
406
|
+
trigger: /*#__PURE__*/React.createElement("button", null, "click me")
|
|
407
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
408
|
+
id: "page0"
|
|
409
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
410
|
+
id: "option0"
|
|
411
|
+
}, "Option 0")))));
|
|
412
|
+
const option_0 = screen.queryByText('Option 0');
|
|
413
|
+
expect(option_0).not.toBeInTheDocument();
|
|
414
|
+
});
|
|
415
|
+
it('should render into a mountNode', async () => {
|
|
416
|
+
const container = document.createElement('div');
|
|
417
|
+
container.setAttribute('data-testid', 'container');
|
|
418
|
+
document.body.appendChild(container);
|
|
419
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
420
|
+
rootPageId: "page0",
|
|
421
|
+
mountNode: container,
|
|
422
|
+
trigger: _button7 || (_button7 = /*#__PURE__*/React.createElement("button", null, "Options"))
|
|
423
|
+
}, _Drilldown$Page10 || (_Drilldown$Page10 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
424
|
+
id: "page0"
|
|
425
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
426
|
+
id: "option0"
|
|
427
|
+
}, "Option 0")))));
|
|
428
|
+
const optionsContainer = screen.getByTestId('container');
|
|
429
|
+
const trigger = screen.getByRole('button');
|
|
430
|
+
expect(optionsContainer).not.toHaveTextContent('Option 0');
|
|
431
|
+
await userEvent.click(trigger);
|
|
432
|
+
await waitFor(() => {
|
|
433
|
+
const updatedOptionsContainer = screen.getByTestId('container');
|
|
434
|
+
expect(updatedOptionsContainer).toHaveTextContent('Option 0');
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
it('should have an aria-haspopup attribute', async () => {
|
|
438
|
+
render(_Drilldown11 || (_Drilldown11 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
439
|
+
rootPageId: "page0",
|
|
440
|
+
trigger: /*#__PURE__*/React.createElement("button", null, "Options")
|
|
441
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
442
|
+
id: "page0"
|
|
443
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
444
|
+
id: "option0"
|
|
445
|
+
}, "Option 0")))));
|
|
446
|
+
const trigger = screen.getByRole('button');
|
|
447
|
+
expect(trigger).toHaveAttribute('aria-haspopup');
|
|
448
|
+
});
|
|
449
|
+
it('should call onToggle when Drilldown is opened', async () => {
|
|
450
|
+
const onToggle = vi.fn();
|
|
451
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
452
|
+
rootPageId: "page0",
|
|
453
|
+
trigger: _button8 || (_button8 = /*#__PURE__*/React.createElement("button", null, "Options")),
|
|
454
|
+
onToggle: onToggle,
|
|
455
|
+
"data-testid": "drilldown"
|
|
456
|
+
}, _Drilldown$Page11 || (_Drilldown$Page11 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
457
|
+
id: "page0"
|
|
458
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
459
|
+
id: "option0"
|
|
460
|
+
}, "Option 0")))));
|
|
461
|
+
const trigger = screen.getByRole('button');
|
|
462
|
+
await userEvent.click(trigger);
|
|
463
|
+
await waitFor(() => {
|
|
464
|
+
expect(onToggle).toHaveBeenCalled();
|
|
465
|
+
const args = onToggle.mock.calls[0][1];
|
|
466
|
+
expect(args).toHaveProperty('shown', true);
|
|
467
|
+
expect(args).toHaveProperty('pageHistory', ['page0']);
|
|
468
|
+
expect(args.goToPage).toBeInstanceOf(Function);
|
|
469
|
+
expect(args.goToPreviousPage).toBeInstanceOf(Function);
|
|
470
|
+
expect(args.drilldown.props).toHaveProperty('role', 'menu');
|
|
471
|
+
expect(args.drilldown.props).toHaveProperty('data-testid', 'drilldown');
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
it('should call onToggle when Drilldown is closed', async () => {
|
|
475
|
+
const onToggle = vi.fn();
|
|
476
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
477
|
+
rootPageId: "page0",
|
|
478
|
+
trigger: _button9 || (_button9 = /*#__PURE__*/React.createElement("button", null, "Options")),
|
|
479
|
+
onToggle: onToggle,
|
|
480
|
+
defaultShow: true
|
|
481
|
+
}, _Drilldown$Page12 || (_Drilldown$Page12 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
482
|
+
id: "page0"
|
|
483
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
484
|
+
id: "option0"
|
|
485
|
+
}, "Option 0")))));
|
|
486
|
+
const trigger = screen.getByRole('button');
|
|
487
|
+
await userEvent.click(trigger);
|
|
488
|
+
await waitFor(() => {
|
|
489
|
+
expect(onToggle).toHaveBeenCalled();
|
|
490
|
+
const args = onToggle.mock.calls[0][1];
|
|
491
|
+
expect(args).toHaveProperty('shown', false);
|
|
492
|
+
expect(args).toHaveProperty('pageHistory', ['page0']);
|
|
493
|
+
expect(args).toHaveProperty('drilldown');
|
|
494
|
+
expect(args.goToPage).toBeInstanceOf(Function);
|
|
495
|
+
expect(args.goToPreviousPage).toBeInstanceOf(Function);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
describe('placement prop', () => {
|
|
500
|
+
it('should be passed to Popover', async () => {
|
|
501
|
+
let popoverRef = null;
|
|
502
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
503
|
+
rootPageId: "page0",
|
|
504
|
+
trigger: _button10 || (_button10 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
505
|
+
defaultShow: true,
|
|
506
|
+
popoverRef: e => {
|
|
507
|
+
popoverRef = e;
|
|
508
|
+
},
|
|
509
|
+
placement: 'top start'
|
|
510
|
+
}, _Drilldown$Page13 || (_Drilldown$Page13 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
511
|
+
id: "page0"
|
|
512
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
513
|
+
id: "option01"
|
|
514
|
+
}, "Option")))));
|
|
515
|
+
const popoverProps = popoverRef.props;
|
|
516
|
+
expect(popoverProps.placement).toBe('top start');
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
describe('defaultShow prop', () => {
|
|
520
|
+
it('should display Popover on render', async () => {
|
|
521
|
+
render(_Drilldown12 || (_Drilldown12 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
522
|
+
rootPageId: "page0",
|
|
523
|
+
trigger: /*#__PURE__*/React.createElement("button", null, "Toggle"),
|
|
524
|
+
defaultShow: true
|
|
525
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
526
|
+
id: "page0"
|
|
527
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
528
|
+
id: "option01"
|
|
529
|
+
}, "Option")))));
|
|
530
|
+
const popoverContent = screen.getByText('Option');
|
|
531
|
+
expect(popoverContent).toBeVisible();
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
describe('show prop', () => {
|
|
535
|
+
it('should display popover', async () => {
|
|
536
|
+
const onToggle = vi.fn();
|
|
537
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
538
|
+
rootPageId: "page0",
|
|
539
|
+
trigger: _button11 || (_button11 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
540
|
+
show: true,
|
|
541
|
+
onToggle: onToggle
|
|
542
|
+
}, _Drilldown$Page14 || (_Drilldown$Page14 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
543
|
+
id: "page0"
|
|
544
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
545
|
+
id: "option01"
|
|
546
|
+
}, "Option")))));
|
|
547
|
+
const popoverContent = screen.getByText('Option');
|
|
548
|
+
expect(popoverContent).toBeVisible();
|
|
549
|
+
});
|
|
550
|
+
it('should give error if onToggle is not provided (controllable)', async () => {
|
|
551
|
+
render(_Drilldown13 || (_Drilldown13 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
552
|
+
rootPageId: "page0",
|
|
553
|
+
trigger: /*#__PURE__*/React.createElement("button", null, "Toggle"),
|
|
554
|
+
show: true
|
|
555
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
556
|
+
id: "page0"
|
|
557
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
558
|
+
id: "option01"
|
|
559
|
+
}, "Option")))));
|
|
560
|
+
const popoverContent = screen.getByText('Option');
|
|
561
|
+
expect(popoverContent).toBeVisible();
|
|
562
|
+
expect(popoverContent).toBeVisible();
|
|
563
|
+
expect(consoleErrorMock).toHaveBeenCalled();
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
describe('onFocus prop', () => {
|
|
567
|
+
it('should be passed to Popover', async () => {
|
|
568
|
+
let popoverRef = null;
|
|
569
|
+
const onFocus = vi.fn();
|
|
570
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
571
|
+
rootPageId: "page0",
|
|
572
|
+
trigger: _button12 || (_button12 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
573
|
+
popoverRef: e => {
|
|
574
|
+
popoverRef = e;
|
|
575
|
+
},
|
|
576
|
+
onFocus: onFocus
|
|
577
|
+
}, _Drilldown$Page15 || (_Drilldown$Page15 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
578
|
+
id: "page0"
|
|
579
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
580
|
+
id: "option01"
|
|
581
|
+
}, "Option")))));
|
|
582
|
+
const popoverProps = popoverRef.props;
|
|
583
|
+
expect(popoverProps.onFocus).toEqual(onFocus);
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
describe('onMouseOver prop', () => {
|
|
587
|
+
it('should be passed to Popover', async () => {
|
|
588
|
+
let popoverRef = null;
|
|
589
|
+
const onMouseOver = vi.fn();
|
|
590
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
591
|
+
rootPageId: "page0",
|
|
592
|
+
trigger: _button13 || (_button13 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
593
|
+
popoverRef: e => {
|
|
594
|
+
popoverRef = e;
|
|
595
|
+
},
|
|
596
|
+
onMouseOver: onMouseOver
|
|
597
|
+
}, _Drilldown$Page16 || (_Drilldown$Page16 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
598
|
+
id: "page0"
|
|
599
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
600
|
+
id: "option01"
|
|
601
|
+
}, "Option")))));
|
|
602
|
+
const popoverProps = popoverRef.props;
|
|
603
|
+
expect(popoverProps.onMouseOver).toEqual(onMouseOver);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
describe('shouldContainFocus prop', () => {
|
|
607
|
+
it('should be passed to Popover', async () => {
|
|
608
|
+
let popoverRef = null;
|
|
609
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
610
|
+
rootPageId: "page0",
|
|
611
|
+
trigger: _button14 || (_button14 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
612
|
+
popoverRef: e => {
|
|
613
|
+
popoverRef = e;
|
|
614
|
+
},
|
|
615
|
+
shouldContainFocus: true
|
|
616
|
+
}, _Drilldown$Page17 || (_Drilldown$Page17 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
617
|
+
id: "page0"
|
|
618
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
619
|
+
id: "option01"
|
|
620
|
+
}, "Option")))));
|
|
621
|
+
const popoverProps = popoverRef.props;
|
|
622
|
+
expect(popoverProps.shouldContainFocus).toEqual(true);
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
describe('shouldReturnFocus prop', () => {
|
|
626
|
+
it('should be passed to Popover', async () => {
|
|
627
|
+
let popoverRef = null;
|
|
628
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
629
|
+
rootPageId: "page0",
|
|
630
|
+
trigger: _button15 || (_button15 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
631
|
+
popoverRef: e => {
|
|
632
|
+
popoverRef = e;
|
|
633
|
+
},
|
|
634
|
+
shouldReturnFocus: false
|
|
635
|
+
}, _Drilldown$Page18 || (_Drilldown$Page18 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
636
|
+
id: "page0"
|
|
637
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
638
|
+
id: "option01"
|
|
639
|
+
}, "Option")))));
|
|
640
|
+
const popoverProps = popoverRef.props;
|
|
641
|
+
expect(popoverProps.shouldReturnFocus).toEqual(false);
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
describe('withArrow prop', () => {
|
|
645
|
+
it('should be passed to Popover', async () => {
|
|
646
|
+
let popoverRef = null;
|
|
647
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
648
|
+
rootPageId: "page0",
|
|
649
|
+
trigger: _button16 || (_button16 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
650
|
+
popoverRef: e => {
|
|
651
|
+
popoverRef = e;
|
|
652
|
+
},
|
|
653
|
+
withArrow: false
|
|
654
|
+
}, _Drilldown$Page19 || (_Drilldown$Page19 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
655
|
+
id: "page0"
|
|
656
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
657
|
+
id: "option01"
|
|
658
|
+
}, "Option")))));
|
|
659
|
+
const popoverProps = popoverRef.props;
|
|
660
|
+
expect(popoverProps.withArrow).toEqual(false);
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
describe('offsetX prop', () => {
|
|
664
|
+
it('should be passed to Popover', async () => {
|
|
665
|
+
let popoverRef = null;
|
|
666
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
667
|
+
rootPageId: "page0",
|
|
668
|
+
trigger: _button17 || (_button17 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
669
|
+
popoverRef: e => {
|
|
670
|
+
popoverRef = e;
|
|
671
|
+
},
|
|
672
|
+
offsetX: '2rem'
|
|
673
|
+
}, _Drilldown$Page20 || (_Drilldown$Page20 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
674
|
+
id: "page0"
|
|
675
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
676
|
+
id: "option01"
|
|
677
|
+
}, "Option")))));
|
|
678
|
+
const popoverProps = popoverRef.props;
|
|
679
|
+
expect(popoverProps.offsetX).toEqual('2rem');
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
describe('offsetY prop', () => {
|
|
683
|
+
it('should be passed to Popover', async () => {
|
|
684
|
+
let popoverRef = null;
|
|
685
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
686
|
+
rootPageId: "page0",
|
|
687
|
+
trigger: _button18 || (_button18 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
688
|
+
popoverRef: e => {
|
|
689
|
+
popoverRef = e;
|
|
690
|
+
},
|
|
691
|
+
offsetY: '2rem'
|
|
692
|
+
}, _Drilldown$Page21 || (_Drilldown$Page21 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
693
|
+
id: "page0"
|
|
694
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
695
|
+
id: "option01"
|
|
696
|
+
}, "Option")))));
|
|
697
|
+
const popoverProps = popoverRef.props;
|
|
698
|
+
expect(popoverProps.offsetY).toEqual('2rem');
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
describe('positionContainerDisplay prop', () => {
|
|
702
|
+
it('should be passed to Popover', async () => {
|
|
703
|
+
let popoverRef = null;
|
|
704
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
705
|
+
rootPageId: "page0",
|
|
706
|
+
trigger: _button19 || (_button19 = /*#__PURE__*/React.createElement("button", null, "Toggle")),
|
|
707
|
+
popoverRef: e => {
|
|
708
|
+
popoverRef = e;
|
|
709
|
+
},
|
|
710
|
+
positionContainerDisplay: "block"
|
|
711
|
+
}, _Drilldown$Page22 || (_Drilldown$Page22 = /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
712
|
+
id: "page0"
|
|
713
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
714
|
+
id: "option01"
|
|
715
|
+
}, "Option")))));
|
|
716
|
+
const popoverProps = popoverRef.props;
|
|
717
|
+
expect(popoverProps.positionContainerDisplay).toEqual('block');
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
describe('for a11y', () => {
|
|
721
|
+
it('should be accessible', async () => {
|
|
722
|
+
const _render9 = render(_Drilldown14 || (_Drilldown14 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
723
|
+
rootPageId: "page0"
|
|
724
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
725
|
+
id: "page0",
|
|
726
|
+
renderTitle: "Page Title",
|
|
727
|
+
renderActionLabel: "Action Label"
|
|
728
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
729
|
+
id: "item01"
|
|
730
|
+
}, "Item1"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
731
|
+
id: "item02",
|
|
732
|
+
subPageId: "page1"
|
|
733
|
+
}, "Item2"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
734
|
+
id: "item03",
|
|
735
|
+
description: "This is a description"
|
|
736
|
+
}, "Item3"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
737
|
+
id: "item04",
|
|
738
|
+
renderLabelInfo: "After"
|
|
739
|
+
}, "Item4"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
740
|
+
id: "item05",
|
|
741
|
+
disabled: true
|
|
742
|
+
}, "Item5"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
743
|
+
id: "item06",
|
|
744
|
+
href: "/"
|
|
745
|
+
}, "Item6"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
746
|
+
id: "item07",
|
|
747
|
+
renderBeforeLabel: /*#__PURE__*/React.createElement(IconCheckSolid, null)
|
|
748
|
+
}, "Item7"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
749
|
+
id: "item08",
|
|
750
|
+
renderAfterLabel: /*#__PURE__*/React.createElement(IconCheckSolid, null)
|
|
751
|
+
}, "Item8"), /*#__PURE__*/React.createElement(Drilldown.Separator, {
|
|
752
|
+
id: "sep1"
|
|
753
|
+
}), /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
754
|
+
id: "group1",
|
|
755
|
+
renderGroupTitle: "Multi-select group",
|
|
756
|
+
selectableType: "multiple"
|
|
757
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
758
|
+
id: "groupItem11"
|
|
759
|
+
}, "GroupItem"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
760
|
+
id: "groupItem12"
|
|
761
|
+
}, "GroupItem"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
762
|
+
id: "groupItem13"
|
|
763
|
+
}, "GroupItem")), /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
764
|
+
id: "group2",
|
|
765
|
+
renderGroupTitle: "Single-select group",
|
|
766
|
+
selectableType: "single"
|
|
767
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
768
|
+
id: "groupItem21"
|
|
769
|
+
}, "GroupItem"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
770
|
+
id: "groupItem22"
|
|
771
|
+
}, "GroupItem"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
772
|
+
id: "groupItem23"
|
|
773
|
+
}, "GroupItem"))), /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
774
|
+
id: "page1"
|
|
775
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
776
|
+
id: "item11"
|
|
777
|
+
}, "Item1"))))),
|
|
778
|
+
container = _render9.container;
|
|
779
|
+
|
|
780
|
+
// 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.
|
|
781
|
+
// TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
|
|
782
|
+
// https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
|
|
783
|
+
const axeCheck = await runAxeCheck(container, {
|
|
784
|
+
ignores: ['aria-required-children']
|
|
785
|
+
});
|
|
786
|
+
expect(axeCheck).toBe(true);
|
|
787
|
+
});
|
|
788
|
+
it('should meet a11y standarts when drilldown is open', async () => {
|
|
789
|
+
const _render10 = render(_Drilldown15 || (_Drilldown15 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
790
|
+
defaultShow: true,
|
|
791
|
+
rootPageId: "page0"
|
|
792
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
793
|
+
id: "page0"
|
|
794
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
795
|
+
id: "option0"
|
|
796
|
+
}, "Option 0"))))),
|
|
797
|
+
container = _render10.container;
|
|
798
|
+
const axeCheck = await runAxeCheck(container);
|
|
799
|
+
expect(axeCheck).toBe(true);
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
describe('with generated examples', () => {
|
|
803
|
+
const generatedComponents = generateA11yTests(Drilldown, DrilldownExamples);
|
|
804
|
+
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
|
805
|
+
content
|
|
806
|
+
}) => {
|
|
807
|
+
const _render11 = render(content),
|
|
808
|
+
container = _render11.container;
|
|
809
|
+
const axeCheck = await runAxeCheck(container, {
|
|
810
|
+
// 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.
|
|
811
|
+
// TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
|
|
812
|
+
// https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
|
|
813
|
+
ignores: ['aria-required-children']
|
|
814
|
+
});
|
|
815
|
+
expect(axeCheck).toBe(true);
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
});
|