@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
@@ -0,0 +1,161 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React from 'react'
26
+ import { fireEvent, render, screen } from '@testing-library/react'
27
+ import '@testing-library/jest-dom'
28
+
29
+ import { MenuItem } from '../index'
30
+ import type { MenuItemProps } from '../props'
31
+
32
+ interface ExtendedMenuItemProps extends MenuItemProps {
33
+ to: string
34
+ }
35
+
36
+ const ExtendedMenuItem: React.FC<ExtendedMenuItemProps> = ({ ...props }) => {
37
+ return <MenuItem {...props} />
38
+ }
39
+
40
+ describe('<MenuItem />', () => {
41
+ it('should render', () => {
42
+ render(<MenuItem>Menu Item Text</MenuItem>)
43
+ const menuItem = screen.getByText('Menu Item Text')
44
+
45
+ expect(menuItem).toBeInTheDocument()
46
+ })
47
+
48
+ it('should render as a link when an href is provided', () => {
49
+ render(<MenuItem href="example.html">Menu Item Text</MenuItem>)
50
+
51
+ const menuItem = screen.getByRole('menuitem')
52
+
53
+ expect(menuItem).toBeInTheDocument()
54
+ expect(menuItem).toHaveAttribute('href', 'example.html')
55
+ })
56
+
57
+ it('should render as a link when a to is provided', () => {
58
+ render(<ExtendedMenuItem to="/example">Hello</ExtendedMenuItem>)
59
+
60
+ const menuItem = screen.getByRole('menuitem')
61
+
62
+ expect(menuItem).toHaveAttribute('to', '/example')
63
+ })
64
+
65
+ it('should call onSelect after click', () => {
66
+ const onSelect = jest.fn()
67
+ render(
68
+ <MenuItem onSelect={onSelect} value="foo">
69
+ Hello
70
+ </MenuItem>
71
+ )
72
+ const menuItem = screen.getByRole('menuitem')
73
+
74
+ fireEvent.click(menuItem)
75
+
76
+ expect(onSelect).toHaveBeenCalledWith(
77
+ expect.any(Object),
78
+ 'foo',
79
+ true,
80
+ expect.any(Object)
81
+ )
82
+ })
83
+
84
+ it('should call onClick after click', () => {
85
+ const onClick = jest.fn()
86
+ render(
87
+ <MenuItem onClick={onClick} value="foo">
88
+ Hello
89
+ </MenuItem>
90
+ )
91
+ const menuItem = screen.getByRole('menuitem')
92
+
93
+ fireEvent.click(menuItem)
94
+
95
+ expect(onClick).toHaveBeenCalled()
96
+ })
97
+
98
+ it('should set the tabIndex attribute', () => {
99
+ render(<MenuItem>Hello</MenuItem>)
100
+ const menuItem = screen.getByRole('menuitem')
101
+
102
+ expect(menuItem).toHaveAttribute('tabIndex', '-1')
103
+ })
104
+
105
+ it('should set the aria-controls attribute', () => {
106
+ render(<MenuItem controls="testId">Hello</MenuItem>)
107
+ const menuItem = screen.getByRole('menuitem')
108
+
109
+ expect(menuItem).toHaveAttribute('aria-controls', 'testId')
110
+ })
111
+
112
+ it('should set the aria-disabled attribute', () => {
113
+ render(<MenuItem disabled>Hello</MenuItem>)
114
+ const menuItem = screen.getByRole('menuitem')
115
+
116
+ expect(menuItem).toHaveAttribute('aria-disabled', 'true')
117
+ })
118
+
119
+ it('should set the aria-checked attribute when defaultSelected prop is true', () => {
120
+ render(
121
+ <MenuItem type="checkbox" defaultSelected>
122
+ Hello
123
+ </MenuItem>
124
+ )
125
+ const menuItem = screen.getByRole('menuitemcheckbox')
126
+
127
+ expect(menuItem).toHaveAttribute('aria-checked', 'true')
128
+ })
129
+
130
+ it('should set the aria-checked attribute when selected prop is true', () => {
131
+ render(
132
+ <MenuItem type="checkbox" selected onSelect={jest.fn()}>
133
+ Hello
134
+ </MenuItem>
135
+ )
136
+ const menuItem = screen.getByRole('menuitemcheckbox')
137
+
138
+ expect(menuItem).toHaveAttribute('aria-checked', 'true')
139
+ })
140
+
141
+ it('should default to the "menuitem" role', () => {
142
+ const { container } = render(<MenuItem>Menu Item Text</MenuItem>)
143
+ const menuItem = container.querySelector("span[class$='-menuItem']")
144
+
145
+ expect(menuItem).toHaveAttribute('role', 'menuitem')
146
+ })
147
+
148
+ it('should set the role to "menuitemcheckbox" when the type is "checkbox"', () => {
149
+ const { container } = render(<MenuItem type="checkbox">Hello</MenuItem>)
150
+ const menuItem = container.querySelector("span[class$='-menuItem']")
151
+
152
+ expect(menuItem).toHaveAttribute('role', 'menuitemcheckbox')
153
+ })
154
+
155
+ it('should set the role to "menuitemradio" when the type is "radio"', () => {
156
+ const { container } = render(<MenuItem type="radio">Hello</MenuItem>)
157
+ const menuItem = container.querySelector("span[class$='-menuItem']")
158
+
159
+ expect(menuItem).toHaveAttribute('role', 'menuitemradio')
160
+ })
161
+ })
@@ -0,0 +1,222 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React from 'react'
26
+ import { fireEvent, render, screen } from '@testing-library/react'
27
+ import '@testing-library/jest-dom'
28
+
29
+ import { MenuItem } from '../../MenuItem'
30
+ import { MenuItemSeparator } from '../../MenuItemSeparator'
31
+ import { MenuItemGroup } from '../index'
32
+
33
+ describe('<MenuItemGroup />', () => {
34
+ it('should render', () => {
35
+ const { container } = render(
36
+ <MenuItemGroup label="Menu Label">
37
+ <MenuItem>Item Text 1</MenuItem>
38
+ <MenuItem>Item Text 2</MenuItem>
39
+ <MenuItemSeparator />
40
+ </MenuItemGroup>
41
+ )
42
+ const group = container.querySelector("[id*='MenuItemGroup_']")
43
+ const groupMenu = screen.getByRole('menu')
44
+
45
+ expect(group).toBeInTheDocument()
46
+ expect(group).toHaveTextContent('Menu Label')
47
+
48
+ expect(groupMenu).toBeInTheDocument()
49
+ expect(groupMenu).toHaveTextContent('Item Text 1')
50
+ expect(groupMenu).toHaveTextContent('Item Text 2')
51
+ })
52
+
53
+ it('should set the role to "menu"', () => {
54
+ const { container } = render(
55
+ <MenuItemGroup label="Select one">
56
+ <MenuItem>Foo</MenuItem>
57
+ <MenuItem>Bar</MenuItem>
58
+ <MenuItemSeparator />
59
+ </MenuItemGroup>
60
+ )
61
+ const menuItemGroup = container.querySelector(
62
+ "[class*='menuItemGroup__items']"
63
+ )
64
+
65
+ expect(menuItemGroup).toHaveAttribute('role', 'menu')
66
+ })
67
+
68
+ it('should set the list item role to "none"', () => {
69
+ render(
70
+ <MenuItemGroup label="Select one">
71
+ <MenuItem>Food</MenuItem>
72
+ <MenuItem>Bar</MenuItem>
73
+ </MenuItemGroup>
74
+ )
75
+ const menu = screen.getByRole('menu')
76
+ const menuListItem = menu.firstChild as HTMLElement
77
+
78
+ expect(menuListItem.tagName).toBe('LI')
79
+ expect(menuListItem).toHaveAttribute('role', 'none')
80
+ })
81
+
82
+ it('should default to children with type "radio"', () => {
83
+ render(
84
+ <MenuItemGroup label="Select one">
85
+ <MenuItem>Foo</MenuItem>
86
+ <MenuItem>Bar</MenuItem>
87
+ <MenuItemSeparator />
88
+ </MenuItemGroup>
89
+ )
90
+ const menuItems = screen.getAllByRole('menuitemradio')
91
+
92
+ expect(menuItems).toHaveLength(2)
93
+ })
94
+
95
+ it('should render children with type "checkbox" if allowMultiple is true', () => {
96
+ render(
97
+ <MenuItemGroup label="Select a few" allowMultiple>
98
+ <MenuItem>Foo</MenuItem>
99
+ <MenuItem>Bar</MenuItem>
100
+ <MenuItemSeparator />
101
+ </MenuItemGroup>
102
+ )
103
+ const menuItems = screen.getAllByRole('menuitemcheckbox')
104
+
105
+ expect(menuItems).toHaveLength(2)
106
+ })
107
+
108
+ it('should set aria-disabled', () => {
109
+ render(
110
+ <MenuItemGroup label="Select one" disabled>
111
+ <MenuItem>Foo</MenuItem>
112
+ <MenuItem>Bar</MenuItem>
113
+ <MenuItemSeparator />
114
+ </MenuItemGroup>
115
+ )
116
+ const menu = screen.getByRole('menu')
117
+ const menuItems = screen.getAllByRole('menuitemradio')
118
+
119
+ expect(menu).toHaveAttribute('aria-disabled', 'true')
120
+ expect(menuItems).toHaveLength(2)
121
+ expect(menuItems[0]).toHaveAttribute('aria-disabled', 'true')
122
+ expect(menuItems[1]).toHaveAttribute('aria-disabled', 'true')
123
+ })
124
+
125
+ it('should set selected from defaultSelected prop', () => {
126
+ render(
127
+ <MenuItemGroup label="Select one" defaultSelected={[1]}>
128
+ <MenuItem>Foo</MenuItem>
129
+ <MenuItem>Bar</MenuItem>
130
+ <MenuItemSeparator />
131
+ </MenuItemGroup>
132
+ )
133
+ const menuItems = screen.getAllByRole('menuitemradio')
134
+
135
+ expect(menuItems).toHaveLength(2)
136
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'false')
137
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'true')
138
+ })
139
+
140
+ it('should set selected from selected prop', () => {
141
+ render(
142
+ <MenuItemGroup label="Select one" onSelect={jest.fn()} selected={[1]}>
143
+ <MenuItem>Foo</MenuItem>
144
+ <MenuItem>Bar</MenuItem>
145
+ <MenuItemSeparator />
146
+ </MenuItemGroup>
147
+ )
148
+ const menuItems = screen.getAllByRole('menuitemradio')
149
+
150
+ expect(menuItems).toHaveLength(2)
151
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'false')
152
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'true')
153
+ })
154
+
155
+ it('should set selected from children', () => {
156
+ render(
157
+ <MenuItemGroup label="Select a few" allowMultiple>
158
+ <MenuItem key="foo" defaultSelected>
159
+ Foo
160
+ </MenuItem>
161
+ <MenuItem key="bar" selected onSelect={jest.fn()}>
162
+ Bar
163
+ </MenuItem>
164
+ </MenuItemGroup>
165
+ )
166
+ const menuItems = screen.getAllByRole('menuitemcheckbox')
167
+
168
+ expect(menuItems).toHaveLength(2)
169
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'true')
170
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'true')
171
+ })
172
+
173
+ it('should honor the allowMultiple prop (defaults to false)', () => {
174
+ render(
175
+ <MenuItemGroup label="Select one">
176
+ <MenuItem defaultSelected>Foo</MenuItem>
177
+ <MenuItem selected onSelect={jest.fn()}>
178
+ Bar
179
+ </MenuItem>
180
+ </MenuItemGroup>
181
+ )
182
+ const menuItems = screen.getAllByRole('menuitemradio')
183
+
184
+ expect(menuItems).toHaveLength(2)
185
+ expect(menuItems[0]).toHaveAttribute('aria-checked', 'true')
186
+ expect(menuItems[1]).toHaveAttribute('aria-checked', 'false')
187
+ })
188
+
189
+ it('calls onSelect when items are selected', () => {
190
+ const onSelect = jest.fn()
191
+ render(
192
+ <MenuItemGroup label="Select one" onSelect={onSelect} selected={[1]}>
193
+ <MenuItem>Item 1</MenuItem>
194
+ <MenuItem>Item 2</MenuItem>
195
+ <MenuItemSeparator />
196
+ </MenuItemGroup>
197
+ )
198
+ const menuItem = screen.getByText('Item 1')
199
+
200
+ fireEvent.click(menuItem)
201
+
202
+ expect(onSelect).toHaveBeenCalled()
203
+ expect(onSelect.mock.calls[0][1]).toEqual([0])
204
+ expect(onSelect.mock.calls[0][2]).toEqual(true)
205
+ })
206
+
207
+ it('does not call onSelect when disabled', () => {
208
+ const onSelect = jest.fn()
209
+ render(
210
+ <MenuItemGroup label="Select one" onSelect={onSelect} disabled>
211
+ <MenuItem>Item 1</MenuItem>
212
+ <MenuItem>Item 2</MenuItem>
213
+ <MenuItemSeparator />
214
+ </MenuItemGroup>
215
+ )
216
+ const menuItem = screen.getByText('Item 1')
217
+
218
+ fireEvent.click(menuItem)
219
+
220
+ expect(onSelect).not.toHaveBeenCalled()
221
+ })
222
+ })