@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.
Files changed (24) hide show
  1. package/CHANGELOG.md +4 -2
  2. package/es/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.js +46 -6
  3. package/es/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +136 -0
  4. package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +106 -0
  5. package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/props.js +2 -2
  6. package/es/TopNavBar/utils/exampleHelpers.js +15 -4
  7. package/lib/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.js +46 -6
  8. package/lib/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +139 -0
  9. package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +109 -0
  10. package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/props.js +2 -2
  11. package/lib/TopNavBar/utils/exampleHelpers.js +16 -5
  12. package/package.json +29 -29
  13. package/src/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.tsx +46 -3
  14. package/src/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.tsx +170 -0
  15. package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.tsx +139 -0
  16. package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/props.ts +2 -2
  17. package/src/TopNavBar/utils/exampleHelpers.tsx +26 -4
  18. package/tsconfig.build.tsbuildinfo +1 -1
  19. package/types/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.d.ts +2 -0
  20. package/types/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.d.ts.map +1 -0
  21. package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.d.ts +2 -0
  22. package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.d.ts.map +1 -0
  23. package/types/TopNavBar/utils/exampleHelpers.d.ts +3 -1
  24. package/types/TopNavBar/utils/exampleHelpers.d.ts.map +1 -1
@@ -0,0 +1,109 @@
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('<TopNavBarSmallViewportLayout />', () => {
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 link', () => {
46
+ const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
47
+ value: {
48
+ layout: 'smallViewport',
49
+ inverseColor: true
50
+ }
51
+ }, /*#__PURE__*/_react.default.createElement(_index.TopNavBarSmallViewportLayout, {
52
+ dropdownMenuToggleButtonLabel: "Toggle Menu",
53
+ renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)(),
54
+ renderUser: (0, _exampleHelpers.getUser)(),
55
+ renderActionItems: (0, _exampleHelpers.getActionItems)()
56
+ }))),
57
+ getByText = _render.getByText;
58
+ const crumb = getByText('Course page 2');
59
+ expect(crumb).toBeVisible();
60
+ });
61
+ it('should not render breadcrumb link if inverseColor is false', () => {
62
+ const consoleMock = jest.spyOn(console, 'error').mockImplementation();
63
+ const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
64
+ value: {
65
+ layout: 'smallViewport',
66
+ inverseColor: false
67
+ }
68
+ }, /*#__PURE__*/_react.default.createElement(_index.TopNavBarSmallViewportLayout, {
69
+ dropdownMenuToggleButtonLabel: "Toggle Menu",
70
+ renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)(),
71
+ renderUser: (0, _exampleHelpers.getUser)(),
72
+ renderActionItems: (0, _exampleHelpers.getActionItems)()
73
+ }))),
74
+ queryByText = _render2.queryByText,
75
+ queryByLabelText = _render2.queryByLabelText;
76
+ const breadCrumbContainer = queryByLabelText('You are here');
77
+ const crumb = queryByText('Course page 2');
78
+ expect(breadCrumbContainer).not.toBeInTheDocument();
79
+ expect(crumb).not.toBeInTheDocument();
80
+ expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
81
+ });
82
+ it('should render breadcrumb link but not others', () => {
83
+ const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_TopNavBarContext.default.Provider, {
84
+ value: {
85
+ layout: 'smallViewport',
86
+ inverseColor: true
87
+ }
88
+ }, /*#__PURE__*/_react.default.createElement(_index.TopNavBarSmallViewportLayout, {
89
+ dropdownMenuToggleButtonLabel: "Toggle Menu",
90
+ renderBrand: (0, _exampleHelpers.getBrand)(),
91
+ renderBreadcrumb: (0, _exampleHelpers.getBreadcrumb)(),
92
+ renderActionItems: (0, _exampleHelpers.getActionItems)(),
93
+ renderUser: (0, _exampleHelpers.getUser)(),
94
+ renderMenuItems: (0, _exampleHelpers.getMenuItems)()
95
+ }))),
96
+ container = _render3.container,
97
+ queryByText = _render3.queryByText;
98
+ const crumb = queryByText('Course page 2');
99
+ const menuTriggerContainer = container.querySelector("[class$='topNavBarSmallViewportLayout__menuTriggerContainer']");
100
+ const brandContainer = container.querySelector("[class$='topNavBarSmallViewportLayout__brandContainer']");
101
+ expect(crumb).toBeInTheDocument();
102
+ expect(menuTriggerContainer).not.toBeInTheDocument();
103
+ expect(brandContainer).not.toBeInTheDocument();
104
+ });
105
+ });
106
+ afterAll(() => {
107
+ global.ResizeObserver = originalResizeObserver;
108
+ });
109
+ });
@@ -30,10 +30,10 @@ var _props = require("../props");
30
30
  */
