Skip to content

Commit 2ef1b2c

Browse files
committed
add tests for loader mock
1 parent 3c04657 commit 2ef1b2c

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/app-layout/__tests__/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ export function describeEachAppLayout(
5959
beforeEach(() => {
6060
globalWithFlags[forceMobileModeSymbol] = size === 'mobile';
6161
globalWithFlags[Symbol.for('awsui-visual-refresh-flag')] = () => theme !== 'classic';
62-
setGlobalFlag('appLayoutWidget', theme === 'refresh-toolbar');
62+
setGlobalFlag('appLayoutToolbar', theme === 'refresh-toolbar');
6363
});
6464
afterEach(() => {
6565
delete globalWithFlags[forceMobileModeSymbol];
6666
delete globalWithFlags[Symbol.for('awsui-visual-refresh-flag')];
67-
setGlobalFlag('appLayoutWidget', undefined);
67+
setGlobalFlag('appLayoutToolbar', undefined);
6868
clearVisualRefreshState();
6969
});
7070
test('mocks applied correctly', () => {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import React from 'react';
4+
import { waitFor } from '@testing-library/react';
5+
6+
import { setGlobalFlag } from '@cloudscape-design/component-toolkit/internal/testing';
7+
8+
import AppLayout from '../../../lib/components/app-layout';
9+
import { describeEachAppLayout, renderComponent } from './utils';
10+
11+
jest.mock('../../../lib/components/internal/widgets/loader-mock', () => {
12+
// set this flag before the module is instantiated
13+
(window as any)[Symbol.for('awsui-custom-flags')] = { appLayoutDelayedWidget: true };
14+
return jest.requireActual('../../../lib/components/internal/widgets/loader-mock');
15+
});
16+
17+
describeEachAppLayout({ themes: ['refresh-toolbar'], sizes: ['desktop'] }, () => {
18+
test('renders instantly when widget is not activated', () => {
19+
const { wrapper } = renderComponent(<AppLayout />);
20+
expect(wrapper.findNavigation()).toBeTruthy();
21+
expect(wrapper.findTools()).toBeTruthy();
22+
});
23+
24+
describe('when widget is active', () => {
25+
beforeEach(() => {
26+
setGlobalFlag('appLayoutWidget', true);
27+
});
28+
29+
afterEach(() => {
30+
setGlobalFlag('appLayoutWidget', undefined);
31+
});
32+
33+
test('renders app layout with a delay', async () => {
34+
const { wrapper } = renderComponent(<AppLayout />);
35+
expect(wrapper.findNavigation()).toBeFalsy();
36+
expect(wrapper.findTools()).toBeFalsy();
37+
38+
await waitFor(() => {
39+
expect(wrapper.findNavigation()).toBeTruthy();
40+
expect(wrapper.findTools()).toBeTruthy();
41+
});
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)