@instructure/ui-menu 8.53.3-snapshot-10 → 8.53.3-snapshot-13

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 (49) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/Menu/MenuItem/__new-tests__/MenuItem.test.js +134 -0
  3. package/es/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.js +166 -0
  4. package/es/Menu/__new-tests__/Menu.test.js +288 -0
  5. package/lib/Menu/MenuItem/__new-tests__/MenuItem.test.js +136 -0
  6. package/lib/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.js +168 -0
  7. package/lib/Menu/__new-tests__/Menu.test.js +291 -0
  8. package/package.json +21 -19
  9. package/src/Menu/MenuItem/__new-tests__/MenuItem.test.tsx +161 -0
  10. package/src/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.tsx +222 -0
  11. package/src/Menu/__new-tests__/Menu.test.tsx +337 -0
  12. package/tsconfig.build.json +2 -3
  13. package/tsconfig.build.tsbuildinfo +1 -1
  14. package/types/Menu/MenuItem/__new-tests__/MenuItem.test.d.ts +2 -0
  15. package/types/Menu/MenuItem/__new-tests__/MenuItem.test.d.ts.map +1 -0
  16. package/types/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.d.ts +2 -0
  17. package/types/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.d.ts.map +1 -0
  18. package/types/Menu/__new-tests__/Menu.test.d.ts +2 -0
  19. package/types/Menu/__new-tests__/Menu.test.d.ts.map +1 -0
  20. package/es/Menu/MenuItem/MenuItemLocator.js +0 -28
  21. package/es/Menu/MenuItem/locator.js +0 -27
  22. package/es/Menu/MenuItemGroup/MenuItemGroupLocator.js +0 -36
  23. package/es/Menu/MenuItemGroup/locator.js +0 -26
  24. package/es/Menu/MenuLocator.js +0 -66
  25. package/es/Menu/locator.js +0 -28
  26. package/lib/Menu/MenuItem/MenuItemLocator.js +0 -34
  27. package/lib/Menu/MenuItem/locator.js +0 -37
  28. package/lib/Menu/MenuItemGroup/MenuItemGroupLocator.js +0 -42
  29. package/lib/Menu/MenuItemGroup/locator.js +0 -37
  30. package/lib/Menu/MenuLocator.js +0 -83
  31. package/lib/Menu/locator.js +0 -49
  32. package/src/Menu/MenuItem/MenuItemLocator.ts +0 -29
  33. package/src/Menu/MenuItem/locator.ts +0 -28
  34. package/src/Menu/MenuItemGroup/MenuItemGroupLocator.ts +0 -38
  35. package/src/Menu/MenuItemGroup/locator.ts +0 -27
  36. package/src/Menu/MenuLocator.ts +0 -67
  37. package/src/Menu/locator.ts +0 -30
  38. package/types/Menu/MenuItem/MenuItemLocator.d.ts +0 -566
  39. package/types/Menu/MenuItem/MenuItemLocator.d.ts.map +0 -1
  40. package/types/Menu/MenuItem/locator.d.ts +0 -4
  41. package/types/Menu/MenuItem/locator.d.ts.map +0 -1
  42. package/types/Menu/MenuItemGroup/MenuItemGroupLocator.d.ts +0 -1961
  43. package/types/Menu/MenuItemGroup/MenuItemGroupLocator.d.ts.map +0 -1
  44. package/types/Menu/MenuItemGroup/locator.d.ts +0 -4
  45. package/types/Menu/MenuItemGroup/locator.d.ts.map +0 -1
  46. package/types/Menu/MenuLocator.d.ts +0 -6154
  47. package/types/Menu/MenuLocator.d.ts.map +0 -1
  48. package/types/Menu/locator.d.ts +0 -5
  49. package/types/Menu/locator.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
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
- ## [8.53.3-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-snapshot-10) (2024-02-28)
6
+ ## [8.53.3-snapshot-13](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-snapshot-13) (2024-02-29)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-menu
9
9
 
