@instructure/ui-top-nav-bar 8.50.0 → 8.50.1-snapshot-0

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 (82) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.js +297 -0
  3. package/es/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.js +1374 -0
  4. package/es/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +318 -2
  5. package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +824 -2
  6. package/es/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.js +164 -0
  7. package/es/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.js +597 -0
  8. package/es/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.js +124 -0
  9. package/es/TopNavBar/__new-tests__/TopNavBar.test.js +107 -0
  10. package/lib/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.js +301 -0
  11. package/lib/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.js +1375 -0
  12. package/lib/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.js +316 -0
  13. package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.js +822 -1
  14. package/lib/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.js +167 -0
  15. package/lib/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.js +600 -0
  16. package/lib/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.js +127 -0
  17. package/lib/TopNavBar/__new-tests__/TopNavBar.test.js +108 -0
  18. package/package.json +32 -30
  19. package/src/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.tsx +376 -0
  20. package/src/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.tsx +1934 -0
  21. package/src/TopNavBar/TopNavBarLayout/DesktopLayout/__new-tests__/TopNavBarDesktopLayout.test.tsx +443 -2
  22. package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.tsx +1383 -2
  23. package/src/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.tsx +219 -0
  24. package/src/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.tsx +731 -0
  25. package/src/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.tsx +158 -0
  26. package/src/TopNavBar/__new-tests__/TopNavBar.test.tsx +128 -0
  27. package/tsconfig.build.json +2 -1
  28. package/tsconfig.build.tsbuildinfo +1 -1
  29. package/types/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.d.ts +2 -0
  30. package/types/TopNavBar/TopNavBarActionItems/__new-tests__/TopNavBarActionItems.test.d.ts.map +1 -0
  31. package/types/TopNavBar/TopNavBarBrand/TopNavBarBrandLocator.d.ts +1 -1
  32. package/types/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.d.ts +2 -0
  33. package/types/TopNavBar/TopNavBarItem/__new-tests__/TopNavBarItem.test.d.ts.map +1 -0
  34. package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/__new-tests__/TopNavBarSmallViewportLayout.test.d.ts.map +1 -1
  35. package/types/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.d.ts +2 -0
  36. package/types/TopNavBar/TopNavBarLayout/__new-tests__/TopNavBarLayout.test.d.ts.map +1 -0
  37. package/types/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.d.ts +2 -0
  38. package/types/TopNavBar/TopNavBarMenuItems/__new-tests__/TopNavBarMenuItems.test.d.ts.map +1 -0
  39. package/types/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.d.ts +2 -0
  40. package/types/TopNavBar/TopNavBarUser/__new-tests__/TopNavBarUser.test.d.ts.map +1 -0
  41. package/types/TopNavBar/__new-tests__/TopNavBar.test.d.ts +2 -0
  42. package/types/TopNavBar/__new-tests__/TopNavBar.test.d.ts.map +1 -0
  43. package/es/TopNavBar/TopNavBarActionItems/TopNavBarActionItemsLocator.js +0 -49
  44. package/es/TopNavBar/TopNavBarItem/TopNavBarItemLocator.js +0 -99
  45. package/es/TopNavBar/TopNavBarLayout/DesktopLayout/TopNavBarDesktopLayoutLocator.js +0 -68
  46. package/es/TopNavBar/TopNavBarLayout/SmallViewportLayout/TopNavBarSmallViewportLayoutLocator.js +0 -94
  47. package/es/TopNavBar/TopNavBarLayout/TopNavBarLayoutLocator.js +0 -38
  48. package/es/TopNavBar/TopNavBarLocator.js +0 -30
  49. package/es/TopNavBar/TopNavBarMenuItems/TopNavBarMenuItemsLocator.js +0 -51
  50. package/es/TopNavBar/TopNavBarUser/TopNavBarUserLocator.js +0 -31
  51. package/lib/TopNavBar/TopNavBarActionItems/TopNavBarActionItemsLocator.js +0 -55
  52. package/lib/TopNavBar/TopNavBarItem/TopNavBarItemLocator.js +0 -108
  53. package/lib/TopNavBar/TopNavBarLayout/DesktopLayout/TopNavBarDesktopLayoutLocator.js +0 -74
  54. package/lib/TopNavBar/TopNavBarLayout/SmallViewportLayout/TopNavBarSmallViewportLayoutLocator.js +0 -102
  55. package/lib/TopNavBar/TopNavBarLayout/TopNavBarLayoutLocator.js +0 -43
  56. package/lib/TopNavBar/TopNavBarLocator.js +0 -36
  57. package/lib/TopNavBar/TopNavBarMenuItems/TopNavBarMenuItemsLocator.js +0 -56
  58. package/lib/TopNavBar/TopNavBarUser/TopNavBarUserLocator.js +0 -36
  59. package/src/TopNavBar/TopNavBarActionItems/TopNavBarActionItemsLocator.ts +0 -53
  60. package/src/TopNavBar/TopNavBarItem/TopNavBarItemLocator.ts +0 -111
  61. package/src/TopNavBar/TopNavBarLayout/DesktopLayout/TopNavBarDesktopLayoutLocator.ts +0 -84
  62. package/src/TopNavBar/TopNavBarLayout/SmallViewportLayout/TopNavBarSmallViewportLayoutLocator.ts +0 -125
  63. package/src/TopNavBar/TopNavBarLayout/TopNavBarLayoutLocator.ts +0 -46
  64. package/src/TopNavBar/TopNavBarLocator.ts +0 -31
  65. package/src/TopNavBar/TopNavBarMenuItems/TopNavBarMenuItemsLocator.ts +0 -56
  66. package/src/TopNavBar/TopNavBarUser/TopNavBarUserLocator.ts +0 -32
  67. package/types/TopNavBar/TopNavBarActionItems/TopNavBarActionItemsLocator.d.ts +0 -2116
  68. package/types/TopNavBar/TopNavBarActionItems/TopNavBarActionItemsLocator.d.ts.map +0 -1
  69. package/types/TopNavBar/TopNavBarItem/TopNavBarItemLocator.d.ts +0 -642
  70. package/types/TopNavBar/TopNavBarItem/TopNavBarItemLocator.d.ts.map +0 -1
  71. package/types/TopNavBar/TopNavBarLayout/DesktopLayout/TopNavBarDesktopLayoutLocator.d.ts +0 -5737
  72. package/types/TopNavBar/TopNavBarLayout/DesktopLayout/TopNavBarDesktopLayoutLocator.d.ts.map +0 -1
  73. package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/TopNavBarSmallViewportLayoutLocator.d.ts +0 -4357
  74. package/types/TopNavBar/TopNavBarLayout/SmallViewportLayout/TopNavBarSmallViewportLayoutLocator.d.ts.map +0 -1
  75. package/types/TopNavBar/TopNavBarLayout/TopNavBarLayoutLocator.d.ts +0 -7
  76. package/types/TopNavBar/TopNavBarLayout/TopNavBarLayoutLocator.d.ts.map +0 -1
  77. package/types/TopNavBar/TopNavBarLocator.d.ts +0 -566
  78. package/types/TopNavBar/TopNavBarLocator.d.ts.map +0 -1
  79. package/types/TopNavBar/TopNavBarMenuItems/TopNavBarMenuItemsLocator.d.ts +0 -1351
  80. package/types/TopNavBar/TopNavBarMenuItems/TopNavBarMenuItemsLocator.d.ts.map +0 -1
  81. package/types/TopNavBar/TopNavBarUser/TopNavBarUserLocator.d.ts +0 -566
  82. package/types/TopNavBar/TopNavBarUser/TopNavBarUserLocator.d.ts.map +0 -1
