@instructure/ui-navigation 9.0.2-snapshot-6 → 9.0.2-snapshot-9

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 (34) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/AppNav/Item/__new-tests__/Item.test.js +111 -0
  3. package/es/AppNav/__new-tests__/AppNav.test.js +157 -0
  4. package/lib/AppNav/Item/__new-tests__/Item.test.js +113 -0
  5. package/lib/AppNav/__new-tests__/AppNav.test.js +159 -0
  6. package/package.json +28 -24
  7. package/src/AppNav/Item/__new-tests__/Item.test.tsx +135 -0
  8. package/src/AppNav/__new-tests__/AppNav.test.tsx +176 -0
  9. package/tsconfig.build.json +2 -1
  10. package/tsconfig.build.tsbuildinfo +1 -1
  11. package/types/AppNav/Item/__new-tests__/Item.test.d.ts +2 -0
  12. package/types/AppNav/Item/__new-tests__/Item.test.d.ts.map +1 -0
  13. package/types/AppNav/__new-tests__/AppNav.test.d.ts +2 -0
  14. package/types/AppNav/__new-tests__/AppNav.test.d.ts.map +1 -0
  15. package/es/AppNav/AppNavLocator.js +0 -37
  16. package/es/AppNav/Item/AppNavItemLocator.js +0 -28
  17. package/es/AppNav/Item/locator.js +0 -26
  18. package/es/AppNav/locator.js +0 -27
  19. package/lib/AppNav/AppNavLocator.js +0 -42
  20. package/lib/AppNav/Item/AppNavItemLocator.js +0 -34
  21. package/lib/AppNav/Item/locator.js +0 -37
  22. package/lib/AppNav/locator.js +0 -37
  23. package/src/AppNav/AppNavLocator.ts +0 -40
  24. package/src/AppNav/Item/AppNavItemLocator.ts +0 -29
  25. package/src/AppNav/Item/locator.ts +0 -27
  26. package/src/AppNav/locator.ts +0 -28
  27. package/types/AppNav/AppNavLocator.d.ts +0 -1961
  28. package/types/AppNav/AppNavLocator.d.ts.map +0 -1
  29. package/types/AppNav/Item/AppNavItemLocator.d.ts +0 -566
  30. package/types/AppNav/Item/AppNavItemLocator.d.ts.map +0 -1
  31. package/types/AppNav/Item/locator.d.ts +0 -4
  32. package/types/AppNav/Item/locator.d.ts.map +0 -1
  33. package/types/AppNav/locator.d.ts +0 -4
  34. package/types/AppNav/locator.d.ts.map +0 -1
