Skip to content

Commit 84d7687

Browse files
committed
fix: desktop.test.tsx
1 parent a85b3a0 commit 84d7687

File tree

2 files changed

+64
-34
lines changed

2 files changed

+64
-34
lines changed

src/app-layout/__tests__/desktop.test.tsx

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import React from 'react';
4-
import { act, fireEvent, screen, within } from '@testing-library/react';
4+
import { act, fireEvent, screen, waitFor, within } from '@testing-library/react';
55

66
import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
77
import customCssProps from '../../../lib/components/internal/generated/custom-css-properties';
@@ -89,16 +89,18 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
8989
}
9090
});
9191

92-
test('uses the provided content width if one is provided', () => {
92+
test('uses the provided content width if one is provided', async () => {
9393
const { wrapper } = renderComponent(<AppLayout minContentWidth={120} maxContentWidth={650} />);
9494

9595
if (theme === 'classic') {
9696
expect(wrapper.findContentRegion().getElement()).toHaveStyle({ minWidth: '120px', maxWidth: '650px' });
9797
} else {
98-
const minWidthInGrid = wrapper.getElement().style.getPropertyValue(customCssProps.minContentWidth);
99-
const maxWidthInGrid = wrapper.getElement().style.getPropertyValue(customCssProps.maxContentWidth);
100-
expect(minWidthInGrid).toBe(theme === 'refresh' ? '120px' : '');
101-
expect(maxWidthInGrid).toBe('650px');
98+
await waitFor(() => {
99+
const minWidthInGrid = wrapper.getElement().style.getPropertyValue(customCssProps.minContentWidth);
100+
const maxWidthInGrid = wrapper.getElement().style.getPropertyValue(customCssProps.maxContentWidth);
101+
expect(minWidthInGrid).toBe(theme === 'refresh' ? '120px' : '');
102+
expect(maxWidthInGrid).toBe('650px');
103+
});
102104
}
103105
});
104106

@@ -125,14 +127,16 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
125127
expect(wrapper.findOpenNavigationPanel()).toBeTruthy();
126128
});
127129

128-
test('Allows notifications to be sticky', () => {
130+
test('Allows notifications to be sticky', async () => {
129131
const { wrapper } = renderComponent(<AppLayout notifications="Test" stickyNotifications={true} />);
130132
const stickyNotificationsClassName = {
131133
classic: notificationStyles['notifications-sticky'],
132134
refresh: visualRefreshStyles['sticky-notifications'],
133135
'refresh-toolbar': visualRefreshToolbarNotificationStyles['sticky-notifications'],
134136
}[theme];
135-
expect(wrapper.findByClassName(stickyNotificationsClassName)).not.toBeNull();
137+
await waitFor(() => {
138+
expect(wrapper.findByClassName(stickyNotificationsClassName)).not.toBeNull();
139+
});
136140
});
137141

138142
describe('unfocusable content', () => {
@@ -152,30 +156,37 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
152156
});
153157
});
154158