31
31
 
32
32
  const propTypes = exports.propTypes = {
33
- // Edit PropTypes in TopNabBarLayout/props.ts
33
+ // Edit PropTypes in TopNavBarLayout/props.ts
34
34
  ..._props.commonPropTypes,
35
35
  ..._props.smallViewportPropTypes
36
36
  };
37
37
  const allowedProps = exports.allowedProps = [
38
- // Edit allowed props in TopNabBarLayout/props.ts
38
+ // Edit allowed props in TopNavBarLayout/props.ts
39
39
  ..._props.commonAllowedProps, ..._props.smallViewportAllowedProps];
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.itemSubmenuExample = exports.getUser = exports.getMenuItems = exports.getLayoutProps = exports.getInPlaceDialogConfig = exports.getCustomPopoverContent = exports.getCustomPopoverConfig = exports.getBrand = exports.getActionItems = exports.avatarExample = exports.SmallViewportModeWrapper = void 0;
7
+ exports.itemSubmenuExample = exports.getUser = exports.getMenuItems = exports.getLayoutProps = exports.getInPlaceDialogConfig = exports.getCustomPopoverContent = exports.getCustomPopoverConfig = exports.getBreadcrumb = exports.getBrand = exports.getActionItems = exports.avatarExample = exports.SmallViewportModeWrapper = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _Drilldown = require("@instructure/ui-drilldown/lib/Drilldown");
10
10
  var _IconQuestionLine = require("@instructure/ui-icons/lib/IconQuestionLine.js");
@@ -16,6 +16,8 @@ var _IconDashboardLine = require("@instructure/ui-icons/lib/IconDashboardLine.js
16
16
  var _TopNavBarContext = require("../TopNavBarContext");
17
17
  var _index = require("../index");
18
18
  var _exampleSvgFiles = require("./exampleSvgFiles");
19
+ var _Breadcrumb = require("@instructure/ui-breadcrumb/lib/Breadcrumb");
20
+ var _TopNavBar$Breadcrumb;
19
21
  /*
20
22
  * The MIT License (MIT)
21
23
  *
@@ -39,7 +41,6 @@ var _exampleSvgFiles = require("./exampleSvgFiles");
39
41
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
42
  * SOFTWARE.
41
43
  */
42
-
43
44
  const avatarExample = exports.avatarExample = {
44
45
  avatarName: 'User Name',
45
46
  avatarSrc: 'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'
@@ -180,6 +181,12 @@ const getUser = (config = {}) => {
180
181
  }, config.userItemProps), ((_config$userItemProps = config.userItemProps) === null || _config$userItemProps === void 0 ? void 0 : _config$userItemProps.children) || (config.userVariant === 'button' ? 'Log In/Register' : 'User Name')));
181
182
  };
182
183
  exports.getUser = getUser;
