@instructure/ui-top-nav-bar 8.48.1-snapshot-2 → 8.48.1
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 +4 -2
- package/es/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.js +46 -6
- package/es/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +136 -0
- package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +106 -0
- package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/props.js +2 -2
- package/es/TopNavBar/utils/exampleHelpers.js +15 -4
- package/lib/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.js +46 -6
- package/lib/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +139 -0
- package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +109 -0
- package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/props.js +2 -2
- package/lib/TopNavBar/utils/exampleHelpers.js +16 -5
- package/package.json +29 -29
- package/src/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.tsx +46 -3
- package/src/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.tsx +170 -0
- package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.tsx +139 -0
- package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/props.ts +2 -2
- package/src/TopNavBar/utils/exampleHelpers.tsx +26 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.d.ts +2 -0
- package/types/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.d.ts.map +1 -0
- package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.d.ts +2 -0
- package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.d.ts.map +1 -0
- package/types/TopNavBar/utils/exampleHelpers.d.ts +3 -1
- package/types/TopNavBar/utils/exampleHelpers.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
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
|
-
## [8.48.1
|
|
6
|
+
## [8.48.1](https://github.com/instructure/instructure-ui/compare/v8.48.0...v8.48.1) (2023-11-17)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **ui-top-nav-bar:** add Breadcrumb to TopNavBar ([e340ae9](https://github.com/instructure/instructure-ui/commit/e340ae91fc0eeb961762453db020b80a44d0b70a))
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _Breadcrumb, _BaseExample, _BaseExample2, _BaseExample3, _BaseExample4;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -24,7 +24,7 @@ var _TopNavBarBreadcrumb, _BaseExample, _BaseExample2, _BaseExample3;
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
|
-
import { render } from '@testing-library/react';
|
|
27
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
28
28
|
import '@testing-library/jest-dom';
|
|
29
29
|
|
|
30
30
|
// eslint-disable-next-line no-restricted-imports
|
|
@@ -66,9 +66,19 @@ const BaseExample = props => {
|
|
|
66
66
|
layout: props.layout,
|
|
67
67
|
inverseColor: props.inverseColor
|
|
68
68
|
}
|
|
69
|
-
},
|
|
69
|
+
}, /*#__PURE__*/React.createElement(TopNavBarBreadcrumb, {
|
|
70
|
+
onClick: props.onClick
|
|
71
|
+
}, _Breadcrumb || (_Breadcrumb = /*#__PURE__*/React.createElement(Breadcrumb, {
|
|
70
72
|
label: TEST_BREADCRUMB_LABEL
|
|
71
|
-
}, /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 1"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 2"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 3"), /*#__PURE__*/React.createElement(Breadcrumb.Link,
|
|
73
|
+
}, /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 1"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 2"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 3"), /*#__PURE__*/React.createElement(Breadcrumb.Link, {
|
|
74
|
+
href: "https://www.instructure.com"
|
|
75
|
+
}, "Course page 4"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 5")))));
|
|
76
|
+
};
|
|
77
|
+
BaseExample.defaultProps = {
|
|
78
|
+
inverseColor: true,
|
|
79
|
+
layout: 'desktop',
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
81
|
+
onClick: () => {}
|
|
72
82
|
};
|
|
73
83
|
describe('<TopNavBarBreadcrumb />', () => {
|
|
74
84
|
it('should render', () => {
|
|
@@ -91,13 +101,43 @@ describe('<TopNavBarBreadcrumb />', () => {
|
|
|
91
101
|
expect(element).not.toBeInTheDocument();
|
|
92
102
|
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
|
|
93
103
|
});
|
|
104
|
+
it('should render last but one crumb in smallViewPort mode', () => {
|
|
105
|
+
const _render3 = render(_BaseExample3 || (_BaseExample3 = /*#__PURE__*/React.createElement(BaseExample, {
|
|
106
|
+
inverseColor: true,
|
|
107
|
+
layout: "smallViewport"
|
|
108
|
+
}))),
|
|
109
|
+
queryByText = _render3.queryByText;
|
|
110
|
+
const page1 = queryByText('Course page 1');
|
|
111
|
+
const page2 = queryByText('Course page 2');
|
|
112
|
+
const page3 = queryByText('Course page 3');
|
|
113
|
+
const page4 = queryByText('Course page 4');
|
|
114
|
+
const page5 = queryByText('Course page 5');
|
|
115
|
+
expect(page1).not.toBeInTheDocument();
|
|
116
|
+
expect(page2).not.toBeInTheDocument();
|
|
117
|
+
expect(page3).not.toBeInTheDocument();
|
|
118
|
+
expect(page4).toBeInTheDocument();
|
|
119
|
+
expect(page5).not.toBeInTheDocument();
|
|
120
|
+
});
|
|
121
|
+
it('should fire onClick', () => {
|
|
122
|
+
const onClick = jest.fn();
|
|
123
|
+
const _render4 = render( /*#__PURE__*/React.createElement(BaseExample, {
|
|
124
|
+
inverseColor: true,
|
|
125
|
+
layout: "desktop",
|
|
126
|
+
onClick: onClick
|
|
127
|
+
})),
|
|
128
|
+
getByRole = _render4.getByRole;
|
|
129
|
+
const hamburger = getByRole('button');
|
|
130
|
+
expect(hamburger).toBeInTheDocument();
|
|
131
|
+
fireEvent.click(hamburger);
|
|
132
|
+
expect(onClick).toHaveBeenCalled();
|
|
133
|
+
});
|
|
94
134
|
describe('should be accessible', () => {
|
|
95
135
|
it('a11y', async () => {
|
|
96
|
-
const
|
|
136
|
+
const _render5 = render(_BaseExample4 || (_BaseExample4 = /*#__PURE__*/React.createElement(BaseExample, {
|
|
97
137
|
inverseColor: true,
|
|
98
138
|
layout: "desktop"
|
|
99
139
|
}))),
|
|
100
|
-
container =
|
|
140
|
+
container = _render5.container;
|
|
101
141
|
const axeCheck = await runAxeCheck(container);
|
|
102
142
|
expect(axeCheck).toBe(true);
|
|
103
143
|
});
|
package/es/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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 { render } from '@testing-library/react';
|
|
27
|
+
import '@testing-library/jest-dom';
|
|
28
|
+
import { getActionItems, getBrand, getMenuItems, getUser, getBreadcrumb } from '../../../utils/exampleHelpers';
|
|
29
|
+
import { TopNavBarDesktopLayout } from '../index';
|
|
30
|
+
import TopNavBarContext from '../../../TopNavBarContext';
|
|
31
|
+
const originalResizeObserver = global.ResizeObserver;
|
|
32
|
+
describe('<TopNavBarDesktopLayout />', () => {
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
// Mock for ResizeObserver browser API
|
|
35
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
36
|
+
observe: jest.fn(),
|
|
37
|
+
unobserve: jest.fn(),
|
|
38
|
+
disconnect: jest.fn()
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
describe('renderBreadcrumb', () => {
|
|
42
|
+
it('should render breadcrumb container', () => {
|
|
43
|
+
const _render = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
44
|
+
value: {
|
|
45
|
+
layout: 'desktop',
|
|
46
|
+
inverseColor: true
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/React.createElement(TopNavBarDesktopLayout, {
|
|
49
|
+
renderBreadcrumb: getBreadcrumb(),
|
|
50
|
+
renderUser: getUser(),
|
|
51
|
+
renderActionItems: getActionItems()
|
|
52
|
+
}))),
|
|
53
|
+
getByLabelText = _render.getByLabelText,
|
|
54
|
+
getByText = _render.getByText;
|
|
55
|
+
const breadCrumbContainer = getByLabelText('You are here');
|
|
56
|
+
const crumb1 = getByText('Course page 1');
|
|
57
|
+
const crumb2 = getByText('Course page 2');
|
|
58
|
+
const crumb3 = getByText('Course page 3');
|
|
59
|
+
expect(breadCrumbContainer).toBeInTheDocument();
|
|
60
|
+
expect(crumb1).toBeVisible();
|
|
61
|
+
expect(crumb2).toBeVisible();
|
|
62
|
+
expect(crumb3).toBeVisible();
|
|
63
|
+
});
|
|
64
|
+
it('should not render breadcrumb if inverseColor is false', () => {
|
|
65
|
+
const consoleMock = jest.spyOn(console, 'error').mockImplementation();
|
|
66
|
+
const _render2 = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
67
|
+
value: {
|
|
68
|
+
layout: 'desktop',
|
|
69
|
+
inverseColor: false
|
|
70
|
+
}
|
|
71
|
+
}, /*#__PURE__*/React.createElement(TopNavBarDesktopLayout, {
|
|
72
|
+
renderBreadcrumb: getBreadcrumb(),
|
|
73
|
+
renderUser: getUser(),
|
|
74
|
+
renderActionItems: getActionItems()
|
|
75
|
+
}))),
|
|
76
|
+
queryByText = _render2.queryByText,
|
|
77
|
+
queryByLabelText = _render2.queryByLabelText;
|
|
78
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
79
|
+
const crumb1 = queryByText('Course page 1');
|
|
80
|
+
const crumb2 = queryByText('Course page 2');
|
|
81
|
+
const crumb3 = queryByText('Course page 3');
|
|
82
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
83
|
+
expect(crumb1).not.toBeInTheDocument();
|
|
84
|
+
expect(crumb2).not.toBeInTheDocument();
|
|
85
|
+
expect(crumb3).not.toBeInTheDocument();
|
|
86
|
+
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
|
|
87
|
+
});
|
|
88
|
+
it('should not render breadcrumb if brand exists', () => {
|
|
89
|
+
const consoleMock = jest.spyOn(console, 'warn').mockImplementation();
|
|
90
|
+
const _render3 = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
91
|
+
value: {
|
|
92
|
+
layout: 'desktop',
|
|
93
|
+
inverseColor: true
|
|
94
|
+
}
|
|
95
|
+
}, /*#__PURE__*/React.createElement(TopNavBarDesktopLayout, {
|
|
96
|
+
renderBrand: getBrand(),
|
|
97
|
+
renderBreadcrumb: getBreadcrumb()
|
|
98
|
+
}))),
|
|
99
|
+
queryByLabelText = _render3.queryByLabelText,
|
|
100
|
+
queryByText = _render3.queryByText;
|
|
101
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
102
|
+
const crumb1 = queryByText('Course page 1');
|
|
103
|
+
const crumb2 = queryByText('Course page 2');
|
|
104
|
+
const crumb3 = queryByText('Course page 3');
|
|
105
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
106
|
+
expect(crumb1).not.toBeInTheDocument();
|
|
107
|
+
expect(crumb2).not.toBeInTheDocument();
|
|
108
|
+
expect(crumb3).not.toBeInTheDocument();
|
|
109
|
+
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBrand] is deprecated and will be removed in version 9. Please use the updated TopNavBar design.');
|
|
110
|
+
});
|
|
111
|
+
it('should not render breadcrumb if menuitems exist', () => {
|
|
112
|
+
const _render4 = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
113
|
+
value: {
|
|
114
|
+
layout: 'desktop',
|
|
115
|
+
inverseColor: true
|
|
116
|
+
}
|
|
117
|
+
}, /*#__PURE__*/React.createElement(TopNavBarDesktopLayout, {
|
|
118
|
+
renderMenuItems: getMenuItems(),
|
|
119
|
+
renderBreadcrumb: getBreadcrumb()
|
|
120
|
+
}))),
|
|
121
|
+
queryByText = _render4.queryByText,
|
|
122
|
+
queryByLabelText = _render4.queryByLabelText;
|
|
123
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
124
|
+
const crumb1 = queryByText('Course page 1');
|
|
125
|
+
const crumb2 = queryByText('Course page 2');
|
|
126
|
+
const crumb3 = queryByText('Course page 3');
|
|
127
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
128
|
+
expect(crumb1).not.toBeInTheDocument();
|
|
129
|
+
expect(crumb2).not.toBeInTheDocument();
|
|
130
|
+
expect(crumb3).not.toBeInTheDocument();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
afterAll(() => {
|
|
134
|
+
global.ResizeObserver = originalResizeObserver;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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 { render } from '@testing-library/react';
|
|
27
|
+
import '@testing-library/jest-dom';
|
|
28
|
+
import { getActionItems, getBrand, getUser, getBreadcrumb, getMenuItems } from '../../../utils/exampleHelpers';
|
|
29
|
+
import { TopNavBarSmallViewportLayout } from '../index';
|
|
30
|
+
import TopNavBarContext from '../../../TopNavBarContext';
|
|
31
|
+
const originalResizeObserver = global.ResizeObserver;
|
|
32
|
+
describe('<TopNavBarSmallViewportLayout />', () => {
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
// Mock for ResizeObserver browser API
|
|
35
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
36
|
+
observe: jest.fn(),
|
|
37
|
+
unobserve: jest.fn(),
|
|
38
|
+
disconnect: jest.fn()
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
describe('renderBreadcrumb', () => {
|
|
42
|
+
it('should render breadcrumb link', () => {
|
|
43
|
+
const _render = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
44
|
+
value: {
|
|
45
|
+
layout: 'smallViewport',
|
|
46
|
+
inverseColor: true
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/React.createElement(TopNavBarSmallViewportLayout, {
|
|
49
|
+
dropdownMenuToggleButtonLabel: "Toggle Menu",
|
|
50
|
+
renderBreadcrumb: getBreadcrumb(),
|
|
51
|
+
renderUser: getUser(),
|
|
52
|
+
renderActionItems: getActionItems()
|
|
53
|
+
}))),
|
|
54
|
+
getByText = _render.getByText;
|
|
55
|
+
const crumb = getByText('Course page 2');
|
|
56
|
+
expect(crumb).toBeVisible();
|
|
57
|
+
});
|
|
58
|
+
it('should not render breadcrumb link if inverseColor is false', () => {
|
|
59
|
+
const consoleMock = jest.spyOn(console, 'error').mockImplementation();
|
|
60
|
+
const _render2 = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
61
|
+
value: {
|
|
62
|
+
layout: 'smallViewport',
|
|
63
|
+
inverseColor: false
|
|
64
|
+
}
|
|
65
|
+
}, /*#__PURE__*/React.createElement(TopNavBarSmallViewportLayout, {
|
|
66
|
+
dropdownMenuToggleButtonLabel: "Toggle Menu",
|
|
67
|
+
renderBreadcrumb: getBreadcrumb(),
|
|
68
|
+
renderUser: getUser(),
|
|
69
|
+
renderActionItems: getActionItems()
|
|
70
|
+
}))),
|
|
71
|
+
queryByText = _render2.queryByText,
|
|
72
|
+
queryByLabelText = _render2.queryByLabelText;
|
|
73
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
74
|
+
const crumb = queryByText('Course page 2');
|
|
75
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
76
|
+
expect(crumb).not.toBeInTheDocument();
|
|
77
|
+
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
|
|
78
|
+
});
|
|
79
|
+
it('should render breadcrumb link but not others', () => {
|
|
80
|
+
const _render3 = render( /*#__PURE__*/React.createElement(TopNavBarContext.Provider, {
|
|
81
|
+
value: {
|
|
82
|
+
layout: 'smallViewport',
|
|
83
|
+
inverseColor: true
|
|
84
|
+
}
|
|
85
|
+
}, /*#__PURE__*/React.createElement(TopNavBarSmallViewportLayout, {
|
|
86
|
+
dropdownMenuToggleButtonLabel: "Toggle Menu",
|
|
87
|
+
renderBrand: getBrand(),
|
|
88
|
+
renderBreadcrumb: getBreadcrumb(),
|
|
89
|
+
renderActionItems: getActionItems(),
|
|
90
|
+
renderUser: getUser(),
|
|
91
|
+
renderMenuItems: getMenuItems()
|
|
92
|
+
}))),
|
|
93
|
+
container = _render3.container,
|
|
94
|
+
queryByText = _render3.queryByText;
|
|
95
|
+
const crumb = queryByText('Course page 2');
|
|
96
|
+
const menuTriggerContainer = container.querySelector("[class$='topNavBarSmallViewportLayout__menuTriggerContainer']");
|
|
97
|
+
const brandContainer = container.querySelector("[class$='topNavBarSmallViewportLayout__brandContainer']");
|
|
98
|
+
expect(crumb).toBeInTheDocument();
|
|
99
|
+
expect(menuTriggerContainer).not.toBeInTheDocument();
|
|
100
|
+
expect(brandContainer).not.toBeInTheDocument();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
afterAll(() => {
|
|
104
|
+
global.ResizeObserver = originalResizeObserver;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
|
|
25
25
|
import { commonAllowedProps, commonPropTypes, smallViewportPropTypes, smallViewportAllowedProps } from '../props';
|
|
26
26
|
const propTypes = {
|
|
27
|
-
// Edit PropTypes in
|
|
27
|
+
// Edit PropTypes in TopNavBarLayout/props.ts
|
|
28
28
|
...commonPropTypes,
|
|
29
29
|
...smallViewportPropTypes
|
|
30
30
|
};
|
|
31
31
|
const allowedProps = [
|
|
32
|
-
// Edit allowed props in
|
|
32
|
+
// Edit allowed props in TopNavBarLayout/props.ts
|
|
33
33
|
...commonAllowedProps, ...smallViewportAllowedProps];
|
|
34
34
|
export { propTypes, allowedProps };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _TopNavBar$Breadcrumb;
|
|
1
2
|
/*
|
|
2
3
|
* The MIT License (MIT)
|
|
3
4
|
*
|
|
@@ -28,6 +29,7 @@ import { IconQuestionLine, IconAlertsLine, IconConfigureLine, IconSearchLine, Ic
|
|
|
28
29
|
import { TopNavBarContext } from '../TopNavBarContext';
|
|
29
30
|
import { TopNavBar } from '../index';
|
|
30
31
|
import { elevateIcon, elevateLogo, elevateLogoInverse } from './exampleSvgFiles';
|
|
32
|
+
import { Breadcrumb } from '@instructure/ui-breadcrumb';
|
|
31
33
|
const avatarExample = {
|
|
32
34
|
avatarName: 'User Name',
|
|
33
35
|
avatarSrc: 'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'
|
|
@@ -160,6 +162,11 @@ const getUser = (config = {}) => {
|
|
|
160
162
|
renderSubmenu: config.userWithSubmenu ? itemSubmenuExample : void 0
|
|
161
163
|
}, config.userItemProps), ((_config$userItemProps = config.userItemProps) === null || _config$userItemProps === void 0 ? void 0 : _config$userItemProps.children) || (config.userVariant === 'button' ? 'Log In/Register' : 'User Name')));
|
|
162
164
|
};
|
|
165
|
+
const getBreadcrumb = (_config = {}) => {
|
|
166
|
+
return _TopNavBar$Breadcrumb || (_TopNavBar$Breadcrumb = /*#__PURE__*/React.createElement(TopNavBar.Breadcrumb, null, /*#__PURE__*/React.createElement(Breadcrumb, {
|
|
167
|
+
label: "You are here"
|
|
168
|
+
}, /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 1"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 2"), /*#__PURE__*/React.createElement(Breadcrumb.Link, null, "Course page 3"))));
|
|
169
|
+
};
|
|
163
170
|
const getLayoutProps = (props, config = {}) => {
|
|
164
171
|
return {
|
|
165
172
|
desktopConfig: {
|
|
@@ -171,11 +178,11 @@ const getLayoutProps = (props, config = {}) => {
|
|
|
171
178
|
alternativeTitle: config.hasAlternativeTitle ? 'Page title' : void 0,
|
|
172
179
|
renderInPlaceDialogConfig: config.hasRenderInPlaceDialogConfig ? getInPlaceDialogConfig(props.inverseColor) : void 0
|
|
173
180
|
},
|
|
174
|
-
renderBrand: getBrand({
|
|
181
|
+
renderBrand: config.hasRenderBreadcrumb ? void 0 : getBrand({
|
|
175
182
|
...props,
|
|
176
183
|
...config
|
|
177
184
|
}),
|
|
178
|
-
renderMenuItems: getMenuItems({
|
|
185
|
+
renderMenuItems: config.hasRenderBreadcrumb ? void 0 : getMenuItems({
|
|
179
186
|
...props,
|
|
180
187
|
...config
|
|
181
188
|
}),
|
|
@@ -186,7 +193,11 @@ const getLayoutProps = (props, config = {}) => {
|
|
|
186
193
|
renderUser: getUser({
|
|
187
194
|
...props,
|
|
188
195
|
...config
|
|
189
|
-
})
|
|
196
|
+
}),
|
|
197
|
+
renderBreadcrumb: config.hasRenderBreadcrumb ? getBreadcrumb({
|
|
198
|
+
...props,
|
|
199
|
+
...config
|
|
200
|
+
}) : void 0
|
|
190
201
|
};
|
|
191
202
|
};
|
|
192
|
-
export { avatarExample, itemSubmenuExample, SmallViewportModeWrapper, getCustomPopoverConfig, getCustomPopoverContent, getInPlaceDialogConfig, getBrand, getMenuItems, getActionItems, getUser, getLayoutProps };
|
|
203
|
+
export { avatarExample, itemSubmenuExample, SmallViewportModeWrapper, getCustomPopoverConfig, getCustomPopoverContent, getInPlaceDialogConfig, getBrand, getMenuItems, getActionItems, getUser, getLayoutProps, getBreadcrumb };
|
|
@@ -6,9 +6,9 @@ var _react2 = require("@testing-library/react");
|
|
|
6
6
|
require("@testing-library/jest-dom");
|
|
7
7
|
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
8
8
|
var _index = require("../index");
|
|
9
|
-
var
|
|
9
|
+
var _Breadcrumb2 = require("@instructure/ui-breadcrumb/lib/Breadcrumb");
|
|
10
10
|
var _TopNavBarContext = _interopRequireDefault(require("../../TopNavBarContext"));
|
|
11
|
-
var
|
|
11
|
+
var _Breadcrumb, _BaseExample, _BaseExample2, _BaseExample3, _BaseExample4;
|
|
12
12
|
/*
|
|
13
13
|
* The MIT License (MIT)
|
|
14
14
|
*
|
|
@@ -67,9 +67,19 @@ const BaseExample = props => {
|
|
|
67
67
|
layout: props.layout,
|
|
68
68
|
inverseColor: props.inverseColor
|
|
69
69
|
}
|
|
70
|
-
},
|
|
70
|
+
}, /*#__PURE__*/_react.default.createElement(_index.TopNavBarBreadcrumb, {
|
|
71
|
+
onClick: props.onClick
|
|
72
|
+
}, _Breadcrumb || (_Breadcrumb = /*#__PURE__*/_react.default.createElement(_Breadcrumb2.Breadcrumb, {
|
|
71
73
|
label: TEST_BREADCRUMB_LABEL
|
|
72
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
74
|
+
}, /*#__PURE__*/_react.default.createElement(_Breadcrumb2.Breadcrumb.Link, null, "Course page 1"), /*#__PURE__*/_react.default.createElement(_Breadcrumb2.Breadcrumb.Link, null, "Course page 2"), /*#__PURE__*/_react.default.createElement(_Breadcrumb2.Breadcrumb.Link, null, "Course page 3"), /*#__PURE__*/_react.default.createElement(_Breadcrumb2.Breadcrumb.Link, {
|
|
75
|
+
href: "https://www.instructure.com"
|
|
76
|
+
}, "Course page 4"), /*#__PURE__*/_react.default.createElement(_Breadcrumb2.Breadcrumb.Link, null, "Course page 5")))));
|
|
77
|
+
};
|
|
78
|
+
BaseExample.defaultProps = {
|
|
79
|
+
inverseColor: true,
|
|
80
|
+
layout: 'desktop',
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
82
|
+
onClick: () => {}
|
|
73
83
|
};
|
|
74
84
|
describe('<TopNavBarBreadcrumb />', () => {
|
|
75
85
|
it('should render', () => {
|
|
@@ -92,13 +102,43 @@ describe('<TopNavBarBreadcrumb />', () => {
|
|
|
92
102
|
expect(element).not.toBeInTheDocument();
|
|
93
103
|
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
|
|
94
104
|
});
|
|
105
|
+
it('should render last but one crumb in smallViewPort mode', () => {
|
|
106
|
+
const _render3 = (0, _react2.render)(_BaseExample3 || (_BaseExample3 = /*#__PURE__*/_react.default.createElement(BaseExample, {
|
|
107
|
+
inverseColor: true,
|
|
108
|
+
layout: "smallViewport"
|
|
109
|
+
}))),
|
|
110
|
+
queryByText = _render3.queryByText;
|
|
111
|
+
const page1 = queryByText('Course page 1');
|
|
112
|
+
const page2 = queryByText('Course page 2');
|
|
113
|
+
const page3 = queryByText('Course page 3');
|
|
114
|
+
const page4 = queryByText('Course page 4');
|
|
115
|
+
const page5 = queryByText('Course page 5');
|
|
116
|
+
expect(page1).not.toBeInTheDocument();
|
|
117
|
+
expect(page2).not.toBeInTheDocument();
|
|
118
|
+
expect(page3).not.toBeInTheDocument();
|
|
119
|
+
expect(page4).toBeInTheDocument();
|
|
120
|
+
expect(page5).not.toBeInTheDocument();
|
|
121
|
+
});
|
|
122
|
+
it('should fire onClick', () => {
|
|
123
|
+
const onClick = jest.fn();
|
|
124
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(BaseExample, {
|
|
125
|
+
inverseColor: true,
|
|
126
|
+
layout: "desktop",
|
|
127
|
+
onClick: onClick
|
|
128
|
+
})),
|
|
129
|
+
getByRole = _render4.getByRole;
|
|
130
|
+
const hamburger = getByRole('button');
|
|
131
|
+
expect(hamburger).toBeInTheDocument();
|
|
132
|
+
_react2.fireEvent.click(hamburger);
|
|
133
|
+
expect(onClick).toHaveBeenCalled();
|
|
134
|
+
});
|
|
95
135
|
describe('should be accessible', () => {
|
|
96
136
|
it('a11y', async () => {
|
|
97
|
-
const
|
|
137
|
+
const _render5 = (0, _react2.render)(_BaseExample4 || (_BaseExample4 = /*#__PURE__*/_react.default.createElement(BaseExample, {
|
|
98
138
|
inverseColor: true,
|
|
99
139
|
layout: "desktop"
|
|
100
140
|
}))),
|
|
101
|
-
container =
|
|
141
|
+
container = _render5.container;
|
|
102
142
|
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
103
143
|
expect(axeCheck).toBe(true);
|
|
104
144
|
});
|
package/lib/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
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 _exampleHelpers = require("../../../utils/exampleHelpers");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _TopNavBarContext = _interopRequireDefault(require("../../../TopNavBarContext"));
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const originalResizeObserver = global.ResizeObserver;
|
|
35
|
+
describe('<TopNavBarDesktopLayout />', () => {
|
|
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
|
+
describe('renderBreadcrumb', () => {
|
|
45
|
+
it('should render breadcrumb container', () => {
|
|
46
|
+
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
|
|
47
|
+
value: {
|
|
48
|
+
layout: 'desktop',
|
|
49
|
+
inverseColor: true
|
|
50
|
+
}
|
|
51
|
+
}, /*#__PURE__*/_react.default.createElement(_index.TopNavBarDesktopLayout, {
|
|
52
|
+
renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)(),
|
|
53
|
+
renderUser: (0, _exampleHelpers.getUser)(),
|
|
54
|
+
renderActionItems: (0, _exampleHelpers.getActionItems)()
|
|
55
|
+
}))),
|
|
56
|
+
getByLabelText = _render.getByLabelText,
|
|
57
|
+
getByText = _render.getByText;
|
|
58
|
+
const breadCrumbContainer = getByLabelText('You are here');
|
|
59
|
+
const crumb1 = getByText('Course page 1');
|
|
60
|
+
const crumb2 = getByText('Course page 2');
|
|
61
|
+
const crumb3 = getByText('Course page 3');
|
|
62
|
+
expect(breadCrumbContainer).toBeInTheDocument();
|
|
63
|
+
expect(crumb1).toBeVisible();
|
|
64
|
+
expect(crumb2).toBeVisible();
|
|
65
|
+
expect(crumb3).toBeVisible();
|
|
66
|
+
});
|
|
67
|
+
it('should not render breadcrumb if inverseColor is false', () => {
|
|
68
|
+
const consoleMock = jest.spyOn(console, 'error').mockImplementation();
|
|
69
|
+
const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
|
|
70
|
+
value: {
|
|
71
|
+
layout: 'desktop',
|
|
72
|
+
inverseColor: false
|
|
73
|
+
}
|
|
74
|
+
}, /*#__PURE__*/_react.default.createElement(_index.TopNavBarDesktopLayout, {
|
|
75
|
+
renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)(),
|
|
76
|
+
renderUser: (0, _exampleHelpers.getUser)(),
|
|
77
|
+
renderActionItems: (0, _exampleHelpers.getActionItems)()
|
|
78
|
+
}))),
|
|
79
|
+
queryByText = _render2.queryByText,
|
|
80
|
+
queryByLabelText = _render2.queryByLabelText;
|
|
81
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
82
|
+
const crumb1 = queryByText('Course page 1');
|
|
83
|
+
const crumb2 = queryByText('Course page 2');
|
|
84
|
+
const crumb3 = queryByText('Course page 3');
|
|
85
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
86
|
+
expect(crumb1).not.toBeInTheDocument();
|
|
87
|
+
expect(crumb2).not.toBeInTheDocument();
|
|
88
|
+
expect(crumb3).not.toBeInTheDocument();
|
|
89
|
+
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
|
|
90
|
+
});
|
|
91
|
+
it('should not render breadcrumb if brand exists', () => {
|
|
92
|
+
const consoleMock = jest.spyOn(console, 'warn').mockImplementation();
|
|
93
|
+
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
|
|
94
|
+
value: {
|
|
95
|
+
layout: 'desktop',
|
|
96
|
+
inverseColor: true
|
|
97
|
+
}
|
|
98
|
+
}, /*#__PURE__*/_react.default.createElement(_index.TopNavBarDesktopLayout, {
|
|
99
|
+
renderBrand: (0, _exampleHelpers.getBrand)(),
|
|
100
|
+
renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)()
|
|
101
|
+
}))),
|
|
102
|
+
queryByLabelText = _render3.queryByLabelText,
|
|
103
|
+
queryByText = _render3.queryByText;
|
|
104
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
105
|
+
const crumb1 = queryByText('Course page 1');
|
|
106
|
+
const crumb2 = queryByText('Course page 2');
|
|
107
|
+
const crumb3 = queryByText('Course page 3');
|
|
108
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
109
|
+
expect(crumb1).not.toBeInTheDocument();
|
|
110
|
+
expect(crumb2).not.toBeInTheDocument();
|
|
111
|
+
expect(crumb3).not.toBeInTheDocument();
|
|
112
|
+
expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBrand] is deprecated and will be removed in version 9. Please use the updated TopNavBar design.');
|
|
113
|
+
});
|
|
114
|
+
it('should not render breadcrumb if menuitems exist', () => {
|
|
115
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
|
|
116
|
+
value: {
|
|
117
|
+
layout: 'desktop',
|
|
118
|
+
inverseColor: true
|
|
119
|
+
}
|
|
120
|
+
}, /*#__PURE__*/_react.default.createElement(_index.TopNavBarDesktopLayout, {
|
|
121
|
+
renderMenuItems: (0, _exampleHelpers.getMenuItems)(),
|
|
122
|
+
renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)()
|
|
123
|
+
}))),
|
|
124
|
+
queryByText = _render4.queryByText,
|
|
125
|
+
queryByLabelText = _render4.queryByLabelText;
|
|
126
|
+
const breadCrumbContainer = queryByLabelText('You are here');
|
|
127
|
+
const crumb1 = queryByText('Course page 1');
|
|
128
|
+
const crumb2 = queryByText('Course page 2');
|
|
129
|
+
const crumb3 = queryByText('Course page 3');
|
|
130
|
+
expect(breadCrumbContainer).not.toBeInTheDocument();
|
|
131
|
+
expect(crumb1).not.toBeInTheDocument();
|
|
132
|
+
expect(crumb2).not.toBeInTheDocument();
|
|
133
|
+
expect(crumb3).not.toBeInTheDocument();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
afterAll(() => {
|
|
137
|
+
global.ResizeObserver = originalResizeObserver;
|
|
138
|
+
});
|
|
139
|
+
});
|