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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +573 -0
  3. package/es/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +595 -0
  4. package/es/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +299 -0
  5. package/es/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +56 -0
  6. package/es/Drilldown/__new-tests__/Drilldown.test.js +818 -0
  7. package/lib/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.js +575 -0
  8. package/lib/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.js +598 -0
  9. package/lib/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.js +301 -0
  10. package/lib/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.js +58 -0
  11. package/lib/Drilldown/__new-tests__/Drilldown.test.js +819 -0
  12. package/package.json +25 -20
  13. package/src/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.tsx +634 -0
  14. package/src/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.tsx +774 -0
  15. package/src/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.tsx +352 -0
  16. package/src/Drilldown/{locator.ts → DrilldownSeparator/__new-tests__/DrilldownSeparator.test.tsx} +35 -3
  17. package/src/Drilldown/__new-tests__/Drilldown.test.tsx +979 -0
  18. package/tsconfig.build.json +3 -2
  19. package/tsconfig.build.tsbuildinfo +1 -1
  20. package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts +2 -0
  21. package/types/Drilldown/DrilldownGroup/__new-tests__/DrilldownGroup.test.d.ts.map +1 -0
  22. package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts +2 -0
  23. package/types/Drilldown/DrilldownOption/__new-tests__/DrilldownOption.test.d.ts.map +1 -0
  24. package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts +2 -0
  25. package/types/Drilldown/DrilldownPage/__new-tests__/DrilldownPage.test.d.ts.map +1 -0
  26. package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts +2 -0
  27. package/types/Drilldown/DrilldownSeparator/__new-tests__/DrilldownSeparator.test.d.ts.map +1 -0
  28. package/types/Drilldown/__new-tests__/Drilldown.test.d.ts +2 -0
  29. package/types/Drilldown/__new-tests__/Drilldown.test.d.ts.map +1 -0
  30. package/es/Drilldown/DrilldownLocator.js +0 -99
  31. package/es/Drilldown/locator.js +0 -27
  32. package/lib/Drilldown/DrilldownLocator.js +0 -106
  33. package/lib/Drilldown/locator.js +0 -37
  34. package/src/Drilldown/DrilldownLocator.ts +0 -104
  35. package/types/Drilldown/DrilldownLocator.d.ts +0 -7484
  36. package/types/Drilldown/DrilldownLocator.d.ts.map +0 -1
  37. package/types/Drilldown/locator.d.ts +0 -4
  38. package/types/Drilldown/locator.d.ts.map +0 -1