184
+ const getBreadcrumb = (_config = {}) => {
185
+ return _TopNavBar$Breadcrumb || (_TopNavBar$Breadcrumb = /*#__PURE__*/_react.default.createElement(_index.TopNavBar.Breadcrumb, null, /*#__PURE__*/_react.default.createElement(_Breadcrumb.Breadcrumb, {
186
+ label: "You are here"
187
+ }, /*#__PURE__*/_react.default.createElement(_Breadcrumb.Breadcrumb.Link, null, "Course page 1"), /*#__PURE__*/_react.default.createElement(_Breadcrumb.Breadcrumb.Link, null, "Course page 2"), /*#__PURE__*/_react.default.createElement(_Breadcrumb.Breadcrumb.Link, null, "Course page 3"))));
188
+ };
189
+ exports.getBreadcrumb = getBreadcrumb;
183
190
  const getLayoutProps = (props, config = {}) => {
184
191
  return {
185
192
  desktopConfig: {
@@ -191,11 +198,11 @@ const getLayoutProps = (props, config = {}) => {
191
198
  alternativeTitle: config.hasAlternativeTitle ? 'Page title' : void 0,
192
199
  renderInPlaceDialogConfig: config.hasRenderInPlaceDialogConfig ? getInPlaceDialogConfig(props.inverseColor) : void 0
193
200
  },
194
- renderBrand: getBrand({
201
+ renderBrand: config.hasRenderBreadcrumb ? void 0 : getBrand({
195
202
  ...props,
196
203
  ...config
197
204
  }),
198
- renderMenuItems: getMenuItems({
205
+ renderMenuItems: config.hasRenderBreadcrumb ? void 0 : getMenuItems({
199
206
  ...props,
200
207
  ...config
201
208
  }),
@@ -206,7 +213,11 @@ const getLayoutProps = (props, config = {}) => {
206
213
  renderUser: getUser({
207
214
  ...props,
208
215
  ...config
209
- })
216
+ }),
217
+ renderBreadcrumb: config.hasRenderBreadcrumb ? getBreadcrumb({
218
+ ...props,
219
+ ...config
220
+ }) : void 0
210
221
  };
211
222
  };
212
223
  exports.getLayoutProps = getLayoutProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-top-nav-bar",
3
- "version": "8.48.1-snapshot-2",
3
+ "version": "8.48.1",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,37 +24,37 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.23.2",
27
- "@instructure/console": "8.48.1-snapshot-2",
28
- "@instructure/emotion": "8.48.1-snapshot-2",
29
- "@instructure/shared-types": "8.48.1-snapshot-2",
30
- "@instructure/ui-a11y-content": "8.48.1-snapshot-2",
31
- "@instructure/ui-avatar": "8.48.1-snapshot-2",
32
- "@instructure/ui-breadcrumb": "8.48.1-snapshot-2",
33
- "@instructure/ui-buttons": "8.48.1-snapshot-2",
34
- "@instructure/ui-dialog": "8.48.1-snapshot-2",
35
- "@instructure/ui-dom-utils": "8.48.1-snapshot-2",
36
- "@instructure/ui-drilldown": "8.48.1-snapshot-2",
37
- "@instructure/ui-icons": "8.48.1-snapshot-2",
38
- "@instructure/ui-link": "8.48.1-snapshot-2",
39
- "@instructure/ui-popover": "8.48.1-snapshot-2",
40
- "@instructure/ui-prop-types": "8.48.1-snapshot-2",
41
- "@instructure/ui-react-utils": "8.48.1-snapshot-2",
42
- "@instructure/ui-responsive": "8.48.1-snapshot-2",
43
- "@instructure/ui-testable": "8.48.1-snapshot-2",
44
- "@instructure/ui-tooltip": "8.48.1-snapshot-2",
45
- "@instructure/ui-tray": "8.48.1-snapshot-2",
46
- "@instructure/ui-truncate-list": "8.48.1-snapshot-2",
47
- "@instructure/ui-utils": "8.48.1-snapshot-2",
48
- "@instructure/ui-view": "8.48.1-snapshot-2",
27
+ "@instructure/console": "8.48.1",
28
+ "@instructure/emotion": "8.48.1",
29
+ "@instructure/shared-types": "8.48.1",
30
+ "@instructure/ui-a11y-content": "8.48.1",
31
+ "@instructure/ui-avatar": "8.48.1",
32
+ "@instructure/ui-breadcrumb": "8.48.1",
33
+ "@instructure/ui-buttons": "8.48.1",
34
+ "@instructure/ui-dialog": "8.48.1",
35
+ "@instructure/ui-dom-utils": "8.48.1",
36
+ "@instructure/ui-drilldown": "8.48.1",
37
+ "@instructure/ui-icons": "8.48.1",
38
+ "@instructure/ui-link": "8.48.1",
39
+ "@instructure/ui-popover": "8.48.1",
40
+ "@instructure/ui-prop-types": "8.48.1",
41
+ "@instructure/ui-react-utils": "8.48.1",
42
+ "@instructure/ui-responsive": "8.48.1",
43
+ "@instructure/ui-testable": "8.48.1",
44
+ "@instructure/ui-tooltip": "8.48.1",
45
+ "@instructure/ui-tray": "8.48.1",
46
+ "@instructure/ui-truncate-list": "8.48.1",
47
+ "@instructure/ui-utils": "8.48.1",
48
+ "@instructure/ui-view": "8.48.1",
49
49
  "prop-types": "^15.8.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@instructure/ui-axe-check": "8.48.1-snapshot-2",
53
- "@instructure/ui-babel-preset": "8.48.1-snapshot-2",
54
- "@instructure/ui-color-utils": "8.48.1-snapshot-2",
55
- "@instructure/ui-test-locator": "8.48.1-snapshot-2",
56
- "@instructure/ui-test-utils": "8.48.1-snapshot-2",
57
- "@instructure/ui-themes": "8.48.1-snapshot-2",
52
+ "@instructure/ui-axe-check": "8.48.1",
53
+ "@instructure/ui-babel-preset": "8.48.1",
54
+ "@instructure/ui-color-utils": "8.48.1",
55
+ "@instructure/ui-test-locator": "8.48.1",
56
+ "@instructure/ui-test-utils": "8.48.1",
57
+ "@instructure/ui-themes": "8.48.1",
58
58
  "@testing-library/jest-dom": "^6.1.4",
59
59
  "@testing-library/react": "^14.1.0"
60
60
  },
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import React from 'react'
26
- import { render } from '@testing-library/react'
26
+ import { fireEvent, render } from '@testing-library/react'
27
27
  import '@testing-library/jest-dom'
28
28
 
29
29
  // eslint-disable-next-line no-restricted-imports
@@ -67,6 +67,7 @@ const TEST_BREADCRUMB_LABEL = 'You are here:'
67
67
  const BaseExample = (props: {
68
68
  inverseColor: boolean
69
69
  layout: 'desktop' | 'smallViewport'
70
+ onClick?: () => void
70
71
  }) => {
71
72
  return (
72
73
  <TopNavBarContext.Provider
@@ -75,12 +76,14 @@ const BaseExample = (props: {
75
76
  inverseColor: props.inverseColor
76
77
  }}
77
78
  >
78
- <TopNavBarBreadcrumb>
79
+ <TopNavBarBreadcrumb onClick={props.onClick}>
79
80
  <Breadcrumb label={TEST_BREADCRUMB_LABEL}>
80
81
  <Breadcrumb.Link>Course page 1</Breadcrumb.Link>
81
82
  <Breadcrumb.Link>Course page 2</Breadcrumb.Link>
82
83
  <Breadcrumb.Link>Course page 3</Breadcrumb.Link>
83
- <Breadcrumb.Link>Course page 4</Breadcrumb.Link>
84
+ <Breadcrumb.Link href="https://www.instructure.com">
85
+ Course page 4
86
+ </Breadcrumb.Link>
84
87
  <Breadcrumb.Link>Course page 5</Breadcrumb.Link>
85
88
  </Breadcrumb>
86
89
  </TopNavBarBreadcrumb>
@@ -88,6 +91,13 @@ const BaseExample = (props: {
88
91
  )
89
92
  }
90
93
 
94
+ BaseExample.defaultProps = {
95
+ inverseColor: true,
96
+ layout: 'desktop',
97
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
98
+ onClick: () => {}
99
+ }
100
+
91
101
  describe('<TopNavBarBreadcrumb />', () => {
92
102
  it('should render', () => {
93
103
  const { getByLabelText } = render(
@@ -114,6 +124,39 @@ describe('<TopNavBarBreadcrumb />', () => {
114
124
  )
115
125
  })
116
126
 
127
+ it('should render last but one crumb in smallViewPort mode', () => {
128
+ const { queryByText } = render(
129
+ <BaseExample inverseColor={true} layout="smallViewport" />
130
+ )
131
+
132
+ const page1 = queryByText('Course page 1')
133
+ const page2 = queryByText('Course page 2')
134
+ const page3 = queryByText('Course page 3')
135
+ const page4 = queryByText('Course page 4')
136
+ const page5 = queryByText('Course page 5')
137
+
138
+ expect(page1).not.toBeInTheDocument()
139
+ expect(page2).not.toBeInTheDocument()
140
+ expect(page3).not.toBeInTheDocument()
141
+ expect(page4).toBeInTheDocument()
142
+ expect(page5).not.toBeInTheDocument()
143
+ })
144
+
145
+ it('should fire onClick', () => {
146
+ const onClick = jest.fn()
147
+
148
+ const { getByRole } = render(
149
+ <BaseExample inverseColor={true} layout="desktop" onClick={onClick} />
150
+ )
151
+
152
+ const hamburger = getByRole('button')
153
+ expect(hamburger).toBeInTheDocument()
154
+
155
+ fireEvent.click(hamburger)
156
+
157
+ expect(onClick).toHaveBeenCalled()
158
+ })
159
+
117
160
  describe('should be accessible', () => {
118
161
  it('a11y', async () => {
119
162
  const { container } = render(
@@ -0,0 +1,170 @@
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
+
29
+ import {
30
+ getActionItems,
31
+ getBrand,
32
+ getMenuItems,
33
+ getUser,
34
+ getBreadcrumb
35
+ } from '../../../utils/exampleHelpers'
36
+
37
+ import { TopNavBarDesktopLayout } from '../index'
38
+ import TopNavBarContext from '../../../TopNavBarContext'
39
+
40
+ const originalResizeObserver = global.ResizeObserver
41
+
42
+ describe('<TopNavBarDesktopLayout />', () => {
43
+ beforeAll(() => {
44
+ // Mock for ResizeObserver browser API
45
+ global.ResizeObserver = jest.fn().mockImplementation(() => ({
46
+ observe: jest.fn(),
47
+ unobserve: jest.fn(),
48
+ disconnect: jest.fn()
49
+ }))
50
+ })
51
+
52
+ describe('renderBreadcrumb', () => {
53
+ it('should render breadcrumb container', () => {
54
+ const { getByLabelText, getByText } = render(
55
+ <TopNavBarContext.Provider
56
+ value={{
57
+ layout: 'desktop',
58
+ inverseColor: true
59
+ }}
60
+ >
61
+ <TopNavBarDesktopLayout
62
+ renderBreadcrumb={getBreadcrumb()}
63
+ renderUser={getUser()}
64
+ renderActionItems={getActionItems()}
65
+ />
66
+ </TopNavBarContext.Provider>
67
+ )
68
+ const breadCrumbContainer = getByLabelText('You are here')
69
+ const crumb1 = getByText('Course page 1')
70
+ const crumb2 = getByText('Course page 2')
71
+ const crumb3 = getByText('Course page 3')
72
+
73
+ expect(breadCrumbContainer).toBeInTheDocument()
74
+ expect(crumb1).toBeVisible()
75
+ expect(crumb2).toBeVisible()
76
+ expect(crumb3).toBeVisible()
77
+ })
78
+
79
+ it('should not render breadcrumb if inverseColor is false', () => {
80
+ const consoleMock = jest.spyOn(console, 'error').mockImplementation()
81
+
82
+ const { queryByText, queryByLabelText } = render(
83
+ <TopNavBarContext.Provider
84
+ value={{
85
+ layout: 'desktop',
86
+ inverseColor: false
87
+ }}
88
+ >
89
+ <TopNavBarDesktopLayout
90
+ renderBreadcrumb={getBreadcrumb()}
91
+ renderUser={getUser()}
92
+ renderActionItems={getActionItems()}
93
+ />
94
+ </TopNavBarContext.Provider>
95
+ )
96
+ const breadCrumbContainer = queryByLabelText('You are here')
97
+ const crumb1 = queryByText('Course page 1')
98
+ const crumb2 = queryByText('Course page 2')
99
+ const crumb3 = queryByText('Course page 3')
100
+
101
+ expect(breadCrumbContainer).not.toBeInTheDocument()
102
+ expect(crumb1).not.toBeInTheDocument()
103
+ expect(crumb2).not.toBeInTheDocument()
104
+ expect(crumb3).not.toBeInTheDocument()
105
+
106
+ expect(consoleMock.mock.calls[0][0]).toEqual(
107
+ 'Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.'
108
+ )
109
+ })
110
+
111
+ it('should not render breadcrumb if brand exists', () => {
112
+ const consoleMock = jest.spyOn(console, 'warn').mockImplementation()
113
+
114
+ const { queryByLabelText, queryByText } = render(
115
+ <TopNavBarContext.Provider
116
+ value={{
117
+ layout: 'desktop',
118
+ inverseColor: true
119
+ }}
120
+ >
121
+ <TopNavBarDesktopLayout
122
+ renderBrand={getBrand()}
123
+ renderBreadcrumb={getBreadcrumb()}
124
+ />
125
+ </TopNavBarContext.Provider>
126
+ )
127
+ const breadCrumbContainer = queryByLabelText('You are here')
128
+ const crumb1 = queryByText('Course page 1')
129
+ const crumb2 = queryByText('Course page 2')
130
+ const crumb3 = queryByText('Course page 3')
131
+
132
+ expect(breadCrumbContainer).not.toBeInTheDocument()
133
+ expect(crumb1).not.toBeInTheDocument()
134
+ expect(crumb2).not.toBeInTheDocument()
135
+ expect(crumb3).not.toBeInTheDocument()
136
+ expect(consoleMock.mock.calls[0][0]).toEqual(
137
+ 'Warning: [TopNavBarBrand] is deprecated and will be removed in version 9. Please use the updated TopNavBar design.'
138
+ )
139
+ })
140
+
141
+ it('should not render breadcrumb if menuitems exist', () => {
142
+ const { queryByText, queryByLabelText } = render(
143
+ <TopNavBarContext.Provider
144
+ value={{
145
+ layout: 'desktop',
146
+ inverseColor: true
147
+ }}
148
+ >
149
+ <TopNavBarDesktopLayout
150
+ renderMenuItems={getMenuItems()}
151
+ renderBreadcrumb={getBreadcrumb()}
152
+ />
153
+ </TopNavBarContext.Provider>
154
+ )
155
+ const breadCrumbContainer = queryByLabelText('You are here')
156
+ const crumb1 = queryByText('Course page 1')
157
+ const crumb2 = queryByText('Course page 2')
158
+ const crumb3 = queryByText('Course page 3')
159
+
160
+ expect(breadCrumbContainer).not.toBeInTheDocument()
161
+ expect(crumb1).not.toBeInTheDocument()
162
+ expect(crumb2).not.toBeInTheDocument()
163
+ expect(crumb3).not.toBeInTheDocument()
164
+ })
165
+ })
166
+
167
+ afterAll(() => {
168
+ global.ResizeObserver = originalResizeObserver
169
+ })
170
+ })
@@ -0,0 +1,139 @@
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
+
29
+ import {
30
+ getActionItems,
31
+ getBrand,
32
+ getUser,
33
+ getBreadcrumb,
34
+ getMenuItems
35
+ } from '../../../utils/exampleHelpers'
36
+
37
+ import { TopNavBarSmallViewportLayout } from '../index'
38
+ import TopNavBarContext from '../../../TopNavBarContext'
39
+
40
+ const originalResizeObserver = global.ResizeObserver
41
+
42
+ describe('<TopNavBarSmallViewportLayout />', () => {
43
+ beforeAll(() => {
44
+ // Mock for ResizeObserver browser API
45
+ global.ResizeObserver = jest.fn().mockImplementation(() => ({
46
+ observe: jest.fn(),
47
+ unobserve: jest.fn(),
48
+ disconnect: jest.fn()
49
+ }))
50
+ })
51
+
52
+ describe('renderBreadcrumb', () => {
53
+ it('should render breadcrumb link', () => {
54
+ const { getByText } = render(
55
+ <TopNavBarContext.Provider
56
+ value={{
57
+ layout: 'smallViewport',
58
+ inverseColor: true
59
+ }}
60
+ >
61
+ <TopNavBarSmallViewportLayout
62
+ dropdownMenuToggleButtonLabel="Toggle Menu"
63
+ renderBreadcrumb={getBreadcrumb()}
64
+ renderUser={getUser()}
65
+ renderActionItems={getActionItems()}
66
+ />
67
+ </TopNavBarContext.Provider>
68
+ )
69
+ const crumb = getByText('Course page 2')
70
+
71
+ expect(crumb).toBeVisible()
72
+ })
73
+
74
+ it('should not render breadcrumb link if inverseColor is false', () => {
75
+ const consoleMock = jest.spyOn(console, 'error').mockImplementation()
76
+
77
+ const { queryByText, queryByLabelText } = render(
78
+ <TopNavBarContext.Provider
79
+ value={{
80
+ layout: 'smallViewport',
81
+ inverseColor: false
82
+ }}
83
+ >
84
+ <TopNavBarSmallViewportLayout
85
+ dropdownMenuToggleButtonLabel="Toggle Menu"
86
+ renderBreadcrumb={getBreadcrumb()}
87
+ renderUser={getUser()}
88
+ renderActionItems={getActionItems()}
89
+ />
90
+ </TopNavBarContext.Provider>
91
+ )
92
+ const breadCrumbContainer = queryByLabelText('You are here')
93
+ const crumb = queryByText('Course page 2')
94
+
95
+ expect(breadCrumbContainer).not.toBeInTheDocument()
96
+ expect(crumb).not.toBeInTheDocument()
97
+
98
+ expect(consoleMock.mock.calls[0][0]).toEqual(
99
+ 'Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.'
100
+ )
101
+ })
102
+
103
+ it('should render breadcrumb link but not others', () => {
104
+ const { container, queryByText } = render(
105
+ <TopNavBarContext.Provider
106
+ value={{
107
+ layout: 'smallViewport',
108
+ inverseColor: true
109
+ }}
110
+ >
111
+ <TopNavBarSmallViewportLayout
112
+ dropdownMenuToggleButtonLabel="Toggle Menu"
113
+ renderBrand={getBrand()}
114
+ renderBreadcrumb={getBreadcrumb()}
115
+ renderActionItems={getActionItems()}
116
+ renderUser={getUser()}
117
+ renderMenuItems={getMenuItems()}
118
+ />
119
+ </TopNavBarContext.Provider>
120
+ )
121
+
122
+ const crumb = queryByText('Course page 2')
123
+ const menuTriggerContainer = container.querySelector(
124
+ "[class$='topNavBarSmallViewportLayout__menuTriggerContainer']"
125
+ )
126
+ const brandContainer = container.querySelector(
127
+ "[class$='topNavBarSmallViewportLayout__brandContainer']"
128
+ )
129
+
130
+ expect(crumb).toBeInTheDocument()
131
+ expect(menuTriggerContainer).not.toBeInTheDocument()
132
+ expect(brandContainer).not.toBeInTheDocument()
133
+ })
134
+ })
135
+
136
+ afterAll(() => {
137
+ global.ResizeObserver = originalResizeObserver
138
+ })
139
+ })
@@ -164,13 +164,13 @@ type TopNavBarSmallViewportLayoutStyleProps = {
164
164
  }
165
165
 
166
166
  const propTypes: PropValidators<PropKeys> = {
167
- // Edit PropTypes in TopNabBarLayout/props.ts
167
+ // Edit PropTypes in TopNavBarLayout/props.ts
168
168
  ...commonPropTypes,
169
169
  ...smallViewportPropTypes
170
170
  }
171
171
 
172
172
  const allowedProps: AllowedPropKeys = [
173
- // Edit allowed props in TopNabBarLayout/props.ts
173
+ // Edit allowed props in TopNavBarLayout/props.ts
174
174
  ...commonAllowedProps,
175
175
  ...smallViewportAllowedProps
176
176
  ]