@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.
- package/CHANGELOG.md +1 -1
- package/es/AppNav/Item/__new-tests__/Item.test.js +111 -0
- package/es/AppNav/__new-tests__/AppNav.test.js +157 -0
- package/lib/AppNav/Item/__new-tests__/Item.test.js +113 -0
- package/lib/AppNav/__new-tests__/AppNav.test.js +159 -0
- package/package.json +28 -24
- package/src/AppNav/Item/__new-tests__/Item.test.tsx +135 -0
- package/src/AppNav/__new-tests__/AppNav.test.tsx +176 -0
- package/tsconfig.build.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/AppNav/Item/__new-tests__/Item.test.d.ts +2 -0
- package/types/AppNav/Item/__new-tests__/Item.test.d.ts.map +1 -0
- package/types/AppNav/__new-tests__/AppNav.test.d.ts +2 -0
- package/types/AppNav/__new-tests__/AppNav.test.d.ts.map +1 -0
- package/es/AppNav/AppNavLocator.js +0 -37
- package/es/AppNav/Item/AppNavItemLocator.js +0 -28
- package/es/AppNav/Item/locator.js +0 -26
- package/es/AppNav/locator.js +0 -27
- package/lib/AppNav/AppNavLocator.js +0 -42
- package/lib/AppNav/Item/AppNavItemLocator.js +0 -34
- package/lib/AppNav/Item/locator.js +0 -37
- package/lib/AppNav/locator.js +0 -37
- package/src/AppNav/AppNavLocator.ts +0 -40
- package/src/AppNav/Item/AppNavItemLocator.ts +0 -29
- package/src/AppNav/Item/locator.ts +0 -27
- package/src/AppNav/locator.ts +0 -28
- package/types/AppNav/AppNavLocator.d.ts +0 -1961
- package/types/AppNav/AppNavLocator.d.ts.map +0 -1
- package/types/AppNav/Item/AppNavItemLocator.d.ts +0 -566
- package/types/AppNav/Item/AppNavItemLocator.d.ts.map +0 -1
- package/types/AppNav/Item/locator.d.ts +0 -4
- package/types/AppNav/Item/locator.d.ts.map +0 -1
- package/types/AppNav/locator.d.ts +0 -4
- package/types/AppNav/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
|
-
## [9.0.2-snapshot-
|
|
6
|
+
## [9.0.2-snapshot-9](https://github.com/instructure/instructure-ui/compare/v9.0.1...v9.0.2-snapshot-9) (2024-06-11)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-navigation
|
|
9
9
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var _Item, _Item2, _Item3, _ScreenReaderContent;
|
|
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 { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import userEvent from '@testing-library/user-event';
|
|
29
|
+
import '@testing-library/jest-dom';
|
|
30
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
31
|
+
import { ScreenReaderContent } from '@instructure/ui-a11y-content';
|
|
32
|
+
import { Item } from '../index';
|
|
33
|
+
const icon = /*#__PURE__*/React.createElement("svg", {
|
|
34
|
+
height: "24",
|
|
35
|
+
width: "24"
|
|
36
|
+
}, /*#__PURE__*/React.createElement("title", null, "Some icon"), /*#__PURE__*/React.createElement("circle", {
|
|
37
|
+
cx: "50",
|
|
38
|
+
cy: "50",
|
|
39
|
+
r: "40"
|
|
40
|
+
}));
|
|
41
|
+
describe('<AppNav.Item />', () => {
|
|
42
|
+
it('should render label text', async () => {
|
|
43
|
+
render(_Item || (_Item = /*#__PURE__*/React.createElement(Item, {
|
|
44
|
+
renderLabel: "Some label",
|
|
45
|
+
href: "#"
|
|
46
|
+
})));
|
|
47
|
+
const item = screen.getByRole('link');
|
|
48
|
+
expect(item).toHaveTextContent('Some label');
|
|
49
|
+
});
|
|
50
|
+
it('should render an icon/image/etc.', async () => {
|
|
51
|
+
const _render = render(_Item2 || (_Item2 = /*#__PURE__*/React.createElement(Item, {
|
|
52
|
+
renderIcon: icon,
|
|
53
|
+
renderLabel: /*#__PURE__*/React.createElement(ScreenReaderContent, null, "Some label"),
|
|
54
|
+
href: "#"
|
|
55
|
+
}))),
|
|
56
|
+
container = _render.container;
|
|
57
|
+
const iconTitle = screen.getByTitle('Some icon');
|
|
58
|
+
const iconSvg = container.querySelector('svg');
|
|
59
|
+
const item = screen.getByRole('link');
|
|
60
|
+
expect(iconTitle).toBeInTheDocument();
|
|
61
|
+
expect(iconSvg).toBeInTheDocument();
|
|
62
|
+
expect(iconSvg).toHaveTextContent('Some icon');
|
|
63
|
+
expect(item).toHaveTextContent('Some label');
|
|
64
|
+
});
|
|
65
|
+
it('should render content after the label text to accommodate badges, etc.', async () => {
|
|
66
|
+
render(_Item3 || (_Item3 = /*#__PURE__*/React.createElement(Item, {
|
|
67
|
+
renderLabel: "Some label",
|
|
68
|
+
href: "#",
|
|
69
|
+
renderAfter: /*#__PURE__*/React.createElement("strong", null, "I am rendered after!")
|
|
70
|
+
})));
|
|
71
|
+
const item = screen.getByRole('link');
|
|
72
|
+
const after = screen.getByText('I am rendered after!');
|
|
73
|
+
expect(item).toBeInTheDocument();
|
|
74
|
+
expect(item).toHaveTextContent('Some label');
|
|
75
|
+
expect(after).toBeInTheDocument();
|
|
76
|
+
expect(after.tagName).toBe('STRONG');
|
|
77
|
+
});
|
|
78
|
+
it('should respond to an onClick event', async () => {
|
|
79
|
+
const onClick = jest.fn();
|
|
80
|
+
render( /*#__PURE__*/React.createElement(Item, {
|
|
81
|
+
renderLabel: "Some label",
|
|
82
|
+
onClick: onClick
|
|
83
|
+
}));
|
|
84
|
+
const button = screen.getByRole('button');
|
|
85
|
+
await userEvent.click(button);
|
|
86
|
+
await waitFor(() => {
|
|
87
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
it('should output a console error if icon is used with non-screenreader label text', async () => {
|
|
91
|
+
const consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
92
|
+
render( /*#__PURE__*/React.createElement(Item, {
|
|
93
|
+
renderIcon: icon,
|
|
94
|
+
renderLabel: "Some label",
|
|
95
|
+
onClick: () => 'clicked'
|
|
96
|
+
}));
|
|
97
|
+
const expectedErrorMessage = 'Warning: [AppNav] If an icon is used, the label text should be wrapped in <ScreenReaderContent />.';
|
|
98
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
99
|
+
consoleErrorMock.mockRestore();
|
|
100
|
+
});
|
|
101
|
+
it('should meet a11y standards', async () => {
|
|
102
|
+
const _render2 = render( /*#__PURE__*/React.createElement(Item, {
|
|
103
|
+
renderIcon: icon,
|
|
104
|
+
renderLabel: _ScreenReaderContent || (_ScreenReaderContent = /*#__PURE__*/React.createElement(ScreenReaderContent, null, "Some label")),
|
|
105
|
+
onClick: () => 'clicked'
|
|
106
|
+
})),
|
|
107
|
+
container = _render2.container;
|
|
108
|
+
const axeCheck = await runAxeCheck(container);
|
|
109
|
+
expect(axeCheck).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var _AppNav, _AppNav$Item, _AppNav2, _AppNav3, _AppNav$Item2, _AppNav$Item3, _AppNav$Item4, _AppNav$Item5;
|
|
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 } from '@testing-library/react';
|
|
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
|
+
import { AppNav } from '../index';
|
|
33
|
+
import AppNavExamples from '../__examples__/AppNav.examples';
|
|
34
|
+
const originalResizeObserver = global.ResizeObserver;
|
|
35
|
+
describe('<AppNav />', () => {
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
// Mock for ResizeObserver browser API
|
|
38
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
39
|
+
observe: jest.fn(),
|
|
40
|
+
unobserve: jest.fn(),
|
|
41
|
+
disconnect: jest.fn()
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
afterAll(() => {
|
|
45
|
+
global.ResizeObserver = originalResizeObserver;
|
|
46
|
+
});
|
|
47
|
+
describe('for a11y', () => {
|
|
48
|
+
it('should render a nav element with an aria-label', async () => {
|
|
49
|
+
const _render = render(_AppNav || (_AppNav = /*#__PURE__*/React.createElement(AppNav, {
|
|
50
|
+
screenReaderLabel: "Screen reader label",
|
|
51
|
+
visibleItemsCount: 2
|
|
52
|
+
}, /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
53
|
+
renderLabel: "Some label",
|
|
54
|
+
href: "http://instructure.design"
|
|
55
|
+
}), /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
56
|
+
renderLabel: "Some other label",
|
|
57
|
+
href: "http://instructure.design"
|
|
58
|
+
})))),
|
|
59
|
+
container = _render.container;
|
|
60
|
+
const appNavList = container.querySelector('ul[class$="-appNav__list"]');
|
|
61
|
+
expect(appNavList).toBeInTheDocument();
|
|
62
|
+
expect(appNavList.tagName).toBe('UL');
|
|
63
|
+
expect(appNavList).toHaveAttribute('aria-label', 'Screen reader label');
|
|
64
|
+
});
|
|
65
|
+
it('should render a semantic list of items', async () => {
|
|
66
|
+
render( /*#__PURE__*/React.createElement(AppNav, {
|
|
67
|
+
screenReaderLabel: "App navigation",
|
|
68
|
+
visibleItemsCount: 2
|
|
69
|
+
}, _AppNav$Item || (_AppNav$Item = /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
70
|
+
renderLabel: "Some first label",
|
|
71
|
+
href: "http://instructure.design"
|
|
72
|
+
})), /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
73
|
+
renderLabel: "Some second label",
|
|
74
|
+
onClick: () => 'clicked'
|
|
75
|
+
})));
|
|
76
|
+
const list = screen.getAllByRole('list');
|
|
77
|
+
const items = screen.getAllByRole('listitem');
|
|
78
|
+
const link = screen.getAllByRole('link');
|
|
79
|
+
const button = screen.getAllByRole('button');
|
|
80
|
+
expect(list.length).toBe(1);
|
|
81
|
+
expect(items.length).toBe(2);
|
|
82
|
+
expect(link.length).toBe(1);
|
|
83
|
+
expect(button.length).toBe(1);
|
|
84
|
+
});
|
|
85
|
+
it('should render with a single item', async () => {
|
|
86
|
+
render(_AppNav2 || (_AppNav2 = /*#__PURE__*/React.createElement(AppNav, {
|
|
87
|
+
screenReaderLabel: "App navigation",
|
|
88
|
+
visibleItemsCount: 1
|
|
89
|
+
}, /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
90
|
+
renderLabel: "Some label",
|
|
91
|
+
href: "http://instructure.design"
|
|
92
|
+
}))));
|
|
93
|
+
const list = screen.getAllByRole('list');
|
|
94
|
+
const items = screen.getAllByRole('listitem');
|
|
95
|
+
const link = screen.getAllByRole('link');
|
|
96
|
+
expect(list.length).toBe(1);
|
|
97
|
+
expect(items.length).toBe(1);
|
|
98
|
+
expect(link.length).toBe(1);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('with rendered content', () => {
|
|
102
|
+
it('should render content after the navigation', async () => {
|
|
103
|
+
render(_AppNav3 || (_AppNav3 = /*#__PURE__*/React.createElement(AppNav, {
|
|
104
|
+
screenReaderLabel: "App navigation",
|
|
105
|
+
renderAfterItems: /*#__PURE__*/React.createElement("button", {
|
|
106
|
+
type: "button"
|
|
107
|
+
}, "I am rendered after!"),
|
|
108
|
+
visibleItemsCount: 2
|
|
109
|
+
}, /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
110
|
+
renderLabel: "Some label",
|
|
111
|
+
href: "http://instructure.design"
|
|
112
|
+
}), /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
113
|
+
renderLabel: "Some other label",
|
|
114
|
+
href: "http://instructure.design"
|
|
115
|
+
}))));
|
|
116
|
+
const button = screen.getByRole('button');
|
|
117
|
+
expect(button).toHaveTextContent('I am rendered after!');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('with item truncation', () => {
|
|
121
|
+
it('should pass a custom label to the menu trigger', async () => {
|
|
122
|
+
render( /*#__PURE__*/React.createElement(AppNav, {
|
|
123
|
+
screenReaderLabel: "App navigation",
|
|
124
|
+
visibleItemsCount: 2,
|
|
125
|
+
renderTruncateLabel: function () {
|
|
126
|
+
return 'I am sooo custom!';
|
|
127
|
+
}
|
|
128
|
+
}, _AppNav$Item2 || (_AppNav$Item2 = /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
129
|
+
renderLabel: "Label",
|
|
130
|
+
href: "http://instructure.design"
|
|
131
|
+
})), _AppNav$Item3 || (_AppNav$Item3 = /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
132
|
+
renderLabel: "Label",
|
|
133
|
+
href: "http://instructure.design"
|
|
134
|
+
})), _AppNav$Item4 || (_AppNav$Item4 = /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
135
|
+
renderLabel: "Label",
|
|
136
|
+
href: "http://instructure.design"
|
|
137
|
+
})), _AppNav$Item5 || (_AppNav$Item5 = /*#__PURE__*/React.createElement(AppNav.Item, {
|
|
138
|
+
renderLabel: "Label",
|
|
139
|
+
href: "http://instructure.design"
|
|
140
|
+
}))));
|
|
141
|
+
const items = screen.getAllByRole('listitem');
|
|
142
|
+
expect(items.length).toBe(3);
|
|
143
|
+
expect(items[2]).toHaveTextContent('I am sooo custom!');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe('with generated examples', () => {
|
|
147
|
+
const generatedComponents = generateA11yTests(AppNav, AppNavExamples);
|
|
148
|
+
for (const component of generatedComponents) {
|
|
149
|
+
it(component.description, async () => {
|
|
150
|
+
const _render2 = render(component.content),
|
|
151
|
+
container = _render2.container;
|
|
152
|
+
const axeCheck = await runAxeCheck(container);
|
|
153
|
+
expect(axeCheck).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
|
+
var _ScreenReaderContent2 = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
|
|
10
|
+
var _index = require("../index");
|
|
11
|
+
var _Item, _Item2, _Item3, _ScreenReaderContent;
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
const icon = /*#__PURE__*/_react.default.createElement("svg", {
|
|
36
|
+
height: "24",
|
|
37
|
+
width: "24"
|
|
38
|
+
}, /*#__PURE__*/_react.default.createElement("title", null, "Some icon"), /*#__PURE__*/_react.default.createElement("circle", {
|
|
39
|
+
cx: "50",
|
|
40
|
+
cy: "50",
|
|
41
|
+
r: "40"
|
|
42
|
+
}));
|
|
43
|
+
describe('<AppNav.Item />', () => {
|
|
44
|
+
it('should render label text', async () => {
|
|
45
|
+
(0, _react2.render)(_Item || (_Item = /*#__PURE__*/_react.default.createElement(_index.Item, {
|
|
46
|
+
renderLabel: "Some label",
|
|
47
|
+
href: "#"
|
|
48
|
+
})));
|
|
49
|
+
const item = _react2.screen.getByRole('link');
|
|
50
|
+
expect(item).toHaveTextContent('Some label');
|
|
51
|
+
});
|
|
52
|
+
it('should render an icon/image/etc.', async () => {
|
|
53
|
+
const _render = (0, _react2.render)(_Item2 || (_Item2 = /*#__PURE__*/_react.default.createElement(_index.Item, {
|
|
54
|
+
renderIcon: icon,
|
|
55
|
+
renderLabel: /*#__PURE__*/_react.default.createElement(_ScreenReaderContent2.ScreenReaderContent, null, "Some label"),
|
|
56
|
+
href: "#"
|
|
57
|
+
}))),
|
|
58
|
+
container = _render.container;
|
|
59
|
+
const iconTitle = _react2.screen.getByTitle('Some icon');
|
|
60
|
+
const iconSvg = container.querySelector('svg');
|
|
61
|
+
const item = _react2.screen.getByRole('link');
|
|
62
|
+
expect(iconTitle).toBeInTheDocument();
|
|
63
|
+
expect(iconSvg).toBeInTheDocument();
|
|
64
|
+
expect(iconSvg).toHaveTextContent('Some icon');
|
|
65
|
+
expect(item).toHaveTextContent('Some label');
|
|
66
|
+
});
|
|
67
|
+
it('should render content after the label text to accommodate badges, etc.', async () => {
|
|
68
|
+
(0, _react2.render)(_Item3 || (_Item3 = /*#__PURE__*/_react.default.createElement(_index.Item, {
|
|
69
|
+
renderLabel: "Some label",
|
|
70
|
+
href: "#",
|
|
71
|
+
renderAfter: /*#__PURE__*/_react.default.createElement("strong", null, "I am rendered after!")
|
|
72
|
+
})));
|
|
73
|
+
const item = _react2.screen.getByRole('link');
|
|
74
|
+
const after = _react2.screen.getByText('I am rendered after!');
|
|
75
|
+
expect(item).toBeInTheDocument();
|
|
76
|
+
expect(item).toHaveTextContent('Some label');
|
|
77
|
+
expect(after).toBeInTheDocument();
|
|
78
|
+
expect(after.tagName).toBe('STRONG');
|
|
79
|
+
});
|
|
80
|
+
it('should respond to an onClick event', async () => {
|
|
81
|
+
const onClick = jest.fn();
|
|
82
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Item, {
|
|
83
|
+
renderLabel: "Some label",
|
|
84
|
+
onClick: onClick
|
|
85
|
+
}));
|
|
86
|
+
const button = _react2.screen.getByRole('button');
|
|
87
|
+
await _userEvent.default.click(button);
|
|
88
|
+
await (0, _react2.waitFor)(() => {
|
|
89
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('should output a console error if icon is used with non-screenreader label text', async () => {
|
|
93
|
+
const consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
94
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Item, {
|
|
95
|
+
renderIcon: icon,
|
|
96
|
+
renderLabel: "Some label",
|
|
97
|
+
onClick: () => 'clicked'
|
|
98
|
+
}));
|
|
99
|
+
const expectedErrorMessage = 'Warning: [AppNav] If an icon is used, the label text should be wrapped in <ScreenReaderContent />.';
|
|
100
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
101
|
+
consoleErrorMock.mockRestore();
|
|
102
|
+
});
|
|
103
|
+
it('should meet a11y standards', async () => {
|
|
104
|
+
const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Item, {
|
|
105
|
+
renderIcon: icon,
|
|
106
|
+
renderLabel: _ScreenReaderContent || (_ScreenReaderContent = /*#__PURE__*/_react.default.createElement(_ScreenReaderContent2.ScreenReaderContent, null, "Some label")),
|
|
107
|
+
onClick: () => 'clicked'
|
|
108
|
+
})),
|
|
109
|
+
container = _render2.container;
|
|
110
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
111
|
+
expect(axeCheck).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
8
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
var _AppNav4 = _interopRequireDefault(require("../__examples__/AppNav.examples"));
|
|
11
|
+
var _AppNav, _AppNav$Item, _AppNav2, _AppNav3, _AppNav$Item2, _AppNav$Item3, _AppNav$Item4, _AppNav$Item5;
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
// eslint-disable-next-line no-restricted-imports
|
|
36
|
+
const originalResizeObserver = global.ResizeObserver;
|
|
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
|
+
afterAll(() => {
|
|
47
|
+
global.ResizeObserver = originalResizeObserver;
|
|
48
|
+
});
|
|
49
|
+
describe('for a11y', () => {
|
|
50
|
+
it('should render a nav element with an aria-label', async () => {
|
|
51
|
+
const _render = (0, _react2.render)(_AppNav || (_AppNav = /*#__PURE__*/_react.default.createElement(_index.AppNav, {
|
|
52
|
+
screenReaderLabel: "Screen reader label",
|
|
53
|
+
visibleItemsCount: 2
|
|
54
|
+
}, /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
55
|
+
renderLabel: "Some label",
|
|
56
|
+
href: "http://instructure.design"
|
|
57
|
+
}), /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
58
|
+
renderLabel: "Some other label",
|
|
59
|
+
href: "http://instructure.design"
|
|
60
|
+
})))),
|
|
61
|
+
container = _render.container;
|
|
62
|
+
const appNavList = container.querySelector('ul[class$="-appNav__list"]');
|
|
63
|
+
expect(appNavList).toBeInTheDocument();
|
|
64
|
+
expect(appNavList.tagName).toBe('UL');
|
|
65
|
+
expect(appNavList).toHaveAttribute('aria-label', 'Screen reader label');
|
|
66
|
+
});
|
|
67
|
+
it('should render a semantic list of items', async () => {
|
|
68
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.AppNav, {
|
|
69
|
+
screenReaderLabel: "App navigation",
|
|
70
|
+
visibleItemsCount: 2
|
|
71
|
+
}, _AppNav$Item || (_AppNav$Item = /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
72
|
+
renderLabel: "Some first label",
|
|
73
|
+
href: "http://instructure.design"
|
|
74
|
+
})), /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
75
|
+
renderLabel: "Some second label",
|
|
76
|
+
onClick: () => 'clicked'
|
|
77
|
+
})));
|
|
78
|
+
const list = _react2.screen.getAllByRole('list');
|
|
79
|
+
const items = _react2.screen.getAllByRole('listitem');
|
|
80
|
+
const link = _react2.screen.getAllByRole('link');
|
|
81
|
+
const button = _react2.screen.getAllByRole('button');
|
|
82
|
+
expect(list.length).toBe(1);
|
|
83
|
+
expect(items.length).toBe(2);
|
|
84
|
+
expect(link.length).toBe(1);
|
|
85
|
+
expect(button.length).toBe(1);
|
|
86
|
+
});
|
|
87
|
+
it('should render with a single item', async () => {
|
|
88
|
+
(0, _react2.render)(_AppNav2 || (_AppNav2 = /*#__PURE__*/_react.default.createElement(_index.AppNav, {
|
|
89
|
+
screenReaderLabel: "App navigation",
|
|
90
|
+
visibleItemsCount: 1
|
|
91
|
+
}, /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
92
|
+
renderLabel: "Some label",
|
|
93
|
+
href: "http://instructure.design"
|
|
94
|
+
}))));
|
|
95
|
+
const list = _react2.screen.getAllByRole('list');
|
|
96
|
+
const items = _react2.screen.getAllByRole('listitem');
|
|
97
|
+
const link = _react2.screen.getAllByRole('link');
|
|
98
|
+
expect(list.length).toBe(1);
|
|
99
|
+
expect(items.length).toBe(1);
|
|
100
|
+
expect(link.length).toBe(1);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('with rendered content', () => {
|
|
104
|
+
it('should render content after the navigation', async () => {
|
|
105
|
+
(0, _react2.render)(_AppNav3 || (_AppNav3 = /*#__PURE__*/_react.default.createElement(_index.AppNav, {
|
|
106
|
+
screenReaderLabel: "App navigation",
|
|
107
|
+
renderAfterItems: /*#__PURE__*/_react.default.createElement("button", {
|
|
108
|
+
type: "button"
|
|
109
|
+
}, "I am rendered after!"),
|
|
110
|
+
visibleItemsCount: 2
|
|
111
|
+
}, /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
112
|
+
renderLabel: "Some label",
|
|
113
|
+
href: "http://instructure.design"
|
|
114
|
+
}), /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
115
|
+
renderLabel: "Some other label",
|
|
116
|
+
href: "http://instructure.design"
|
|
117
|
+
}))));
|
|
118
|
+
const button = _react2.screen.getByRole('button');
|
|
119
|
+
expect(button).toHaveTextContent('I am rendered after!');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe('with item truncation', () => {
|
|
123
|
+
it('should pass a custom label to the menu trigger', async () => {
|
|
124
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.AppNav, {
|
|
125
|
+
screenReaderLabel: "App navigation",
|
|
126
|
+
visibleItemsCount: 2,
|
|
127
|
+
renderTruncateLabel: function () {
|
|
128
|
+
return 'I am sooo custom!';
|
|
129
|
+
}
|
|
130
|
+
}, _AppNav$Item2 || (_AppNav$Item2 = /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
131
|
+
renderLabel: "Label",
|
|
132
|
+
href: "http://instructure.design"
|
|
133
|
+
})), _AppNav$Item3 || (_AppNav$Item3 = /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
134
|
+
renderLabel: "Label",
|
|
135
|
+
href: "http://instructure.design"
|
|
136
|
+
})), _AppNav$Item4 || (_AppNav$Item4 = /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
137
|
+
renderLabel: "Label",
|
|
138
|
+
href: "http://instructure.design"
|
|
139
|
+
})), _AppNav$Item5 || (_AppNav$Item5 = /*#__PURE__*/_react.default.createElement(_index.AppNav.Item, {
|
|
140
|
+
renderLabel: "Label",
|
|
141
|
+
href: "http://instructure.design"
|
|
142
|
+
}))));
|
|
143
|
+
const items = _react2.screen.getAllByRole('listitem');
|
|
144
|
+
expect(items.length).toBe(3);
|
|
145
|
+
expect(items[2]).toHaveTextContent('I am sooo custom!');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('with generated examples', () => {
|
|
149
|
+
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.AppNav, _AppNav4.default);
|
|
150
|
+
for (const component of generatedComponents) {
|
|
151
|
+
it(component.description, async () => {
|
|
152
|
+
const _render2 = (0, _react2.render)(component.content),
|
|
153
|
+
container = _render2.container;
|
|
154
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
155
|
+
expect(axeCheck).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-navigation",
|
|
3
|
-
"version": "9.0.2-snapshot-
|
|
3
|
+
"version": "9.0.2-snapshot-9",
|
|
4
4
|
"description": "Main and application level navigational components",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,32 +23,36 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-
|
|
27
|
-
"@instructure/ui-
|
|
28
|
-
"@instructure/ui-
|
|
29
|
-
"@instructure/ui-
|
|
30
|
-
"@instructure/ui-
|
|
26
|
+
"@instructure/ui-axe-check": "9.0.2-snapshot-9",
|
|
27
|
+
"@instructure/ui-babel-preset": "9.0.2-snapshot-9",
|
|
28
|
+
"@instructure/ui-color-utils": "9.0.2-snapshot-9",
|
|
29
|
+
"@instructure/ui-scripts": "9.0.2-snapshot-9",
|
|
30
|
+
"@instructure/ui-test-utils": "9.0.2-snapshot-9",
|
|
31
|
+
"@instructure/ui-themes": "9.0.2-snapshot-9",
|
|
32
|
+
"@testing-library/jest-dom": "^6.4.5",
|
|
33
|
+
"@testing-library/react": "^15.0.7",
|
|
34
|
+
"@testing-library/user-event": "^14.5.2"
|
|
31
35
|
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"@babel/runtime": "^7.24.5",
|
|
34
|
-
"@instructure/console": "9.0.2-snapshot-
|
|
35
|
-
"@instructure/debounce": "9.0.2-snapshot-
|
|
36
|
-
"@instructure/emotion": "9.0.2-snapshot-
|
|
37
|
-
"@instructure/shared-types": "9.0.2-snapshot-
|
|
38
|
-
"@instructure/ui-a11y-content": "9.0.2-snapshot-
|
|
39
|
-
"@instructure/ui-a11y-utils": "9.0.2-snapshot-
|
|
40
|
-
"@instructure/ui-badge": "9.0.2-snapshot-
|
|
41
|
-
"@instructure/ui-dom-utils": "9.0.2-snapshot-
|
|
42
|
-
"@instructure/ui-focusable": "9.0.2-snapshot-
|
|
43
|
-
"@instructure/ui-icons": "9.0.2-snapshot-
|
|
44
|
-
"@instructure/ui-menu": "9.0.2-snapshot-
|
|
45
|
-
"@instructure/ui-prop-types": "9.0.2-snapshot-
|
|
46
|
-
"@instructure/ui-react-utils": "9.0.2-snapshot-
|
|
47
|
-
"@instructure/ui-testable": "9.0.2-snapshot-
|
|
48
|
-
"@instructure/ui-tooltip": "9.0.2-snapshot-
|
|
49
|
-
"@instructure/ui-truncate-list": "9.0.2-snapshot-
|
|
50
|
-
"@instructure/ui-utils": "9.0.2-snapshot-
|
|
51
|
-
"@instructure/ui-view": "9.0.2-snapshot-
|
|
38
|
+
"@instructure/console": "9.0.2-snapshot-9",
|
|
39
|
+
"@instructure/debounce": "9.0.2-snapshot-9",
|
|
40
|
+
"@instructure/emotion": "9.0.2-snapshot-9",
|
|
41
|
+
"@instructure/shared-types": "9.0.2-snapshot-9",
|
|
42
|
+
"@instructure/ui-a11y-content": "9.0.2-snapshot-9",
|
|
43
|
+
"@instructure/ui-a11y-utils": "9.0.2-snapshot-9",
|
|
44
|
+
"@instructure/ui-badge": "9.0.2-snapshot-9",
|
|
45
|
+
"@instructure/ui-dom-utils": "9.0.2-snapshot-9",
|
|
46
|
+
"@instructure/ui-focusable": "9.0.2-snapshot-9",
|
|
47
|
+
"@instructure/ui-icons": "9.0.2-snapshot-9",
|
|
48
|
+
"@instructure/ui-menu": "9.0.2-snapshot-9",
|
|
49
|
+
"@instructure/ui-prop-types": "9.0.2-snapshot-9",
|
|
50
|
+
"@instructure/ui-react-utils": "9.0.2-snapshot-9",
|
|
51
|
+
"@instructure/ui-testable": "9.0.2-snapshot-9",
|
|
52
|
+
"@instructure/ui-tooltip": "9.0.2-snapshot-9",
|
|
53
|
+
"@instructure/ui-truncate-list": "9.0.2-snapshot-9",
|
|
54
|
+
"@instructure/ui-utils": "9.0.2-snapshot-9",
|
|
55
|
+
"@instructure/ui-view": "9.0.2-snapshot-9",
|
|
52
56
|
"prop-types": "^15.8.1"
|
|
53
57
|
},
|
|
54
58
|
"peerDependencies": {
|