@instructure/ui-top-nav-bar 9.2.1-snapshot-0 → 9.2.1-snapshot-2

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 (40) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +2 -2
  3. package/es/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.js +15 -19
  4. package/es/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.js +17 -17
  5. package/es/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.js +46 -75
  6. package/es/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +13 -14
  7. package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +28 -38
  8. package/es/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.js +15 -14
  9. package/es/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.js +17 -27
  10. package/es/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.js +14 -4
  11. package/es/TopNavBar/__new-tests__/TopNavBar.test.js +15 -14
  12. package/lib/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.js +15 -19
  13. package/lib/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.js +17 -17
  14. package/lib/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.js +46 -75
  15. package/lib/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +13 -14
  16. package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +28 -38
  17. package/lib/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.js +15 -14
  18. package/lib/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.js +17 -27
  19. package/lib/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.js +14 -4
  20. package/lib/TopNavBar/__new-tests__/TopNavBar.test.js +15 -14
  21. package/package.json +32 -31
  22. package/src/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.tsx +22 -27
  23. package/src/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.tsx +25 -17
  24. package/src/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.tsx +54 -129
  25. package/src/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.tsx +20 -17
  26. package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.tsx +34 -56
  27. package/src/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.tsx +23 -13
  28. package/src/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.tsx +24 -45
  29. package/src/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.tsx +21 -7
  30. package/src/TopNavBar/__new-tests__/TopNavBar.test.tsx +23 -13
  31. package/tsconfig.build.tsbuildinfo +1 -1
  32. package/types/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.d.ts.map +1 -1
  33. package/types/TopNavBar/TopNavBarBreadcrumb/__new-tests__/TopNavBarBreadcrumb.test.d.ts.map +1 -1
  34. package/types/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.d.ts.map +1 -1
  35. package/types/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.d.ts.map +1 -1
  36. package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.d.ts.map +1 -1
  37. package/types/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.d.ts.map +1 -1
  38. package/types/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.d.ts.map +1 -1
  39. package/types/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.d.ts.map +1 -1
  40. package/types/TopNavBar/__new-tests__/TopNavBar.test.d.ts.map +1 -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.2.1-snapshot-0](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.2.1-snapshot-0) (2024-07-09)
6
+ ## [9.2.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.2.1-snapshot-2) (2024-07-10)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-top-nav-bar
9
9
 
package/README.md CHANGED
@@ -4,8 +4,8 @@ category: packages
4
4
 
5
5
  ## ui-top-nav-bar
6
6
 
7
- [![npm][npm]][npm-url] 
8
- [![MIT License][license-badge]][license] 
7
+ [![npm][npm]][npm-url]
8
+ [![MIT License][license-badge]][license]
9
9
  [![Code of Conduct][coc-badge]][coc]
10
10
 
11
11
  A UI component library made by Instructure Inc.
@@ -24,6 +24,7 @@
24
24
 
25
25
  import React from 'react';
26
26
  import { render, screen } from '@testing-library/react';
27
+ import { vi } from 'vitest';
27
28
  import '@testing-library/jest-dom';
28
29
  import { avatarExample, getActionItems, SmallViewportModeWrapper } from '../../utils/exampleHelpers';
29
30
  // eslint-disable-next-line no-restricted-imports
@@ -31,15 +32,17 @@ import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11y
31
32
  import { runAxeCheck } from '@instructure/ui-axe-check';
32
33
  import { TopNavBarActionItems } from '../index';
33
34
  import TopNavBarActionItemsExamples from '../__examples__/TopNavBarActionItems.examples';
34
- const originalResizeObserver = global.ResizeObserver;
35
35
  describe('<TopNavBarActionItems />', () => {
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
- }));
36
+ let consoleWarningMock;
37
+ let consoleErrorMock;
38
+ beforeEach(() => {
39
+ // Mocking console to prevent test output pollution and expect for messages
40
+ consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
41
+ consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
42
+ });
43
+ afterEach(() => {
44
+ consoleWarningMock.mockRestore();
45
+ consoleErrorMock.mockRestore();
43
46
  });
