@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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.2.1-snapshot-1](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1-snapshot-1) (2024-08-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-drilldown
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [10.2.0](https://github.com/instructure/instructure-ui/compare/v10.0.0...v10.2.0) (2024-08-23)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-drilldown
|
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
var _Drilldown, _Drilldown$Option, _Drilldown2, _Drilldown$Option2, _Drilldown3, _Drilldown4, _Drilldown5, _Drilldown6, _Drilldown7, _Drilldown8, _Drilldown9, _Drilldown10, _Drilldown11, _Drilldown12, _Drilldown13, _Drilldown14, _Drilldown15, _Drilldown16, _Drilldown$Option3, _Drilldown$Option4, _Drilldown$Option5, _Drilldown$Option6, _Drilldown$Option7, _Drilldown$Option8, _Drilldown$Option9, _Drilldown$Option10, _Drilldown$Option11, _Drilldown$Option12, _Drilldown$Option13, _Drilldown$Option14, _Drilldown$Option15, _Drilldown$Option16, _Drilldown$Option17;
|
|
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.Group />', () => {
|
|
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('should not allow de-selecting an option when selectableType = "single"', async () => {
|
|
45
|
+
const options = ['one', 'two', 'three'];
|
|
46
|
+
const Example = ({
|
|
47
|
+
opts
|
|
48
|
+
}) => {
|
|
49
|
+
return /*#__PURE__*/React.createElement(Drilldown, {
|
|
50
|
+
rootPageId: "page0"
|
|
51
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
52
|
+
id: "page0"
|
|
53
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
54
|
+
id: "group0",
|
|
55
|
+
selectableType: "single"
|
|
56
|
+
}, opts.map(opt => {
|
|
57
|
+
return /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
58
|
+
key: opt,
|
|
59
|
+
value: opt,
|
|
60
|
+
name: opt,
|
|
61
|
+
id: opt,
|
|
62
|
+
defaultSelected: opt === 'three',
|
|
63
|
+
"data-testid": opt
|
|
64
|
+
}, opt);
|
|
65
|
+
}))));
|
|
66
|
+
};
|
|
67
|
+
render( /*#__PURE__*/React.createElement(Example, {
|
|
68
|
+
opts: options
|
|
69
|
+
}));
|
|
70
|
+
const selectedOption = screen.getByTestId('three');
|
|
71
|
+
expect(selectedOption).toHaveAttribute('aria-checked', 'true');
|
|
72
|
+
await userEvent.click(selectedOption);
|
|
73
|
+
await waitFor(() => {
|
|
74
|
+
const updatedSelectedOption = screen.getByTestId('three');
|
|
75
|
+
expect(updatedSelectedOption).toHaveAttribute('aria-checked', 'true');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
it("shouldn't render non-DrilldownGroup children", async () => {
|
|
79
|
+
render(_Drilldown || (_Drilldown = /*#__PURE__*/React.createElement(Drilldown, {
|
|
80
|
+
rootPageId: "page0"
|
|
81
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
82
|
+
id: "page0"
|
|
83
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
84
|
+
id: "group0"
|
|
85
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
86
|
+
"data-testid": "testDiv"
|
|
87
|
+
}, "Div"))))));
|
|
88
|
+
const nonGroupChild = screen.queryByTestId('testDiv');
|
|
89
|
+
const childText = screen.queryByText('Div');
|
|
90
|
+
expect(nonGroupChild).not.toBeInTheDocument();
|
|
91
|
+
expect(childText).not.toBeInTheDocument();
|
|
92
|
+
});
|
|
93
|
+
it('elementRef should return ref to the group', async () => {
|
|
94
|
+
const elementRef = vi.fn();
|
|
95
|
+
const _render = render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
96
|
+
rootPageId: "page0"
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
98
|
+
id: "page0"
|
|
99
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
100
|
+
id: "group0",
|
|
101
|
+
elementRef: elementRef
|
|
102
|
+
}, _Drilldown$Option || (_Drilldown$Option = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
103
|
+
id: "groupOption01"
|
|
104
|
+
}, "Option")))))),
|
|
105
|
+
container = _render.container;
|
|
106
|
+
const group = container.querySelector('#group0');
|
|
107
|
+
expect(elementRef).toHaveBeenCalledWith(group);
|
|
108
|
+
});
|
|
109
|
+
describe('renderGroupTitle', () => {
|
|
110
|
+
it('should display', async () => {
|
|
111
|
+
render(_Drilldown2 || (_Drilldown2 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
112
|
+
rootPageId: "page0"
|
|
113
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
114
|
+
id: "page0"
|
|
115
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
116
|
+
id: "group0",
|
|
117
|
+
renderGroupTitle: "Group Title"
|
|
118
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
119
|
+
id: "groupOption01"
|
|
120
|
+
}, "Option"))))));
|
|
121
|
+
const title = screen.getByText('Group Title');
|
|
122
|
+
expect(title).toBeInTheDocument();
|
|
123
|
+
});
|
|
124
|
+
it('should display, if function is provided', async () => {
|
|
125
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
126
|
+
rootPageId: "page0"
|
|
127
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
128
|
+
id: "page0"
|
|
129
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
130
|
+
id: "group0",
|
|
131
|
+
renderGroupTitle: () => 'Group Title'
|
|
132
|
+
}, _Drilldown$Option2 || (_Drilldown$Option2 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
133
|
+
id: "groupOption01"
|
|
134
|
+
}, "Option"))))));
|
|
135
|
+
const title = screen.getByText('Group Title');
|
|
136
|
+
expect(title).toBeInTheDocument();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('separators', () => {
|
|
140
|
+
it("shouldn't display, when group is first and/or last item", async () => {
|
|
141
|
+
const _render2 = render(_Drilldown3 || (_Drilldown3 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
142
|
+
rootPageId: "page0"
|
|
143
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
144
|
+
id: "page0"
|
|
145
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
146
|
+
id: "group0"
|
|
147
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
148
|
+
id: "groupOption01"
|
|
149
|
+
}, "Option")))))),
|
|
150
|
+
container = _render2.container;
|
|
151
|
+
const separators = container.querySelectorAll('[class$="-separator"]');
|
|
152
|
+
expect(separators.length).toBe(0);
|
|
153
|
+
});
|
|
154
|
+
it('should display by default, if group is between other items', async () => {
|
|
155
|
+
const _render3 = render(_Drilldown4 || (_Drilldown4 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
156
|
+
rootPageId: "page0"
|
|
157
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
158
|
+
id: "page0"
|
|
159
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
160
|
+
id: "option1"
|
|
161
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
162
|
+
id: "group0"
|
|
163
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
164
|
+
id: "groupOption01"
|
|
165
|
+
}, "Option")), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
166
|
+
id: "option2"
|
|
167
|
+
}, "Option"))))),
|
|
168
|
+
container = _render3.container;
|
|
169
|
+
const separators = container.querySelectorAll('[class$="-separator"]');
|
|
170
|
+
expect(separators.length).toBe(2);
|
|
171
|
+
});
|
|
172
|
+
it("shouldn't display extra separator between groups", async () => {
|
|
173
|
+
const _render4 = render(_Drilldown5 || (_Drilldown5 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
174
|
+
rootPageId: "page0"
|
|
175
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
176
|
+
id: "page0"
|
|
177
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
178
|
+
id: "option1"
|
|
179
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
180
|
+
id: "group0"
|
|
181
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
182
|
+
id: "groupOption01"
|
|
183
|
+
}, "Option")), /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
184
|
+
id: "group1"
|
|
185
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
186
|
+
id: "groupOption11"
|
|
187
|
+
}, "Option")), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
188
|
+
id: "option2"
|
|
189
|
+
}, "Option"))))),
|
|
190
|
+
container = _render4.container;
|
|
191
|
+
const separators = container.querySelectorAll('[class$="-separator"]');
|
|
192
|
+
expect(separators.length).toBe(3);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
describe('disabled prop', () => {
|
|
196
|
+
it('should disable all items in the group', async () => {
|
|
197
|
+
const _render5 = render(_Drilldown6 || (_Drilldown6 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
198
|
+
rootPageId: "page0"
|
|
199
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
200
|
+
id: "page0"
|
|
201
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
202
|
+
id: "option1"
|
|
203
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
204
|
+
id: "group0",
|
|
205
|
+
disabled: true
|
|
206
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
207
|
+
id: "groupOption01"
|
|
208
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
209
|
+
id: "groupOption02"
|
|
210
|
+
}, "Option")), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
211
|
+
id: "option2"
|
|
212
|
+
}, "Option"))))),
|
|
213
|
+
container = _render5.container;
|
|
214
|
+
const disabledOption_1 = container.querySelector('#groupOption01');
|
|
215
|
+
const disabledOption_2 = container.querySelector('#groupOption02');
|
|
216
|
+
const option_1 = container.querySelector('#option1');
|
|
217
|
+
const option_2 = container.querySelector('#option2');
|
|
218
|
+
expect(disabledOption_1).toHaveAttribute('aria-disabled', 'true');
|
|
219
|
+
expect(disabledOption_2).toHaveAttribute('aria-disabled', 'true');
|
|
220
|
+
expect(option_1).not.toHaveAttribute('aria-disabled');
|
|
221
|
+
expect(option_2).not.toHaveAttribute('aria-disabled');
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
describe('role prop', () => {
|
|
225
|
+
it('should be "group" by default', async () => {
|
|
226
|
+
const _render6 = render(_Drilldown7 || (_Drilldown7 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
227
|
+
rootPageId: "page0"
|
|
228
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
229
|
+
id: "page0"
|
|
230
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
231
|
+
id: "group0"
|
|
232
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
233
|
+
id: "groupOption01"
|
|
234
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
235
|
+
id: "groupOption02"
|
|
236
|
+
}, "Option")))))),
|
|
237
|
+
container = _render6.container;
|
|
238
|
+
const group = container.querySelector('#group0');
|
|
239
|
+
expect(group).toHaveAttribute('role', 'group');
|
|
240
|
+
});
|
|
241
|
+
it('should render the group with passed role', async () => {
|
|
242
|
+
const _render7 = render(_Drilldown8 || (_Drilldown8 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
243
|
+
rootPageId: "page0"
|
|
244
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
245
|
+
id: "page0"
|
|
246
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
247
|
+
id: "group0",
|
|
248
|
+
role: "menu"
|
|
249
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
250
|
+
id: "groupOption01"
|
|
251
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
252
|
+
id: "groupOption02"
|
|
253
|
+
}, "Option")))))),
|
|
254
|
+
container = _render7.container;
|
|
255
|
+
const group = container.querySelector('#group0');
|
|
256
|
+
expect(group).toHaveAttribute('role', 'menu');
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
describe('as prop', () => {
|
|
260
|
+
it('should inherit Drilldown\'s "ul" by default', async () => {
|
|
261
|
+
const _render8 = render(_Drilldown9 || (_Drilldown9 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
262
|
+
rootPageId: "page0"
|
|
263
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
264
|
+
id: "page0"
|
|
265
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
266
|
+
id: "group0"
|
|
267
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
268
|
+
id: "groupOption01"
|
|
269
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
270
|
+
id: "groupOption02"
|
|
271
|
+
}, "Option")))))),
|
|
272
|
+
container = _render8.container;
|
|
273
|
+
const drilldownContainer = container.querySelector('[id^=Selectable_][id$=-list]');
|
|
274
|
+
const group = container.querySelector('#group0');
|
|
275
|
+
expect(drilldownContainer.tagName).toBe('UL');
|
|
276
|
+
expect(group.tagName).toBe('UL');
|
|
277
|
+
});
|
|
278
|
+
it('should inherit Drilldown\'s "as" prop', async () => {
|
|
279
|
+
const _render9 = render(_Drilldown10 || (_Drilldown10 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
280
|
+
rootPageId: "page0",
|
|
281
|
+
as: "ol"
|
|
282
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
283
|
+
id: "page0"
|
|
284
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
285
|
+
id: "group0"
|
|
286
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
287
|
+
id: "groupOption01"
|
|
288
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
289
|
+
id: "groupOption02"
|
|
290
|
+
}, "Option")))))),
|
|
291
|
+
container = _render9.container;
|
|
292
|
+
const drilldownContainer = container.querySelector('[id^=Selectable_][id$=-list]');
|
|
293
|
+
const group = container.querySelector('#group0');
|
|
294
|
+
expect(drilldownContainer.tagName).toBe('OL');
|
|
295
|
+
expect(group.tagName).toBe('OL');
|
|
296
|
+
});
|
|
297
|
+
it('should render the group as other element', async () => {
|
|
298
|
+
const _render10 = render(_Drilldown11 || (_Drilldown11 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
299
|
+
rootPageId: "page0"
|
|
300
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
301
|
+
id: "page0"
|
|
302
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
303
|
+
id: "group0",
|
|
304
|
+
as: "ol"
|
|
305
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
306
|
+
id: "groupOption01"
|
|
307
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
308
|
+
id: "groupOption02"
|
|
309
|
+
}, "Option")))))),
|
|
310
|
+
container = _render10.container;
|
|
311
|
+
const drilldownContainer = container.querySelector('[id^=Selectable_][id$=-list]');
|
|
312
|
+
const group = container.querySelector('#group0');
|
|
313
|
+
expect(drilldownContainer.tagName).toBe('UL');
|
|
314
|
+
expect(group.tagName).toBe('OL');
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
describe('selectableType', () => {
|
|
318
|
+
it('if not set, should render role="menuitem" options without icon by default', async () => {
|
|
319
|
+
const _render11 = render(_Drilldown12 || (_Drilldown12 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
320
|
+
rootPageId: "page0"
|
|
321
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
322
|
+
id: "page0"
|
|
323
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
324
|
+
id: "group0"
|
|
325
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
326
|
+
id: "groupOption01"
|
|
327
|
+
}, "Option")))))),
|
|
328
|
+
container = _render11.container;
|
|
329
|
+
const icon = container.querySelector('svg[name="IconCheck"]');
|
|
330
|
+
const groupOption = container.querySelector('#groupOption01');
|
|
331
|
+
expect(icon).not.toBeInTheDocument();
|
|
332
|
+
expect(groupOption).toHaveAttribute('role', 'menuitem');
|
|
333
|
+
});
|
|
334
|
+
it('value "single" should render role="menuitemradio" options with icon', async () => {
|
|
335
|
+
const _render12 = render(_Drilldown13 || (_Drilldown13 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
336
|
+
rootPageId: "page0"
|
|
337
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
338
|
+
id: "page0"
|
|
339
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
340
|
+
id: "group0",
|
|
341
|
+
selectableType: "single"
|
|
342
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
343
|
+
id: "groupOption01"
|
|
344
|
+
}, "Option")))))),
|
|
345
|
+
container = _render12.container;
|
|
346
|
+
const icon = container.querySelector('svg[name="IconCheck"]');
|
|
347
|
+
const groupOption = container.querySelector('#groupOption01');
|
|
348
|
+
expect(icon).toBeInTheDocument();
|
|
349
|
+
expect(groupOption).toHaveAttribute('role', 'menuitemradio');
|
|
350
|
+
});
|
|
351
|
+
it('value "multiple" should render role="menuitemcheckbox" options with icon', async () => {
|
|
352
|
+
const _render13 = render(_Drilldown14 || (_Drilldown14 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
353
|
+
rootPageId: "page0"
|
|
354
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
355
|
+
id: "page0"
|
|
356
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
357
|
+
id: "group0",
|
|
358
|
+
selectableType: "multiple"
|
|
359
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
360
|
+
id: "groupOption01"
|
|
361
|
+
}, "Option")))))),
|
|
362
|
+
container = _render13.container;
|
|
363
|
+
const icon = container.querySelector('svg[name="IconCheck"]');
|
|
364
|
+
const groupOption = container.querySelector('#groupOption01');
|
|
365
|
+
expect(icon).toBeInTheDocument();
|
|
366
|
+
expect(groupOption).toHaveAttribute('role', 'menuitemcheckbox');
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
describe('defaultSelected', () => {
|
|
370
|
+
describe('if not provided', () => {
|
|
371
|
+
it('all group options has to be unselected', async () => {
|
|
372
|
+
render(_Drilldown15 || (_Drilldown15 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
373
|
+
rootPageId: "page0"
|
|
374
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
375
|
+
id: "page0"
|
|
376
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
377
|
+
id: "group0",
|
|
378
|
+
selectableType: "multiple"
|
|
379
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
380
|
+
id: "groupOption01",
|
|
381
|
+
value: 1
|
|
382
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
383
|
+
id: "groupOption02",
|
|
384
|
+
value: 2
|
|
385
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
386
|
+
id: "groupOption03",
|
|
387
|
+
value: 3
|
|
388
|
+
}, "Option"))))));
|
|
389
|
+
const options = screen.getAllByRole('menuitemcheckbox');
|
|
390
|
+
expect(options.length).toBe(3);
|
|
391
|
+
options.forEach(option => {
|
|
392
|
+
expect(option).toHaveAttribute('aria-checked', 'false');
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
it('all checkboxes should not be visible', async () => {
|
|
396
|
+
const _render14 = render(_Drilldown16 || (_Drilldown16 = /*#__PURE__*/React.createElement(Drilldown, {
|
|
397
|
+
rootPageId: "page0"
|
|
398
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
399
|
+
id: "page0"
|
|
400
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
401
|
+
id: "group0",
|
|
402
|
+
selectableType: "multiple"
|
|
403
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
404
|
+
id: "groupOption01",
|
|
405
|
+
value: 1
|
|
406
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
407
|
+
id: "groupOption02",
|
|
408
|
+
value: 2
|
|
409
|
+
}, "Option"), /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
410
|
+
id: "groupOption03",
|
|
411
|
+
value: 3
|
|
412
|
+
}, "Option")))))),
|
|
413
|
+
container = _render14.container;
|
|
414
|
+
const icons = container.querySelectorAll('svg[name="IconCheck"]');
|
|
415
|
+
expect(icons.length).toBe(3);
|
|
416
|
+
icons.forEach(icon => {
|
|
417
|
+
expect(icon).not.toBeVisible();
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
describe('if provided', () => {
|
|
422
|
+
it('all selected checkboxes should be visible', async () => {
|
|
423
|
+
const selectedValues = ['item1', 'item3'];
|
|
424
|
+
const _render15 = render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
425
|
+
rootPageId: "page0"
|
|
426
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
427
|
+
id: "page0"
|
|
428
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
429
|
+
id: "group0",
|
|
430
|
+
selectableType: "multiple",
|
|
431
|
+
defaultSelected: selectedValues
|
|
432
|
+
}, _Drilldown$Option3 || (_Drilldown$Option3 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
433
|
+
id: "groupOption01",
|
|
434
|
+
value: "item1"
|
|
435
|
+
}, "Option")), _Drilldown$Option4 || (_Drilldown$Option4 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
436
|
+
id: "groupOption02",
|
|
437
|
+
value: "item2"
|
|
438
|
+
}, "Option")), _Drilldown$Option5 || (_Drilldown$Option5 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
439
|
+
id: "groupOption03",
|
|
440
|
+
value: "item3"
|
|
441
|
+
}, "Option")))))),
|
|
442
|
+
container = _render15.container;
|
|
443
|
+
const options = screen.getAllByRole('menuitemcheckbox');
|
|
444
|
+
const icons = container.querySelectorAll('svg');
|
|
445
|
+
expect(options[0]).toHaveAttribute('aria-checked', 'true');
|
|
446
|
+
expect(options[1]).toHaveAttribute('aria-checked', 'false');
|
|
447
|
+
expect(options[2]).toHaveAttribute('aria-checked', 'true');
|
|
448
|
+
expect(icons[0]).toBeVisible();
|
|
449
|
+
expect(icons[1]).not.toBeVisible();
|
|
450
|
+
expect(icons[2]).toBeVisible();
|
|
451
|
+
});
|
|
452
|
+
it("should be overridden by the Option's own defaultSelected", async () => {
|
|
453
|
+
const selectedValues = ['item1', 'item3'];
|
|
454
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
455
|
+
rootPageId: "page0"
|
|
456
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
457
|
+
id: "page0"
|
|
458
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
459
|
+
id: "group0",
|
|
460
|
+
selectableType: "multiple",
|
|
461
|
+
defaultSelected: selectedValues
|
|
462
|
+
}, _Drilldown$Option6 || (_Drilldown$Option6 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
463
|
+
id: "groupOption01",
|
|
464
|
+
value: "item1"
|
|
465
|
+
}, "Option")), _Drilldown$Option7 || (_Drilldown$Option7 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
466
|
+
id: "groupOption02",
|
|
467
|
+
value: "item2",
|
|
468
|
+
defaultSelected: true
|
|
469
|
+
}, "Option")), _Drilldown$Option8 || (_Drilldown$Option8 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
470
|
+
id: "groupOption03",
|
|
471
|
+
value: "item3",
|
|
472
|
+
defaultSelected: false
|
|
473
|
+
}, "Option"))))));
|
|
474
|
+
const options = screen.getAllByRole('menuitemcheckbox');
|
|
475
|
+
expect(options[0]).toHaveAttribute('aria-checked', 'true'); // from the group,
|
|
476
|
+
expect(options[1]).toHaveAttribute('aria-checked', 'true'); // from own prop,
|
|
477
|
+
expect(options[2]).toHaveAttribute('aria-checked', 'false'); // override group's
|
|
478
|
+
});
|
|
479
|
+
describe('for "single" selectableType', () => {
|
|
480
|
+
it('the selected option should be checked', async () => {
|
|
481
|
+
const selectedValues = ['item2'];
|
|
482
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
483
|
+
rootPageId: "page0"
|
|
484
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
485
|
+
id: "page0"
|
|
486
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
487
|
+
id: "group0",
|
|
488
|
+
selectableType: "single",
|
|
489
|
+
defaultSelected: selectedValues
|
|
490
|
+
}, _Drilldown$Option9 || (_Drilldown$Option9 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
491
|
+
id: "groupOption01",
|
|
492
|
+
value: "item1"
|
|
493
|
+
}, "Option")), _Drilldown$Option10 || (_Drilldown$Option10 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
494
|
+
id: "groupOption02",
|
|
495
|
+
value: "item2"
|
|
496
|
+
}, "Option")), _Drilldown$Option11 || (_Drilldown$Option11 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
497
|
+
id: "groupOption03",
|
|
498
|
+
value: "item3"
|
|
499
|
+
}, "Option"))))));
|
|
500
|
+
const options = screen.getAllByRole('menuitemradio');
|
|
501
|
+
expect(options[0]).toHaveAttribute('aria-checked', 'false');
|
|
502
|
+
expect(options[1]).toHaveAttribute('aria-checked', 'true');
|
|
503
|
+
expect(options[2]).toHaveAttribute('aria-checked', 'false');
|
|
504
|
+
});
|
|
505
|
+
it("should throw error if multiple items are selected, and shouldn't select any item", async () => {
|
|
506
|
+
const selectedValues = ['item1', 'item3'];
|
|
507
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
508
|
+
rootPageId: "page0"
|
|
509
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
510
|
+
id: "page0"
|
|
511
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
512
|
+
id: "group0",
|
|
513
|
+
selectableType: "single",
|
|
514
|
+
defaultSelected: selectedValues
|
|
515
|
+
}, _Drilldown$Option12 || (_Drilldown$Option12 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
516
|
+
id: "groupOption01",
|
|
517
|
+
value: "item1"
|
|
518
|
+
}, "Option")), _Drilldown$Option13 || (_Drilldown$Option13 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
519
|
+
id: "groupOption02",
|
|
520
|
+
value: "item2"
|
|
521
|
+
}, "Option")), _Drilldown$Option14 || (_Drilldown$Option14 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
522
|
+
id: "groupOption03",
|
|
523
|
+
value: "item3"
|
|
524
|
+
}, "Option"))))));
|
|
525
|
+
const options = screen.getAllByRole('menuitemradio');
|
|
526
|
+
expect(options[0]).toHaveAttribute('aria-checked', 'false');
|
|
527
|
+
expect(options[1]).toHaveAttribute('aria-checked', 'false');
|
|
528
|
+
expect(options[2]).toHaveAttribute('aria-checked', 'false');
|
|
529
|
+
expect(consoleErrorMock).toHaveBeenCalled();
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
describe('selection', () => {
|
|
535
|
+
it('should fire "onSelect" callback', async () => {
|
|
536
|
+
const onSelect = vi.fn();
|
|
537
|
+
render( /*#__PURE__*/React.createElement(Drilldown, {
|
|
538
|
+
rootPageId: "page0"
|
|
539
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Page, {
|
|
540
|
+
id: "page0"
|
|
541
|
+
}, /*#__PURE__*/React.createElement(Drilldown.Group, {
|
|
542
|
+
id: "group0",
|
|
543
|
+
selectableType: "multiple",
|
|
544
|
+
onSelect: onSelect
|
|
545
|
+
}, _Drilldown$Option15 || (_Drilldown$Option15 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
546
|
+
id: "groupOption01",
|
|
547
|
+
value: "item1"
|
|
548
|
+
}, "Option 1")), _Drilldown$Option16 || (_Drilldown$Option16 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
549
|
+
id: "groupOption02",
|
|
550
|
+
value: "item2"
|
|
551
|
+
}, "Option 2")), _Drilldown$Option17 || (_Drilldown$Option17 = /*#__PURE__*/React.createElement(Drilldown.Option, {
|
|
552
|
+
id: "groupOption03",
|
|
553
|
+
value: "item3"
|
|
554
|
+
}, "Option 3"))))));
|
|
555
|
+
const option2 = screen.getByText('Option 2');
|
|
556
|
+
await userEvent.click(option2);
|
|
557
|
+
await waitFor(() => {
|
|
558
|
+
expect(onSelect).toHaveBeenCalledTimes(1);
|
|
559
|
+
const args = onSelect.mock.calls[0][1];
|
|
560
|
+
const event = onSelect.mock.calls[0][0];
|
|
561
|
+
expect(args).toHaveProperty('value', ['item2']);
|
|
562
|
+
expect(args).toHaveProperty('isSelected', true);
|
|
563
|
+
expect(args.selectedOption).toBeInstanceOf(Object);
|
|
564
|
+
expect(args.selectedOption.props).toHaveProperty('id', 'groupOption02');
|
|
565
|
+
expect(args.selectedOption.props).toHaveProperty('value', 'item2');
|
|
566
|
+
expect(args.drilldown).toBeInstanceOf(Object);
|
|
567
|
+
expect(args.drilldown.props).toHaveProperty('role', 'menu');
|
|
568
|
+
expect(args.drilldown.hide).toBeInstanceOf(Function);
|
|
569
|
+
expect(event.target).toBe(option2);
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
});
|