@@ -0,0 +1,1374 @@
1
+ var _TopNavBarItem, _TopNavBarItem2, _TopNavBarItem3, _TopNavBarItem4, _TopNavBarItem5, _TopNavBarItem6, _TopNavBarItem7, _TopNavBarItem8, _span, _TopNavBarItem9, _TopNavBarItem10, _TopNavBarItem11, _TopNavBarItem12, _Drilldown$Page, _TopNavBarItem13, _TopNavBarItem14, _div, _TopNavBarItem15, _TopNavBarItem16, _TopNavBarItem17, _TopNavBarItem18, _TopNavBarItem19, _TopNavBarItem20, _TopNavBarItem21, _TopNavBarItem22, _div2, _TopNavBarItem23, _TopNavBarItem24, _SmallViewportModeWra, _SmallViewportModeWra2, _TopNavBarItem25, _TopNavBarItem26, _TopNavBarItem27, _TopNavBarItem28;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
28
+ import userEvent from '@testing-library/user-event';
29
+ import '@testing-library/jest-dom';
30
+
31
+ // eslint-disable-next-line no-restricted-imports
32
+ import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
33
+ import { runAxeCheck } from '@instructure/ui-axe-check';
34
+ import { IconSearchLine } from '@instructure/ui-icons';
35
+ import { Drilldown } from '@instructure/ui-drilldown';
36
+ import { TopNavBarItem } from '../index';
37
+ import TopNavBarItemExamples from '../__examples__/TopNavBarItem.examples';
38
+ import { avatarExample, SmallViewportModeWrapper, itemSubmenuExample, getCustomPopoverConfig } from '../../utils/exampleHelpers';
39
+ const ITEM_TEXT = 'Menu Item';
40
+ const variants = ['default', 'button', 'icon', 'avatar'];
41
+ describe('<TopNavBarItem />', () => {
42
+ describe('variant prop', () => {
43
+ // TODO convert to e2e
44
+ // describe('should have "inverse" color focus ring', () => {
45
+ // it.each(variants)(`with %s variant`, (variant) => {
46
+ // render(
47
+ // <TopNavBarItem
48
+ // id="item"
49
+ // variant={variant}
50
+ // {...(variant === 'icon' ? { renderIcon: IconSearchLine } : {})}
51
+ // {...(variant === 'avatar' ? { renderAvatar: avatarExample } : {})}
52
+ // >
53
+ // {ITEM_TEXT}
54
+ // </TopNavBarItem>
55
+ // )
56
+
57
+ // const item = screen.getByRole('button', { name: ITEM_TEXT })
58
+ // const itemPseudoStyle = getComputedStyle(item, '::before')
59
+ // const focusRingColor = itemPseudoStyle.getPropertyValue('border-color')
60
+
61
+ // expect(focusRingColor).to.equal('rgb(255, 255, 255)')
62
+ // })
63
+ // })
64
+
65
+ // TODO convert to e2e
66
+ // describe('should have "info" color focus ring in "inverseColor" mode', () => {
67
+ // variants.forEach((variant) => {
68
+ // it(`with ${variant} variant`, () => {
69
+ // render(
70
+ // <SmallViewportModeWrapper layout="desktop" inverseColor>
71
+ // <TopNavBarItem
72
+ // id="item"
73
+ // variant={variant}
74
+ // renderIcon={variant === 'icon' ? IconSearchLine : undefined}
75
+ // renderAvatar={variant === 'avatar' ? avatarExample : undefined}
76
+ // >
77
+ // Menu Item
78
+ // </TopNavBarItem>
79
+ // </SmallViewportModeWrapper>
80
+ // )
81
+ // const item = screen.getByRole('button', { name: ITEM_TEXT })
82
+ // const itemPseudoStyle = getComputedStyle(item, '::before')
83
+ // const focusRingColor = itemPseudoStyle.getPropertyValue('border-color')
84
+
85
+ // // expect(focusRingColor).toBe('rgb(3, 116, 181)')
86
+ // expect(focusRingColor).toBe('buttonface')
87
+
88
+ // })
89
+ // })
90
+ // })
91
+
92
+ describe('with "default" variant', () => {
93
+ it('should render the text', () => {
94
+ const _render = render(_TopNavBarItem || (_TopNavBarItem = /*#__PURE__*/React.createElement(TopNavBarItem, {
95
+ id: "item",
96
+ variant: "default"
97
+ }, ITEM_TEXT))),
98
+ container = _render.container;
99
+ const item = screen.getByRole('button');
100
+ const screenReaderContent = container.querySelector("[class$='screenReaderContent']");
101
+ expect(screenReaderContent).not.toBeInTheDocument();
102
+ expect(item).toHaveTextContent(ITEM_TEXT);
103
+ });
104
+
105
+ // TODO convert to e2e
106
+ // it('should have no background and border', () => {
107
+ // render(
108
+ // <TopNavBarItem id="item" variant="default">
109
+ // Menu Item
110
+ // </TopNavBarItem>
111
+ // )
112
+ // const component = await TopNavBarItemLocator.find()
113
+ // const background = await component.getButtonBackground()
114
+ // const borderWidth = await component.getButtonBorder()
115
+
116
+ // expect(background).to.equal('rgba(0, 0, 0, 0)')
117
+ // expect(borderWidth).to.equal('0px none rgb(255, 255, 255)')
118
+ // })
119
+ });
120
+
121
+ describe('with "button" variant', () => {
122
+ it('should render the text', () => {
123
+ const _render2 = render(_TopNavBarItem2 || (_TopNavBarItem2 = /*#__PURE__*/React.createElement(TopNavBarItem, {
124
+ id: "item",
125
+ variant: "button"
126
+ }, "Menu Item"))),
127
+ container = _render2.container;
128
+ const item = screen.getByRole('button');
129
+ const screenReaderContent = container.querySelector("[class$='screenReaderContent']");
130
+ expect(screenReaderContent).not.toBeInTheDocument();
131
+ expect(item).toHaveTextContent(ITEM_TEXT);
132
+ });
133
+
134
+ // TODO convert to e2e
135
+ // it('should have "secondary" color background and border', async () => {
136
+ // await mount(
137
+ // <TopNavBarItem id="item" variant="button">
138
+ // Menu Item
139
+ // </TopNavBarItem>
140
+ // )
141
+ // const component = await TopNavBarItemLocator.find()
142
+ // const background = await component.getButtonBackground()
143
+ // const borderWidth = await component.getButtonBorder()
144
+
145
+ // expect(background).to.equal('rgb(255, 255, 255)')
146
+ // expect(borderWidth).to.equal('1px solid rgb(219, 219, 219)')
147
+ // })
148
+
149
+ // it('should have "primary" color background and border in inverse mode', async () => {
150
+ // await mount(
151
+ // <SmallViewportModeWrapper layout="desktop" inverseColor>
152
+ // <TopNavBarItem id="item" variant="button">
153
+ // Menu Item
154
+ // </TopNavBarItem>
155
+ // </SmallViewportModeWrapper>
156
+ // )
157
+ // const component = await TopNavBarItemLocator.find()
158
+ // const background = await component.getButtonBackground()
159
+ // const borderWidth = await component.getButtonBorder()
160
+
161
+ // expect(background).to.equal('rgb(3, 116, 181)')
162
+ // expect(borderWidth).to.equal('1px solid rgb(2, 84, 131)')
163
+ // })
164
+ });
165
+
166
+ describe('with "icon" variant', () => {
167
+ it('should throw error if no icon is provided', () => {
168
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
169
+ render(_TopNavBarItem3 || (_TopNavBarItem3 = /*#__PURE__*/React.createElement(TopNavBarItem, {
170
+ id: "item",
171
+ variant: "icon"
172
+ }, "Menu Item")));
173
+ const expectedErrorMessage = 'The "renderIcon" prop is required for the `variant="icon"` type <TopNavBar.Item> components, but the item with id "item" is missing it.';
174
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
175
+ consoleErrorSpy.mockRestore();
176
+ });
177
+ it('should render the icon', () => {
178
+ const _render3 = render(_TopNavBarItem4 || (_TopNavBarItem4 = /*#__PURE__*/React.createElement(TopNavBarItem, {
179
+ id: "item",
180
+ variant: "icon",
181
+ renderIcon: IconSearchLine
182
+ }, "Menu Item"))),
183
+ container = _render3.container;
184
+ const icon = container.querySelector('svg');
185
+ expect(icon).toBeVisible();
186
+ expect(icon).toHaveAttribute('name', 'IconSearch');
187
+ });
188
+ it('should render the text in a screen reader label', () => {
189
+ const _render4 = render(_TopNavBarItem5 || (_TopNavBarItem5 = /*#__PURE__*/React.createElement(TopNavBarItem, {
190
+ id: "item",
191
+ variant: "icon",
192
+ renderIcon: IconSearchLine
193
+ }, ITEM_TEXT))),
194
+ container = _render4.container;
195
+ const content = container.querySelector("[class*='topNavBarItem__content']");
196
+ const screenReaderContent = container.querySelector("[class$='screenReaderContent']");
197
+ expect(content).not.toBeInTheDocument();
198
+ expect(screenReaderContent).toHaveTextContent(ITEM_TEXT);
199
+ });
200
+
201
+ // TODO convert to e2e
202
+ // it('should have no background and border', async () => {
203
+ // await mount(
204
+ // <TopNavBarItem id="item" variant="icon" renderIcon={IconSearchLine}>
205
+ // Menu Item
206
+ // </TopNavBarItem>
207
+ // )
208
+ // const component = await TopNavBarItemLocator.find()
209
+ // const background = await component.getButtonBackground()
210
+ // const borderWidth = await component.getButtonBorder()
211
+
212
+ // expect(background).to.equal('rgba(0, 0, 0, 0)')
213
+ // expect(borderWidth).to.equal('0px none rgb(255, 255, 255)')
214
+ // })
215
+
216
+ it('should not allow the "renderAvatar" prop', () => {
217
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
218
+ const _render5 = render(_TopNavBarItem6 || (_TopNavBarItem6 = /*#__PURE__*/React.createElement(TopNavBarItem, {
219
+ id: "item",
220
+ variant: "icon",
221
+ renderIcon: IconSearchLine,
222
+ renderAvatar: avatarExample
223
+ }, "Menu Item"))),
224
+ container = _render5.container;
225
+ const avatar = container.querySelector("[class$='inlineBlock-avatar']");
226
+ const icon = container.querySelector('svg');
227
+ const expectedErrorMessage = 'Warning: <TopNavBar.Item> components with icons cannot display avatars, so the "renderAvatar" config prop will be ignored for item with id "item".';
228
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
229
+ expect(avatar).not.toBeInTheDocument();
230
+ expect(icon).toBeVisible();
231
+ consoleWarningSpy.mockRestore();
232
+ });
233
+
234
+ // TODO convert to e2e
235
+ // it('should have at least 42px size button in small viewport mode', async () => {
236
+ // await mount(
237
+ // <SmallViewportModeWrapper>
238
+ // <TopNavBarItem id="item" variant="icon" renderIcon={IconSearchLine}>
239
+ // Menu Item
240
+ // </TopNavBarItem>
241
+ // </SmallViewportModeWrapper>
242
+ // )
243
+ // const component = await TopNavBarItemLocator.find()
244
+ // const button = await component.findButton()
245
+ // const buttonStyle = getComputedStyle(button.getDOMNode())
246
+
247
+ // expect(parseInt(buttonStyle.width, 10)).to.be.greaterThanOrEqual(42)
248
+ // expect(parseInt(buttonStyle.height, 10)).to.be.greaterThanOrEqual(42)
249
+ // })
250
+ });
251
+
252
+ describe('with "avatar" variant', () => {
253
+ it('should throw error if no avatar is provided', () => {
254
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
255
+ const _render6 = render(_TopNavBarItem7 || (_TopNavBarItem7 = /*#__PURE__*/React.createElement(TopNavBarItem, {
256
+ id: "item",
257
+ variant: "avatar"
258
+ }, "Menu Item"))),
259
+ container = _render6.container;
260
+ const avatar = container.querySelector("[class$='inlineBlock-avatar']");
261
+ 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".`;
262
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
263
+ expect(avatar).not.toBeInTheDocument();
264
+ consoleWarningSpy.mockRestore();
265
+ });
266
+ it('should throw error if no "renderAvatar.avatarName" is provided', () => {
267
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
268
+ const _render7 = render(
269
+ /*#__PURE__*/
270
+ // @ts-expect-error We are passing it incorrectly on purpose
271
+ React.createElement(TopNavBarItem, {
272
+ id: "item",
273
+ variant: "avatar",
274
+ renderAvatar: {}
275
+ }, "Menu Item")),
276
+ container = _render7.container;
277
+ const avatar = container.querySelector("[class$='inlineBlock-avatar']");
278
+ const expectedErrorMessage = `Warning: The "avatarName" prop is required for for <TopNavBar.Item> components with avatar, but the item with id "item" is missing it.`;
279
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
280
+ expect(avatar).not.toBeInTheDocument();
281
+ consoleErrorSpy.mockRestore();
282
+ });
283
+ it('should render the avatar', () => {
284
+ const _render8 = render(_TopNavBarItem8 || (_TopNavBarItem8 = /*#__PURE__*/React.createElement(TopNavBarItem, {
285
+ id: "item",
286
+ variant: "avatar",
287
+ renderAvatar: avatarExample
288
+ }, "Menu Item"))),
289
+ container = _render8.container;
290
+ const avatar = container.querySelector("[class$='inlineBlock-avatar']");
291
+ expect(avatar).toBeVisible();
292
+ });
293
+
294
+ // TODO convert to e2e
295
+ // it('should have no background and border', async () => {
296
+ // await mount(
297
+ // <TopNavBarItem
298
+ // id="item"
299
+ // variant="avatar"
300
+ // renderAvatar={avatarExample}
301
+ // >
302
+ // Menu Item
303
+ // </TopNavBarItem>
304
+ // )
305
+ // const component = await TopNavBarItemLocator.find()
306
+ // const background = await component.getButtonBackground()
307
+ // const borderWidth = await component.getButtonBorder()
308
+
309
+ // expect(background).to.equal('rgba(0, 0, 0, 0)')
310
+ // expect(borderWidth).to.equal('0px none rgb(255, 255, 255)')
311
+ // })
312
+
313
+ it('should have either string type "children" or "avatarAlt"', () => {
314
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
315
+ render( /*#__PURE__*/React.createElement(SmallViewportModeWrapper, null, /*#__PURE__*/React.createElement(TopNavBarItem, {
316
+ id: "item",
317
+ variant: "avatar",
318
+ renderAvatar: {
319
+ ...avatarExample,
320
+ avatarAlt: void 0
321
+ }
322
+ }, _span || (_span = /*#__PURE__*/React.createElement("span", null, "Text")))));
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".';
324
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
325
+ consoleWarningSpy.mockRestore();
326
+ });
327
+ });
328
+ });
329
+ describe('status prop', () => {
330
+ // TODO convert to e2e
331
+ // describe('with "default" status', () => {
332
+ // it('should have no underline', () => {
333
+ // render(
334
+ // <TopNavBarItem id="item" status="default">
335
+ // Menu Item
336
+ // </TopNavBarItem>
337
+ // )
338
+ // const component = await TopNavBarItemLocator.find()
339
+ // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
340
+ // // class$="-topNavBarItem__container" ::after
341
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal(
342
+ // 'rgba(0, 0, 0, 0)'
343
+ // )
344
+ // })
345
+ // })
346
+
347
+ describe('with "active" status', () => {
348
+ // TODO convert to e2e
349
+ // it('should be indicated with "inverse" color underline', async () => {
350
+ // await mount(
351
+ // <TopNavBarItem id="item" status="active">
352
+ // Menu Item
353
+ // </TopNavBarItem>
354
+ // )
355
+ // const component = await TopNavBarItemLocator.find()
356
+ // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
357
+
358
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal(
359
+ // 'rgb(255, 255, 255)'
360
+ // )
361
+ // })
362
+
363
+ // TODO convert to e2e
364
+ // it('should be indicated with "text" color underline in "inverseColor" mode', async () => {
365
+ // await mount(
366
+ // <SmallViewportModeWrapper layout="desktop" inverseColor>
367
+ // <TopNavBarItem id="item" status="active">
368
+ // Menu Item
369
+ // </TopNavBarItem>
370
+ // </SmallViewportModeWrapper>
371
+ // )
372
+ // const component = await TopNavBarItemLocator.find()
373
+ // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
374
+
375
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal(
376
+ // 'rgb(45, 59, 69)'
377
+ // )
378
+ // })
379
+
380
+ variants.forEach(variant => {
381
+ const isDefaultVariant = variant === 'default';
382
+ it(`should be${!isDefaultVariant ? ' not' : ''} allowed for "${variant}" variant items`, () => {
383
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
384
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
385
+ id: "item",
386
+ variant: variant,
387
+ status: "active",
388
+ renderIcon: variant === 'icon' ? IconSearchLine : void 0,
389
+ renderAvatar: variant === 'avatar' ? avatarExample : void 0
390
+ }, "Menu Item"));
391
+
392
+ // TODO convert to e2e
393
+ // class$="-topNavBarItem__container" ::after
394
+ // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
395
+
396
+ if (isDefaultVariant) {
397
+ expect(consoleWarningSpy).not.toHaveBeenCalled();
398
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal('rgb(255, 255, 255)')
399
+ consoleWarningSpy.mockRestore();
400
+ } else {
401
+ const expectedErrorMessage = `Warning: Only \`variant="default"\` <TopNavBar.Item> components can be set to active, but item with id "item" has variant: "${variant}".`;
402
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
403
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal('rgba(0, 0, 0, 0)')
404
+
405
+ consoleWarningSpy.mockRestore();
406
+ }
407
+ });
408
+ });
409
+ it('should not be allowed with avatar + text items', () => {
410
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
411
+ render(_TopNavBarItem9 || (_TopNavBarItem9 = /*#__PURE__*/React.createElement(TopNavBarItem, {
412
+ id: "item",
413
+ status: "active",
414
+ renderAvatar: avatarExample
415
+ }, "Menu Item")));
416
+ 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.`;
417
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
418
+
419
+ // TODO convert to e2e
420
+ // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
421
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal(
422
+ // 'rgba(0, 0, 0, 0)'
423
+ // )
424
+ consoleWarningSpy.mockRestore();
425
+ });
426
+ });
427
+ describe('with "disabled" status', () => {
428
+ variants.forEach(variant => {
429
+ it(`should be set to disabled for "${variant}" variant items`, () => {
430
+ const _render9 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
431
+ id: "item",
432
+ variant: variant,
433
+ status: "disabled",
434
+ renderIcon: variant === 'icon' ? IconSearchLine : void 0,
435
+ renderAvatar: variant === 'avatar' ? avatarExample : void 0
436
+ }, "Menu Item")),
437
+ container = _render9.container;
438
+ const item = screen.getByRole('button');
439
+ const baseButtonContent = container.querySelector("[class$='baseButton__content']");
440
+ const baseButtonContentStyle = getComputedStyle(baseButtonContent);
441
+ expect(item).toBeDisabled();
442
+ expect(item).toHaveAttribute('aria-disabled', 'true');
443
+ expect(baseButtonContentStyle.opacity).toBe('0.5');
444
+ });
445
+ });
446
+ it('should disable submenus too', async () => {
447
+ const _render10 = render(_TopNavBarItem10 || (_TopNavBarItem10 = /*#__PURE__*/React.createElement(TopNavBarItem, {
448
+ id: "item",
449
+ status: "disabled",
450
+ renderSubmenu: itemSubmenuExample
451
+ }, "Menu Item"))),
452
+ container = _render10.container;
453
+ const item = screen.getByRole('button');
454
+ const submenuTrigger = container.querySelector("[class$='submenuTriggerContainer']");
455
+ expect(item).toBeDisabled();
456
+ expect(item).toHaveAttribute('aria-disabled', 'true');
457
+ expect(submenuTrigger).toHaveAttribute('disabled');
458
+ expect(submenuTrigger).toHaveAttribute('aria-disabled', 'true');
459
+ userEvent.click(item);
460
+ await waitFor(() => {
461
+ expect(item).toBeVisible();
462
+ });
463
+ });
464
+ });
465
+ });
466
+ describe('renderSubmenu prop', () => {
467
+ it('should not accept non-Drilldown elements', () => {
468
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
469
+ const _render11 = render(_TopNavBarItem11 || (_TopNavBarItem11 = /*#__PURE__*/React.createElement(TopNavBarItem, {
470
+ id: "item",
471
+ renderSubmenu: /*#__PURE__*/React.createElement("div", null, "submenu")
472
+ }, "Menu Item"))),
473
+ container = _render11.container;
474
+ const submenuTrigger = container.querySelector("[class$='submenuTriggerContainer']");
475
+ expect(submenuTrigger).not.toBeInTheDocument();
476
+ expect(consoleErrorSpy).toHaveBeenCalled();
477
+ consoleErrorSpy.mockRestore();
478
+ });
479
+ it('should render submenu', async () => {
480
+ const _render12 = render(_TopNavBarItem12 || (_TopNavBarItem12 = /*#__PURE__*/React.createElement(TopNavBarItem, {
481
+ id: "item",
482
+ renderSubmenu: itemSubmenuExample
483
+ }, "Menu Item"))),
484
+ container = _render12.container,
485
+ findAllByRole = _render12.findAllByRole;
486
+ const customElementInitial = container.querySelector("span[class$='-position']");
487
+ expect(customElementInitial).toBeInTheDocument();
488
+ expect(customElementInitial).not.toHaveAttribute('data-cid', expect.stringContaining('Drilldown'));
489
+ const button = container.querySelector("[class$='inlineBlock-baseButton']");
490
+ expect(button).toHaveAttribute('aria-haspopup', 'menu');
491
+ expect(button).toHaveAttribute('aria-expanded', 'false');
492
+ userEvent.click(button);
493
+ await waitFor(() => {
494
+ expect(button).toHaveAttribute('aria-haspopup', 'menu');
495
+ expect(button).toHaveAttribute('aria-expanded', 'true');
496
+ const customElementDrilldown = container.querySelector("span[class$='-position']");
497
+ expect(customElementDrilldown).toBeInTheDocument();
498
+ expect(customElementDrilldown).toHaveAttribute('data-cid', expect.stringContaining('Drilldown'));
499
+ });
500
+ const options = await findAllByRole('link');
501
+ expect(options).toHaveLength(3);
502
+ options.forEach(option => {
503
+ expect(option).toHaveAttribute('id', expect.stringContaining('linkExampleOption'));
504
+ expect(option).toBeVisible();
505
+ });
506
+ });
507
+ it('should throw warning about controlled Drilldown', () => {
508
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
509
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
510
+ id: "item",
511
+ renderSubmenu: /*#__PURE__*/React.createElement(Drilldown, {
512
+ rootPageId: "root",
513
+ onToggle: jest.fn(),
514
+ show: true
515
+ }, _Drilldown$Page || (_Drilldown$Page = /*#__PURE__*/React.createElement(Drilldown.Page, {
516
+ id: "root"
517
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
518
+ id: "linkExampleOption1",
519
+ href: "/#One"
520
+ }, "Link One"))))
521
+ }, "Menu Item"));
522
+ 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".`;
523
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
524
+ consoleWarningSpy.mockRestore();
525
+ });
526
+ it('should throw warning when trigger is passed to Drilldown', () => {
527
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
528
+ render(_TopNavBarItem13 || (_TopNavBarItem13 = /*#__PURE__*/React.createElement(TopNavBarItem, {
529
+ id: "item",
530
+ renderSubmenu: /*#__PURE__*/React.createElement(Drilldown, {
531
+ rootPageId: "root",
532
+ trigger: /*#__PURE__*/React.createElement("div", null, "trigger")
533
+ }, /*#__PURE__*/React.createElement(Drilldown.Page, {
534
+ id: "root"
535
+ }, /*#__PURE__*/React.createElement(Drilldown.Option, {
536
+ id: "linkExampleOption1",
537
+ href: "/#One"
538
+ }, "Link One")))
539
+ }, "Menu Item")));
540
+ 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".`;
541
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
542
+ consoleWarningSpy.mockRestore();
543
+ });
544
+ it('should open on ArrowDown', async () => {
545
+ const _render13 = render(_TopNavBarItem14 || (_TopNavBarItem14 = /*#__PURE__*/React.createElement(TopNavBarItem, {
546
+ id: "item",
547
+ renderSubmenu: itemSubmenuExample
548
+ }, "Menu Item"))),
549
+ container = _render13.container,
550
+ findAllByRole = _render13.findAllByRole;
551
+ const customElementInitial = container.querySelector("span[class$='-position']");
552
+ expect(customElementInitial).toBeInTheDocument();
553
+ expect(customElementInitial).not.toHaveAttribute('data-cid', expect.stringContaining('Drilldown'));
554
+ const button = container.querySelector("[class$='inlineBlock-baseButton']");
555
+ expect(button).toHaveAttribute('aria-haspopup', 'menu');
556
+ expect(button).toHaveAttribute('aria-expanded', 'false');
557
+ userEvent.type(button, '{arrowdown}');
558
+ await waitFor(() => {
559
+ expect(button).toHaveAttribute('aria-haspopup', 'menu');
560
+ expect(button).toHaveAttribute('aria-expanded', 'true');
561
+ const customElementDrilldown = container.querySelector("span[class$='-position']");
562
+ expect(customElementDrilldown).toBeInTheDocument();
563
+ expect(customElementDrilldown).toHaveAttribute('data-cid', expect.stringContaining('Drilldown'));
564
+ });
565
+ const options = await findAllByRole('link');
566
+ expect(options).toHaveLength(3);
567
+ options.forEach(option => {
568
+ expect(option).toHaveAttribute('id', expect.stringContaining('linkExampleOption'));
569
+ expect(option).toBeVisible();
570
+ });
571
+ });
572
+ });
573
+ describe('customPopoverConfig prop', () => {
574
+ it('should render popover', async () => {
575
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
576
+ id: "item",
577
+ customPopoverConfig: getCustomPopoverConfig(false, {
578
+ isShowingContent: void 0,
579
+ on: 'click'
580
+ })
581
+ }, "Menu Item"));
582
+ const button = screen.getByRole('button');
583
+ expect(button).toHaveAttribute('aria-haspopup', 'true');
584
+ expect(button).toHaveAttribute('aria-expanded', 'false');
585
+ userEvent.click(button);
586
+ await waitFor(() => {
587
+ expect(button).toHaveAttribute('aria-haspopup', 'true');
588
+ expect(button).toHaveAttribute('aria-expanded', 'true');
589
+ });
590
+ const popoverContent = screen.getByText('dialog content');
591
+ expect(popoverContent).toBeInTheDocument();
592
+ });
593
+ it('should throw error when passed to item with submenu', () => {
594
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
595
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
596
+ id: "item",
597
+ renderSubmenu: itemSubmenuExample,
598
+ customPopoverConfig: getCustomPopoverConfig()
599
+ }, "Menu Item"));
600
+ const button = screen.getByRole('button');
601
+ expect(button).toHaveAttribute('aria-haspopup', 'menu');
602
+ expect(button).toHaveAttribute('aria-expanded', 'false');
603
+ 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.`;
604
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
605
+ consoleWarningSpy.mockRestore();
606
+ });
607
+ it('should throw warning when no content is passed', () => {
608
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
609
+ const _render14 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
610
+ id: "item",
611
+ customPopoverConfig: getCustomPopoverConfig(false, {
612
+ children: null
613
+ })
614
+ }, "Menu Item")),
615
+ container = _render14.container;
616
+ const customElementInitialPopover = container.querySelector("span[class$='-position']");
617
+ expect(customElementInitialPopover).not.toBeInTheDocument();
618
+ const expectedErrorMessage = `Warning: Pass the content of the custom Popover as "customPopoverConfig.children" for the item with id: "item".`;
619
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
620
+ consoleWarningSpy.mockRestore();
621
+ });
622
+ it('should throw warning when renderTrigger is passed in the config', () => {
623
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
624
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
625
+ id: "item",
626
+ customPopoverConfig: getCustomPopoverConfig(false, {
627
+ // @ts-expect-error Intentionally wrong
628
+ renderTrigger: _div || (_div = /*#__PURE__*/React.createElement("div", null, "trigger"))
629
+ })
630
+ }, "Menu Item"));
631
+ 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".`;
632
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
633
+ consoleWarningSpy.mockRestore();
634
+ });
635
+ describe('should not put aria-expanded on the popover trigger, just the button', () => {
636
+ it('when popover `shouldContainFocus="true"`', async () => {
637
+ const _render15 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
638
+ id: "item",
639
+ customPopoverConfig: getCustomPopoverConfig(false, {
640
+ shouldContainFocus: true,
641
+ isShowingContent: void 0,
642
+ on: 'click'
643
+ })
644
+ }, "Menu Item")),
645
+ container = _render15.container;
646
+ const customElementInitial = container.querySelector("span[class$='-position']");
647
+ expect(customElementInitial).toBeInTheDocument();
648
+ expect(customElementInitial).not.toHaveAttribute('data-cid', expect.stringContaining('Popover'));
649
+ const button = screen.getByRole('button');
650
+ expect(button).toHaveAttribute('aria-haspopup', 'true');
651
+ expect(button).toHaveAttribute('aria-expanded', 'false');
652
+ const popoverTrigger = container.querySelector("div[class$='submenuTriggerContainer']");
653
+ expect(popoverTrigger).toHaveAttribute('data-popover-trigger', 'true');
654
+ expect(popoverTrigger).not.toHaveAttribute('aria-expanded');
655
+ userEvent.click(button);
656
+ await waitFor(() => {
657
+ expect(button).toHaveAttribute('aria-haspopup', 'true');
658
+ expect(button).toHaveAttribute('aria-expanded', 'true');
659
+ const customElementPopover = container.querySelector("span[class$='-position']");
660
+ expect(customElementPopover).toBeInTheDocument();
661
+ expect(customElementPopover).toHaveAttribute('data-cid', expect.stringContaining('Popover'));
662
+ const popoverTriggerActive = container.querySelector("div[class$='submenuTriggerContainer']");
663
+ expect(popoverTriggerActive).not.toHaveAttribute('aria-expanded');
664
+ const popoverContent = screen.getByText('dialog content');
665
+ expect(popoverContent).toBeInTheDocument();
666
+ });
667
+ });
668
+ it('when popover `shouldContainFocus="false"`', async () => {
669
+ const _render16 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
670
+ id: "item",
671
+ customPopoverConfig: getCustomPopoverConfig(false, {
672
+ shouldContainFocus: false,
673
+ isShowingContent: void 0,
674
+ on: 'click'
675
+ })
676
+ }, "Menu Item")),
677
+ container = _render16.container;
678
+ const customElementInitial = container.querySelector("span[class$='-position']");
679
+ expect(customElementInitial).toBeInTheDocument();
680
+ expect(customElementInitial).not.toHaveAttribute('data-cid', expect.stringContaining('Popover'));
681
+ const button = screen.getByRole('button');
682
+ expect(button).toHaveAttribute('aria-haspopup', 'true');
683
+ expect(button).toHaveAttribute('aria-expanded', 'false');
684
+ const popoverTrigger = container.querySelector("div[class$='submenuTriggerContainer']");
685
+ expect(popoverTrigger).toHaveAttribute('data-popover-trigger', 'true');
686
+ expect(popoverTrigger).not.toHaveAttribute('aria-expanded');
687
+ userEvent.click(button);
688
+ await waitFor(() => {
689
+ expect(button).toHaveAttribute('aria-haspopup', 'true');
690
+ expect(button).toHaveAttribute('aria-expanded', 'true');
691
+ const customElementPopover = container.querySelector("span[class$='-position']");
692
+ expect(customElementPopover).toBeInTheDocument();
693
+ expect(customElementPopover).toHaveAttribute('data-cid', expect.stringContaining('Popover'));
694
+ const popoverTriggerActive = container.querySelector("div[class$='submenuTriggerContainer']");
695
+ expect(popoverTriggerActive).not.toHaveAttribute('aria-expanded');
696
+ const popoverContent = screen.getByText('dialog content');
697
+ expect(popoverContent).toBeInTheDocument();
698
+ });
699
+ });
700
+ });
701
+ it('should open on ArrowDown', async () => {
702
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
703
+ id: "item",
704
+ customPopoverConfig: getCustomPopoverConfig(false, {
705
+ isShowingContent: void 0,
706
+ on: 'click'
707
+ })
708
+ }, "Menu Item"));
709
+ const popoverContentInitial = screen.queryByText('dialog content');
710
+ expect(popoverContentInitial).not.toBeInTheDocument();
711
+ const button = screen.getByRole('button');
712
+ userEvent.type(button, '{arrowdown}');
713
+ await waitFor(() => {
714
+ const popoverContentActive = screen.getByText('dialog content');
715
+ expect(popoverContentActive).toBeInTheDocument();
716
+ });
717
+ });
718
+ it('should work controlled too', async () => {
719
+ class ControlledExample extends React.Component {
720
+ constructor(...args) {
721
+ super(...args);
722
+ this.state = {
723
+ isPopoverOpen: false
724
+ };
725
+ }
726
+ render() {
727
+ return /*#__PURE__*/React.createElement(TopNavBarItem, {
728
+ id: "item",
729
+ customPopoverConfig: getCustomPopoverConfig(false, {
730
+ isShowingContent: this.state.isPopoverOpen,
731
+ on: 'click',
732
+ onShowContent: () => {
733
+ this.setState({
734
+ isPopoverOpen: true
735
+ });
736
+ },
737
+ onHideContent: () => {
738
+ this.setState({
739
+ isPopoverOpen: false
740
+ });
741
+ }
742
+ })
743
+ }, "Menu Item");
744
+ }
745
+ }
746
+ ControlledExample.displayName = "ControlledExample";
747
+ render( /*#__PURE__*/React.createElement(ControlledExample, null));
748
+ const popoverContentInitial = screen.queryByText('dialog content');
749
+ const button = screen.getByRole('button');
750
+ expect(popoverContentInitial).not.toBeInTheDocument();
751
+ userEvent.type(button, '{arrowdown}');
752
+ await waitFor(() => {
753
+ const popoverContentActive = screen.getByText('dialog content');
754
+ expect(popoverContentActive).toBeInTheDocument();
755
+ });
756
+ userEvent.click(button);
757
+ await waitFor(() => {
758
+ const popoverContentInactive = screen.queryByText('dialog content');
759
+ expect(popoverContentInactive).toBeVisible();
760
+ });
761
+ });
762
+ });
763
+ describe('showSubmenuChevron prop', () => {
764
+ it('should not show when no submenu or popover', () => {
765
+ const _render17 = render(_TopNavBarItem15 || (_TopNavBarItem15 = /*#__PURE__*/React.createElement(TopNavBarItem, {
766
+ id: "item"
767
+ }, "Menu Item"))),
768
+ container = _render17.container;
769
+ const chevron = container.querySelector("svg[class$='inlineSVG-svgIcon']");
770
+ expect(chevron).not.toBeInTheDocument();
771
+ });
772
+ describe('when true (by default), should show chevron icon', () => {
773
+ it('next to items with submenu', async () => {
774
+ const _render18 = render(_TopNavBarItem16 || (_TopNavBarItem16 = /*#__PURE__*/React.createElement(TopNavBarItem, {
775
+ id: "item",
776
+ renderSubmenu: itemSubmenuExample
777
+ }, "Menu Item"))),
778
+ container = _render18.container;
779
+ const button = screen.getByRole('button');
780
+ const chevronClosed = container.querySelector('svg[name="IconArrowOpenDown"]');
781
+ expect(chevronClosed).toBeVisible();
782
+ userEvent.click(button);
783
+ await waitFor(() => {
784
+ const chevronOpen = container.querySelector('svg[name="IconArrowOpenUp"]');
785
+ expect(chevronOpen).toBeVisible();
786
+ });
787
+ });
788
+ it('next to items with custom popover', async () => {
789
+ const _render19 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
790
+ id: "item",
791
+ customPopoverConfig: getCustomPopoverConfig(false, {
792
+ isShowingContent: void 0,
793
+ on: 'click'
794
+ })
795
+ }, "Menu Item")),
796
+ container = _render19.container;
797
+ const button = screen.getByRole('button');
798
+ const chevronClosed = container.querySelector('svg[name="IconArrowOpenDown"]');
799
+ expect(chevronClosed).toBeVisible();
800
+ userEvent.click(button);
801
+ await waitFor(() => {
802
+ const chevronOpen = container.querySelector('svg[name="IconArrowOpenUp"]');
803
+ expect(chevronOpen).toBeVisible();
804
+ });
805
+ });
806
+ describe('should show for all variants:', () => {
807
+ variants.forEach(variant => {
808
+ it(`with "${variant}" variant`, async () => {
809
+ const _render20 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
810
+ id: "item",
811
+ variant: variant,
812
+ renderSubmenu: itemSubmenuExample,
813
+ renderIcon: variant === 'icon' ? IconSearchLine : void 0,
814
+ renderAvatar: variant === 'avatar' ? avatarExample : void 0
815
+ }, "Menu Item")),
816
+ container = _render20.container;
817
+ const button = screen.getByRole('button');
818
+ const chevronClosed = container.querySelector('svg[name="IconArrowOpenDown"]');
819
+ expect(chevronClosed).toBeVisible();
820
+ userEvent.click(button);
821
+ await waitFor(() => {
822
+ const chevronOpen = container.querySelector('svg[name="IconArrowOpenUp"]');
823
+ expect(chevronOpen).toBeVisible();
824
+ });
825
+ });
826
+ });
827
+ });
828
+ });
829
+ describe('when false, should not show chevron icon', () => {
830
+ it('next to items with submenu', async () => {
831
+ const _render21 = render(_TopNavBarItem17 || (_TopNavBarItem17 = /*#__PURE__*/React.createElement(TopNavBarItem, {
832
+ id: "item",
833
+ renderSubmenu: itemSubmenuExample,
834
+ showSubmenuChevron: false
835
+ }, "Menu Item"))),
836
+ container = _render21.container;
837
+ const button = screen.getByRole('button');
838
+ const chevron = container.querySelector("svg[class$='inlineSVG-svgIcon']");
839
+ expect(chevron).not.toBeInTheDocument();
840
+ userEvent.click(button);
841
+ await waitFor(() => {
842
+ const chevronAfterClick = container.querySelector("svg[class$='inlineSVG-svgIcon']");
843
+ expect(chevronAfterClick).not.toBeInTheDocument();
844
+ });
845
+ });
846
+ it('next to items with custom popover', async () => {
847
+ const _render22 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
848
+ id: "item",
849
+ showSubmenuChevron: false,
850
+ customPopoverConfig: getCustomPopoverConfig(false, {
851
+ isShowingContent: void 0,
852
+ on: 'click'
853
+ })
854
+ }, "Menu Item")),
855
+ container = _render22.container;
856
+ const button = screen.getByRole('button');
857
+ const chevron = container.querySelector("svg[class$='inlineSVG-svgIcon']");
858
+ expect(chevron).not.toBeInTheDocument();
859
+ userEvent.click(button);
860
+ await waitFor(() => {
861
+ const chevronAfterClick = container.querySelector("svg[class$='inlineSVG-svgIcon']");
862
+ expect(chevronAfterClick).not.toBeInTheDocument();
863
+ });
864
+ });
865
+ describe('should show for all variants:', () => {
866
+ variants.forEach(variant => {
867
+ it(`with "${variant}" variant`, async () => {
868
+ const _render23 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
869
+ id: "item",
870
+ variant: variant,
871
+ showSubmenuChevron: false,
872
+ renderSubmenu: itemSubmenuExample,
873
+ renderIcon: variant === 'icon' ? IconSearchLine : void 0,
874
+ renderAvatar: variant === 'avatar' ? avatarExample : void 0
875
+ }, "Menu Item")),
876
+ container = _render23.container;
877
+ const button = screen.getByRole('button');
878
+ const chevronClosed = container.querySelector('svg[name="IconArrowOpenDown"]');
879
+ expect(chevronClosed).not.toBeInTheDocument();
880
+ userEvent.click(button);
881
+ await waitFor(() => {
882
+ const chevronOpen = container.querySelector('svg[name="IconArrowOpenUp"]');
883
+ expect(chevronOpen).not.toBeInTheDocument();
884
+ });
885
+ });
886
+ });
887
+ });
888
+ });
889
+ });
890
+ describe('tooltip prop', () => {
891
+ describe('should render tooltip', () => {
892
+ it('with string value', () => {
893
+ render(_TopNavBarItem18 || (_TopNavBarItem18 = /*#__PURE__*/React.createElement(TopNavBarItem, {
894
+ id: "item",
895
+ tooltip: "Tooltip content"
896
+ }, "Menu Item")));
897
+ const tooltip = screen.getByRole('tooltip');
898
+ expect(tooltip).toHaveTextContent('Tooltip content');
899
+ });
900
+ it('with config value', () => {
901
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
902
+ id: "item",
903
+ tooltip: {
904
+ renderTip: 'Tooltip config content'
905
+ }
906
+ }, "Menu Item"));
907
+ const tooltip = screen.getByRole('tooltip');
908
+ expect(tooltip).toHaveTextContent('Tooltip config content');
909
+ });
910
+ });
911
+ it('should be able to render with submenu too', () => {
912
+ const _render24 = render(_TopNavBarItem19 || (_TopNavBarItem19 = /*#__PURE__*/React.createElement(TopNavBarItem, {
913
+ id: "item",
914
+ tooltip: "Tooltip content",
915
+ renderSubmenu: itemSubmenuExample
916
+ }, "Menu Item"))),
917
+ container = _render24.container;
918
+ const ariaExpandedElements = container.querySelectorAll('[aria-expanded="true"], [aria-expanded="false"]');
919
+
920
+ // the only aria-expanded item should be the BaseButton element
921
+ expect(ariaExpandedElements).toHaveLength(1);
922
+ expect(ariaExpandedElements[0].tagName).toBe('BUTTON');
923
+ const tooltip = screen.getByRole('tooltip');
924
+ expect(tooltip).toBeInTheDocument();
925
+ expect(tooltip).toHaveTextContent('Tooltip content');
926
+ const submenu = container.querySelector("[class$='submenuTriggerContainer']");
927
+ expect(submenu).toBeInTheDocument();
928
+ expect(submenu).toHaveAttribute('aria-haspopup', 'menu');
929
+ });
930
+ it('should be able to render with custom popover too', () => {
931
+ const _render25 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
932
+ id: "item",
933
+ tooltip: "Tooltip content",
934
+ customPopoverConfig: getCustomPopoverConfig()
935
+ }, "Menu Item")),
936
+ container = _render25.container;
937
+ const ariaExpandedElements = container.querySelectorAll('[aria-expanded="true"], [aria-expanded="false"]');
938
+
939
+ // the only aria-expanded item should be the BaseButton element
940
+ expect(ariaExpandedElements).toHaveLength(1);
941
+ expect(ariaExpandedElements[0].tagName).toBe('BUTTON');
942
+ const tooltip = screen.getByRole('tooltip');
943
+ expect(tooltip).toBeInTheDocument();
944
+ expect(tooltip).toHaveTextContent('Tooltip content');
945
+ const customElementInitial = container.querySelector("span[class$='-position']");
946
+ expect(customElementInitial).toBeInTheDocument();
947
+ expect(customElementInitial).toHaveAttribute('data-position', expect.stringContaining('Popover'));
948
+ const customPopoverContent = screen.getByText('dialog content');
949
+ expect(customPopoverContent).toBeInTheDocument();
950
+ });
951
+
952
+ // TODO convert to e2e
953
+ // it('should have "primary-inverse" color by default', async () => {
954
+ // render(
955
+ // <TopNavBarItem id="item" tooltip="Tooltip content">
956
+ // Menu Item
957
+ // </TopNavBarItem>
958
+ // )
959
+
960
+ // const tooltip = screen.getByRole('tooltip')
961
+ // screen.debug(tooltip)
962
+ // const customPopoverContent = screen.getByText('Tooltip content')
963
+
964
+ // //expect(getComputedStyle(customPopoverContent!.firstChild).backgroundColor).toBe('rgb(255, 255, 255)')
965
+ // })
966
+
967
+ // it('should have "primary" color in "inverseColor" mode', async () => {
968
+ // await mount(
969
+ // <SmallViewportModeWrapper layout="desktop" inverseColor>
970
+ // <TopNavBarItem id="item" tooltip="Tooltip content">
971
+ // console.log('tooltip', JSON.stringify(tooltip, null, 2))
972
+ // Menu Item
973
+ // </TopNavBarItem>
974
+ // </SmallViewportModeWrapper>
975
+ // )
976
+
977
+ // const component = await TopNavBarItemLocator.find()
978
+ // const tooltip = await component.findTooltip()
979
+ // const tooltipContent = await tooltip.findContent()
980
+
981
+ // expect(
982
+ // getComputedStyle(tooltipContent.getDOMNode().childNodes[0])
983
+ // .backgroundColor
984
+ // ).to.equal('rgb(45, 59, 69)')
985
+ // })
986
+ });
987
+
988
+ describe('renderAvatar prop', () => {
989
+ it('displays avatar', () => {
990
+ const _render26 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
991
+ id: "item",
992
+ renderAvatar: {
993
+ ...avatarExample,
994
+ avatarName: 'User Name'
995
+ }
996
+ }, "Menu Item")),
997
+ container = _render26.container;
998
+ const button = screen.getByRole('button');
999
+ const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1000
+ expect(avatar).toBeVisible();
1001
+ expect(avatar).toHaveAttribute('name', 'User Name');
1002
+ expect(avatar).toHaveAttribute('alt', 'Menu Item');
1003
+ expect(avatar).toHaveAttribute('aria-label', 'Menu Item');
1004
+ expect(avatar).toHaveTextContent('UN');
1005
+ expect(button).toHaveTextContent('Menu Item');
1006
+ });
1007
+ it('display only the avatar in "avatar" variant', () => {
1008
+ const _render27 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1009
+ id: "item",
1010
+ variant: "avatar",
1011
+ renderAvatar: {
1012
+ ...avatarExample,
1013
+ avatarName: 'User Name'
1014
+ }
1015
+ }, "Menu Item")),
1016
+ container = _render27.container;
1017
+ const button = screen.getByRole('button');
1018
+ const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1019
+ expect(avatar).toBeVisible();
1020
+ expect(avatar).toHaveAttribute('name', 'User Name');
1021
+ expect(avatar).toHaveAttribute('alt', 'Menu Item');
1022
+ expect(avatar).toHaveAttribute('aria-label', 'Menu Item');
1023
+ expect(avatar).toHaveTextContent('UN');
1024
+ expect(button).not.toHaveTextContent('Menu Item');
1025
+ });
1026
+ describe('throws warning', () => {
1027
+ it('when not passed to "avatar" variant', () => {
1028
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1029
+ const _render28 = render(_TopNavBarItem20 || (_TopNavBarItem20 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1030
+ id: "item",
1031
+ variant: "avatar"
1032
+ }, "Menu Item"))),
1033
+ container = _render28.container;
1034
+ const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1035
+ expect(avatar).not.toBeInTheDocument();
1036
+ 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".`;
1037
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1038
+ consoleWarningSpy.mockRestore();
1039
+ });
1040
+ it('when passed to item with "renderIcon"', () => {
1041
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1042
+ const _render29 = render(_TopNavBarItem21 || (_TopNavBarItem21 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1043
+ id: "item",
1044
+ renderIcon: IconSearchLine,
1045
+ renderAvatar: avatarExample
1046
+ }, "Menu Item"))),
1047
+ container = _render29.container;
1048
+ const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1049
+ expect(avatar).not.toBeInTheDocument();
1050
+ const expectedErrorMessage = `Warning: <TopNavBar.Item> components with icons cannot display avatars, so the "renderAvatar" config prop will be ignored for item with id "item".`;
1051
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1052
+ consoleWarningSpy.mockRestore();
1053
+ });
1054
+ it('when passed to item with "active" status', () => {
1055
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1056
+ const _render30 = render(_TopNavBarItem22 || (_TopNavBarItem22 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1057
+ id: "item",
1058
+ renderAvatar: avatarExample,
1059
+ status: "active"
1060
+ }, "Menu Item"))),
1061
+ container = _render30.container;
1062
+ const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1063
+ expect(avatar).toBeInTheDocument();
1064
+ 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.`;
1065
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1066
+
1067
+ // TODO convert to e2e
1068
+ // topNavBarItem__container ::after
1069
+ // const activeIndicatorStyle = await component.getActiveIndicatorStyle()
1070
+ // expect(activeIndicatorStyle?.backgroundColor).to.equal(
1071
+ // 'rgba(0, 0, 0, 0)'
1072
+ // )
1073
+
1074
+ consoleWarningSpy.mockRestore();
1075
+ });
1076
+ it('when there is no string type "children" or "avatarAlt" passed', () => {
1077
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1078
+ const _render31 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1079
+ id: "item",
1080
+ renderAvatar: {
1081
+ ...avatarExample,
1082
+ avatarAlt: void 0
1083
+ }
1084
+ }, _div2 || (_div2 = /*#__PURE__*/React.createElement("div", null, "avatar")))),
1085
+ container = _render31.container;
1086
+ const avatar = container.querySelector("span[class$='inlineBlock-avatar']");
1087
+ expect(avatar).toBeInTheDocument();
1088
+ 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".`;
1089
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1090
+ consoleWarningSpy.mockRestore();
1091
+ });
1092
+ });
1093
+ });
1094
+ describe('renderIcon prop', () => {
1095
+ describe('should render icon', () => {
1096
+ it('for default variant', () => {
1097
+ const _render32 = render(_TopNavBarItem23 || (_TopNavBarItem23 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1098
+ id: "item",
1099
+ renderIcon: IconSearchLine
1100
+ }, "Menu Item"))),
1101
+ container = _render32.container;
1102
+ const icon = container.querySelector("svg[class$='inlineSVG-svgIcon']");
1103
+ expect(icon).toBeVisible();
1104
+ expect(icon).toHaveAttribute('name', 'IconSearch');
1105
+ // TODO convert to e2e
1106
+ // expect(window.getComputedStyle(icon!).fill).toEqual('rgb(255, 255, 255)')
1107
+
1108
+ const button = screen.getByRole('button');
1109
+ expect(button).toHaveTextContent('Menu Item');
1110
+ // expect(window.getComputedStyle(button).color).toEqual('rgb(255, 255, 255)')
1111
+ });
1112
+
1113
+ it('for button variant', () => {
1114
+ const _render33 = render(_TopNavBarItem24 || (_TopNavBarItem24 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1115
+ id: "item",
1116
+ variant: "button",
1117
+ renderIcon: IconSearchLine
1118
+ }, "Menu Item"))),
1119
+ container = _render33.container;
1120
+ const icon = container.querySelector("svg[class$='inlineSVG-svgIcon']");
1121
+ expect(icon).toBeVisible();
1122
+ expect(icon).toHaveAttribute('name', 'IconSearch');
1123
+ // TODO convert to e2e
1124
+ // expect(window.getComputedStyle(icon!).fill).toEqual('rgb(45, 59, 69)')
1125
+
1126
+ const button = screen.getByRole('button');
1127
+ expect(button).toHaveTextContent('Menu Item');
1128
+ expect(window.getComputedStyle(button).color).toEqual('rgb(45, 59, 69)');
1129
+ });
1130
+ });
1131
+ describe('should render icon in inverse mode', () => {
1132
+ it('for default variant', () => {
1133
+ const _render34 = render(_SmallViewportModeWra || (_SmallViewportModeWra = /*#__PURE__*/React.createElement(SmallViewportModeWrapper, {
1134
+ layout: "desktop",
1135
+ inverseColor: true
1136
+ }, /*#__PURE__*/React.createElement(TopNavBarItem, {
1137
+ id: "item",
1138
+ renderIcon: IconSearchLine
1139
+ }, "Menu Item")))),
1140
+ container = _render34.container;
1141
+ const icon = container.querySelector("svg[class$='inlineSVG-svgIcon']");
1142
+ expect(icon).toBeVisible();
1143
+ expect(icon).toHaveAttribute('name', 'IconSearch');
1144
+ // TODO convert to e2e
1145
+ // expect(window.getComputedStyle(icon!).fill).toEqual('rgb(45, 59, 69)')
1146
+
1147
+ const button = screen.getByRole('button');
1148
+ expect(button).toHaveTextContent('Menu Item');
1149
+ expect(window.getComputedStyle(button).color).toEqual('rgb(45, 59, 69)');
1150
+ });
1151
+ it('for button variant', () => {
1152
+ const _render35 = render(_SmallViewportModeWra2 || (_SmallViewportModeWra2 = /*#__PURE__*/React.createElement(SmallViewportModeWrapper, {
1153
+ layout: "desktop",
1154
+ inverseColor: true
1155
+ }, /*#__PURE__*/React.createElement(TopNavBarItem, {
1156
+ id: "item",
1157
+ variant: "button",
1158
+ renderIcon: IconSearchLine
1159
+ }, "Menu Item")))),
1160
+ container = _render35.container;
1161
+ const icon = container.querySelector("svg[class$='inlineSVG-svgIcon']");
1162
+ expect(icon).toBeVisible();
1163
+ expect(icon).toHaveAttribute('name', 'IconSearch');
1164
+ // TODO convert to e2e
1165
+ // expect(window.getComputedStyle(icon!).fill).toEqual('rgb(255, 255, 255)')
1166
+
1167
+ const button = screen.getByRole('button');
1168
+ expect(button).toHaveTextContent('Menu Item');
1169
+ // expect(window.getComputedStyle(button!).color).toEqual('rgb(255, 255, 255)')
1170
+ });
1171
+ });
1172
+ });
1173
+
1174
+ describe('as prop', () => {
1175
+ it('should render item as a', () => {
1176
+ const _render36 = render(_TopNavBarItem25 || (_TopNavBarItem25 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1177
+ id: "item",
1178
+ as: "a"
1179
+ }, "Menu Item"))),
1180
+ container = _render36.container;
1181
+ const button = container.querySelector("[class$='inlineBlock-baseButton']");
1182
+ expect(button.tagName).toBe('A');
1183
+ expect(button).not.toHaveAttribute('href');
1184
+ });
1185
+ });
1186
+ describe('href prop', () => {
1187
+ it('should render item as link', () => {
1188
+ const _render37 = render(_TopNavBarItem26 || (_TopNavBarItem26 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1189
+ id: "item",
1190
+ href: "/#TopNavBar"
1191
+ }, "Menu Item"))),
1192
+ container = _render37.container;
1193
+ const button = container.querySelector("[class$='inlineBlock-baseButton']");
1194
+ expect(button.tagName).toBe('A');
1195
+ expect(button).toHaveAttribute('href', '/#TopNavBar');
1196
+ });
1197
+ it('should not be allowed for items with submenu', () => {
1198
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1199
+ const _render38 = render(_TopNavBarItem27 || (_TopNavBarItem27 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1200
+ id: "item",
1201
+ href: "/#TopNavBar",
1202
+ renderSubmenu: itemSubmenuExample
1203
+ }, "Menu Item"))),
1204
+ container = _render38.container;
1205
+ const button = container.querySelector("[class$='inlineBlock-baseButton']");
1206
+ expect(button.tagName).toBe('BUTTON');
1207
+ expect(button).not.toHaveAttribute('href');
1208
+ const expectedErrorMessage = `Warning: TopNavBar.Items with submenus are not allowed to have 'href' property, but received href "/#TopNavBar" for item with the id: "item".`;
1209
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1210
+ consoleWarningSpy.mockRestore();
1211
+ });
1212
+ });
1213
+ describe('onClick prop', () => {
1214
+ it('should render item as button', () => {
1215
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1216
+ id: "item",
1217
+ onClick: jest.fn()
1218
+ }, "Menu Item"));
1219
+ const button = screen.getByRole('button');
1220
+ expect(button).toBeInTheDocument();
1221
+ expect(button.tagName).toBe('BUTTON');
1222
+ });
1223
+ it('should fire onClick on click', () => {
1224
+ const onClick = jest.fn();
1225
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1226
+ id: "item",
1227
+ onClick: onClick
1228
+ }, "Menu Item"));
1229
+ const button = screen.getByRole('button');
1230
+ fireEvent.click(button);
1231
+ expect(onClick).toHaveBeenCalled();
1232
+ });
1233
+ it('should work combined with "href" prop', () => {
1234
+ const onClick = jest.fn();
1235
+ const _render39 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1236
+ id: "item",
1237
+ onClick: onClick,
1238
+ href: "/#TopNavBar"
1239
+ }, "Menu Item")),
1240
+ container = _render39.container;
1241
+ const button = container.querySelector("[class$='inlineBlock-baseButton']");
1242
+ expect(button.tagName).toBe('A');
1243
+ expect(button).toHaveAttribute('href', '/#TopNavBar');
1244
+ });
1245
+ it('should not be allowed for items with submenu', () => {
1246
+ const onClick = jest.fn();
1247
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1248
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1249
+ id: "item",
1250
+ onClick: onClick,
1251
+ renderSubmenu: itemSubmenuExample
1252
+ }, "Menu Item"));
1253
+ const button = screen.getByRole('button');
1254
+ fireEvent.click(button);
1255
+ expect(onClick).not.toHaveBeenCalled();
1256
+ 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:`;
1257
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
1258
+ consoleWarningSpy.mockRestore();
1259
+ });
1260
+ });
1261
+ describe('onSubmenuToggle prop', () => {
1262
+ it('should be called on submenu toggle', () => {
1263
+ const onSubmenuToggle = jest.fn();
1264
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1265
+ id: "item",
1266
+ onSubmenuToggle: onSubmenuToggle,
1267
+ renderSubmenu: itemSubmenuExample
1268
+ }, "Menu Item"));
1269
+ const button = screen.getByRole('button');
1270
+ fireEvent.click(button);
1271
+ expect(onSubmenuToggle).toHaveBeenLastCalledWith(expect.anything(),
1272
+ // First argument is the event object
1273
+ expect.objectContaining({
1274
+ shown: true
1275
+ }));
1276
+ fireEvent.click(button);
1277
+ expect(onSubmenuToggle).toHaveBeenLastCalledWith(expect.anything(),
1278
+ // First argument is the event object
1279
+ expect.objectContaining({
1280
+ shown: false
1281
+ }));
1282
+ });
1283
+ });
1284
+ describe('other event handlers', () => {
1285
+ it('onMouseOver and onMouseOut should be called', () => {
1286
+ const onMouseOver = jest.fn();
1287
+ const onMouseOut = jest.fn();
1288
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1289
+ id: "item",
1290
+ onMouseOver: onMouseOver,
1291
+ onMouseOut: onMouseOut
1292
+ }, "Menu Item"));
1293
+ const button = screen.getByRole('button');
1294
+ fireEvent.mouseOver(button);
1295
+ expect(onMouseOver).toHaveBeenCalled();
1296
+ fireEvent.mouseOut(button);
1297
+ expect(onMouseOut).toHaveBeenCalled();
1298
+ });
1299
+ it('onFocus and onBlur should be called', () => {
1300
+ const onFocus = jest.fn();
1301
+ const onBlur = jest.fn();
1302
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1303
+ id: "item",
1304
+ onFocus: onFocus,
1305
+ onBlur: onBlur
1306
+ }, "Menu Item"));
1307
+ const button = screen.getByRole('button');
1308
+ fireEvent.focus(button);
1309
+ expect(onFocus).toHaveBeenCalled();
1310
+ fireEvent.blur(button);
1311
+ expect(onBlur).toHaveBeenCalled();
1312
+ });
1313
+ it('onKeyDown and onKeyUp should be called', () => {
1314
+ const onKeyDown = jest.fn();
1315
+ const onKeyUp = jest.fn();
1316
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1317
+ id: "item",
1318
+ onKeyDown: onKeyDown,
1319
+ onKeyUp: onKeyUp
1320
+ }, "Menu Item"));
1321
+ const button = screen.getByRole('button');
1322
+ fireEvent.keyDown(button, {
1323
+ key: 'ArrowLeft'
1324
+ });
1325
+ expect(onKeyDown).toHaveBeenCalled();
1326
+ fireEvent.keyUp(button, {
1327
+ key: 'ArrowLeft'
1328
+ });
1329
+ expect(onKeyUp).toHaveBeenCalled();
1330
+ });
1331
+ });
1332
+ describe('refs', () => {
1333
+ it('elementRef should return root element', () => {
1334
+ const elementRef = jest.fn();
1335
+ const _render40 = render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1336
+ id: "item",
1337
+ elementRef: elementRef
1338
+ }, "Menu Item")),
1339
+ container = _render40.container;
1340
+ const topNavBarItem = container.querySelector("[class$='topNavBarItem']");
1341
+ expect(elementRef).toHaveBeenCalledWith(topNavBarItem);
1342
+ });
1343
+ it('itemRef should return the button element', () => {
1344
+ const itemRef = jest.fn();
1345
+ render( /*#__PURE__*/React.createElement(TopNavBarItem, {
1346
+ id: "item",
1347
+ itemRef: itemRef
1348
+ }, "Menu Item"));
1349
+ const button = screen.getByRole('button');
1350
+ expect(itemRef).toHaveBeenCalledWith(button);
1351
+ });
1352
+ });
1353
+ describe('should be accessible', () => {
1354
+ it('a11y', async () => {
1355
+ const _render41 = render(_TopNavBarItem28 || (_TopNavBarItem28 = /*#__PURE__*/React.createElement(TopNavBarItem, {
1356
+ id: "item"
1357
+ }, "Menu Item"))),
1358
+ container = _render41.container;
1359
+ const axeCheck = await runAxeCheck(container);
1360
+ expect(axeCheck).toBe(true);
1361
+ });
1362
+ describe('with generated examples', () => {
1363
+ const generatedComponents = generateA11yTests(TopNavBarItem, TopNavBarItemExamples);
1364
+ it.each(generatedComponents)('should be accessible with example: $description', async ({
1365
+ content
1366
+ }) => {
1367
+ const _render42 = render(content),
1368
+ container = _render42.container;
1369
+ const axeCheck = await runAxeCheck(container);
1370
+ expect(axeCheck).toBe(true);
1371
+ });
1372
+ });
1373
+ });
1374
+ });