155-
test('should render an active drawer', () => {
159+
test('should render an active drawer', async () => {
156160
const { wrapper } = renderComponent(
157161
<AppLayout activeDrawerId={testDrawer.id} drawers={[testDrawer]} onDrawerChange={() => {}} />
158162
);
159163

160-
expect(wrapper.findActiveDrawer()).toBeTruthy();
164+
await waitFor(() => {
165+
expect(wrapper.findActiveDrawer()).toBeTruthy();
166+
});
161167
});
162168

163-
test(`should toggle drawer on click`, () => {
169+
test(`should toggle drawer on click`, async () => {
164170
const { wrapper } = renderComponent(<AppLayout toolsHide={true} drawers={[testDrawer]} />);
165-
wrapper.findDrawersTriggers()![0].click();
171+
await waitFor(() => {
172+
wrapper.findDrawersTriggers()![0].click();
173+
});
174+
166175
expect(wrapper.findActiveDrawer()).toBeTruthy();
167176
wrapper.findDrawersTriggers()![0].click();
168177
expect(wrapper.findActiveDrawer()).toBeFalsy();
169178
});
170179

171-
test(`Moves focus to slider when opened`, () => {
180+
test(`Moves focus to slider when opened`, async () => {
172181
const { wrapper } = renderComponent(<AppLayout drawers={[{ ...testDrawer, resizable: true }]} />);
173182

174-
wrapper.findDrawerTriggerById('security')!.click();
183+
await waitFor(() => {
184+
wrapper.findDrawerTriggerById('security')!.click();
185+
});
175186
expect(wrapper.findActiveDrawerResizeHandle()!.getElement()).toHaveFocus();
176187
});
177188

178-
test('should change size via keyboard events on slider handle', () => {
189+
test('should change size via keyboard events on slider handle', async () => {
179190
const onDrawerItemResize = jest.fn();
180191
const testDrawerResizable: AppLayoutProps.Drawer = {
181192
...testDrawer,
@@ -186,12 +197,14 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
186197
const { wrapper } = renderComponent(
187198
<AppLayout activeDrawerId={testDrawerResizable.id} drawers={[testDrawerResizable]} />
188199
);
189-
wrapper.findActiveDrawerResizeHandle()!.keydown(KeyCode.left);
200+
await waitFor(() => {
201+
wrapper.findActiveDrawerResizeHandle()!.keydown(KeyCode.left);
202+
});
190203

191204
expect(onDrawerItemResize).toHaveBeenCalledWith({ size: expect.any(Number), id: 'security' });
192205
});
193206

194-
test('should change size via mouse pointer on slider handle', () => {
207+
test('should change size via mouse pointer on slider handle', async () => {
195208
const onDrawerItemResize = jest.fn();
196209
const testDrawerResizable: AppLayoutProps.Drawer = {
197210
...testDrawer,
@@ -201,18 +214,23 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
201214
const { wrapper } = renderComponent(
202215
<AppLayout activeDrawerId={testDrawerResizable.id} drawers={[testDrawerResizable]} />
203216
);
204-
wrapper.findActiveDrawerResizeHandle()!.fireEvent(new MouseEvent('pointerdown', { bubbles: true }));
217+
await waitFor(() => {
218+
wrapper.findActiveDrawerResizeHandle()!.fireEvent(new MouseEvent('pointerdown', { bubbles: true }));
219+
});
205220
const resizeEvent = new MouseEvent('pointermove', { bubbles: true });
206221
wrapper.findActiveDrawerResizeHandle()!.fireEvent(resizeEvent);
207222
wrapper.findActiveDrawerResizeHandle()!.fireEvent(new MouseEvent('pointerup', { bubbles: true }));
208223

209224
expect(onDrawerItemResize).toHaveBeenCalledWith({ size: expect.any(Number), id: 'security' });
210225
});
211226

212-
test('should read relative size on resize handle', () => {
227+
test('should read relative size on resize handle', async () => {
213228
const { wrapper } = renderComponent(<AppLayout drawers={[{ ...testDrawer, resizable: true }]} />);
214229

215-
wrapper.findDrawerTriggerById(testDrawer.id)!.click();
230+
await waitFor(() => {
231+
wrapper.findDrawerTriggerById(testDrawer.id)!.click();
232+
});
233+
216234
expect(wrapper.findActiveDrawerResizeHandle()!.getElement()).toHaveAttribute('aria-valuenow', '0');
217235
});
218236

@@ -222,18 +240,22 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
222240
expect(wrapper.findDrawersTriggers()!.length).toBeLessThan(100);
223241
});
224242

225-
test('Renders aria-controls on toggle only when active', () => {
243+
test('Renders aria-controls on toggle only when active', async () => {
226244
const { wrapper } = renderComponent(<AppLayout drawers={[testDrawer]} />);
227-
expect(wrapper.findDrawerTriggerById('security')!.getElement()).not.toHaveAttribute('aria-controls');
245+
await waitFor(() => {
246+
expect(wrapper.findDrawerTriggerById('security')!.getElement()).not.toHaveAttribute('aria-controls');
247+
});
228248
wrapper.findDrawerTriggerById('security')!.click();
229249
expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute('aria-controls', 'security');
230250
});
231251

232-
test('should render badge when defined', () => {
252+
test('should render badge when defined', async () => {
233253
const { wrapper } = renderComponent(<AppLayout drawers={manyDrawers} />);
234254

235-
expect(wrapper.findDrawerTriggerById(manyDrawers[0].id, { hasBadge: true })).toBeTruthy();
236-
expect(wrapper.findDrawerTriggerById(manyDrawers[1].id, { hasBadge: false })).toBeTruthy();
255+
await waitFor(() => {
256+
expect(wrapper.findDrawerTriggerById(manyDrawers[0].id, { hasBadge: true })).toBeTruthy();
257+
expect(wrapper.findDrawerTriggerById(manyDrawers[1].id, { hasBadge: false })).toBeTruthy();
258+
});
237259
});
238260

239261
test('should return null when searching for a non-existing drawer with hasBadge condition', () => {
@@ -243,10 +265,12 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
243265
expect(wrapper.findDrawerTriggerById('non-existing', { hasBadge: false })).toBeNull();
244266
});
245267

246-
test('should have width equal to the size declaration', () => {
268+
test('should have width equal to the size declaration', async () => {
247269
const { wrapper } = renderComponent(<AppLayout drawers={[{ ...testDrawer, resizable: true, defaultSize: 500 }]} />);
248270

249-
wrapper.findDrawersTriggers()![0].click();
271+
await waitFor(() => {
272+
wrapper.findDrawersTriggers()![0].click();
273+
});
250274
expect(getActiveDrawerWidth(wrapper)).toEqual('500px');
251275
});
252276
});
@@ -304,23 +328,28 @@ describeEachAppLayout({ themes: ['classic'], sizes: ['desktop'] }, () => {
304328

305329
describeEachAppLayout({ themes: ['refresh', 'refresh-toolbar'], sizes: ['desktop'] }, ({ theme }) => {
306330
const styles = theme === 'refresh' ? visualRefreshStyles : toolbarStyles;
307-
test(`${theme} - renders roles only when aria labels are not provided`, () => {
331+
test(`${theme} - renders roles only when aria labels are not provided`, async () => {
308332
const { wrapper } = renderComponent(<AppLayout navigationHide={true} drawers={[testDrawerWithoutLabels]} />);
309333

310-
expect(wrapper.findDrawerTriggerById(testDrawer.id)!.getElement()).not.toHaveAttribute('aria-label');
334+
await waitFor(() => {
335+
expect(wrapper.findDrawerTriggerById(testDrawer.id)!.getElement()).not.toHaveAttribute('aria-label');
336+
});
337+
311338
expect(wrapper.findByClassName(styles['drawers-desktop-triggers-container'])!.getElement()).not.toHaveAttribute(
312339
'aria-label'
313340
);
314341
expect(wrapper.findByClassName(styles['drawers-trigger-content'])!.getElement()).toHaveAttribute('role', 'toolbar');
315342
});
316343

317-
test(`${theme} - renders roles and aria labels when provided`, () => {
344+
test(`${theme} - renders roles and aria labels when provided`, async () => {
318345
const { wrapper } = renderComponent(<AppLayout drawers={[testDrawer]} ariaLabels={{ drawers: 'Drawers' }} />);
319346

320-
expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute(
321-
'aria-label',
322-
'Security trigger button'
323-
);
347+
await waitFor(() => {
348+
expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute(
349+
'aria-label',
350+
'Security trigger button'
351+
);
352+
});
324353
expect(wrapper.findByClassName(styles['drawers-desktop-triggers-container'])!.getElement()).toHaveAttribute(
325354
'aria-label',
326355
'Drawers'

src/app-layout/visual-refresh-toolbar/skeleton/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const SkeletonLayout = (props: RootSkeletonLayoutProps) => {
125125
placement,
126126
navigationOpen: resolvedNavigationOpen,
127127
breadcrumbs,
128+
navigation,
128129
},
129130
toolbarProps,
130131
registered,

0 commit comments

Comments
 (0)