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