@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,299 @@
1
+ var _Drilldown, _Drilldown2, _Drilldown$Option, _Drilldown$Option2, _Drilldown3, _Drilldown$Option3, _Drilldown$Option4, _Drilldown$Option5, _Drilldown4, _Drilldown5, _Drilldown$Option6, _Drilldown$Option7, _Drilldown6, _Drilldown7, _Drilldown8, _Drilldown9, _Drilldown10;
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
+ import { Drilldown } from '../../index';
32
+ describe('<Drilldown.Page />', () => {
33
+ let consoleWarningMock;
34
+ let consoleErrorMock;
35
+ beforeEach(() => {
36
+ // Mocking console to prevent test output pollution and expect for messages
37
+ consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
38
+ consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
39
+ });
40
+ afterEach(() => {
41
+ consoleWarningMock.mockRestore();
42
+ consoleErrorMock.mockRestore();
43
+ });
44
+ it("shouldn't render non-DrilldownPage children", async () => {
45
+ render(_Drilldown || (_Drilldown = /*#__PURE__*/React.createElement(Drilldown, {
46
+ rootPageId: "page0"
47
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
48
+ id: "page0"
49
+ }, /*#__PURE__*/React.createElement("div", {
50
+ id: "testDiv"
51
+ }, "Div")))));
52
+ const nonPageChild = screen.queryByText('DIV');
53
+ expect(nonPageChild).not.toBeInTheDocument();
54
+ });
55
+ describe('header title', () => {
56
+ it('should be displayed in the header', async () => {
57
+ const _render = render(_Drilldown2 || (_Drilldown2 = /*#__PURE__*/React.createElement(Drilldown, {
58
+ rootPageId: "page0"
59
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
60
+ id: "page0",
61
+ renderTitle: "HeaderTitleString"
62
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
63
+ id: "option1"
64
+ }, "Option"))))),
65
+ container = _render.container;
66
+ const titleContainer = container.querySelector('[id^="DrilldownHeader-Title-Label_"]');
67
+ const title = screen.queryByText('HeaderTitleString');
68
+ expect(titleContainer).toBeInTheDocument();
69
+ expect(title).toBeInTheDocument();
70
+ });
71
+ it('should be displayed when function is passed', async () => {
72
+ render( /*#__PURE__*/React.createElement(Drilldown, {
73
+ rootPageId: "page0"
74
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
75
+ id: "page0",
76
+ renderTitle: () => 'HeaderTitleFunction'
77
+ }, _Drilldown$Option || (_Drilldown$Option = /*#__PURE__*/React.createElement(Drilldown.Option, {
78
+ id: "option1"
79
+ }, "Option")))));
80
+ const title = screen.queryByText('HeaderTitleFunction');
81
+ expect(title).toBeInTheDocument();
82
+ });
83
+ it("shouldn't be displayed when function has no return value", async () => {
84
+ const _render2 = render( /*#__PURE__*/React.createElement(Drilldown, {
85
+ rootPageId: "page0"
86
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
87
+ id: "page0",
88
+ renderTitle: () => null
89
+ }, _Drilldown$Option2 || (_Drilldown$Option2 = /*#__PURE__*/React.createElement(Drilldown.Option, {
90
+ id: "option1"
91
+ }, "Option"))))),
92
+ container = _render2.container;
93
+ const title = container.querySelector('[id^="DrilldownHeader-Title-Label_"]');
94
+ const listItem = container.querySelector('li');
95
+ expect(title).not.toBeInTheDocument();
96
+ expect(listItem).toBeInTheDocument();
97
+ });
98
+ });
99
+ describe('header action label', () => {
100
+ it('should be displayed in the header', async () => {
101
+ render(_Drilldown3 || (_Drilldown3 = /*#__PURE__*/React.createElement(Drilldown, {
102
+ rootPageId: "page0"
103
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
104
+ id: "page0",
105
+ renderActionLabel: "HeaderActionLabelString"
106
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
107
+ id: "option1"
108
+ }, "Option")))));
109
+ const actionLabel = screen.queryByText('HeaderActionLabelString');
110
+ expect(actionLabel).toBeInTheDocument();
111
+ });
112
+ it('should be displayed when function is passed', async () => {
113
+ render( /*#__PURE__*/React.createElement(Drilldown, {
114
+ rootPageId: "page0"
115
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
116
+ id: "page0",
117
+ renderActionLabel: () => 'HeaderActionLabelFunction'
118
+ }, _Drilldown$Option3 || (_Drilldown$Option3 = /*#__PURE__*/React.createElement(Drilldown.Option, {
119
+ id: "option1"
120
+ }, "Option")))));
121
+ const actionLabel = screen.queryByText('HeaderActionLabelFunction');
122
+ expect(actionLabel).toBeInTheDocument();
123
+ });
124
+ it("shouldn't be displayed when function has no return value", async () => {
125
+ const _render3 = render( /*#__PURE__*/React.createElement(Drilldown, {
126
+ rootPageId: "page0"
127
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
128
+ id: "page0",
129
+ renderActionLabel: () => null
130
+ }, _Drilldown$Option4 || (_Drilldown$Option4 = /*#__PURE__*/React.createElement(Drilldown.Option, {
131
+ id: "option1"
132
+ }, "Option"))))),
133
+ container = _render3.container;
134
+ const listItem = container.querySelector('li');
135
+ const title = container.querySelector('[id^="DrilldownHeader-Title-Label_"]');
136
+ expect(listItem).toBeInTheDocument();
137
+ expect(title).not.toBeInTheDocument();
138
+ });
139
+ it('should fire header action callback', async () => {
140
+ const actionCallback = vi.fn();
141
+ render( /*#__PURE__*/React.createElement(Drilldown, {
142
+ rootPageId: "page0"
143
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
144
+ id: "page0",
145
+ renderActionLabel: "ActionWithCallback",
146
+ onHeaderActionClicked: actionCallback
147
+ }, _Drilldown$Option5 || (_Drilldown$Option5 = /*#__PURE__*/React.createElement(Drilldown.Option, {
148
+ id: "option1"
149
+ }, "Option")))));
150
+ const actionLabel = screen.getByText('ActionWithCallback');
151
+ await userEvent.click(actionLabel);
152
+ await waitFor(() => {
153
+ expect(actionCallback).toHaveBeenCalled();
154
+ });
155
+ });
156
+ });
157
+ describe('header back navigation', () => {
158
+ it('should not be displayed on root page', async () => {
159
+ render(_Drilldown4 || (_Drilldown4 = /*#__PURE__*/React.createElement(Drilldown, {
160
+ rootPageId: "page0"
161
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
162
+ id: "page0",
163
+ renderBackButtonLabel: "HeaderBackString"
164
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
165
+ id: "option1"
166
+ }, "Option")))));
167
+ const label = screen.queryByText('HeaderBackString');
168
+ expect(label).not.toBeInTheDocument();
169
+ });
170
+ it('should be displayed on subpages', async () => {
171
+ render(_Drilldown5 || (_Drilldown5 = /*#__PURE__*/React.createElement(Drilldown, {
172
+ rootPageId: "page0"
173
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
174
+ id: "page0"
175
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
176
+ id: "option1",
177
+ subPageId: "page2"
178
+ }, "Option")), /*#__PURE__*/React.createElement(Drilldown.Page, {
179
+ id: "page2",
180
+ renderBackButtonLabel: "HeaderBackString"
181
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
182
+ id: "option2"
183
+ }, "Option")))));
184
+ const option = screen.getByText('Option');
185
+ await userEvent.click(option);
186
+ await waitFor(() => {
187
+ const label = screen.queryByText('HeaderBackString');
188
+ expect(label).toBeInTheDocument();
189
+ });
190
+ });
191
+ it('should be displayed when function is passed, and can use former page title', async () => {
192
+ const pageTitle = 'Page Title';
193
+ render( /*#__PURE__*/React.createElement(Drilldown, {
194
+ rootPageId: "page0"
195
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
196
+ id: "page0",
197
+ renderTitle: pageTitle
198
+ }, _Drilldown$Option6 || (_Drilldown$Option6 = /*#__PURE__*/React.createElement(Drilldown.Option, {
199
+ id: "option1",
200
+ subPageId: "page2"
201
+ }, "Option"))), /*#__PURE__*/React.createElement(Drilldown.Page, {
202
+ id: "page2",
203
+ renderBackButtonLabel: prevPageTitle => `Back to ${prevPageTitle}`
204
+ }, _Drilldown$Option7 || (_Drilldown$Option7 = /*#__PURE__*/React.createElement(Drilldown.Option, {
205
+ id: "option2"
206
+ }, "Option")))));
207
+ const option = screen.getByText('Option');
208
+ await userEvent.click(option);
209
+ await waitFor(() => {
210
+ const label = screen.queryByText(`Back to ${pageTitle}`);
211
+ expect(label).toBeInTheDocument();
212
+ });
213
+ });
214
+ });
215
+ describe('header separator', () => {
216
+ it('should not be displayed, if no item is on the header', async () => {
217
+ const _render4 = render(_Drilldown6 || (_Drilldown6 = /*#__PURE__*/React.createElement(Drilldown, {
218
+ rootPageId: "page0"
219
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
220
+ id: "page0"
221
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
222
+ id: "option1"
223
+ }, "Option"))))),
224
+ container = _render4.container;
225
+ const separator = container.querySelector('[id^="DrilldownHeader-Separator_"]');
226
+ expect(separator).not.toBeInTheDocument();
227
+ });
228
+ it('should be displayed, if there are items in the header', async () => {
229
+ const _render5 = render(_Drilldown7 || (_Drilldown7 = /*#__PURE__*/React.createElement(Drilldown, {
230
+ rootPageId: "page0"
231
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
232
+ id: "page0",
233
+ renderTitle: "Title"
234
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
235
+ id: "option1"
236
+ }, "Option"))))),
237
+ container = _render5.container;
238
+ const separator = container.querySelector('[id^="DrilldownHeader-Separator_"]');
239
+ expect(separator).toBeInTheDocument();
240
+ });
241
+ it('should not be displayed, if withoutHeaderSeparator is set', async () => {
242
+ const _render6 = render(_Drilldown8 || (_Drilldown8 = /*#__PURE__*/React.createElement(Drilldown, {
243
+ rootPageId: "page0"
244
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
245
+ id: "page0",
246
+ renderTitle: "Title",
247
+ withoutHeaderSeparator: true
248
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
249
+ id: "option1"
250
+ }, "Option"))))),
251
+ container = _render6.container;
252
+ const separator = container.querySelector('[id^="DrilldownHeader-Separator_"]');
253
+ expect(separator).not.toBeInTheDocument();
254
+ });
255
+ });
256
+ describe('disabled prop', () => {
257
+ it('should make all options disabled', async () => {
258
+ render(_Drilldown9 || (_Drilldown9 = /*#__PURE__*/React.createElement(Drilldown, {
259
+ rootPageId: "page0"
260
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
261
+ id: "page0",
262
+ renderActionLabel: "Action Label",
263
+ disabled: true
264
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
265
+ id: "option1"
266
+ }, "Option")))));
267
+ const allOptions = screen.getAllByRole('menuitem');
268
+ allOptions.forEach(option => {
269
+ expect(option).toHaveAttribute('aria-disabled', 'true');
270
+ });
271
+ });
272
+ it("shouldn't make header Back options disabled", async () => {
273
+ render(_Drilldown10 || (_Drilldown10 = /*#__PURE__*/React.createElement(Drilldown, {
274
+ rootPageId: "page0"
275
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
276
+ id: "page0"
277
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
278
+ id: "option1",
279
+ subPageId: "page2"
280
+ }, "Option1")), /*#__PURE__*/React.createElement(Drilldown.Page, {
281
+ id: "page2",
282
+ disabled: true,
283
+ renderBackButtonLabel: "HeaderBackString"
284
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
285
+ id: "option2"
286
+ }, "Option2")))));
287
+ const subPageOption = screen.getByText('Option1');
288
+ await userEvent.click(subPageOption);
289
+ await waitFor(() => {
290
+ const option2 = screen.getByLabelText('Option2');
291
+ const backOption = screen.getByLabelText('HeaderBackString');
292
+ expect(option2).toHaveAttribute('role', 'menuitem');
293
+ expect(option2).toHaveAttribute('aria-disabled', 'true');
294
+ expect(backOption).toHaveAttribute('role', 'menuitem');
295
+ expect(backOption).not.toHaveAttribute('aria-disabled');
296
+ });
297
+ });
298
+ });
299
+ });
@@ -0,0 +1,56 @@
1
+ var _Drilldown, _Drilldown2;
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 } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { Drilldown } from '../../index';
30
+ describe('<Drilldown.Separator />', () => {
31
+ it('should render', async () => {
32
+ render(_Drilldown || (_Drilldown = /*#__PURE__*/React.createElement(Drilldown, {
33
+ rootPageId: "page0"
34
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
35
+ id: "page0"
36
+ }, /*#__PURE__*/React.createElement(Drilldown.Separator, {
37
+ id: "sep1",
38
+ "data-testid": "separator1"
39
+ })))));
40
+ const separator = screen.getByTestId('separator1');
41
+ expect(separator).toBeVisible();
42
+ expect(separator.getAttribute('class')).toContain('-separator');
43
+ });
44
+ it('should not render children', async () => {
45
+ render(_Drilldown2 || (_Drilldown2 = /*#__PURE__*/React.createElement(Drilldown, {
46
+ rootPageId: "page0"
47
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
48
+ id: "page0"
49
+ }, /*#__PURE__*/React.createElement(Drilldown.Separator, {
50
+ id: "sep1",
51
+ "data-testid": "separator1"
52
+ }, "Children")))));
53
+ const separatorChild = screen.queryByText('Children');
54
+ expect(separatorChild).not.toBeInTheDocument();
55
+ });
56
+ });