@@ -0,0 +1,352 @@
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
+ import { Drilldown } from '../../index'
32
+
33
+ describe('<Drilldown.Page />', () => {
34
+ let consoleWarningMock: ReturnType<typeof vi.spyOn>
35
+ let consoleErrorMock: ReturnType<typeof vi.spyOn>
36
+
37
+ beforeEach(() => {
38
+ // Mocking console to prevent test output pollution and expect for messages
39
+ consoleWarningMock = vi
40
+ .spyOn(console, 'warn')
41
+ .mockImplementation(() => {}) as any
42
+ consoleErrorMock = vi
43
+ .spyOn(console, 'error')
44
+ .mockImplementation(() => {}) as any
45
+ })
46
+
47
+ afterEach(() => {
48
+ consoleWarningMock.mockRestore()
49
+ consoleErrorMock.mockRestore()
50
+ })
51
+
52
+ it("shouldn't render non-DrilldownPage children", async () => {
53
+ render(
54
+ <Drilldown rootPageId="page0">
55
+ <Drilldown.Page id="page0">
56
+ <div id="testDiv">Div</div>
57
+ </Drilldown.Page>
58
+ </Drilldown>
59
+ )
60
+ const nonPageChild = screen.queryByText('DIV')
61
+
62
+ expect(nonPageChild).not.toBeInTheDocument()
63
+ })
64
+
65
+ describe('header title', () => {
66
+ it('should be displayed in the header', async () => {
67
+ const { container } = render(
68
+ <Drilldown rootPageId="page0">
69
+ <Drilldown.Page id="page0" renderTitle="HeaderTitleString">
70
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
71
+ </Drilldown.Page>
72
+ </Drilldown>
73
+ )
74
+ const titleContainer = container.querySelector(
75
+ '[id^="DrilldownHeader-Title-Label_"]'
76
+ )
77
+ const title = screen.queryByText('HeaderTitleString')
78
+
79
+ expect(titleContainer).toBeInTheDocument()
80
+ expect(title).toBeInTheDocument()
81
+ })
82
+
83
+ it('should be displayed when function is passed', async () => {
84
+ render(
85
+ <Drilldown rootPageId="page0">
86
+ <Drilldown.Page id="page0" renderTitle={() => 'HeaderTitleFunction'}>
87
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
88
+ </Drilldown.Page>
89
+ </Drilldown>
90
+ )
91
+ const title = screen.queryByText('HeaderTitleFunction')
92
+
93
+ expect(title).toBeInTheDocument()
94
+ })
95
+
96
+ it("shouldn't be displayed when function has no return value", async () => {
97
+ const { container } = render(
98
+ <Drilldown rootPageId="page0">
99
+ <Drilldown.Page id="page0" renderTitle={() => null}>
100
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
101
+ </Drilldown.Page>
102
+ </Drilldown>
103
+ )
104
+ const title = container.querySelector(
105
+ '[id^="DrilldownHeader-Title-Label_"]'
106
+ )
107
+ const listItem = container.querySelector('li')
108
+
109
+ expect(title).not.toBeInTheDocument()
110
+ expect(listItem).toBeInTheDocument()
111
+ })
112
+ })
113
+
114
+ describe('header action label', () => {
115
+ it('should be displayed in the header', async () => {
116
+ render(
117
+ <Drilldown rootPageId="page0">
118
+ <Drilldown.Page
119
+ id="page0"
120
+ renderActionLabel="HeaderActionLabelString"
121
+ >
122
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
123
+ </Drilldown.Page>
124
+ </Drilldown>
125
+ )
126
+ const actionLabel = screen.queryByText('HeaderActionLabelString')
127
+
128
+ expect(actionLabel).toBeInTheDocument()
129
+ })
130
+
131
+ it('should be displayed when function is passed', async () => {
132
+ render(
133
+ <Drilldown rootPageId="page0">
134
+ <Drilldown.Page
135
+ id="page0"
136
+ renderActionLabel={() => 'HeaderActionLabelFunction'}
137
+ >
138
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
139
+ </Drilldown.Page>
140
+ </Drilldown>
141
+ )
142
+ const actionLabel = screen.queryByText('HeaderActionLabelFunction')
143
+
144
+ expect(actionLabel).toBeInTheDocument()
145
+ })
146
+
147
+ it("shouldn't be displayed when function has no return value", async () => {
148
+ const { container } = render(
149
+ <Drilldown rootPageId="page0">
150
+ <Drilldown.Page id="page0" renderActionLabel={() => null}>
151
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
152
+ </Drilldown.Page>
153
+ </Drilldown>
154
+ )
155
+ const listItem = container.querySelector('li')
156
+ const title = container.querySelector(
157
+ '[id^="DrilldownHeader-Title-Label_"]'
158
+ )
159
+
160
+ expect(listItem).toBeInTheDocument()
161
+ expect(title).not.toBeInTheDocument()
162
+ })
163
+
164
+ it('should fire header action callback', async () => {
165
+ const actionCallback = vi.fn()
166
+ render(
167
+ <Drilldown rootPageId="page0">
168
+ <Drilldown.Page
169
+ id="page0"
170
+ renderActionLabel="ActionWithCallback"
171
+ onHeaderActionClicked={actionCallback}
172
+ >
173
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
174
+ </Drilldown.Page>
175
+ </Drilldown>
176
+ )
177
+ const actionLabel = screen.getByText('ActionWithCallback')
178
+
179
+ await userEvent.click(actionLabel)
180
+
181
+ await waitFor(() => {
182
+ expect(actionCallback).toHaveBeenCalled()
183
+ })
184
+ })
185
+ })
186
+
187
+ describe('header back navigation', () => {
188
+ it('should not be displayed on root page', async () => {
189
+ render(
190
+ <Drilldown rootPageId="page0">
191
+ <Drilldown.Page id="page0" renderBackButtonLabel="HeaderBackString">
192
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
193
+ </Drilldown.Page>
194
+ </Drilldown>
195
+ )
196
+ const label = screen.queryByText('HeaderBackString')
197
+
198
+ expect(label).not.toBeInTheDocument()
199
+ })
200
+
201
+ it('should be displayed on subpages', async () => {
202
+ render(
203
+ <Drilldown rootPageId="page0">
204
+ <Drilldown.Page id="page0">
205
+ <Drilldown.Option id="option1" subPageId="page2">
206
+ Option
207
+ </Drilldown.Option>
208
+ </Drilldown.Page>
209
+ <Drilldown.Page id="page2" renderBackButtonLabel="HeaderBackString">
210
+ <Drilldown.Option id="option2">Option</Drilldown.Option>
211
+ </Drilldown.Page>
212
+ </Drilldown>
213
+ )
214
+ const option = screen.getByText('Option')
215
+
216
+ await userEvent.click(option)
217
+
218
+ await waitFor(() => {
219
+ const label = screen.queryByText('HeaderBackString')
220
+
221
+ expect(label).toBeInTheDocument()
222
+ })
223
+ })
224
+
225
+ it('should be displayed when function is passed, and can use former page title', async () => {
226
+ const pageTitle = 'Page Title'
227
+ render(
228
+ <Drilldown rootPageId="page0">
229
+ <Drilldown.Page id="page0" renderTitle={pageTitle}>
230
+ <Drilldown.Option id="option1" subPageId="page2">
231
+ Option
232
+ </Drilldown.Option>
233
+ </Drilldown.Page>
234
+ <Drilldown.Page
235
+ id="page2"
236
+ renderBackButtonLabel={(prevPageTitle) =>
237
+ `Back to ${prevPageTitle}`
238
+ }
239
+ >
240
+ <Drilldown.Option id="option2">Option</Drilldown.Option>
241
+ </Drilldown.Page>
242
+ </Drilldown>
243
+ )
244
+ const option = screen.getByText('Option')
245
+
246
+ await userEvent.click(option)
247
+
248
+ await waitFor(() => {
249
+ const label = screen.queryByText(`Back to ${pageTitle}`)
250
+
251
+ expect(label).toBeInTheDocument()
252
+ })
253
+ })
254
+ })
255
+
256
+ describe('header separator', () => {
257
+ it('should not be displayed, if no item is on the header', async () => {
258
+ const { container } = render(
259
+ <Drilldown rootPageId="page0">
260
+ <Drilldown.Page id="page0">
261
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
262
+ </Drilldown.Page>
263
+ </Drilldown>
264
+ )
265
+ const separator = container.querySelector(
266
+ '[id^="DrilldownHeader-Separator_"]'
267
+ )
268
+
269
+ expect(separator).not.toBeInTheDocument()
270
+ })
271
+
272
+ it('should be displayed, if there are items in the header', async () => {
273
+ const { container } = render(
274
+ <Drilldown rootPageId="page0">
275
+ <Drilldown.Page id="page0" renderTitle="Title">
276
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
277
+ </Drilldown.Page>
278
+ </Drilldown>
279
+ )
280
+ const separator = container.querySelector(
281
+ '[id^="DrilldownHeader-Separator_"]'
282
+ )
283
+
284
+ expect(separator).toBeInTheDocument()
285
+ })
286
+
287
+ it('should not be displayed, if withoutHeaderSeparator is set', async () => {
288
+ const { container } = render(
289
+ <Drilldown rootPageId="page0">
290
+ <Drilldown.Page id="page0" renderTitle="Title" withoutHeaderSeparator>
291
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
292
+ </Drilldown.Page>
293
+ </Drilldown>
294
+ )
295
+ const separator = container.querySelector(
296
+ '[id^="DrilldownHeader-Separator_"]'
297
+ )
298
+
299
+ expect(separator).not.toBeInTheDocument()
300
+ })
301
+ })
302
+
303
+ describe('disabled prop', () => {
304
+ it('should make all options disabled', async () => {
305
+ render(
306
+ <Drilldown rootPageId="page0">
307
+ <Drilldown.Page id="page0" renderActionLabel="Action Label" disabled>
308
+ <Drilldown.Option id="option1">Option</Drilldown.Option>
309
+ </Drilldown.Page>
310
+ </Drilldown>
311
+ )
312
+ const allOptions = screen.getAllByRole('menuitem')
313
+
314
+ allOptions.forEach((option) => {
315
+ expect(option).toHaveAttribute('aria-disabled', 'true')
316
+ })
317
+ })
318
+
319
+ it("shouldn't make header Back options disabled", async () => {
320
+ render(
321
+ <Drilldown rootPageId="page0">
322
+ <Drilldown.Page id="page0">
323
+ <Drilldown.Option id="option1" subPageId="page2">
324
+ Option1
325
+ </Drilldown.Option>
326
+ </Drilldown.Page>
327
+ <Drilldown.Page
328
+ id="page2"
329
+ disabled
330
+ renderBackButtonLabel="HeaderBackString"
331
+ >
332
+ <Drilldown.Option id="option2">Option2</Drilldown.Option>
333
+ </Drilldown.Page>
334
+ </Drilldown>
335
+ )
336
+ const subPageOption = screen.getByText('Option1')
337
+
338
+ await userEvent.click(subPageOption)
339
+
340
+ await waitFor(() => {
341
+ const option2 = screen.getByLabelText('Option2')
342
+ const backOption = screen.getByLabelText('HeaderBackString')
343
+
344
+ expect(option2).toHaveAttribute('role', 'menuitem')
345
+ expect(option2).toHaveAttribute('aria-disabled', 'true')
346
+
347
+ expect(backOption).toHaveAttribute('role', 'menuitem')
348
+ expect(backOption).not.toHaveAttribute('aria-disabled')
349
+ })
350
+ })
351
+ })
352
+ })
@@ -22,7 +22,39 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import { DrilldownLocator } from './DrilldownLocator'
25
+ import React from 'react'
26
+ import { render, screen } from '@testing-library/react'
27
+ import '@testing-library/jest-dom'
26
28
 
27
- export { DrilldownLocator }
28
- export default DrilldownLocator
29
+ import { Drilldown } from '../../index'
30
+
31
+ describe('<Drilldown.Separator />', () => {
32
+ it('should render', async () => {
33
+ render(
34
+ <Drilldown rootPageId="page0">
35
+ <Drilldown.Page id="page0">
36
+ <Drilldown.Separator id="sep1" data-testid="separator1" />
37
+ </Drilldown.Page>
38
+ </Drilldown>
39
+ )
40
+ const separator = screen.getByTestId('separator1')
41
+
42
+ expect(separator).toBeVisible()
43
+ expect(separator.getAttribute('class')).toContain('-separator')
44
+ })
45
+
46
+ it('should not render children', async () => {
47
+ render(
48
+ <Drilldown rootPageId="page0">
49
+ <Drilldown.Page id="page0">
50
+ <Drilldown.Separator id="sep1" data-testid="separator1">
51
+ Children
52
+ </Drilldown.Separator>
53
+ </Drilldown.Page>
54
+ </Drilldown>
55
+ )
56
+ const separatorChild = screen.queryByText('Children')
57
+
58
+ expect(separatorChild).not.toBeInTheDocument()
59
+ })
60
+ })