@@ -0,0 +1,135 @@
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
+
27
+ import { render, screen, waitFor } from '@testing-library/react'
28
+ import userEvent from '@testing-library/user-event'
29
+ import '@testing-library/jest-dom'
30
+
31
+ import { runAxeCheck } from '@instructure/ui-axe-check'
32
+ import { ScreenReaderContent } from '@instructure/ui-a11y-content'
33
+ import { Item } from '../index'
34
+
35
+ const icon = (
36
+ <svg height="24" width="24">
37
+ <title>Some icon</title>
38
+ <circle cx="50" cy="50" r="40" />
39
+ </svg>
40
+ )
41
+
42
+ describe('<AppNav.Item />', () => {
43
+ it('should render label text', async () => {
44
+ render(<Item renderLabel="Some label" href="#" />)
45
+ const item = screen.getByRole('link')
46
+
47
+ expect(item).toHaveTextContent('Some label')
48
+ })
49
+
50
+ it('should render an icon/image/etc.', async () => {
51
+ const { container } = render(
52
+ <Item
53
+ renderIcon={icon}
54
+ renderLabel={<ScreenReaderContent>Some label</ScreenReaderContent>}
55
+ href="#"
56
+ />
57
+ )
58
+
59
+ const iconTitle = screen.getByTitle('Some icon')
60
+ const iconSvg = container.querySelector('svg')
61
+ const item = screen.getByRole('link')
62
+
63
+ expect(iconTitle).toBeInTheDocument()
64
+ expect(iconSvg).toBeInTheDocument()
65
+
66
+ expect(iconSvg).toHaveTextContent('Some icon')
67
+ expect(item).toHaveTextContent('Some label')
68
+ })
69
+
70
+ it('should render content after the label text to accommodate badges, etc.', async () => {
71
+ render(
72
+ <Item
73
+ renderLabel="Some label"
74
+ href="#"
75
+ renderAfter={<strong>I am rendered after!</strong>}
76
+ />
77
+ )
78
+ const item = screen.getByRole('link')
79
+ const after = screen.getByText('I am rendered after!')
80
+
81
+ expect(item).toBeInTheDocument()
82
+ expect(item).toHaveTextContent('Some label')
83
+
84
+ expect(after).toBeInTheDocument()
85
+ expect(after.tagName).toBe('STRONG')
86
+ })
87
+
88
+ it('should respond to an onClick event', async () => {
89
+ const onClick = jest.fn()
90
+ render(<Item renderLabel="Some label" onClick={onClick} />)
91
+
92
+ const button = screen.getByRole('button')
93
+
94
+ await userEvent.click(button)
95
+
96
+ await waitFor(() => {
97
+ expect(onClick).toHaveBeenCalledTimes(1)
98
+ })
99
+ })
100
+
101
+ it('should output a console error if icon is used with non-screenreader label text', async () => {
102
+ const consoleErrorMock = jest.spyOn(console, 'error').mockImplementation()
103
+ render(
104
+ <Item
105
+ renderIcon={icon}
106
+ renderLabel="Some label"
107
+ onClick={() => 'clicked'}
108
+ />
109
+ )
110
+
111
+ const expectedErrorMessage =
112
+ 'Warning: [AppNav] If an icon is used, the label text should be wrapped in <ScreenReaderContent />.'
113
+
114
+ expect(consoleErrorMock).toHaveBeenCalledWith(
115
+ expect.stringContaining(expectedErrorMessage),
116
+ expect.any(String)
117
+ )
118
+
119
+ consoleErrorMock.mockRestore()
120
+ })
121
+
122
+ it('should meet a11y standards', async () => {
123
+ const { container } = render(
124
+ <Item
125
+ renderIcon={icon}
126
+ renderLabel={<ScreenReaderContent>Some label</ScreenReaderContent>}
127
+ onClick={() => 'clicked'}
128
+ />
129
+ )
130
+
131
+ const axeCheck = await runAxeCheck(container)
132
+
133
+ expect(axeCheck).toBe(true)
134
+ })
135
+ })
@@ -0,0 +1,176 @@
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
+ import React from 'react'
25
+ import { render, screen } from '@testing-library/react'
26
+ import '@testing-library/jest-dom'
27
+
28
+ // eslint-disable-next-line no-restricted-imports
29
+ import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests'
30
+ import { runAxeCheck } from '@instructure/ui-axe-check'
31
+
32
+ import { AppNav } from '../index'
33
+ import AppNavExamples from '../__examples__/AppNav.examples'
34
+
35
+ const originalResizeObserver = global.ResizeObserver
36
+
37
+ describe('<AppNav />', () => {
38
+ beforeAll(() => {
39
+ // Mock for ResizeObserver browser API
40
+ global.ResizeObserver = jest.fn().mockImplementation(() => ({
41
+ observe: jest.fn(),
42
+ unobserve: jest.fn(),
43
+ disconnect: jest.fn()
44
+ }))
45
+ })
46
+
47
+ afterAll(() => {
48
+ global.ResizeObserver = originalResizeObserver
49
+ })
50
+
51
+ describe('for a11y', () => {
52
+ it('should render a nav element with an aria-label', async () => {
53
+ const { container } = render(
54
+ <AppNav screenReaderLabel="Screen reader label" visibleItemsCount={2}>
55
+ <AppNav.Item
56
+ renderLabel="Some label"
57
+ href="http://instructure.design"
58
+ />
59
+ <AppNav.Item
60
+ renderLabel="Some other label"
61
+ href="http://instructure.design"
62
+ />
63
+ </AppNav>
64
+ )
65
+
66
+ const appNavList = container.querySelector('ul[class$="-appNav__list"]')!
67
+
68
+ expect(appNavList).toBeInTheDocument()
69
+ expect(appNavList.tagName).toBe('UL')
70
+ expect(appNavList).toHaveAttribute('aria-label', 'Screen reader label')
71
+ })
72
+
73
+ it('should render a semantic list of items', async () => {
74
+ render(
75
+ <AppNav screenReaderLabel="App navigation" visibleItemsCount={2}>
76
+ <AppNav.Item
77
+ renderLabel="Some first label"
78
+ href="http://instructure.design"
79
+ />
80
+ <AppNav.Item
81
+ renderLabel="Some second label"
82
+ onClick={() => 'clicked'}
83
+ />
84
+ </AppNav>
85
+ )
86
+
87
+ const list = screen.getAllByRole('list')
88
+ const items = screen.getAllByRole('listitem')
89
+ const link = screen.getAllByRole('link')
90
+ const button = screen.getAllByRole('button')
91
+
92
+ expect(list.length).toBe(1)
93
+ expect(items.length).toBe(2)
94
+ expect(link.length).toBe(1)
95
+ expect(button.length).toBe(1)
96
+ })
97
+
98
+ it('should render with a single item', async () => {
99
+ render(
100
+ <AppNav screenReaderLabel="App navigation" visibleItemsCount={1}>
101
+ <AppNav.Item
102
+ renderLabel="Some label"
103
+ href="http://instructure.design"
104
+ />
105
+ </AppNav>
106
+ )
107
+
108
+ const list = screen.getAllByRole('list')
109
+ const items = screen.getAllByRole('listitem')
110
+ const link = screen.getAllByRole('link')
111
+
112
+ expect(list.length).toBe(1)
113
+ expect(items.length).toBe(1)
114
+ expect(link.length).toBe(1)
115
+ })
116
+ })
117
+
118
+ describe('with rendered content', () => {
119
+ it('should render content after the navigation', async () => {
120
+ render(
121
+ <AppNav
122
+ screenReaderLabel="App navigation"
123
+ renderAfterItems={<button type="button">I am rendered after!</button>}
124
+ visibleItemsCount={2}
125
+ >
126
+ <AppNav.Item
127
+ renderLabel="Some label"
128
+ href="http://instructure.design"
129
+ />
130
+ <AppNav.Item
131
+ renderLabel="Some other label"
132
+ href="http://instructure.design"
133
+ />
134
+ </AppNav>
135
+ )
136
+ const button = screen.getByRole('button')
137
+
138
+ expect(button).toHaveTextContent('I am rendered after!')
139
+ })
140
+ })
141
+
142
+ describe('with item truncation', () => {
143
+ it('should pass a custom label to the menu trigger', async () => {
144
+ render(
145
+ <AppNav
146
+ screenReaderLabel="App navigation"
147
+ visibleItemsCount={2}
148
+ renderTruncateLabel={function () {
149
+ return 'I am sooo custom!'
150
+ }}
151
+ >
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.Item renderLabel="Label" href="http://instructure.design" />
156
+ </AppNav>
157
+ )
158
+
159
+ const items = screen.getAllByRole('listitem')
160
+
161
+ expect(items.length).toBe(3)
162
+ expect(items[2]).toHaveTextContent('I am sooo custom!')
163
+ })
164
+ })
165
+
166
+ describe('with generated examples', () => {
167
+ const generatedComponents = generateA11yTests(AppNav, AppNavExamples)
168
+ for (const component of generatedComponents) {
169
+ it(component.description, async () => {
170
+ const { container } = render(component.content)
171
+ const axeCheck = await runAxeCheck(container)
172
+ expect(axeCheck).toBe(true)
173
+ })
174
+ }
175
+ })
176
+ })
@@ -9,7 +9,6 @@
9
9
  "references": [
10
10
  { "path": "../ui-babel-preset/tsconfig.build.json" },
11
11
  { "path": "../ui-color-utils/tsconfig.build.json" },
12
- { "path": "../ui-test-locator/tsconfig.build.json" },
13
12
  { "path": "../ui-test-utils/tsconfig.build.json" },
14
13
  { "path": "../ui-themes/tsconfig.build.json" },
15
14
  { "path": "../console/tsconfig.build.json" },
@@ -18,6 +17,7 @@
18
17
  { "path": "../shared-types/tsconfig.build.json" },
19
18
  { "path": "../ui-a11y-content/tsconfig.build.json" },
20
19
  { "path": "../ui-a11y-utils/tsconfig.build.json" },
20
+ { "path": "../ui-axe-check/tsconfig.build.json" },
21
21
  { "path": "../ui-badge/tsconfig.build.json" },
22
22
  { "path": "../ui-dom-utils/tsconfig.build.json" },
23
23
  { "path": "../ui-focusable/tsconfig.build.json" },
@@ -25,6 +25,7 @@
25
25
  { "path": "../ui-menu/tsconfig.build.json" },
26
26
  { "path": "../ui-prop-types/tsconfig.build.json" },
27
27
  { "path": "../ui-react-utils/tsconfig.build.json" },
28
+ { "path": "../ui-scripts/tsconfig.build.json" },
28
29
  { "path": "../ui-testable/tsconfig.build.json" },
29
30
  { "path": "../ui-tooltip/tsconfig.build.json" },
30
31
  { "path": "../ui-truncate-list/tsconfig.build.json" },