@instructure/ui-menu 10.19.2-snapshot-2 → 10.19.2-snapshot-4

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.
@@ -1,191 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("@testing-library/react");
4
- var _vitest = require("vitest");
5
- require("@testing-library/jest-dom");
6
- var _MenuItem11 = require("../../MenuItem");
7
- var _MenuItemSeparator5 = require("../../MenuItemSeparator");
8
- var _index = require("../index");
9
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
- var _MenuItemGroup, _MenuItemGroup2, _MenuItemGroup3, _MenuItemGroup4, _MenuItem, _MenuItem2, _MenuItemSeparator, _MenuItem3, _MenuItem4, _MenuItemSeparator2, _MenuItem5, _MenuItem6, _MenuItem7, _MenuItem8, _MenuItemSeparator3, _MenuItem9, _MenuItem10, _MenuItemSeparator4;
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
- describe('<MenuItemGroup />', () => {
35
- it('should render', () => {
36
- const _render = (0, _react.render)(_MenuItemGroup || (_MenuItemGroup = (0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
37
- label: "Menu Label",
38
- children: [(0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
39
- children: "Item Text 1"
40
- }), (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
41
- children: "Item Text 2"
42
- }), (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {})]
43
- }))),
44
- container = _render.container;
45
- const group = container.querySelector("[class*='menuItemGroup']");
46
- expect(group).toBeInTheDocument();
47
- expect(group).toHaveTextContent('Menu Label');
48
- expect(group).toHaveTextContent('Item Text 1');
49
- expect(group).toHaveTextContent('Item Text 2');
50
- });
51
- it('should default to children with type "radio"', () => {
52
- (0, _react.render)(_MenuItemGroup2 || (_MenuItemGroup2 = (0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
53
- label: "Select one",
54
- children: [(0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
55
- children: "Foo"
56
- }), (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
57
- children: "Bar"
58
- }), (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {})]
59
- })));
60
- const menuItems = _react.screen.getAllByRole('menuitemradio');
61
- expect(menuItems).toHaveLength(2);
62
- });
63
- it('should render children with type "checkbox" if allowMultiple is true', () => {
64
- (0, _react.render)(_MenuItemGroup3 || (_MenuItemGroup3 = (0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
65
- label: "Select a few",
66
- allowMultiple: true,
67
- children: [(0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
68
- children: "Foo"
69
- }), (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
70
- children: "Bar"
71
- }), (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {})]
72
- })));
73
- const menuItems = _react.screen.getAllByRole('menuitemcheckbox');
74
- expect(menuItems).toHaveLength(2);
75
- });
76
- it('should set aria-disabled', () => {
77
- (0, _react.render)(_MenuItemGroup4 || (_MenuItemGroup4 = (0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
78
- label: "Select one",
79
- disabled: true,
80
- children: [(0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
81
- children: "Foo"
82
- }), (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
83
- children: "Bar"
84
- }), (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {})]
85
- })));
86
- const menuItems = _react.screen.getAllByRole('menuitemradio');
87
- expect(menuItems).toHaveLength(2);
88
- expect(menuItems[0]).toHaveAttribute('aria-disabled', 'true');
89
- expect(menuItems[1]).toHaveAttribute('aria-disabled', 'true');
90
- });
91
- it('should set selected from defaultSelected prop', () => {
92
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
93
- label: "Select one",
94
- defaultSelected: [1],
95
- children: [_MenuItem || (_MenuItem = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
96
- children: "Foo"
97
- })), _MenuItem2 || (_MenuItem2 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
98
- children: "Bar"
99
- })), _MenuItemSeparator || (_MenuItemSeparator = (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {}))]
100
- }));
101
- const menuItems = _react.screen.getAllByRole('menuitemradio');
102
- expect(menuItems).toHaveLength(2);
103
- expect(menuItems[0]).toHaveAttribute('aria-checked', 'false');
104
- expect(menuItems[1]).toHaveAttribute('aria-checked', 'true');
105
- });
106
- it('should set selected from selected prop', () => {
107
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
108
- label: "Select one",
109
- onSelect: _vitest.vi.fn(),
110
- selected: [1],
111
- children: [_MenuItem3 || (_MenuItem3 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
112
- children: "Foo"
113
- })), _MenuItem4 || (_MenuItem4 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
114
- children: "Bar"
115
- })), _MenuItemSeparator2 || (_MenuItemSeparator2 = (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {}))]
116
- }));
117
- const menuItems = _react.screen.getAllByRole('menuitemradio');
118
- expect(menuItems).toHaveLength(2);
119
- expect(menuItems[0]).toHaveAttribute('aria-checked', 'false');
120
- expect(menuItems[1]).toHaveAttribute('aria-checked', 'true');
121
- });
122
- it('should set selected from children', () => {
123
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
124
- label: "Select a few",
125
- allowMultiple: true,
126
- children: [_MenuItem5 || (_MenuItem5 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
127
- defaultSelected: true,
128
- children: "Foo"
129
- }, "foo")), (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
130
- selected: true,
131
- onSelect: _vitest.vi.fn(),
132
- children: "Bar"
133
- }, "bar")]
134
- }));
135
- const menuItems = _react.screen.getAllByRole('menuitemcheckbox');
136
- expect(menuItems).toHaveLength(2);
137
- expect(menuItems[0]).toHaveAttribute('aria-checked', 'true');
138
- expect(menuItems[1]).toHaveAttribute('aria-checked', 'true');
139
- });
140
- it('should honor the allowMultiple prop (defaults to false)', () => {
141
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
142
- label: "Select one",
143
- children: [_MenuItem6 || (_MenuItem6 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
144
- defaultSelected: true,
145
- children: "Foo"
146
- })), (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
147
- selected: true,
148
- onSelect: _vitest.vi.fn(),
149
- children: "Bar"
150
- })]
151
- }));
152
- const menuItems = _react.screen.getAllByRole('menuitemradio');
153
- expect(menuItems).toHaveLength(2);
154
- expect(menuItems[0]).toHaveAttribute('aria-checked', 'true');
155
- expect(menuItems[1]).toHaveAttribute('aria-checked', 'false');
156
- });
157
- it('calls onSelect when items are selected', () => {
158
- const onSelect = _vitest.vi.fn();
159
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
160
- label: "Select one",
161
- onSelect: onSelect,
162
- selected: [1],
163
- children: [_MenuItem7 || (_MenuItem7 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
164
- children: "Item 1"
165
- })), _MenuItem8 || (_MenuItem8 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
166
- children: "Item 2"
167
- })), _MenuItemSeparator3 || (_MenuItemSeparator3 = (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {}))]
168
- }));
169
- const menuItem = _react.screen.getByText('Item 1');
170
- _react.fireEvent.click(menuItem);
171
- expect(onSelect).toHaveBeenCalled();
172
- expect(onSelect.mock.calls[0][1]).toEqual([0]);
173
- expect(onSelect.mock.calls[0][2]).toEqual(true);
174
- });
175
- it('does not call onSelect when disabled', () => {
176
- const onSelect = _vitest.vi.fn();
177
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.MenuItemGroup, {
178
- label: "Select one",
179
- onSelect: onSelect,
180
- disabled: true,
181
- children: [_MenuItem9 || (_MenuItem9 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
182
- children: "Item 1"
183
- })), _MenuItem10 || (_MenuItem10 = (0, _jsxRuntime.jsx)(_MenuItem11.MenuItem, {
184
- children: "Item 2"
185
- })), _MenuItemSeparator4 || (_MenuItemSeparator4 = (0, _jsxRuntime.jsx)(_MenuItemSeparator5.MenuItemSeparator, {}))]
186
- }));
187
- const menuItem = _react.screen.getByText('Item 1');
188
- _react.fireEvent.click(menuItem);
189
- expect(onSelect).not.toHaveBeenCalled();
190
- });
191
- });
@@ -1,401 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("@testing-library/react");
4
- var _vitest = require("vitest");
5
- var _userEvent = require("@testing-library/user-event");
6
- require("@testing-library/jest-dom");
7
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
8
- var _index = require("../index");
9
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
- var _Menu, _Menu2, _Menu3, _Menu4, _MenuItem, _MenuItem2, _MenuItem3, _Menu5, _button, _MenuItem4, _Menu6, _button2, _MenuItem5, _MenuItem6, _button3, _MenuItem7, _MenuItem8, _Menu7, _Menu8, _button4, _MenuItem9, _MenuItem10, _button5, _MenuItem11, _MenuItem12, _button6, _MenuItem13, _MenuItem14, _Menu9, _button7, _MenuItem15, _MenuItem16;
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
- describe('<Menu />', () => {
35
- let consoleWarningMock;
36
- let consoleErrorMock;
37
- beforeEach(() => {
38
- // Mocking console to prevent test output pollution and expect for messages
39
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
40
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
41
- });
42
- afterEach(() => {
43
- consoleWarningMock.mockRestore();
44
- consoleErrorMock.mockRestore();
45
- });
46
- describe('without a trigger', () => {
47
- it('should render', () => {
48
- (0, _react.render)(_Menu || (_Menu = (0, _jsxRuntime.jsx)(_index.Menu, {
49
- label: "Menu-label-text",
50
- children: (0, _jsxRuntime.jsx)(_index.MenuItem, {
51
- children: "Menu Item Text"
52
- })
53
- })));
54
- const menu = _react.screen.getByRole('menu');
55
- expect(menu).toBeInTheDocument();
56
- expect(menu).toHaveTextContent('Menu Item Text');
57
- expect(menu).toHaveAttribute('aria-label', 'Menu-label-text');
58
- });
59
- it('should meet a11y standards', async () => {
60
- const _render = (0, _react.render)(_Menu2 || (_Menu2 = (0, _jsxRuntime.jsx)(_index.Menu, {
61
- label: "Menu-label-text",
62
- children: (0, _jsxRuntime.jsx)(_index.MenuItem, {
63
- children: "Menu Item Text"
64
- })
65
- }))),
66
- container = _render.container;
67
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
68
- expect(axeCheck).toBe(true);
69
- });
70
- it('should meet standards when menu is closed', async () => {
71
- const _render2 = (0, _react.render)(_Menu3 || (_Menu3 = (0, _jsxRuntime.jsxs)(_index.Menu, {
72
- trigger: (0, _jsxRuntime.jsx)("button", {
73
- children: "More"
74
- }),
75
- children: [(0, _jsxRuntime.jsx)(_index.MenuItem, {
76
- children: "Learning Mastery"
77
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
78
- disabled: true,
79
- children: "Gradebook"
80
- })]
81
- }))),
82
- container = _render2.container;
83
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
84
- expect(axeCheck).toBe(true);
85
- });
86
- it('should meet standards when menu is open', async () => {
87
- const _render3 = (0, _react.render)(_Menu4 || (_Menu4 = (0, _jsxRuntime.jsxs)(_index.Menu, {
88
- trigger: (0, _jsxRuntime.jsx)("button", {
89
- children: "More"
90
- }),
91
- defaultShow: true,
92
- children: [(0, _jsxRuntime.jsx)(_index.MenuItem, {
93
- children: "Learning Mastery"
94
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
95
- disabled: true,
96
- children: "Gradebook"
97
- })]
98
- }))),
99
- container = _render3.container;
100
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
101
- expect(axeCheck).toBe(true);
102
- });
103
- it('should call onSelect when menu item is selected', async () => {
104
- const onSelect = _vitest.vi.fn();
105
- const _render4 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.Menu, {
106
- label: "Settings",
107
- onSelect: onSelect,
108
- children: _MenuItem || (_MenuItem = (0, _jsxRuntime.jsx)(_index.MenuItem, {
109
- value: "Test",
110
- children: "Test Item"
111
- }))
112
- })),
113
- getByText = _render4.getByText;
114
- const item = getByText('Test Item');
115
- await _userEvent.userEvent.click(item);
116
- expect(onSelect).toHaveBeenCalled();
117
- expect(onSelect.mock.calls[0][1]).toEqual('Test');
118
- });
119
- it('should not call onSelect when disabled', () => {
120
- const onSelect = _vitest.vi.fn();
121
- const _render5 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.Menu, {
122
- label: "Settings",
123
- onSelect: onSelect,
124
- disabled: true,
125
- children: _MenuItem2 || (_MenuItem2 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
126
- value: "Account",
127
- children: "Account"
128
- }))
129
- })),
130
- getByText = _render5.getByText;
131
- const itemText = getByText('Account');
132
- const menu = _react.screen.getByRole('menu');
133
- const menuItem = _react.screen.getByRole('menuitem');
134
- expect(itemText).toBeInTheDocument();
135
- expect(menu).toHaveAttribute('aria-disabled', 'true');
136
- expect(menuItem).toHaveAttribute('aria-disabled', 'true');
137
- });
138
- it('should provide a menu ref', () => {
139
- const menuRef = _vitest.vi.fn();
140
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.Menu, {
141
- label: "Settings",
142
- menuRef: menuRef,
143
- children: _MenuItem3 || (_MenuItem3 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
144
- value: "Account",
145
- children: "Account"
146
- }))
147
- }));
148
- const menu = _react.screen.getByRole('menu');
149
- expect(menuRef).toHaveBeenLastCalledWith(menu);
150
- });
151
- it('should set aria attributes properly', () => {
152
- (0, _react.render)(_Menu5 || (_Menu5 = (0, _jsxRuntime.jsx)(_index.Menu, {
153
- disabled: true,
154
- label: "Settings",
155
- children: (0, _jsxRuntime.jsx)(_index.MenuItem, {
156
- value: "Account",
157
- children: "Account"
158
- })
159
- })));
160
- const menu = _react.screen.getByRole('menu');
161
- expect(menu).toHaveAttribute('aria-disabled', 'true');
162
- expect(menu).toHaveAttribute('aria-label', 'Settings');
163
- });
164
- });
165
- describe('with a trigger', () => {
166
- it('should render into a mountNode', () => {
167
- const mountNode = document.createElement('div');
168
- document.body.appendChild(mountNode);
169
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.Menu, {
170
- defaultShow: true,
171
- mountNode: mountNode,
172
- label: "Settings",
173
- trigger: _button || (_button = (0, _jsxRuntime.jsx)("button", {
174
- children: "Settings"
175
- })),
176
- children: _MenuItem4 || (_MenuItem4 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
177
- children: "Account"
178
- }))
179
- }));
180
- expect(mountNode).toHaveTextContent('Account');
181
- document.body.removeChild(mountNode);
182
- });
183
- it('should set aria attributes properly', () => {
184
- (0, _react.render)(_Menu6 || (_Menu6 = (0, _jsxRuntime.jsxs)(_index.Menu, {
185
- trigger: (0, _jsxRuntime.jsx)("button", {
186
- children: "Settings"
187
- }),
188
- defaultShow: true,
189
- children: [(0, _jsxRuntime.jsx)(_index.MenuItem, {
190
- children: "Learning Mastery"
191
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
192
- disabled: true,
193
- children: "Gradebook"
194
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
195
- type: "radio",
196
- defaultChecked: true,
197
- children: "Default (Grid view)"
198
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
199
- type: "radio",
200
- children: "Individual (List view)"
201
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
202
- type: "checkbox",
203
- defaultChecked: true,
204
- children: "Include Anchor Standards"
205
- }), (0, _jsxRuntime.jsx)(_index.MenuItemSeparator, {}), (0, _jsxRuntime.jsx)(_index.MenuItem, {
206
- children: "Open grading history..."
207
- })]
208
- })));
209
- const menu = _react.screen.getByRole('menu');
210
- const trigger = _react.screen.getByRole('button', {
211
- name: 'Settings'
212
- });
213
- expect(menu).toBeInTheDocument();
214
- expect(menu).toHaveAttribute('aria-labelledby', trigger.getAttribute('id'));
215
- });
216
- it('should call onFocus on focus', () => {
217
- const onFocus = _vitest.vi.fn();
218
- const _render6 = (0, _react.render)((0, _jsxRuntime.jsxs)(_index.Menu, {
219
- trigger: _button2 || (_button2 = (0, _jsxRuntime.jsx)("button", {
220
- children: "More"
221
- })),
222
- onFocus: onFocus,
223
- children: [_MenuItem5 || (_MenuItem5 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
224
- children: "Learning Mastery"
225
- })), _MenuItem6 || (_MenuItem6 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
226
- disabled: true,
227
- children: "Gradebook"
228
- }))]
229
- })),
230
- getByRole = _render6.getByRole;
231
- const triggerButton = getByRole('button', {
232
- name: 'More'
233
- });
234
- _react.fireEvent.focus(triggerButton);
235
- expect(onFocus).toHaveBeenCalled();
236
- });
237
- it('should render when show and onToggle props are set', () => {
238
- const _render7 = (0, _react.render)((0, _jsxRuntime.jsxs)(_index.Menu, {
239
- trigger: _button3 || (_button3 = (0, _jsxRuntime.jsx)("button", {
240
- children: "More"
241
- })),
242
- show: true,
243
- onToggle: () => {},
244
- children: [_MenuItem7 || (_MenuItem7 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
245
- children: "Test1"
246
- })), _MenuItem8 || (_MenuItem8 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
247
- disabled: true,
248
- children: "Test2"
249
- }))]
250
- })),
251
- getByRole = _render7.getByRole,
252
- getAllByRole = _render7.getAllByRole,
253
- queryByText = _render7.queryByText;
254
- const menuItems = getAllByRole('menuitem');
255
- const triggerButton = getByRole('button', {
256
- name: 'More'
257
- });
258
- const menuItem1 = queryByText('Test1');
259
- const menuItem2 = queryByText('Test2');
260
- expect(triggerButton).toBeInTheDocument();
261
- expect(menuItems).toHaveLength(2);
262
- expect(menuItem1).toBeInTheDocument();
263
- expect(menuItem2).toBeInTheDocument();
264
- });
265
- it('should not show by default', () => {
266
- const _render8 = (0, _react.render)(_Menu7 || (_Menu7 = (0, _jsxRuntime.jsxs)(_index.Menu, {
267
- trigger: (0, _jsxRuntime.jsx)("button", {
268
- children: "More"
269
- }),
270
- children: [(0, _jsxRuntime.jsx)(_index.MenuItem, {
271
- children: "Test1"
272
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
273
- disabled: true,
274
- children: "Test2"
275
- })]
276
- }))),
277
- queryByText = _render8.queryByText,
278
- getByRole = _render8.getByRole;
279
- const triggerButton = getByRole('button', {
280
- name: 'More'
281
- });
282
- const menuItem1 = queryByText('Test1');
283
- const menuItem2 = queryByText('Test2');
284
- expect(triggerButton).toBeInTheDocument();
285
- expect(menuItem1).not.toBeInTheDocument();
286
- expect(menuItem2).not.toBeInTheDocument();
287
- });
288
- it('should accept a default show', () => {
289
- const _render9 = (0, _react.render)(_Menu8 || (_Menu8 = (0, _jsxRuntime.jsxs)(_index.Menu, {
290
- trigger: (0, _jsxRuntime.jsx)("button", {
291
- children: "More"
292
- }),
293
- defaultShow: true,
294
- children: [(0, _jsxRuntime.jsx)(_index.MenuItem, {
295
- children: "Test1"
296
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
297
- disabled: true,
298
- children: "Test2"
299
- })]
300
- }))),
301
- queryByText = _render9.queryByText,
302
- getByRole = _render9.getByRole;
303
- const triggerButton = getByRole('button', {
304
- name: 'More'
305
- });
306
- const menuItem1 = queryByText('Test1');
307
- const menuItem2 = queryByText('Test2');
308
- expect(triggerButton).toBeInTheDocument();
309
- expect(menuItem1).toBeInTheDocument();
310
- expect(menuItem2).toBeInTheDocument();
311
- });
312
- it('should provide a menu ref', () => {
313
- const menuRef = _vitest.vi.fn();
314
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.Menu, {
315
- trigger: _button4 || (_button4 = (0, _jsxRuntime.jsx)("button", {
316
- children: "More"
317
- })),
318
- defaultShow: true,
319
- menuRef: menuRef,
320
- children: [_MenuItem9 || (_MenuItem9 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
321
- children: "Learning Mastery"
322
- })), _MenuItem10 || (_MenuItem10 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
323
- disabled: true,
324
- children: "Gradebook"
325
- }))]
326
- }));
327
- const menu = _react.screen.getByRole('menu');
328
- expect(menuRef).toHaveBeenCalledWith(menu);
329
- });
330
- it('should provide a popoverRef ref', () => {
331
- const popoverRef = _vitest.vi.fn();
332
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.Menu, {
333
- trigger: _button5 || (_button5 = (0, _jsxRuntime.jsx)("button", {
334
- children: "More"
335
- })),
336
- defaultShow: true,
337
- popoverRef: popoverRef,
338
- children: [_MenuItem11 || (_MenuItem11 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
339
- children: "Learning Mastery"
340
- })), _MenuItem12 || (_MenuItem12 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
341
- disabled: true,
342
- children: "Gradebook"
343
- }))]
344
- }));
345
- expect(popoverRef).toHaveBeenCalled();
346
- });
347
- it('should call onToggle on click', () => {
348
- const onToggle = _vitest.vi.fn();
349
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.Menu, {
350
- trigger: _button6 || (_button6 = (0, _jsxRuntime.jsx)("button", {
351
- children: "More"
352
- })),
353
- onToggle: onToggle,
354
- children: [_MenuItem13 || (_MenuItem13 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
355
- children: "Learning Mastery"
356
- })), _MenuItem14 || (_MenuItem14 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
357
- disabled: true,
358
- children: "Gradebook"
359
- }))]
360
- }));
361
- const trigger = _react.screen.getByRole('button');
362
- _react.fireEvent.click(trigger);
363
- expect(onToggle).toHaveBeenCalled();
364
- });
365
- it('should have an aria-haspopup attribute', () => {
366
- (0, _react.render)(_Menu9 || (_Menu9 = (0, _jsxRuntime.jsxs)(_index.Menu, {
367
- trigger: (0, _jsxRuntime.jsx)("button", {
368
- children: "More"
369
- }),
370
- children: [(0, _jsxRuntime.jsx)(_index.MenuItem, {
371
- children: "Learning Mastery"
372
- }), (0, _jsxRuntime.jsx)(_index.MenuItem, {
373
- disabled: true,
374
- children: "Gradebook"
375
- })]
376
- })));
377
- const trigger = _react.screen.getByRole('button');
378
- expect(trigger).toHaveAttribute('aria-haspopup');
379
- });
380
- it('should pass positionContainerDisplay prop to Popover', () => {
381
- let popoverRef = null;
382
- (0, _react.render)((0, _jsxRuntime.jsxs)(_index.Menu, {
383
- trigger: _button7 || (_button7 = (0, _jsxRuntime.jsx)("button", {
384
- children: "More"
385
- })),
386
- popoverRef: e => {
387
- popoverRef = e;
388
- },
389
- positionContainerDisplay: "block",
390
- children: [_MenuItem15 || (_MenuItem15 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
391
- children: "Learning Mastery"
392
- })), _MenuItem16 || (_MenuItem16 = (0, _jsxRuntime.jsx)(_index.MenuItem, {
393
- disabled: true,
394
- children: "Gradebook"
395
- }))]
396
- }));
397
- const popoverProps = popoverRef.props;
398
- expect(popoverProps.positionContainerDisplay).toBe('block');
399
- });
400
- });
401
- });