|
| 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