@@ -0,0 +1,134 @@
1
+ var _MenuItem, _MenuItem2, _ExtendedMenuItem, _MenuItem3, _MenuItem4, _MenuItem5, _MenuItem6, _MenuItem7, _MenuItem8, _MenuItem9;
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 { fireEvent, render, screen } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { MenuItem } from '../index';
30
+ const ExtendedMenuItem = ({
31
+ ...props
32
+ }) => {
33
+ return /*#__PURE__*/React.createElement(MenuItem, props);
34
+ };
35
+ describe('<MenuItem />', () => {
36
+ it('should render', () => {
37
+ render(_MenuItem || (_MenuItem = /*#__PURE__*/React.createElement(MenuItem, null, "Menu Item Text")));
38
+ const menuItem = screen.getByText('Menu Item Text');
39
+ expect(menuItem).toBeInTheDocument();
40
+ });
41
+ it('should render as a link when an href is provided', () => {
42
+ render(_MenuItem2 || (_MenuItem2 = /*#__PURE__*/React.createElement(MenuItem, {
43
+ href: "example.html"
44
+ }, "Menu Item Text")));
45
+ const menuItem = screen.getByRole('menuitem');
46
+ expect(menuItem).toBeInTheDocument();
47
+ expect(menuItem).toHaveAttribute('href', 'example.html');
48
+ });
49
+ it('should render as a link when a to is provided', () => {
50
+ render(_ExtendedMenuItem || (_ExtendedMenuItem = /*#__PURE__*/React.createElement(ExtendedMenuItem, {
51
+ to: "/example"
52
+ }, "Hello")));
53
+ const menuItem = screen.getByRole('menuitem');
54
+ expect(menuItem).toHaveAttribute('to', '/example');
55
+ });
56
+ it('should call onSelect after click', () => {
57
+ const onSelect = jest.fn();
58
+ render( /*#__PURE__*/React.createElement(MenuItem, {
59
+ onSelect: onSelect,
60
+ value: "foo"
61
+ }, "Hello"));
62
+ const menuItem = screen.getByRole('menuitem');
63
+ fireEvent.click(menuItem);
64
+ expect(onSelect).toHaveBeenCalledWith(expect.any(Object), 'foo', true, expect.any(Object));
65
+ });
66
+ it('should call onClick after click', () => {
67
+ const onClick = jest.fn();
68
+ render( /*#__PURE__*/React.createElement(MenuItem, {
69
+ onClick: onClick,
70
+ value: "foo"
71
+ }, "Hello"));
72
+ const menuItem = screen.getByRole('menuitem');
73
+ fireEvent.click(menuItem);
74
+ expect(onClick).toHaveBeenCalled();
75
+ });
76
+ it('should set the tabIndex attribute', () => {
77
+ render(_MenuItem3 || (_MenuItem3 = /*#__PURE__*/React.createElement(MenuItem, null, "Hello")));
78
+ const menuItem = screen.getByRole('menuitem');
79
+ expect(menuItem).toHaveAttribute('tabIndex', '-1');
80
+ });
81
+ it('should set the aria-controls attribute', () => {
82
+ render(_MenuItem4 || (_MenuItem4 = /*#__PURE__*/React.createElement(MenuItem, {
83
+ controls: "testId"
84
+ }, "Hello")));
85
+ const menuItem = screen.getByRole('menuitem');
86
+ expect(menuItem).toHaveAttribute('aria-controls', 'testId');
87
+ });
88
+ it('should set the aria-disabled attribute', () => {
89
+ render(_MenuItem5 || (_MenuItem5 = /*#__PURE__*/React.createElement(MenuItem, {
90
+ disabled: true
91
+ }, "Hello")));
92
+ const menuItem = screen.getByRole('menuitem');
93
+ expect(menuItem).toHaveAttribute('aria-disabled', 'true');
94
+ });
95
+ it('should set the aria-checked attribute when defaultSelected prop is true', () => {
96
+ render(_MenuItem6 || (_MenuItem6 = /*#__PURE__*/React.createElement(MenuItem, {
97
+ type: "checkbox",
98
+ defaultSelected: true
99
+ }, "Hello")));
100
+ const menuItem = screen.getByRole('menuitemcheckbox');
101
+ expect(menuItem).toHaveAttribute('aria-checked', 'true');
102
+ });
103
+ it('should set the aria-checked attribute when selected prop is true', () => {
104
+ render( /*#__PURE__*/React.createElement(MenuItem, {
105
+ type: "checkbox",
106
+ selected: true,
107
+ onSelect: jest.fn()
108
+ }, "Hello"));
109
+ const menuItem = screen.getByRole('menuitemcheckbox');
110
+ expect(menuItem).toHaveAttribute('aria-checked', 'true');
111
+ });
112
+ it('should default to the "menuitem" role', () => {
113
+ const _render = render(_MenuItem7 || (_MenuItem7 = /*#__PURE__*/React.createElement(MenuItem, null, "Menu Item Text"))),
114
+ container = _render.container;
115
+ const menuItem = container.querySelector("span[class$='-menuItem']");
116
+ expect(menuItem).toHaveAttribute('role', 'menuitem');
117
+ });
118
+ it('should set the role to "menuitemcheckbox" when the type is "checkbox"', () => {
119
+ const _render2 = render(_MenuItem8 || (_MenuItem8 = /*#__PURE__*/React.createElement(MenuItem, {
120
+ type: "checkbox"
121
+ }, "Hello"))),
122
+ container = _render2.container;
123
+ const menuItem = container.querySelector("span[class$='-menuItem']");
124
+ expect(menuItem).toHaveAttribute('role', 'menuitemcheckbox');
125
+ });
126
+ it('should set the role to "menuitemradio" when the type is "radio"', () => {
127
+ const _render3 = render(_MenuItem9 || (_MenuItem9 = /*#__PURE__*/React.createElement(MenuItem, {
128
+ type: "radio"
129
+ }, "Hello"))),
130
+ container = _render3.container;
131
+ const menuItem = container.querySelector("span[class$='-menuItem']");
132
+ expect(menuItem).toHaveAttribute('role', 'menuitemradio');
133
+ });
134
+ });
@@ -0,0 +1,166 @@
1
+ var _MenuItemGroup, _MenuItemGroup2, _MenuItemGroup3, _MenuItemGroup4, _MenuItemGroup5, _MenuItemGroup6, _MenuItem, _MenuItem2, _MenuItemSeparator, _MenuItem3, _MenuItem4, _MenuItemSeparator2, _MenuItem5, _MenuItem6, _MenuItem7, _MenuItem8, _MenuItemSeparator3, _MenuItem9, _MenuItem10, _MenuItemSeparator4;
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 { fireEvent, render, screen } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { MenuItem } from '../../MenuItem';
30
+ import { MenuItemSeparator } from '../../MenuItemSeparator';
31
+ import { MenuItemGroup } from '../index';
32
+ describe('<MenuItemGroup />', () => {
33
+ it('should render', () => {
34
+ const _render = render(_MenuItemGroup || (_MenuItemGroup = /*#__PURE__*/React.createElement(MenuItemGroup, {
35
+ label: "Menu Label"
36
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Item Text 1"), /*#__PURE__*/React.createElement(MenuItem, null, "Item Text 2"), /*#__PURE__*/React.createElement(MenuItemSeparator, null)))),
37
+ container = _render.container;
38
+ const group = container.querySelector("[id*='MenuItemGroup_']");
39
+ const groupMenu = screen.getByRole('menu');
40
+ expect(group).toBeInTheDocument();
41
+ expect(group).toHaveTextContent('Menu Label');
42
+ expect(groupMenu).toBeInTheDocument();
43
+ expect(groupMenu).toHaveTextContent('Item Text 1');
44
+ expect(groupMenu).toHaveTextContent('Item Text 2');
45
+ });
46
+ it('should set the role to "menu"', () => {
47
+ const _render2 = render(_MenuItemGroup2 || (_MenuItemGroup2 = /*#__PURE__*/React.createElement(MenuItemGroup, {
48
+ label: "Select one"
49
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Foo"), /*#__PURE__*/React.createElement(MenuItem, null, "Bar"), /*#__PURE__*/React.createElement(MenuItemSeparator, null)))),
50
+ container = _render2.container;
51
+ const menuItemGroup = container.querySelector("[class*='menuItemGroup__items']");
52
+ expect(menuItemGroup).toHaveAttribute('role', 'menu');
53
+ });
54
+ it('should set the list item role to "none"', () => {
55
+ render(_MenuItemGroup3 || (_MenuItemGroup3 = /*#__PURE__*/React.createElement(MenuItemGroup, {
56
+ label: "Select one"
57
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Food"), /*#__PURE__*/React.createElement(MenuItem, null, "Bar"))));
58
+ const menu = screen.getByRole('menu');
59
+ const menuListItem = menu.firstChild;
60
+ expect(menuListItem.tagName).toBe('LI');
61
+ expect(menuListItem).toHaveAttribute('role', 'none');
62
+ });
63
+ it('should default to children with type "radio"', () => {
64
+ render(_MenuItemGroup4 || (_MenuItemGroup4 = /*#__PURE__*/React.createElement(MenuItemGroup, {
65
+ label: "Select one"
66
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Foo"), /*#__PURE__*/React.createElement(MenuItem, null, "Bar"), /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
67
+ const menuItems = screen.getAllByRole('menuitemradio');
68
+ expect(menuItems).toHaveLength(2);
69
+ });
70
+ it('should render children with type "checkbox" if allowMultiple is true', () => {
71
+ render(_MenuItemGroup5 || (_MenuItemGroup5 = /*#__PURE__*/React.createElement(MenuItemGroup, {
72
+ label: "Select a few",
73
+ allowMultiple: true
74
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Foo"), /*#__PURE__*/React.createElement(MenuItem, null, "Bar"), /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
75
+ const menuItems = screen.getAllByRole('menuitemcheckbox');
76
+ expect(menuItems).toHaveLength(2);
77
+ });
78
+ it('should set aria-disabled', () => {
79
+ render(_MenuItemGroup6 || (_MenuItemGroup6 = /*#__PURE__*/React.createElement(MenuItemGroup, {
80
+ label: "Select one",
81
+ disabled: true
82
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Foo"), /*#__PURE__*/React.createElement(MenuItem, null, "Bar"), /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
83
+ const menu = screen.getByRole('menu');
84
+ const menuItems = screen.getAllByRole('menuitemradio');
85
+ expect(menu).toHaveAttribute('aria-disabled', 'true');
86
+ expect(menuItems).toHaveLength(2);
87
+ expect(menuItems[0]).toHaveAttribute('aria-disabled', 'true');
88
+ expect(menuItems[1]).toHaveAttribute('aria-disabled', 'true');
89
+ });
90
+ it('should set selected from defaultSelected prop', () => {
91
+ render( /*#__PURE__*/React.createElement(MenuItemGroup, {
92
+ label: "Select one",
93
+ defaultSelected: [1]
94
+ }, _MenuItem || (_MenuItem = /*#__PURE__*/React.createElement(MenuItem, null, "Foo")), _MenuItem2 || (_MenuItem2 = /*#__PURE__*/React.createElement(MenuItem, null, "Bar")), _MenuItemSeparator || (_MenuItemSeparator = /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
95
+ const menuItems = screen.getAllByRole('menuitemradio');
96
+ expect(menuItems).toHaveLength(2);
97
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'false');
98
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'true');
99
+ });
100
+ it('should set selected from selected prop', () => {
101
+ render( /*#__PURE__*/React.createElement(MenuItemGroup, {
102
+ label: "Select one",
103
+ onSelect: jest.fn(),
104
+ selected: [1]
105
+ }, _MenuItem3 || (_MenuItem3 = /*#__PURE__*/React.createElement(MenuItem, null, "Foo")), _MenuItem4 || (_MenuItem4 = /*#__PURE__*/React.createElement(MenuItem, null, "Bar")), _MenuItemSeparator2 || (_MenuItemSeparator2 = /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
106
+ const menuItems = screen.getAllByRole('menuitemradio');
107
+ expect(menuItems).toHaveLength(2);
108
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'false');
109
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'true');
110
+ });
111
+ it('should set selected from children', () => {
112
+ render( /*#__PURE__*/React.createElement(MenuItemGroup, {
113
+ label: "Select a few",
114
+ allowMultiple: true
115
+ }, _MenuItem5 || (_MenuItem5 = /*#__PURE__*/React.createElement(MenuItem, {
116
+ key: "foo",
117
+ defaultSelected: true
118
+ }, "Foo")), /*#__PURE__*/React.createElement(MenuItem, {
119
+ key: "bar",
120
+ selected: true,
121
+ onSelect: jest.fn()
122
+ }, "Bar")));
123
+ const menuItems = screen.getAllByRole('menuitemcheckbox');
124
+ expect(menuItems).toHaveLength(2);
125
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'true');
126
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'true');
127
+ });
128
+ it('should honor the allowMultiple prop (defaults to false)', () => {
129
+ render( /*#__PURE__*/React.createElement(MenuItemGroup, {
130
+ label: "Select one"
131
+ }, _MenuItem6 || (_MenuItem6 = /*#__PURE__*/React.createElement(MenuItem, {
132
+ defaultSelected: true
133
+ }, "Foo")), /*#__PURE__*/React.createElement(MenuItem, {
134
+ selected: true,
135
+ onSelect: jest.fn()
136
+ }, "Bar")));
137
+ const menuItems = screen.getAllByRole('menuitemradio');
138
+ expect(menuItems).toHaveLength(2);
139
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'true');
140
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'false');
141
+ });
142
+ it('calls onSelect when items are selected', () => {
143
+ const onSelect = jest.fn();
144
+ render( /*#__PURE__*/React.createElement(MenuItemGroup, {
145
+ label: "Select one",
146
+ onSelect: onSelect,
147
+ selected: [1]
148
+ }, _MenuItem7 || (_MenuItem7 = /*#__PURE__*/React.createElement(MenuItem, null, "Item 1")), _MenuItem8 || (_MenuItem8 = /*#__PURE__*/React.createElement(MenuItem, null, "Item 2")), _MenuItemSeparator3 || (_MenuItemSeparator3 = /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
149
+ const menuItem = screen.getByText('Item 1');
150
+ fireEvent.click(menuItem);
151
+ expect(onSelect).toHaveBeenCalled();
152
+ expect(onSelect.mock.calls[0][1]).toEqual([0]);
153
+ expect(onSelect.mock.calls[0][2]).toEqual(true);
154
+ });
155
+ it('does not call onSelect when disabled', () => {
156
+ const onSelect = jest.fn();
157
+ render( /*#__PURE__*/React.createElement(MenuItemGroup, {
158
+ label: "Select one",
159
+ onSelect: onSelect,
160
+ disabled: true
161
+ }, _MenuItem9 || (_MenuItem9 = /*#__PURE__*/React.createElement(MenuItem, null, "Item 1")), _MenuItem10 || (_MenuItem10 = /*#__PURE__*/React.createElement(MenuItem, null, "Item 2")), _MenuItemSeparator4 || (_MenuItemSeparator4 = /*#__PURE__*/React.createElement(MenuItemSeparator, null))));
162
+ const menuItem = screen.getByText('Item 1');
163
+ fireEvent.click(menuItem);
164
+ expect(onSelect).not.toHaveBeenCalled();
165
+ });
166
+ });
@@ -0,0 +1,288 @@
1
+ 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;
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
+ import React from 'react';
26
+ import { render, screen, fireEvent } from '@testing-library/react';
27
+ import { userEvent } from '@testing-library/user-event';
28
+ import '@testing-library/jest-dom';
29
+ import { runAxeCheck } from '@instructure/ui-axe-check';
30
+ import { Menu, MenuItem, MenuItemSeparator } from '../index';
31
+ describe('<Menu />', () => {
32
+ describe('without a trigger', () => {
33
+ it('should render', () => {
34
+ render(_Menu || (_Menu = /*#__PURE__*/React.createElement(Menu, {
35
+ label: "Menu-label-text"
36
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Menu Item Text"))));
37
+ const menu = screen.getByRole('menu');
38
+ expect(menu).toBeInTheDocument();
39
+ expect(menu).toHaveTextContent('Menu Item Text');
40
+ expect(menu).toHaveAttribute('aria-label', 'Menu-label-text');
41
+ });
42
+ it('should meet a11y standards', async () => {
43
+ const _render = render(_Menu2 || (_Menu2 = /*#__PURE__*/React.createElement(Menu, {
44
+ label: "Menu-label-text"
45
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Menu Item Text")))),
46
+ container = _render.container;
47
+ const axeCheck = await runAxeCheck(container);
48
+ expect(axeCheck).toBe(true);
49
+ });
50
+ it('should meet standards when menu is closed', async () => {
51
+ const _render2 = render(_Menu3 || (_Menu3 = /*#__PURE__*/React.createElement(Menu, {
52
+ trigger: /*#__PURE__*/React.createElement("button", null, "More")
53
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery"), /*#__PURE__*/React.createElement(MenuItem, {
54
+ disabled: true
55
+ }, "Gradebook")))),
56
+ container = _render2.container;
57
+ const axeCheck = await runAxeCheck(container);
58
+ expect(axeCheck).toBe(true);
59
+ });
60
+ it('should meet standards when menu is open', async () => {
61
+ const _render3 = render(_Menu4 || (_Menu4 = /*#__PURE__*/React.createElement(Menu, {
62
+ trigger: /*#__PURE__*/React.createElement("button", null, "More"),
63
+ defaultShow: true
64
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery"), /*#__PURE__*/React.createElement(MenuItem, {
65
+ disabled: true
66
+ }, "Gradebook")))),
67
+ container = _render3.container;
68
+ const axeCheck = await runAxeCheck(container);
69
+ expect(axeCheck).toBe(true);
70
+ });
71
+ it('should call onSelect when menu item is selected', async () => {
72
+ const onSelect = jest.fn();
73
+ const _render4 = render( /*#__PURE__*/React.createElement(Menu, {
74
+ label: "Settings",
75
+ onSelect: onSelect
76
+ }, _MenuItem || (_MenuItem = /*#__PURE__*/React.createElement(MenuItem, {
77
+ value: "Test"
78
+ }, "Test Item")))),
79
+ getByText = _render4.getByText;
80
+ const item = getByText('Test Item');
81
+ await userEvent.click(item);
82
+ expect(onSelect).toHaveBeenCalled();
83
+ expect(onSelect.mock.calls[0][1]).toEqual('Test');
84
+ });
85
+ it('should not call onSelect when disabled', () => {
86
+ const onSelect = jest.fn();
87
+ const _render5 = render( /*#__PURE__*/React.createElement(Menu, {
88
+ label: "Settings",
89
+ onSelect: onSelect,
90
+ disabled: true
91
+ }, _MenuItem2 || (_MenuItem2 = /*#__PURE__*/React.createElement(MenuItem, {
92
+ value: "Account"
93
+ }, "Account")))),
94
+ getByText = _render5.getByText;
95
+ const item = getByText('Account');
96
+ userEvent.click(item);
97
+ expect(onSelect).not.toHaveBeenCalled();
98
+ });
99
+ it('should provide a menu ref', () => {
100
+ const menuRef = jest.fn();
101
+ render( /*#__PURE__*/React.createElement(Menu, {
102
+ label: "Settings",
103
+ menuRef: menuRef
104
+ }, _MenuItem3 || (_MenuItem3 = /*#__PURE__*/React.createElement(MenuItem, {
105
+ value: "Account"
106
+ }, "Account"))));
107
+ const menu = screen.getByRole('menu');
108
+ expect(menuRef).toHaveBeenLastCalledWith(menu);
109
+ });
110
+ it('should set aria attributes properly', () => {
111
+ render(_Menu5 || (_Menu5 = /*#__PURE__*/React.createElement(Menu, {
112
+ disabled: true,
113
+ label: "Settings"
114
+ }, /*#__PURE__*/React.createElement(MenuItem, {
115
+ value: "Account"
116
+ }, "Account"))));
117
+ const menu = screen.getByRole('menu');
118
+ expect(menu).toHaveAttribute('aria-disabled', 'true');
119
+ expect(menu).toHaveAttribute('aria-label', 'Settings');
120
+ });
121
+ });
122
+ describe('with a trigger', () => {
123
+ it('should render into a mountNode', () => {
124
+ const mountNode = document.createElement('div');
125
+ document.body.appendChild(mountNode);
126
+ render( /*#__PURE__*/React.createElement(Menu, {
127
+ defaultShow: true,
128
+ mountNode: mountNode,
129
+ label: "Settings",
130
+ trigger: _button || (_button = /*#__PURE__*/React.createElement("button", null, "Settings"))
131
+ }, _MenuItem4 || (_MenuItem4 = /*#__PURE__*/React.createElement(MenuItem, null, "Account"))));
132
+ expect(mountNode).toHaveTextContent('Account');
133
+ document.body.removeChild(mountNode);
134
+ });
135
+ it('should set aria attributes properly', () => {
136
+ render(_Menu6 || (_Menu6 = /*#__PURE__*/React.createElement(Menu, {
137
+ trigger: /*#__PURE__*/React.createElement("button", null, "Settings"),
138
+ defaultShow: true
139
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery"), /*#__PURE__*/React.createElement(MenuItem, {
140
+ disabled: true
141
+ }, "Gradebook"), /*#__PURE__*/React.createElement(MenuItem, {
142
+ type: "radio",
143
+ defaultChecked: true
144
+ }, "Default (Grid view)"), /*#__PURE__*/React.createElement(MenuItem, {
145
+ type: "radio"
146
+ }, "Individual (List view)"), /*#__PURE__*/React.createElement(MenuItem, {
147
+ type: "checkbox",
148
+ defaultChecked: true
149
+ }, "Include Anchor Standards"), /*#__PURE__*/React.createElement(MenuItemSeparator, null), /*#__PURE__*/React.createElement(MenuItem, null, "Open grading history..."))));
150
+ const menu = screen.getByRole('menu');
151
+ const trigger = screen.getByRole('button', {
152
+ name: 'Settings'
153
+ });
154
+ expect(menu).toBeInTheDocument();
155
+ expect(menu).toHaveAttribute('aria-labelledby', trigger.getAttribute('id'));
156
+ });
157
+ it('should call onFocus on focus', () => {
158
+ const onFocus = jest.fn();
159
+ const _render6 = render( /*#__PURE__*/React.createElement(Menu, {
160
+ trigger: _button2 || (_button2 = /*#__PURE__*/React.createElement("button", null, "More")),
161
+ onFocus: onFocus
162
+ }, _MenuItem5 || (_MenuItem5 = /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery")), _MenuItem6 || (_MenuItem6 = /*#__PURE__*/React.createElement(MenuItem, {
163
+ disabled: true
164
+ }, "Gradebook")))),
165
+ getByRole = _render6.getByRole;
166
+ const triggerButton = getByRole('button', {
167
+ name: 'More'
168
+ });
169
+ fireEvent.focus(triggerButton);
170
+ expect(onFocus).toHaveBeenCalled();
171
+ });
172
+ it('should render when show and onToggle props are set', () => {
173
+ const _render7 = render( /*#__PURE__*/React.createElement(Menu, {
174
+ trigger: _button3 || (_button3 = /*#__PURE__*/React.createElement("button", null, "More")),
175
+ show: true,
176
+ onToggle: () => {}
177
+ }, _MenuItem7 || (_MenuItem7 = /*#__PURE__*/React.createElement(MenuItem, null, "Test1")), _MenuItem8 || (_MenuItem8 = /*#__PURE__*/React.createElement(MenuItem, {
178
+ disabled: true
179
+ }, "Test2")))),
180
+ getByRole = _render7.getByRole,
181
+ getAllByRole = _render7.getAllByRole,
182
+ queryByText = _render7.queryByText;
183
+ const menuItems = getAllByRole('menuitem');
184
+ const triggerButton = getByRole('button', {
185
+ name: 'More'
186
+ });
187
+ const menuItem1 = queryByText('Test1');
188
+ const menuItem2 = queryByText('Test2');
189
+ expect(triggerButton).toBeInTheDocument();
190
+ expect(menuItems).toHaveLength(2);
191
+ expect(menuItem1).toBeInTheDocument();
192
+ expect(menuItem2).toBeInTheDocument();
193
+ });
194
+ it('should not show by default', () => {
195
+ const _render8 = render(_Menu7 || (_Menu7 = /*#__PURE__*/React.createElement(Menu, {
196
+ trigger: /*#__PURE__*/React.createElement("button", null, "More")
197
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Test1"), /*#__PURE__*/React.createElement(MenuItem, {
198
+ disabled: true
199
+ }, "Test2")))),
200
+ queryByText = _render8.queryByText,
201
+ getByRole = _render8.getByRole;
202
+ const triggerButton = getByRole('button', {
203
+ name: 'More'
204
+ });
205
+ const menuItem1 = queryByText('Test1');
206
+ const menuItem2 = queryByText('Test2');
207
+ expect(triggerButton).toBeInTheDocument();
208
+ expect(menuItem1).not.toBeInTheDocument();
209
+ expect(menuItem2).not.toBeInTheDocument();
210
+ });
211
+ it('should accept a default show', () => {
212
+ const _render9 = render(_Menu8 || (_Menu8 = /*#__PURE__*/React.createElement(Menu, {
213
+ trigger: /*#__PURE__*/React.createElement("button", null, "More"),
214
+ defaultShow: true
215
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Test1"), /*#__PURE__*/React.createElement(MenuItem, {
216
+ disabled: true
217
+ }, "Test2")))),
218
+ queryByText = _render9.queryByText,
219
+ getByRole = _render9.getByRole;
220
+ const triggerButton = getByRole('button', {
221
+ name: 'More'
222
+ });
223
+ const menuItem1 = queryByText('Test1');
224
+ const menuItem2 = queryByText('Test2');
225
+ expect(triggerButton).toBeInTheDocument();
226
+ expect(menuItem1).toBeInTheDocument();
227
+ expect(menuItem2).toBeInTheDocument();
228
+ });
229
+ it('should provide a menu ref', () => {
230
+ const menuRef = jest.fn();
231
+ render( /*#__PURE__*/React.createElement(Menu, {
232
+ trigger: _button4 || (_button4 = /*#__PURE__*/React.createElement("button", null, "More")),
233
+ defaultShow: true,
234
+ menuRef: menuRef
235
+ }, _MenuItem9 || (_MenuItem9 = /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery")), _MenuItem10 || (_MenuItem10 = /*#__PURE__*/React.createElement(MenuItem, {
236
+ disabled: true
237
+ }, "Gradebook"))));
238
+ const menu = screen.getByRole('menu');
239
+ expect(menuRef).toHaveBeenCalledWith(menu);
240
+ });
241
+ it('should provide a popoverRef ref', () => {
242
+ const popoverRef = jest.fn();
243
+ render( /*#__PURE__*/React.createElement(Menu, {
244
+ trigger: _button5 || (_button5 = /*#__PURE__*/React.createElement("button", null, "More")),
245
+ defaultShow: true,
246
+ popoverRef: popoverRef
247
+ }, _MenuItem11 || (_MenuItem11 = /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery")), _MenuItem12 || (_MenuItem12 = /*#__PURE__*/React.createElement(MenuItem, {
248
+ disabled: true
249
+ }, "Gradebook"))));
250
+ expect(popoverRef).toHaveBeenCalled();
251
+ });
252
+ it('should call onToggle on click', () => {
253
+ const onToggle = jest.fn();
254
+ render( /*#__PURE__*/React.createElement(Menu, {
255
+ trigger: _button6 || (_button6 = /*#__PURE__*/React.createElement("button", null, "More")),
256
+ onToggle: onToggle
257
+ }, _MenuItem13 || (_MenuItem13 = /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery")), _MenuItem14 || (_MenuItem14 = /*#__PURE__*/React.createElement(MenuItem, {
258
+ disabled: true
259
+ }, "Gradebook"))));
260
+ const trigger = screen.getByRole('button');
261
+ fireEvent.click(trigger);
262
+ expect(onToggle).toHaveBeenCalled();
263
+ });
264
+ it('should have an aria-haspopup attribute', () => {
265
+ render(_Menu9 || (_Menu9 = /*#__PURE__*/React.createElement(Menu, {
266
+ trigger: /*#__PURE__*/React.createElement("button", null, "More")
267
+ }, /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery"), /*#__PURE__*/React.createElement(MenuItem, {
268
+ disabled: true
269
+ }, "Gradebook"))));
270
+ const trigger = screen.getByRole('button');
271
+ expect(trigger).toHaveAttribute('aria-haspopup');
272
+ });
273
+ it('should pass positionContainerDisplay prop to Popover', () => {
274
+ let popoverRef = null;
275
+ render( /*#__PURE__*/React.createElement(Menu, {
276
+ trigger: _button7 || (_button7 = /*#__PURE__*/React.createElement("button", null, "More")),
277
+ popoverRef: e => {
278
+ popoverRef = e;
279
+ },
280
+ positionContainerDisplay: "block"
281
+ }, _MenuItem15 || (_MenuItem15 = /*#__PURE__*/React.createElement(MenuItem, null, "Learning Mastery")), _MenuItem16 || (_MenuItem16 = /*#__PURE__*/React.createElement(MenuItem, {
282
+ disabled: true
283
+ }, "Gradebook"))));
284
+ const popoverProps = popoverRef.props;
285
+ expect(popoverProps.positionContainerDisplay).toBe('block');
286
+ });
287
+ });
288
+ });