@instructure/ui-menu 10.19.2-snapshot-3 → 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.
- package/CHANGELOG.md +1 -1
- package/package.json +19 -19
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/Menu/MenuItem/__new-tests__/MenuItem.test.js +0 -153
- package/es/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.js +0 -190
- package/es/Menu/__new-tests__/Menu.test.js +0 -400
- package/lib/Menu/MenuItem/__new-tests__/MenuItem.test.js +0 -154
- package/lib/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.js +0 -191
- package/lib/Menu/__new-tests__/Menu.test.js +0 -401
- package/src/Menu/MenuItem/__new-tests__/MenuItem.test.tsx +0 -161
- package/src/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.tsx +0 -187
- package/src/Menu/__new-tests__/Menu.test.tsx +0 -358
- package/types/Menu/MenuItem/__new-tests__/MenuItem.test.d.ts +0 -2
- package/types/Menu/MenuItem/__new-tests__/MenuItem.test.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.d.ts +0 -2
- package/types/Menu/MenuItemGroup/__new-tests__/MenuItemGroup.test.d.ts.map +0 -1
- package/types/Menu/__new-tests__/Menu.test.d.ts +0 -2
- package/types/Menu/__new-tests__/Menu.test.d.ts.map +0 -1
|
@@ -1,161 +0,0 @@
|
|
|
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 { fireEvent, render, screen } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
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 = vi.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 = vi.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={vi.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
|
-
})
|
|
@@ -1,187 +0,0 @@
|
|
|
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 { fireEvent, render, screen } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
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("[class*='menuItemGroup']")
|
|
43
|
-
expect(group).toBeInTheDocument()
|
|
44
|
-
expect(group).toHaveTextContent('Menu Label')
|
|
45
|
-
expect(group).toHaveTextContent('Item Text 1')
|
|
46
|
-
expect(group).toHaveTextContent('Item Text 2')
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('should default to children with type "radio"', () => {
|
|
50
|
-
render(
|
|
51
|
-
<MenuItemGroup label="Select one">
|
|
52
|
-
<MenuItem>Foo</MenuItem>
|
|
53
|
-
<MenuItem>Bar</MenuItem>
|
|
54
|
-
<MenuItemSeparator />
|
|
55
|
-
</MenuItemGroup>
|
|
56
|
-
)
|
|
57
|
-
const menuItems = screen.getAllByRole('menuitemradio')
|
|
58
|
-
|
|
59
|
-
expect(menuItems).toHaveLength(2)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('should render children with type "checkbox" if allowMultiple is true', () => {
|
|
63
|
-
render(
|
|
64
|
-
<MenuItemGroup label="Select a few" allowMultiple>
|
|
65
|
-
<MenuItem>Foo</MenuItem>
|
|
66
|
-
<MenuItem>Bar</MenuItem>
|
|
67
|
-
<MenuItemSeparator />
|
|
68
|
-
</MenuItemGroup>
|
|
69
|
-
)
|
|
70
|
-
const menuItems = screen.getAllByRole('menuitemcheckbox')
|
|
71
|
-
|
|
72
|
-
expect(menuItems).toHaveLength(2)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should set aria-disabled', () => {
|
|
76
|
-
render(
|
|
77
|
-
<MenuItemGroup label="Select one" disabled>
|
|
78
|
-
<MenuItem>Foo</MenuItem>
|
|
79
|
-
<MenuItem>Bar</MenuItem>
|
|
80
|
-
<MenuItemSeparator />
|
|
81
|
-
</MenuItemGroup>
|
|
82
|
-
)
|
|
83
|
-
const menuItems = screen.getAllByRole('menuitemradio')
|
|
84
|
-
|
|
85
|
-
expect(menuItems).toHaveLength(2)
|
|
86
|
-
expect(menuItems[0]).toHaveAttribute('aria-disabled', 'true')
|
|
87
|
-
expect(menuItems[1]).toHaveAttribute('aria-disabled', 'true')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should set selected from defaultSelected prop', () => {
|
|
91
|
-
render(
|
|
92
|
-
<MenuItemGroup label="Select one" defaultSelected={[1]}>
|
|
93
|
-
<MenuItem>Foo</MenuItem>
|
|
94
|
-
<MenuItem>Bar</MenuItem>
|
|
95
|
-
<MenuItemSeparator />
|
|
96
|
-
</MenuItemGroup>
|
|
97
|
-
)
|
|
98
|
-
const menuItems = screen.getAllByRole('menuitemradio')
|
|
99
|
-
|
|
100
|
-
expect(menuItems).toHaveLength(2)
|
|
101
|
-
expect(menuItems[0]).toHaveAttribute('aria-checked', 'false')
|
|
102
|
-
expect(menuItems[1]).toHaveAttribute('aria-checked', 'true')
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('should set selected from selected prop', () => {
|
|
106
|
-
render(
|
|
107
|
-
<MenuItemGroup label="Select one" onSelect={vi.fn()} selected={[1]}>
|
|
108
|
-
<MenuItem>Foo</MenuItem>
|
|
109
|
-
<MenuItem>Bar</MenuItem>
|
|
110
|
-
<MenuItemSeparator />
|
|
111
|
-
</MenuItemGroup>
|
|
112
|
-
)
|
|
113
|
-
const menuItems = screen.getAllByRole('menuitemradio')
|
|
114
|
-
|
|
115
|
-
expect(menuItems).toHaveLength(2)
|
|
116
|
-
expect(menuItems[0]).toHaveAttribute('aria-checked', 'false')
|
|
117
|
-
expect(menuItems[1]).toHaveAttribute('aria-checked', 'true')
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('should set selected from children', () => {
|
|
121
|
-
render(
|
|
122
|
-
<MenuItemGroup label="Select a few" allowMultiple>
|
|
123
|
-
<MenuItem key="foo" defaultSelected>
|
|
124
|
-
Foo
|
|
125
|
-
</MenuItem>
|
|
126
|
-
<MenuItem key="bar" selected onSelect={vi.fn()}>
|
|
127
|
-
Bar
|
|
128
|
-
</MenuItem>
|
|
129
|
-
</MenuItemGroup>
|
|
130
|
-
)
|
|
131
|
-
const menuItems = screen.getAllByRole('menuitemcheckbox')
|
|
132
|
-
|
|
133
|
-
expect(menuItems).toHaveLength(2)
|
|
134
|
-
expect(menuItems[0]).toHaveAttribute('aria-checked', 'true')
|
|
135
|
-
expect(menuItems[1]).toHaveAttribute('aria-checked', 'true')
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('should honor the allowMultiple prop (defaults to false)', () => {
|
|
139
|
-
render(
|
|
140
|
-
<MenuItemGroup label="Select one">
|
|
141
|
-
<MenuItem defaultSelected>Foo</MenuItem>
|
|
142
|
-
<MenuItem selected onSelect={vi.fn()}>
|
|
143
|
-
Bar
|
|
144
|
-
</MenuItem>
|
|
145
|
-
</MenuItemGroup>
|
|
146
|
-
)
|
|
147
|
-
const menuItems = screen.getAllByRole('menuitemradio')
|
|
148
|
-
|
|
149
|
-
expect(menuItems).toHaveLength(2)
|
|
150
|
-
expect(menuItems[0]).toHaveAttribute('aria-checked', 'true')
|
|
151
|
-
expect(menuItems[1]).toHaveAttribute('aria-checked', 'false')
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it('calls onSelect when items are selected', () => {
|
|
155
|
-
const onSelect = vi.fn()
|
|
156
|
-
render(
|
|
157
|
-
<MenuItemGroup label="Select one" onSelect={onSelect} selected={[1]}>
|
|
158
|
-
<MenuItem>Item 1</MenuItem>
|
|
159
|
-
<MenuItem>Item 2</MenuItem>
|
|
160
|
-
<MenuItemSeparator />
|
|
161
|
-
</MenuItemGroup>
|
|
162
|
-
)
|
|
163
|
-
const menuItem = screen.getByText('Item 1')
|
|
164
|
-
|
|
165
|
-
fireEvent.click(menuItem)
|
|
166
|
-
|
|
167
|
-
expect(onSelect).toHaveBeenCalled()
|
|
168
|
-
expect(onSelect.mock.calls[0][1]).toEqual([0])
|
|
169
|
-
expect(onSelect.mock.calls[0][2]).toEqual(true)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('does not call onSelect when disabled', () => {
|
|
173
|
-
const onSelect = vi.fn()
|
|
174
|
-
render(
|
|
175
|
-
<MenuItemGroup label="Select one" onSelect={onSelect} disabled>
|
|
176
|
-
<MenuItem>Item 1</MenuItem>
|
|
177
|
-
<MenuItem>Item 2</MenuItem>
|
|
178
|
-
<MenuItemSeparator />
|
|
179
|
-
</MenuItemGroup>
|
|
180
|
-
)
|
|
181
|
-
const menuItem = screen.getByText('Item 1')
|
|
182
|
-
|
|
183
|
-
fireEvent.click(menuItem)
|
|
184
|
-
|
|
185
|
-
expect(onSelect).not.toHaveBeenCalled()
|
|
186
|
-
})
|
|
187
|
-
})
|
|
@@ -1,358 +0,0 @@
|
|
|
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 { render, screen, fireEvent } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import { userEvent } from '@testing-library/user-event'
|
|
28
|
-
import '@testing-library/jest-dom'
|
|
29
|
-
|
|
30
|
-
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
31
|
-
import { Popover } from '@instructure/ui-popover'
|
|
32
|
-
import { Menu, MenuItem, MenuItemSeparator } from '../index'
|
|
33
|
-
|
|
34
|
-
describe('<Menu />', () => {
|
|
35
|
-
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
36
|
-
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
40
|
-
consoleWarningMock = vi
|
|
41
|
-
.spyOn(console, 'warn')
|
|
42
|
-
.mockImplementation(() => {}) as any
|
|
43
|
-
consoleErrorMock = vi
|
|
44
|
-
.spyOn(console, 'error')
|
|
45
|
-
.mockImplementation(() => {}) as any
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
afterEach(() => {
|
|
49
|
-
consoleWarningMock.mockRestore()
|
|
50
|
-
consoleErrorMock.mockRestore()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
describe('without a trigger', () => {
|
|
54
|
-
it('should render', () => {
|
|
55
|
-
render(
|
|
56
|
-
<Menu label="Menu-label-text">
|
|
57
|
-
<MenuItem>Menu Item Text</MenuItem>
|
|
58
|
-
</Menu>
|
|
59
|
-
)
|
|
60
|
-
const menu = screen.getByRole('menu')
|
|
61
|
-
|
|
62
|
-
expect(menu).toBeInTheDocument()
|
|
63
|
-
expect(menu).toHaveTextContent('Menu Item Text')
|
|
64
|
-
expect(menu).toHaveAttribute('aria-label', 'Menu-label-text')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should meet a11y standards', async () => {
|
|
68
|
-
const { container } = render(
|
|
69
|
-
<Menu label="Menu-label-text">
|
|
70
|
-
<MenuItem>Menu Item Text</MenuItem>
|
|
71
|
-
</Menu>
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const axeCheck = await runAxeCheck(container)
|
|
75
|
-
|
|
76
|
-
expect(axeCheck).toBe(true)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should meet standards when menu is closed', async () => {
|
|
80
|
-
const { container } = render(
|
|
81
|
-
<Menu trigger={<button>More</button>}>
|
|
82
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
83
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
84
|
-
</Menu>
|
|
85
|
-
)
|
|
86
|
-
const axeCheck = await runAxeCheck(container)
|
|
87
|
-
|
|
88
|
-
expect(axeCheck).toBe(true)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('should meet standards when menu is open', async () => {
|
|
92
|
-
const { container } = render(
|
|
93
|
-
<Menu trigger={<button>More</button>} defaultShow>
|
|
94
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
95
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
96
|
-
</Menu>
|
|
97
|
-
)
|
|
98
|
-
const axeCheck = await runAxeCheck(container)
|
|
99
|
-
|
|
100
|
-
expect(axeCheck).toBe(true)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should call onSelect when menu item is selected', async () => {
|
|
104
|
-
const onSelect = vi.fn()
|
|
105
|
-
|
|
106
|
-
const { getByText } = render(
|
|
107
|
-
<Menu label="Settings" onSelect={onSelect}>
|
|
108
|
-
<MenuItem value="Test">Test Item</MenuItem>
|
|
109
|
-
</Menu>
|
|
110
|
-
)
|
|
111
|
-
const item = getByText('Test Item')
|
|
112
|
-
|
|
113
|
-
await userEvent.click(item)
|
|
114
|
-
|
|
115
|
-
expect(onSelect).toHaveBeenCalled()
|
|
116
|
-
expect(onSelect.mock.calls[0][1]).toEqual('Test')
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
it('should not call onSelect when disabled', () => {
|
|
120
|
-
const onSelect = vi.fn()
|
|
121
|
-
|
|
122
|
-
const { getByText } = render(
|
|
123
|
-
<Menu label="Settings" onSelect={onSelect} disabled>
|
|
124
|
-
<MenuItem value="Account">Account</MenuItem>
|
|
125
|
-
</Menu>
|
|
126
|
-
)
|
|
127
|
-
const itemText = getByText('Account')
|
|
128
|
-
const menu = screen.getByRole('menu')
|
|
129
|
-
const menuItem = screen.getByRole('menuitem')
|
|
130
|
-
|
|
131
|
-
expect(itemText).toBeInTheDocument()
|
|
132
|
-
expect(menu).toHaveAttribute('aria-disabled', 'true')
|
|
133
|
-
expect(menuItem).toHaveAttribute('aria-disabled', 'true')
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('should provide a menu ref', () => {
|
|
137
|
-
const menuRef = vi.fn()
|
|
138
|
-
|
|
139
|
-
render(
|
|
140
|
-
<Menu label="Settings" menuRef={menuRef}>
|
|
141
|
-
<MenuItem value="Account">Account</MenuItem>
|
|
142
|
-
</Menu>
|
|
143
|
-
)
|
|
144
|
-
const menu = screen.getByRole('menu')
|
|
145
|
-
|
|
146
|
-
expect(menuRef).toHaveBeenLastCalledWith(menu)
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('should set aria attributes properly', () => {
|
|
150
|
-
render(
|
|
151
|
-
<Menu disabled label="Settings">
|
|
152
|
-
<MenuItem value="Account">Account</MenuItem>
|
|
153
|
-
</Menu>
|
|
154
|
-
)
|
|
155
|
-
const menu = screen.getByRole('menu')
|
|
156
|
-
|
|
157
|
-
expect(menu).toHaveAttribute('aria-disabled', 'true')
|
|
158
|
-
expect(menu).toHaveAttribute('aria-label', 'Settings')
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
describe('with a trigger', () => {
|
|
163
|
-
it('should render into a mountNode', () => {
|
|
164
|
-
const mountNode = document.createElement('div')
|
|
165
|
-
|
|
166
|
-
document.body.appendChild(mountNode)
|
|
167
|
-
|
|
168
|
-
render(
|
|
169
|
-
<Menu
|
|
170
|
-
defaultShow
|
|
171
|
-
mountNode={mountNode}
|
|
172
|
-
label="Settings"
|
|
173
|
-
trigger={<button>Settings</button>}
|
|
174
|
-
>
|
|
175
|
-
<MenuItem>Account</MenuItem>
|
|
176
|
-
</Menu>
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
expect(mountNode).toHaveTextContent('Account')
|
|
180
|
-
|
|
181
|
-
document.body.removeChild(mountNode)
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
it('should set aria attributes properly', () => {
|
|
185
|
-
render(
|
|
186
|
-
<Menu trigger={<button>Settings</button>} defaultShow>
|
|
187
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
188
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
189
|
-
<MenuItem type="radio" defaultChecked>
|
|
190
|
-
Default (Grid view)
|
|
191
|
-
</MenuItem>
|
|
192
|
-
<MenuItem type="radio">Individual (List view)</MenuItem>
|
|
193
|
-
<MenuItem type="checkbox" defaultChecked>
|
|
194
|
-
Include Anchor Standards
|
|
195
|
-
</MenuItem>
|
|
196
|
-
<MenuItemSeparator />
|
|
197
|
-
<MenuItem>Open grading history...</MenuItem>
|
|
198
|
-
</Menu>
|
|
199
|
-
)
|
|
200
|
-
const menu = screen.getByRole('menu')
|
|
201
|
-
const trigger = screen.getByRole('button', { name: 'Settings' })
|
|
202
|
-
|
|
203
|
-
expect(menu).toBeInTheDocument()
|
|
204
|
-
expect(menu).toHaveAttribute(
|
|
205
|
-
'aria-labelledby',
|
|
206
|
-
trigger.getAttribute('id')
|
|
207
|
-
)
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
it('should call onFocus on focus', () => {
|
|
211
|
-
const onFocus = vi.fn()
|
|
212
|
-
|
|
213
|
-
const { getByRole } = render(
|
|
214
|
-
<Menu trigger={<button>More</button>} onFocus={onFocus}>
|
|
215
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
216
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
217
|
-
</Menu>
|
|
218
|
-
)
|
|
219
|
-
const triggerButton = getByRole('button', { name: 'More' })
|
|
220
|
-
|
|
221
|
-
fireEvent.focus(triggerButton)
|
|
222
|
-
|
|
223
|
-
expect(onFocus).toHaveBeenCalled()
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('should render when show and onToggle props are set', () => {
|
|
227
|
-
const { getByRole, getAllByRole, queryByText } = render(
|
|
228
|
-
<Menu trigger={<button>More</button>} show onToggle={() => {}}>
|
|
229
|
-
<MenuItem>Test1</MenuItem>
|
|
230
|
-
<MenuItem disabled>Test2</MenuItem>
|
|
231
|
-
</Menu>
|
|
232
|
-
)
|
|
233
|
-
const menuItems = getAllByRole('menuitem')
|
|
234
|
-
const triggerButton = getByRole('button', { name: 'More' })
|
|
235
|
-
|
|
236
|
-
const menuItem1 = queryByText('Test1')
|
|
237
|
-
const menuItem2 = queryByText('Test2')
|
|
238
|
-
|
|
239
|
-
expect(triggerButton).toBeInTheDocument()
|
|
240
|
-
expect(menuItems).toHaveLength(2)
|
|
241
|
-
expect(menuItem1).toBeInTheDocument()
|
|
242
|
-
expect(menuItem2).toBeInTheDocument()
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
it('should not show by default', () => {
|
|
246
|
-
const { queryByText, getByRole } = render(
|
|
247
|
-
<Menu trigger={<button>More</button>}>
|
|
248
|
-
<MenuItem>Test1</MenuItem>
|
|
249
|
-
<MenuItem disabled>Test2</MenuItem>
|
|
250
|
-
</Menu>
|
|
251
|
-
)
|
|
252
|
-
const triggerButton = getByRole('button', { name: 'More' })
|
|
253
|
-
|
|
254
|
-
const menuItem1 = queryByText('Test1')
|
|
255
|
-
const menuItem2 = queryByText('Test2')
|
|
256
|
-
|
|
257
|
-
expect(triggerButton).toBeInTheDocument()
|
|
258
|
-
expect(menuItem1).not.toBeInTheDocument()
|
|
259
|
-
expect(menuItem2).not.toBeInTheDocument()
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
it('should accept a default show', () => {
|
|
263
|
-
const { queryByText, getByRole } = render(
|
|
264
|
-
<Menu trigger={<button>More</button>} defaultShow>
|
|
265
|
-
<MenuItem>Test1</MenuItem>
|
|
266
|
-
<MenuItem disabled>Test2</MenuItem>
|
|
267
|
-
</Menu>
|
|
268
|
-
)
|
|
269
|
-
const triggerButton = getByRole('button', { name: 'More' })
|
|
270
|
-
|
|
271
|
-
const menuItem1 = queryByText('Test1')
|
|
272
|
-
const menuItem2 = queryByText('Test2')
|
|
273
|
-
|
|
274
|
-
expect(triggerButton).toBeInTheDocument()
|
|
275
|
-
expect(menuItem1).toBeInTheDocument()
|
|
276
|
-
expect(menuItem2).toBeInTheDocument()
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
it('should provide a menu ref', () => {
|
|
280
|
-
const menuRef = vi.fn()
|
|
281
|
-
|
|
282
|
-
render(
|
|
283
|
-
<Menu trigger={<button>More</button>} defaultShow menuRef={menuRef}>
|
|
284
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
285
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
286
|
-
</Menu>
|
|
287
|
-
)
|
|
288
|
-
const menu = screen.getByRole('menu')
|
|
289
|
-
|
|
290
|
-
expect(menuRef).toHaveBeenCalledWith(menu)
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
it('should provide a popoverRef ref', () => {
|
|
294
|
-
const popoverRef = vi.fn()
|
|
295
|
-
|
|
296
|
-
render(
|
|
297
|
-
<Menu
|
|
298
|
-
trigger={<button>More</button>}
|
|
299
|
-
defaultShow
|
|
300
|
-
popoverRef={popoverRef}
|
|
301
|
-
>
|
|
302
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
303
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
304
|
-
</Menu>
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
expect(popoverRef).toHaveBeenCalled()
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
it('should call onToggle on click', () => {
|
|
311
|
-
const onToggle = vi.fn()
|
|
312
|
-
|
|
313
|
-
render(
|
|
314
|
-
<Menu trigger={<button>More</button>} onToggle={onToggle}>
|
|
315
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
316
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
317
|
-
</Menu>
|
|
318
|
-
)
|
|
319
|
-
const trigger = screen.getByRole('button')
|
|
320
|
-
|
|
321
|
-
fireEvent.click(trigger)
|
|
322
|
-
|
|
323
|
-
expect(onToggle).toHaveBeenCalled()
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
it('should have an aria-haspopup attribute', () => {
|
|
327
|
-
render(
|
|
328
|
-
<Menu trigger={<button>More</button>}>
|
|
329
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
330
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
331
|
-
</Menu>
|
|
332
|
-
)
|
|
333
|
-
const trigger = screen.getByRole('button')
|
|
334
|
-
|
|
335
|
-
expect(trigger).toHaveAttribute('aria-haspopup')
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
it('should pass positionContainerDisplay prop to Popover', () => {
|
|
339
|
-
let popoverRef: Popover | null = null
|
|
340
|
-
render(
|
|
341
|
-
<Menu
|
|
342
|
-
trigger={<button>More</button>}
|
|
343
|
-
popoverRef={(e) => {
|
|
344
|
-
popoverRef = e
|
|
345
|
-
}}
|
|
346
|
-
positionContainerDisplay="block"
|
|
347
|
-
>
|
|
348
|
-
<MenuItem>Learning Mastery</MenuItem>
|
|
349
|
-
<MenuItem disabled>Gradebook</MenuItem>
|
|
350
|
-
</Menu>
|
|
351
|
-
)
|
|
352
|
-
|
|
353
|
-
const popoverProps = popoverRef!.props
|
|
354
|
-
|
|
355
|
-
expect(popoverProps.positionContainerDisplay).toBe('block')
|
|
356
|
-
})
|
|
357
|
-
})
|
|
358
|
-
})
|