44
47
  it('should render', () => {
45
48
  const _render = render(getActionItems({
@@ -59,7 +62,7 @@ describe('<TopNavBarActionItems />', () => {
59
62
  });
60
63
  describe('elementRef prop should return a ref to the root element', () => {
61
64
  it('in desktop mode', () => {
62
- const elementRef = jest.fn();
65
+ const elementRef = vi.fn();
63
66
  const _render3 = render(getActionItems({
64
67
  actionItemsCount: 6,
65
68
  actionItemsProps: {
@@ -72,7 +75,7 @@ describe('<TopNavBarActionItems />', () => {
72
75
  expect(actionItems.tagName).toBe('UL');
73
76
  });
74
77
  it('in smallViewport mode', () => {
75
- const elementRef = jest.fn();
78
+ const elementRef = vi.fn();
76
79
  const _render4 = render( /*#__PURE__*/React.createElement(SmallViewportModeWrapper, null, getActionItems({
77
80
  actionItemsCount: 6,
78
81
  actionItemsProps: {
@@ -222,7 +225,6 @@ describe('<TopNavBarActionItems />', () => {
222
225
  });
223
226
  describe('item types:', () => {
224
227
  it('should not allow avatars', () => {
225
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
226
228
  render(getActionItems({
227
229
  actionItemsCount: 1,
228
230
  actionItemsItemProps: {
@@ -230,11 +232,9 @@ describe('<TopNavBarActionItems />', () => {
230
232
  }
231
233
  }));
232
234
  const expectedErrorMessage = 'Warning: Items in <TopNavBar.ActionItems> are not allowed to have avatars, please remove it from item with the id "Search".';
233
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
234
- consoleWarningSpy.mockRestore();
235
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
235
236
  });
236
237
  it('should render items without icons in smallViewport mode', () => {
237
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
238
238
  const _render10 = render( /*#__PURE__*/React.createElement(SmallViewportModeWrapper, null, getActionItems({
239
239
  actionItemsCount: 6,
240
240
  actionItemsItemProps: id => id === 'Search' ? {
@@ -248,8 +248,7 @@ describe('<TopNavBarActionItems />', () => {
248
248
  const expectedErrorMessage = 'Warning: Items in <TopNavBar.ActionItems> are required to have the `renderIcon` prop, because only the icons are displayed due to the lack of space. Please add an icon to the item with the id "Search".';
249
249
  expect(listItems.length).toEqual(5);
250
250
  expect(icons.length).toEqual(5);
251
- expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
252
- consoleErrorSpy.mockRestore();
251
+ expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
253
252
  });
254
253
  it('should be converted to icon variant in smallViewport mode', () => {
255
254
  const _render11 = render( /*#__PURE__*/React.createElement(SmallViewportModeWrapper, null, getActionItems({
@@ -290,7 +289,4 @@ describe('<TopNavBarActionItems />', () => {
290
289
  expect(axeCheck).toBe(true);
291
290
  });
292
291
  });
293
- afterAll(() => {
294
- global.ResizeObserver = originalResizeObserver;
295
- });
296
292
  });
@@ -25,6 +25,7 @@ var _Breadcrumb, _BaseExample, _BaseExample2, _BaseExample3, _BaseExample4;
25
25
 
26
26
  import React from 'react';
27
27
  import { fireEvent, render } from '@testing-library/react';
28
+ import { vi } from 'vitest';
28
29
  import '@testing-library/jest-dom';
29
30
 
30
31
  // eslint-disable-next-line no-restricted-imports
@@ -32,31 +33,20 @@ import { runAxeCheck } from '@instructure/ui-axe-check';
32
33
  import { TopNavBarBreadcrumb } from '../index';
33
34
  import { Breadcrumb } from '@instructure/ui-breadcrumb';
34
35
  import TopNavBarContext from '../../TopNavBarContext';
35
- let originalResizeObserver;
36
36
  let originalMatchMedia;
37
37
  beforeAll(() => {
38
- originalResizeObserver = global.ResizeObserver;
39
38
  originalMatchMedia = window.matchMedia;
40
- class MockResizeObserver {
41
- constructor() {
42
- this.observe = jest.fn();
43
- this.unobserve = jest.fn();
44
- this.disconnect = jest.fn();
45
- }
46
- }
47
- global.ResizeObserver = MockResizeObserver;
48
- window.matchMedia = jest.fn().mockImplementation(query => {
39
+ window.matchMedia = vi.fn().mockImplementation(query => {
49
40
  return {
50
41
  matches: false,
51
42
  media: query,
52
43
  onchange: null,
53
- addListener: jest.fn(),
54
- removeListener: jest.fn()
44
+ addListener: vi.fn(),
45
+ removeListener: vi.fn()
55
46
  };
56
47
  });
57
48
  });
58
49
  afterAll(() => {
59
- global.ResizeObserver = originalResizeObserver;
60
50
  window.matchMedia = originalMatchMedia;
61
51
  });
62
52
  const TEST_BREADCRUMB_LABEL = 'You are here:';
@@ -81,6 +71,17 @@ BaseExample.defaultProps = {
81
71
  onClick: () => {}
82
72
  };
83
73
  describe('<TopNavBarBreadcrumb />', () => {
74
+ let consoleWarningMock;
75
+ let consoleErrorMock;
76
+ beforeEach(() => {
77
+ // Mocking console to prevent test output pollution and expect for messages
78
+ consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
79
+ consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
80
+ });
81
+ afterEach(() => {
82
+ consoleWarningMock.mockRestore();
83
+ consoleErrorMock.mockRestore();
84
+ });
84
85
  it('should render', () => {
85
86
  const _render = render(_BaseExample || (_BaseExample = /*#__PURE__*/React.createElement(BaseExample, {
86
87
  inverseColor: true,
@@ -91,7 +92,6 @@ describe('<TopNavBarBreadcrumb />', () => {
91
92
  expect(element).toBeInTheDocument();
92
93
  });
93
94
  it('should warn if inverseColor is false', () => {
94
- const consoleMock = jest.spyOn(console, 'error').mockImplementation();
95
95
  const _render2 = render(_BaseExample2 || (_BaseExample2 = /*#__PURE__*/React.createElement(BaseExample, {
96
96
  inverseColor: false,
97
97
  layout: "desktop"
@@ -99,7 +99,7 @@ describe('<TopNavBarBreadcrumb />', () => {
99
99
  queryByLabelText = _render2.queryByLabelText;
100
100
  const element = queryByLabelText(TEST_BREADCRUMB_LABEL);
101
101
  expect(element).not.toBeInTheDocument();
102
- expect(consoleMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
102
+ expect(consoleErrorMock.mock.calls[0][0]).toEqual('Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.');
103
103
  });
104
104
  it('should render last but one crumb in smallViewPort mode', () => {
105
105
  const _render3 = render(_BaseExample3 || (_BaseExample3 = /*#__PURE__*/React.createElement(BaseExample, {
@@ -119,7 +119,7 @@ describe('<TopNavBarBreadcrumb />', () => {
119
119
  expect(page5).not.toBeInTheDocument();
120
120
  });
121
121
  it('should fire onClick', () => {
122
- const onClick = jest.fn();
122
+ const onClick = vi.fn();
123
123
  const _render4 = render( /*#__PURE__*/React.createElement(BaseExample, {
124
124
  inverseColor: true,
125
125
  layout: "desktop",
@@ -25,6 +25,7 @@ var _TopNavBarItem, _TopNavBarItem2, _TopNavBarItem3, _TopNavBarItem4, _TopNavBa
25
25
 
26
26
  import React from 'react';
27
27
  import { fireEvent, render, screen, waitFor } from '@testing-library/react';
28
+ import { vi } from 'vitest';
28
29
  import userEvent from '@testing-library/user-event';
29
30
  import '@testing-library/jest-dom';
30
31
 
@@ -39,6 +40,17 @@ import { avatarExample, SmallViewportModeWrapper, itemSubmenuExample, getCustomP
39
40
  const ITEM_TEXT = 'Menu Item';
40
41
  const variants = ['default', 'button', 'icon', 'avatar'];
41
42
  describe('<TopNavBarItem />', () => {
43
+ let consoleWarningMock;
44
+ let consoleErrorMock;
45
+ beforeEach(() => {
46
+ // Mocking console to prevent test output pollution and expect for messages
47
+ consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
48
+ consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
49
+ });
50
+ afterEach(() => {
51
+ consoleWarningMock.mockRestore();
52
+ consoleErrorMock.mockRestore();
53
+ });
42
54
  describe('variant prop', () => {
43
55
  // TODO convert to e2e
44
56
  // describe('should have "inverse" color focus ring', () => {
@@ -163,14 +175,12 @@ describe('<TopNavBarItem />', () => {
163
175
  });
164
176
  describe('with "icon" variant', () => {
165
177
  it('should throw error if no icon is provided', () => {
166
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
167
178
  render(_TopNavBarItem3 || (_TopNavBarItem3 = /*#__PURE__*/React.createElement(TopNavBarItem, {
168
179
  id: "item",
169
180
  variant: "icon"
170
181
  }, "Menu Item")));
171
182
  const expectedErrorMessage = 'The "renderIcon" prop is required for the `variant="icon"` type <TopNavBar.Item> components, but the item with id "item" is missing it.';
172
- expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
173
- consoleErrorSpy.mockRestore();
183
+ expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
174
184
  });
175
185
  it('should render the icon', () => {
176
186
  const _render3 = render(_TopNavBarItem4 || (_TopNavBarItem4 = /*#__PURE__*/React.createElement(TopNavBarItem, {
@@ -212,7 +222,6 @@ describe('<TopNavBarItem />', () => {
212
222
  // })
213
223
 
214
224
  it('should not allow the "renderAvatar" prop', () => {
215
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
216
225
  const _render5 = render(_TopNavBarItem6 || (_TopNavBarItem6 = /*#__PURE__*/React.createElement(TopNavBarItem, {
217
226
  id: "item",
218
227
  variant: "icon",
@@ -223,10 +232,9 @@ describe('<TopNavBarItem />', () => {
223
232
  const avatar = container.querySelector("[class$='inlineBlock-avatar']");
224
233
  const icon = container.querySelector('svg');
225
234
  const expectedErrorMessage = 'Warning: <TopNavBar.Item> components with icons cannot display avatars, so the "renderAvatar" config prop will be ignored for item with id "item".';
226
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
235
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
227
236
  expect(avatar).not.toBeInTheDocument();
228
237
  expect(icon).toBeVisible();
229
- consoleWarningSpy.mockRestore();
230
238
  });
231
239
 
232
240
  // TODO convert to e2e
@@ -248,7 +256,6 @@ describe('<TopNavBarItem />', () => {
248
256
  });
249
257
  describe('with "avatar" variant', () => {
250
258
  it('should throw error if no avatar is provided', () => {
251
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
252
259
  const _render6 = render(_TopNavBarItem7 || (_TopNavBarItem7 = /*#__PURE__*/React.createElement(TopNavBarItem, {
253
260
  id: "item",
254
261
  variant: "avatar"
@@ -256,12 +263,10 @@ describe('<TopNavBarItem />', () => {
256
263
  container = _render6.container;
257
264
  const avatar = container.querySelector("[class$='inlineBlock-avatar']");
258
265
  const expectedErrorMessage = `Warning: The "renderAvatar" config is required for the 'variant="avatar"' type <TopNavBar.Item> components, but received none for the item with id "item".`;
259
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
266
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
260
267
  expect(avatar).not.toBeInTheDocument();
261
- consoleWarningSpy.mockRestore();
262
268
  });
263
269
  it('should throw error if no "renderAvatar.avatarName" is provided', () => {
264
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
265
270
  const _render7 = render(
266
271
  /*#__PURE__*/
267
272
  // @ts-expect-error We are passing it incorrectly on purpose
@@ -273,9 +278,8 @@ describe('<TopNavBarItem />', () => {
273
278
  container = _render7.container;
274
279
  const avatar = container.querySelector("[class$='inlineBlock-avatar']");
275
280
  const expectedErrorMessage = `Warning: The "avatarName" prop is required for for <TopNavBar.Item> components with avatar, but the item with id "item" is missing it.`;
276
- expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
281
+ expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
277
282
  expect(avatar).not.toBeInTheDocument();
278
- consoleErrorSpy.mockRestore();
279
283
  });
280
284
  it('should render the avatar', () => {
281
285
  const _render8 = render(_TopNavBarItem8 || (_TopNavBarItem8 = /*#__PURE__*/React.createElement(TopNavBarItem, {
@@ -308,7 +312,6 @@ describe('<TopNavBarItem />', () => {
308
312
  // })
309
313
 
310
314
  it('should have either string type "children" or "avatarAlt"', () => {
311
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
312
315
  render( /*#__PURE__*/React.createElement(SmallViewportModeWrapper, null, /*#__PURE__*/React.createElement(TopNavBarItem, {
313
316
  id: "item",
314
317
  variant: "avatar",
@@ -318,8 +321,7 @@ describe('<TopNavBarItem />', () => {
318
321
  }
319
322
  }, _span || (_span = /*#__PURE__*/React.createElement("span", null, "Text")))));
320
323
  const expectedErrorMessage = 'Warning: Please supply a label for the avatar with either the "renderAvatar.avatarAlt" or the "children" (as string) prop. It is needed for screen reader support, but missing on the item with the id: "item".';
321
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
322
- consoleWarningSpy.mockRestore();
324
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
323
325
  });
324
326
  });
325
327
  });
@@ -377,7 +379,6 @@ describe('<TopNavBarItem />', () => {
377
379
  variants.forEach(variant => {
378
380
  const isDefaultVariant = variant === 'default';
379
381
  it(`should be${!isDefaultVariant ? ' not' : ''} allowed for "${variant}" variant items`, () => {
380
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
381
382
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
382
383
  id: "item",
383
384
  variant: variant,
@@ -391,34 +392,29 @@ describe('<TopNavBarItem />', () => {
391
392
  // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
392
393
 
393
394
  if (isDefaultVariant) {
394
- expect(consoleWarningSpy).not.toHaveBeenCalled();
395
+ expect(consoleWarningMock).not.toHaveBeenCalled();
395
396
  // expect(activeIndicatorStyle?.backgroundColor).to.equal('rgb(255, 255, 255)')
396
- consoleWarningSpy.mockRestore();
397
397
  } else {
398
398
  const expectedErrorMessage = `Warning: Only \`variant="default"\` <TopNavBar.Item> components can be set to active, but item with id "item" has variant: "${variant}".`;
399
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
399
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
400
400
  // expect(activeIndicatorStyle?.backgroundColor).to.equal('rgba(0, 0, 0, 0)')
401
-
402
- consoleWarningSpy.mockRestore();
403
401
  }
404
402
  });
405
403
  });
406
404
  it('should not be allowed with avatar + text items', () => {
407
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
408
405
  render(_TopNavBarItem9 || (_TopNavBarItem9 = /*#__PURE__*/React.createElement(TopNavBarItem, {
409
406
  id: "item",
410
407
  status: "active",
411
408
  renderAvatar: avatarExample
412
409
  }, "Menu Item")));
413
410
  const expectedErrorMessage = `Warning: <TopNavBar.Item> components with avatar cannot have "active" status, so the "active" status on the item with id "item" will be ignored.`;
414
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
411
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
415
412
 
416
413
  // TODO convert to e2e
417
414
  // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
418
415
  // expect(activeIndicatorStyle?.backgroundColor).to.equal(
419
416
  // 'rgba(0, 0, 0, 0)'
420
417
  // )
421
- consoleWarningSpy.mockRestore();
422
418
  });
423
419
  });
424
420
  describe('with "disabled" status', () => {
@@ -462,7 +458,6 @@ describe('<TopNavBarItem />', () => {
462
458
  });
463
459
  describe('renderSubmenu prop', () => {
464
460
  it('should not accept non-Drilldown elements', () => {
465
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
466
461
  const _render11 = render(_TopNavBarItem11 || (_TopNavBarItem11 = /*#__PURE__*/React.createElement(TopNavBarItem, {
467
462
  id: "item",
468
463
  renderSubmenu: /*#__PURE__*/React.createElement("div", null, "submenu")
@@ -470,8 +465,7 @@ describe('<TopNavBarItem />', () => {
470
465
  container = _render11.container;
471
466
  const submenuTrigger = container.querySelector("[class$='submenuTriggerContainer']");
472
467
  expect(submenuTrigger).not.toBeInTheDocument();
473
- expect(consoleErrorSpy).toHaveBeenCalled();
474
- consoleErrorSpy.mockRestore();
468
+ expect(consoleErrorMock).toHaveBeenCalled();
475
469
  });
476
470
  it('should render submenu', async () => {
477
471
  const _render12 = render(_TopNavBarItem12 || (_TopNavBarItem12 = /*#__PURE__*/React.createElement(TopNavBarItem, {
@@ -502,12 +496,11 @@ describe('<TopNavBarItem />', () => {
502
496
  });
503
497
  });
504
498
  it('should throw warning about controlled Drilldown', () => {
505
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
506
499
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
507
500
  id: "item",
508
501
  renderSubmenu: /*#__PURE__*/React.createElement(Drilldown, {
509
502
  rootPageId: "root",
510
- onToggle: jest.fn(),
503
+ onToggle: vi.fn(),
511
504
  show: true
512
505
  }, _Drilldown$Page || (_Drilldown$Page = /*#__PURE__*/React.createElement(Drilldown.Page, {
513
506
  id: "root"
@@ -517,11 +510,9 @@ describe('<TopNavBarItem />', () => {
517
510
  }, "Link One"))))
518
511
  }, "Menu Item"));
519
512
  const expectedErrorMessage = `Warning: TopNavBar.Item Drilldown submenus are controlled by the component. The "show" prop will be ignored on the submenu of the item with id: "item".`;
520
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
521
- consoleWarningSpy.mockRestore();
513
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
522
514
  });
523
515
  it('should throw warning when trigger is passed to Drilldown', () => {
524
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
525
516
  render(_TopNavBarItem13 || (_TopNavBarItem13 = /*#__PURE__*/React.createElement(TopNavBarItem, {
526
517
  id: "item",
527
518
  renderSubmenu: /*#__PURE__*/React.createElement(Drilldown, {
@@ -535,8 +526,7 @@ describe('<TopNavBarItem />', () => {
535
526
  }, "Link One")))
536
527
  }, "Menu Item")));
537
528
  const expectedErrorMessage = `Warning: TopNavBar.Item submenus have the item itself as their trigger. The "trigger" prop will be ignored on the Drilldown submenu of item with id: "item".`;
538
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
539
- consoleWarningSpy.mockRestore();
529
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
540
530
  });
541
531
  it('should open on ArrowDown', async () => {
542
532
  const _render13 = render(_TopNavBarItem14 || (_TopNavBarItem14 = /*#__PURE__*/React.createElement(TopNavBarItem, {
@@ -588,7 +578,6 @@ describe('<TopNavBarItem />', () => {
588
578
  expect(popoverContent).toBeInTheDocument();
589
579
  });
590
580
  it('should throw error when passed to item with submenu', () => {
591
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
592
581
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
593
582
  id: "item",
594
583
  renderSubmenu: itemSubmenuExample,
@@ -598,11 +587,9 @@ describe('<TopNavBarItem />', () => {
598
587
  expect(button).toHaveAttribute('aria-haspopup', 'menu');
599
588
  expect(button).toHaveAttribute('aria-expanded', 'false');
600
589
  const expectedErrorMessage = `Warning: TopNavBar.Items are not allowed to have both the "renderSubmenu" and "customPopoverConfig" props. For submenus, pass a Drilldown component via the "renderSubmenu" prop, and only use "customPopoverConfig" for custom features. Item with id: "item" will ignore the "customPopoverConfig" prop.`;
601
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
602
- consoleWarningSpy.mockRestore();
590
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
603
591
  });
604
592
  it('should throw warning when no content is passed', () => {
605
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
606
593
  const _render14 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
607
594
  id: "item",
608
595
  customPopoverConfig: getCustomPopoverConfig(false, {
@@ -613,11 +600,9 @@ describe('<TopNavBarItem />', () => {
613
600
  const customElementInitialPopover = container.querySelector("span[class$='-position']");
614
601
  expect(customElementInitialPopover).not.toBeInTheDocument();
615
602
  const expectedErrorMessage = `Warning: Pass the content of the custom Popover as "customPopoverConfig.children" for the item with id: "item".`;
616
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
617
- consoleWarningSpy.mockRestore();
603
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
618
604
  });
619
605
  it('should throw warning when renderTrigger is passed in the config', () => {
620
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
621
606
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
622
607
  id: "item",
623
608
  customPopoverConfig: getCustomPopoverConfig(false, {
@@ -626,8 +611,7 @@ describe('<TopNavBarItem />', () => {
626
611
  })
627
612
  }, "Menu Item"));
628
613
  const expectedErrorMessage = `Warning: TopNavBar.Item popovers have the item itself as their trigger. The "renderTrigger" prop will be ignored on the popover of item with id: "item".`;
629
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
630
- consoleWarningSpy.mockRestore();
614
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
631
615
  });
632
616
  describe('should not put aria-expanded on the popover trigger, just the button', () => {
633
617
  it('when popover `shouldContainFocus="true"`', async () => {
@@ -1021,7 +1005,6 @@ describe('<TopNavBarItem />', () => {
1021
1005
  });
1022
1006
  describe('throws warning', () => {
1023
1007
  it('when not passed to "avatar" variant', () => {
1024
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1025
1008
  const _render28 = render(_TopNavBarItem20 || (_TopNavBarItem20 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1026
1009
  id: "item",
1027
1010
  variant: "avatar"
@@ -1030,11 +1013,9 @@ describe('<TopNavBarItem />', () => {
1030
1013
  const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1031
1014
  expect(avatar).not.toBeInTheDocument();
1032
1015
  const expectedErrorMessage = `Warning: The "renderAvatar" config is required for the 'variant="avatar"' type <TopNavBar.Item> components, but received none for the item with id "item".`;
1033
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1034
- consoleWarningSpy.mockRestore();
1016
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1035
1017
  });
1036
1018
  it('when passed to item with "renderIcon"', () => {
1037
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1038
1019
  const _render29 = render(_TopNavBarItem21 || (_TopNavBarItem21 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1039
1020
  id: "item",
1040
1021
  renderIcon: IconSearchLine,
@@ -1044,11 +1025,9 @@ describe('<TopNavBarItem />', () => {
1044
1025
  const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1045
1026
  expect(avatar).not.toBeInTheDocument();
1046
1027
  const expectedErrorMessage = `Warning: <TopNavBar.Item> components with icons cannot display avatars, so the "renderAvatar" config prop will be ignored for item with id "item".`;
1047
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1048
- consoleWarningSpy.mockRestore();
1028
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1049
1029
  });
1050
1030
  it('when passed to item with "active" status', () => {
1051
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1052
1031
  const _render30 = render(_TopNavBarItem22 || (_TopNavBarItem22 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1053
1032
  id: "item",
1054
1033
  renderAvatar: avatarExample,
@@ -1058,7 +1037,7 @@ describe('<TopNavBarItem />', () => {
1058
1037
  const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1059
1038
  expect(avatar).toBeInTheDocument();
1060
1039
  const expectedErrorMessage = `Warning: <TopNavBar.Item> components with avatar cannot have "active" status, so the "active" status on the item with id "item" will be ignored.`;
1061
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1040
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1062
1041
 
1063
1042
  // TODO convert to e2e
1064
1043
  // topNavBarItem__container ::after
@@ -1066,11 +1045,8 @@ describe('<TopNavBarItem />', () => {
1066
1045
  // expect(activeIndicatorStyle?.backgroundColor).to.equal(
1067
1046
  // 'rgba(0, 0, 0, 0)'
1068
1047
  // )
1069
-
1070
- consoleWarningSpy.mockRestore();
1071
1048
  });
1072
1049
  it('when there is no string type "children" or "avatarAlt" passed', () => {
1073
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1074
1050
  const _render31 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1075
1051
  id: "item",
1076
1052
  renderAvatar: {
@@ -1082,8 +1058,7 @@ describe('<TopNavBarItem />', () => {
1082
1058
  const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1083
1059
  expect(avatar).toBeInTheDocument();
1084
1060
  const expectedErrorMessage = `Warning: Please supply a label for the avatar with either the "renderAvatar.avatarAlt" or the "children" (as string) prop. It is needed for screen reader support, but missing on the item with the id: "item".`;
1085
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1086
- consoleWarningSpy.mockRestore();
1061
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1087
1062
  });
1088
1063
  });
1089
1064
  });
@@ -1189,7 +1164,6 @@ describe('<TopNavBarItem />', () => {
1189
1164
  expect(button).toHaveAttribute('href', '/#TopNavBar');
1190
1165
  });
1191
1166
  it('should not be allowed for items with submenu', () => {
1192
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1193
1167
  const _render38 = render(_TopNavBarItem27 || (_TopNavBarItem27 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1194
1168
  id: "item",
1195
1169
  href: "/#TopNavBar",
@@ -1200,22 +1174,21 @@ describe('<TopNavBarItem />', () => {
1200
1174
  expect(button.tagName).toBe('BUTTON');
1201
1175
  expect(button).not.toHaveAttribute('href');
1202
1176
  const expectedErrorMessage = `Warning: TopNavBar.Items with submenus are not allowed to have 'href' property, but received href "/#TopNavBar" for item with the id: "item".`;
1203
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1204
- consoleWarningSpy.mockRestore();
1177
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1205
1178
  });
1206
1179
  });
1207
1180
  describe('onClick prop', () => {
1208
1181
  it('should render item as button', () => {
1209
1182
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1210
1183
  id: "item",
1211
- onClick: jest.fn()
1184
+ onClick: vi.fn()
1212
1185
  }, "Menu Item"));
1213
1186
  const button = screen.getByRole('button');
1214
1187
  expect(button).toBeInTheDocument();
1215
1188
  expect(button.tagName).toBe('BUTTON');
1216
1189
  });
1217
1190
  it('should fire onClick on click', () => {
1218
- const onClick = jest.fn();
1191
+ const onClick = vi.fn();
1219
1192
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1220
1193
  id: "item",
1221
1194
  onClick: onClick
@@ -1225,7 +1198,7 @@ describe('<TopNavBarItem />', () => {
1225
1198
  expect(onClick).toHaveBeenCalled();
1226
1199
  });
1227
1200
  it('should work combined with "href" prop', () => {
1228
- const onClick = jest.fn();
1201
+ const onClick = vi.fn();
1229
1202
  const _render39 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1230
1203
  id: "item",
1231
1204
  onClick: onClick,
@@ -1237,8 +1210,7 @@ describe('<TopNavBarItem />', () => {
1237
1210
  expect(button).toHaveAttribute('href', '/#TopNavBar');
1238
1211
  });
1239
1212
  it('should not be allowed for items with submenu', () => {
1240
- const onClick = jest.fn();
1241
- const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1213
+ const onClick = vi.fn();
1242
1214
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1243
1215
  id: "item",
1244
1216
  onClick: onClick,
@@ -1248,13 +1220,12 @@ describe('<TopNavBarItem />', () => {
1248
1220
  fireEvent.click(button);
1249
1221
  expect(onClick).not.toHaveBeenCalled();
1250
1222
  const expectedErrorMessage = `Warning: TopNavBar.Items with submenus are not allowed to have 'onClick' property, but received onClick for item with the id: "item".Use the \`onSubmenuToggle\` prop instead. OnClick:`;
1251
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1252
- consoleWarningSpy.mockRestore();
1223
+ expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1253
1224
  });
1254
1225
  });
1255
1226
  describe('onSubmenuToggle prop', () => {
1256
1227
  it('should be called on submenu toggle', () => {
1257
- const onSubmenuToggle = jest.fn();
1228
+ const onSubmenuToggle = vi.fn();
1258
1229
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1259
1230
  id: "item",
1260
1231
  onSubmenuToggle: onSubmenuToggle,
@@ -1277,8 +1248,8 @@ describe('<TopNavBarItem />', () => {
1277
1248
  });
1278
1249
  describe('other event handlers', () => {
1279
1250
  it('onMouseOver and onMouseOut should be called', () => {
1280
- const onMouseOver = jest.fn();
1281
- const onMouseOut = jest.fn();
1251
+ const onMouseOver = vi.fn();
1252
+ const onMouseOut = vi.fn();
1282
1253
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1283
1254
  id: "item",
1284
1255
  onMouseOver: onMouseOver,
@@ -1291,8 +1262,8 @@ describe('<TopNavBarItem />', () => {
1291
1262
  expect(onMouseOut).toHaveBeenCalled();
1292
1263
  });
1293
1264
  it('onFocus and onBlur should be called', () => {
1294
- const onFocus = jest.fn();
1295
- const onBlur = jest.fn();
1265
+ const onFocus = vi.fn();
1266
+ const onBlur = vi.fn();
1296
1267
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1297
1268
  id: "item",
1298
1269
  onFocus: onFocus,
@@ -1305,8 +1276,8 @@ describe('<TopNavBarItem />', () => {
1305
1276
  expect(onBlur).toHaveBeenCalled();
1306
1277
  });
1307
1278
  it('onKeyDown and onKeyUp should be called', () => {
1308
- const onKeyDown = jest.fn();
1309
- const onKeyUp = jest.fn();
1279
+ const onKeyDown = vi.fn();
1280
+ const onKeyUp = vi.fn();
1310
1281
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1311
1282
  id: "item",
1312
1283
  onKeyDown: onKeyDown,
@@ -1325,7 +1296,7 @@ describe('<TopNavBarItem />', () => {
1325
1296
  });
1326
1297
  describe('refs', () => {
1327
1298
  it('elementRef should return root element', () => {
1328
- const elementRef = jest.fn();
1299
+ const elementRef = vi.fn();
1329
1300
  const _render40 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1330
1301
  id: "item",
1331
1302
  elementRef: elementRef
@@ -1335,7 +1306,7 @@ describe('<TopNavBarItem />', () => {
1335
1306
  expect(elementRef).toHaveBeenCalledWith(topNavBarItem);
1336
1307
  });
1337
1308
  it('itemRef should return the button element', () => {
1338
- const itemRef = jest.fn();
1309
+ const itemRef = vi.fn();
1339
1310
  render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1340
1311
  id: "item",
1341
1312
  itemRef: itemRef