@instructure/ui-navigation 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.
@@ -1,149 +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, waitFor } 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 { ScreenReaderContent } from '@instructure/ui-a11y-content'
32
- import { Item } from '../index'
33
-
34
- const icon = (
35
- <svg height="24" width="24">
36
- <title>Some icon</title>
37
- <circle cx="50" cy="50" r="40" />
38
- </svg>
39
- )
40
-
41
- describe('<AppNav.Item />', () => {
42
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
43
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
44
-
45
- beforeEach(() => {
46
- // Mocking console to prevent test output pollution and expect for messages
47
- consoleWarningMock = vi
48
- .spyOn(console, 'warn')
49
- .mockImplementation(() => {}) as any
50
- consoleErrorMock = vi
51
- .spyOn(console, 'error')
52
- .mockImplementation(() => {}) as any
53
- })
54
-
55
- afterEach(() => {
56
- consoleWarningMock.mockRestore()
57
- consoleErrorMock.mockRestore()
58
- })
59
-
60
- it('should render label text', async () => {
61
- render(<Item renderLabel="Some label" href="#" />)
62
- const item = screen.getByRole('link')
63
-
64
- expect(item).toHaveTextContent('Some label')
65
- })
66
-
67
- it('should render an icon/image/etc.', async () => {
68
- const { container } = render(
69
- <Item
70
- renderIcon={icon}
71
- renderLabel={<ScreenReaderContent>Some label</ScreenReaderContent>}
72
- href="#"
73
- />
74
- )
75
-
76
- const iconTitle = screen.getByTitle('Some icon')
77
- const iconSvg = container.querySelector('svg')
78
- const item = screen.getByRole('link')
79
-
80
- expect(iconTitle).toBeInTheDocument()
81
- expect(iconSvg).toBeInTheDocument()
82
-
83
- expect(iconSvg).toHaveTextContent('Some icon')
84
- expect(item).toHaveTextContent('Some label')
85
- })
86
-
87
- it('should render content after the label text to accommodate badges, etc.', async () => {
88
- render(
89
- <Item
90
- renderLabel="Some label"
91
- href="#"
92
- renderAfter={<strong>I am rendered after!</strong>}
93
- />
94
- )
95
- const item = screen.getByRole('link')
96
- const after = screen.getByText('I am rendered after!')
97
-
98
- expect(item).toBeInTheDocument()
99
- expect(item).toHaveTextContent('Some label')
100
-
101
- expect(after).toBeInTheDocument()
102
- expect(after.tagName).toBe('STRONG')
103
- })
104
-
105
- it('should respond to an onClick event', async () => {
106
- const onClick = vi.fn()
107
- render(<Item renderLabel="Some label" onClick={onClick} />)
108
-
109
- const button = screen.getByRole('button')
110
-
111
- await userEvent.click(button)
112
-
113
- await waitFor(() => {
114
- expect(onClick).toHaveBeenCalledTimes(1)
115
- })
116
- })
117
-
118
- it('should output a console error if icon is used with non-screenreader label text', async () => {
119
- render(
120
- <Item
121
- renderIcon={icon}
122
- renderLabel="Some label"
123
- onClick={() => 'clicked'}
124
- />
125
- )
126
-
127
- const expectedErrorMessage =
128
- 'Warning: [AppNav] If an icon is used, the label text should be wrapped in <ScreenReaderContent />.'
129
-
130
- expect(consoleErrorMock).toHaveBeenCalledWith(
131
- expect.stringContaining(expectedErrorMessage),
132
- expect.any(String)
133
- )
134
- })
135
-
136
- it('should meet a11y standards', async () => {
137
- const { container } = render(
138
- <Item
139
- renderIcon={icon}
140
- renderLabel={<ScreenReaderContent>Some label</ScreenReaderContent>}
141
- onClick={() => 'clicked'}
142
- />
143
- )
144
-
145
- const axeCheck = await runAxeCheck(container)
146
-
147
- expect(axeCheck).toBe(true)
148
- })
149
- })
@@ -1,175 +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 } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
- import '@testing-library/jest-dom'
28
-
29
- // eslint-disable-next-line no-restricted-imports
30
- import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests'
31
- import { runAxeCheck } from '@instructure/ui-axe-check'
32
-
33
- import { AppNav } from '../index'
34
- import AppNavExamples from '../__examples__/AppNav.examples'
35
-
36
- describe('<AppNav />', () => {
37
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
38
-
39
- beforeEach(() => {
40
- // Mocking console to prevent test output pollution
41
- consoleErrorMock = vi
42
- .spyOn(console, 'error')
43
- .mockImplementation(() => {}) as any
44
- })
45
-
46
- afterEach(() => {
47
- consoleErrorMock.mockRestore()
48
- })
49
-
50
- describe('for a11y', () => {
51
- it('should render a nav element with an aria-label', async () => {
52
- const { container } = render(
53
- <AppNav screenReaderLabel="Screen reader label" visibleItemsCount={2}>
54
- <AppNav.Item
55
- renderLabel="Some label"
56
- href="http://instructure.design"
57
- />
58
- <AppNav.Item
59
- renderLabel="Some other label"
60
- href="http://instructure.design"
61
- />
62
- </AppNav>
63
- )
64
-
65
- const appNavList = container.querySelector('ul[class*="-appNav__list"]')!
66
-
67
- expect(appNavList).toBeInTheDocument()
68
- expect(appNavList.tagName).toBe('UL')
69
- expect(appNavList).toHaveAttribute('aria-label', 'Screen reader label')
70
- })
71
-
72
- it('should render a semantic list of items', async () => {
73
- render(
74
- <AppNav screenReaderLabel="App navigation" visibleItemsCount={2}>
75
- <AppNav.Item
76
- renderLabel="Some first label"
77
- href="http://instructure.design"
78
- />
79
- <AppNav.Item
80
- renderLabel="Some second label"
81
- onClick={() => 'clicked'}
82
- />
83
- </AppNav>
84
- )
85
-
86
- const list = screen.getAllByRole('list')
87
- const items = screen.getAllByRole('listitem')
88
- const link = screen.getAllByRole('link')
89
- const button = screen.getAllByRole('button')
90
-
91
- expect(list.length).toBe(1)
92
- expect(items.length).toBe(2)
93
- expect(link.length).toBe(1)
94
- expect(button.length).toBe(1)
95
- })
96
-
97
- it('should render with a single item', async () => {
98
- render(
99
- <AppNav screenReaderLabel="App navigation" visibleItemsCount={1}>
100
- <AppNav.Item
101
- renderLabel="Some label"
102
- href="http://instructure.design"
103
- />
104
- </AppNav>
105
- )
106
-
107
- const list = screen.getAllByRole('list')
108
- const items = screen.getAllByRole('listitem')
109
- const link = screen.getAllByRole('link')
110
-
111
- expect(list.length).toBe(1)
112
- expect(items.length).toBe(1)
113
- expect(link.length).toBe(1)
114
- })
115
- })
116
-
117
- describe('with rendered content', () => {
118
- it('should render content after the navigation', async () => {
119
- render(
120
- <AppNav
121
- screenReaderLabel="App navigation"
122
- renderAfterItems={<button type="button">I am rendered after!</button>}
123
- visibleItemsCount={2}
124
- >
125
- <AppNav.Item
126
- renderLabel="Some label"
127
- href="http://instructure.design"
128
- />
129
- <AppNav.Item
130
- renderLabel="Some other label"
131
- href="http://instructure.design"
132
- />
133
- </AppNav>
134
- )
135
- const button = screen.getByRole('button')
136
-
137
- expect(button).toHaveTextContent('I am rendered after!')
138
- })
139
- })
140
-
141
- describe('with item truncation', () => {
142
- it('should pass a custom label to the menu trigger', async () => {
143
- render(
144
- <AppNav
145
- screenReaderLabel="App navigation"
146
- visibleItemsCount={2}
147
- renderTruncateLabel={function () {
148
- return 'I am sooo custom!'
149
- }}
150
- >
151
- <AppNav.Item renderLabel="Label" href="http://instructure.design" />
152
- <AppNav.Item renderLabel="Label" href="http://instructure.design" />
153
- <AppNav.Item renderLabel="Label" href="http://instructure.design" />
154
- <AppNav.Item renderLabel="Label" href="http://instructure.design" />
155
- </AppNav>
156
- )
157
-
158
- const items = screen.getAllByRole('listitem')
159
-
160
- expect(items.length).toBe(3)
161
- expect(items[2]).toHaveTextContent('I am sooo custom!')
162
- })
163
- })
164
-
165
- describe('with generated examples', () => {
166
- const generatedComponents = generateA11yTests(AppNav, AppNavExamples)
167
- for (const component of generatedComponents) {
168
- it(component.description, async () => {
169
- const { container } = render(component.content)
170
- const axeCheck = await runAxeCheck(container)
171
- expect(axeCheck).toBe(true)
172
- })
173
- }
174
- })
175
- })
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=Item.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Item.test.d.ts","sourceRoot":"","sources":["../../../../src/AppNav/Item/__new-tests__/Item.test.tsx"],"names":[],"mappings":"AA2BA,OAAO,2BAA2B,CAAA"}
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=AppNav.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AppNav.test.d.ts","sourceRoot":"","sources":["../../../src/AppNav/__new-tests__/AppNav.test.tsx"],"names":[],"mappings":"AA0BA,OAAO,2BAA2B,CAAA"}