Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app-layout/__tests__/app-layout-navigation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary reason for this change. We do not have side-effects in import order anymore, so we can remove this eslint rule exception

import React from 'react';
import { describeEachAppLayout, renderComponent } from './utils';

import AppLayout from '../../../lib/components/app-layout';
import { describeEachAppLayout, renderComponent } from './utils';

import visualRefreshToolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/skeleton/styles.css.js';

Expand Down
4 changes: 2 additions & 2 deletions src/app-layout/__tests__/common.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React from 'react';

import AppLayout from '../../../lib/components/app-layout';
import { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
import { describeEachAppLayout, renderComponent, testDrawer, testDrawerWithoutLabels } from './utils';
import AppLayout from '../../../lib/components/app-layout';

jest.mock('@cloudscape-design/component-toolkit', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit'),
Expand Down
26 changes: 9 additions & 17 deletions src/app-layout/__tests__/desktop.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React from 'react';
import { act, fireEvent, screen, within } from '@testing-library/react';

import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import customCssProps from '../../../lib/components/internal/generated/custom-css-properties';
import { KeyCode } from '../../internal/keycode';
import {
describeEachAppLayout,
getActiveDrawerWidth,
manyDrawers,
renderComponent,
testDrawer,
manyDrawers,
getActiveDrawerWidth,
testDrawerWithoutLabels,
} from './utils';
import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import styles from '../../../lib/components/app-layout/styles.css.js';

import drawerStyles from '../../../lib/components/app-layout/drawer/styles.css.js';
import notificationStyles from '../../../lib/components/app-layout/notifications/styles.css.js';
import styles from '../../../lib/components/app-layout/styles.css.js';
import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js';
import visualRefreshToolbarNotificationStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/notifications/styles.css.js';
import toolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/styles.css.js';
import drawerStyles from '../../../lib/components/app-layout/drawer/styles.css.js';
import customCssProps from '../../../lib/components/internal/generated/custom-css-properties';
import { KeyCode } from '../../internal/keycode';
import { useVisualRefresh } from '../../../lib/components/internal/hooks/use-visual-mode';

jest.mock('@cloudscape-design/component-toolkit', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit'),
Expand Down Expand Up @@ -252,14 +251,7 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
});
});

describe('Classic only features', () => {
beforeEach(() => {
(useVisualRefresh as jest.Mock).mockReturnValue(false);
});
afterEach(() => {
(useVisualRefresh as jest.Mock).mockReset();
});

describeEachAppLayout({ themes: ['classic'], sizes: ['desktop'] }, () => {
test(`should toggle single drawer on click of container`, () => {
const { wrapper } = renderComponent(
<AppLayout toolsHide={true} drawers={[testDrawer]} ariaLabels={{ drawers: 'Drawers' }} />
Expand Down
20 changes: 8 additions & 12 deletions src/app-layout/__tests__/drawers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React from 'react';
import { act, render, fireEvent } from '@testing-library/react';
import { act, fireEvent, render } from '@testing-library/react';

import { KeyCode } from '@cloudscape-design/test-utils-core/utils.js';
import createWrapper from '../../../lib/components/test-utils/dom';

import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import createWrapper from '../../../lib/components/test-utils/dom';
import {
describeEachAppLayout,
renderComponent,
testDrawer,
findActiveDrawerLandmark,
manyDrawers,
manyDrawersWithBadges,
findActiveDrawerLandmark,
renderComponent,
testDrawer,
} from './utils';

import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';
import toolbarTriggerButtonStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/trigger-button/styles.css.js';

jest.mock('../../../lib/components/internal/hooks/use-mobile', () => ({
useMobile: jest.fn().mockReturnValue(true),
}));
Comment on lines -22 to -24
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in many places below – removed direct mock applications, because describeEachAppLayout helper takes care of setting up the correct environment

import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';

const testIf = (condition: boolean) => (condition ? test : test.skip);

Expand Down
14 changes: 8 additions & 6 deletions src/app-layout/__tests__/global-breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */

import React, { useState } from 'react';
import { act, render, cleanup, waitFor } from '@testing-library/react';
import { describeEachAppLayout } from './utils';
import createWrapper from '../../../lib/components/test-utils/dom';
import { act, cleanup, render, waitFor } from '@testing-library/react';

import { activateAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
import { getGeneratedAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata/utils';

import AppLayout from '../../../lib/components/app-layout';
import BreadcrumbGroup, { BreadcrumbGroupProps } from '../../../lib/components/breadcrumb-group';
import { awsuiPluginsInternal } from '../../../lib/components/internal/plugins/api';
import { activateAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
import { getGeneratedAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata/utils';
import createWrapper from '../../../lib/components/test-utils/dom';
import { describeEachAppLayout } from './utils';

const wrapper = createWrapper();

Expand Down
8 changes: 0 additions & 8 deletions src/app-layout/__tests__/header-variant.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import { describeEachAppLayout, renderComponent } from './utils';
import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js';
import toolbarSkeletonStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/skeleton/styles.css.js';

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
useVisualRefresh: jest.fn().mockReturnValue(false),
}));

jest.mock('../../../lib/components/internal/hooks/use-mobile', () => ({
useMobile: jest.fn().mockReturnValue(false),
}));

const hasHighContrastContext = (element: HTMLElement) =>
findUpUntil(element, el => el.classList.contains(highContrastHeaderClassName));

Expand Down
17 changes: 6 additions & 11 deletions src/app-layout/__tests__/main.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import * as React from 'react';
import { waitFor } from '@testing-library/react';
import { describeEachAppLayout, renderComponent, testDrawer } from './utils';

import '../../__a11y__/to-validate-a11y';
import AppLayout from '../../../lib/components/app-layout';
import { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
import { describeEachAppLayout, renderComponent, testDrawer } from './utils';

import mobileStyles from '../../../lib/components/app-layout/mobile-toolbar/styles.css.js';
import sharedStyles from '../../../lib/components/app-layout/styles.css.js';
import '../../__a11y__/to-validate-a11y';

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isMotionDisabled: jest.fn().mockReturnValue(true),
}));

// in our ResizeObserver mock resolves into mobile mode
test('should render mobile mode by default', () => {
test('does not render mobile mode by default', () => {
const { wrapper } = renderComponent(<AppLayout />);
expect(wrapper.findByClassName(mobileStyles['mobile-bar'])).toBeTruthy();
expect(wrapper.findByClassName(mobileStyles['mobile-bar'])).toBeFalsy();
});
Comment on lines -18 to 17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment was wrong, there is no resize observer mock driving this.

It was useMobile: jest.fn().mockReturnValue(true) configuration. When this removed, we can actually see that the default JSDOM rendering is the desktop variant


test('should not create a new stacking context by default', () => {
Expand Down
34 changes: 15 additions & 19 deletions src/app-layout/__tests__/mobile.test.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React, { useState } from 'react';
import { act, within } from '@testing-library/react';

import { findUpUntil } from '@cloudscape-design/component-toolkit/dom';

import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import SideNavigation from '../../../lib/components/side-navigation';
import SplitPanel from '../../../lib/components/split-panel';
import { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
import {
describeEachAppLayout,
renderComponent,
testDrawer,
manyDrawers,
renderComponent,
splitPanelI18nStrings,
testDrawer,
testDrawerWithoutLabels,
} from './utils';
import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import SplitPanel from '../../../lib/components/split-panel';
import { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
import styles from '../../../lib/components/app-layout/styles.css.js';

import drawersMobileStyles from '../../../lib/components/app-layout/mobile-toolbar/styles.css.js';
import mobileToolbarStyles from '../../../lib/components/app-layout/mobile-toolbar/styles.css.js';
import iconStyles from '../../../lib/components/icon/styles.css.js';
import styles from '../../../lib/components/app-layout/styles.css.js';
import testUtilsStyles from '../../../lib/components/app-layout/test-classes/styles.css.js';
import toolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/styles.css.js';
import toolbarTriggerButtonStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/trigger-button/styles.css.js';
import visualRefreshRefactoredStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js';
import toolbarNotificationsStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/notifications/styles.css.js';
import toolbarSkeletonStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/skeleton/styles.css.js';

import visualRefreshRefactoredStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js';
import { findUpUntil } from '@cloudscape-design/component-toolkit/dom';
import SideNavigation from '../../../lib/components/side-navigation';

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isMotionDisabled: jest.fn().mockReturnValue(true),
}));
Comment on lines -31 to -34
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these mocks, because they do not affect the result anyhow. If we need the disabled motion in our tests, we should use our own official utility: disableMotion(true)

import toolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/styles.css.js';
import toolbarTriggerButtonStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/trigger-button/styles.css.js';
import iconStyles from '../../../lib/components/icon/styles.css.js';

function AppLayoutWithControlledNavigation({
initialNavigationOpen,
Expand Down
4 changes: 1 addition & 3 deletions src/app-layout/__tests__/multi-layout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable simple-import-sort/imports */
import React, { useState } from 'react';
import { act, cleanup, render, waitFor } from '@testing-library/react';

import { clearMessageCache } from '@cloudscape-design/component-toolkit/internal';

import { describeEachAppLayout, testDrawer } from './utils';

import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import { awsuiPluginsInternal } from '../../../lib/components/internal/plugins/api';
import SplitPanel from '../../../lib/components/split-panel';
import createWrapper, { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
import { describeEachAppLayout, testDrawer } from './utils';

import testUtilStyles from '../../../lib/components/app-layout/test-classes/styles.css.js';

Expand Down
8 changes: 4 additions & 4 deletions src/app-layout/__tests__/runtime-drawers-layout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React, { RefObject } from 'react';
import { act, render, waitFor } from '@testing-library/react';
import { describeEachAppLayout, getGlobalDrawersTestUtils, testDrawer } from './utils';

import AppLayout from '../../../lib/components/app-layout';
import { awsuiPlugins, awsuiPluginsInternal } from '../../../lib/components/internal/plugins/api';
import { useAppLayoutPlacement } from '../../../lib/components/app-layout/utils/use-app-layout-placement';
import { computeHorizontalLayout } from '../../../lib/components/app-layout/visual-refresh-toolbar/compute-layout';
import { awsuiPlugins, awsuiPluginsInternal } from '../../../lib/components/internal/plugins/api';
import { DrawerConfig } from '../../../lib/components/internal/plugins/controllers/drawers';
import createWrapper from '../../../lib/components/test-utils/dom';
import { KeyCode } from '../../internal/keycode';
import { useAppLayoutPlacement } from '../../../lib/components/app-layout/utils/use-app-layout-placement';
import { describeEachAppLayout, getGlobalDrawersTestUtils, testDrawer } from './utils';

beforeEach(() => {
awsuiPluginsInternal.appLayout.clearRegisteredDrawers();
Expand Down
17 changes: 9 additions & 8 deletions src/app-layout/__tests__/runtime-drawers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React, { useState } from 'react';
import { act, fireEvent, render } from '@testing-library/react';

import { Button } from '../../../lib/components';
import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import { TOOLS_DRAWER_ID } from '../../../lib/components/app-layout/utils/use-drawers';
import { awsuiPlugins, awsuiPluginsInternal } from '../../../lib/components/internal/plugins/api';
import { DrawerConfig } from '../../../lib/components/internal/plugins/controllers/drawers';
import createWrapper from '../../../lib/components/test-utils/dom';
import {
describeEachAppLayout,
findActiveDrawerLandmark,
getActiveDrawerWidth,
getGlobalDrawersTestUtils,
testDrawer,
} from './utils';
import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import { TOOLS_DRAWER_ID } from '../../../lib/components/app-layout/utils/use-drawers';
import { awsuiPlugins, awsuiPluginsInternal } from '../../../lib/components/internal/plugins/api';
import { DrawerConfig } from '../../../lib/components/internal/plugins/controllers/drawers';
import createWrapper from '../../../lib/components/test-utils/dom';

import triggerStyles from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';
import toolbarTriggerStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/trigger-button/styles.selectors.js';
import toolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/styles.selectors.js';
import toolbarTriggerStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/trigger-button/styles.selectors.js';
import iconStyles from '../../../lib/components/icon/styles.selectors.js';
import { Button } from '../../../lib/components';

beforeEach(() => {
awsuiPluginsInternal.appLayout.clearRegisteredDrawers();
Expand Down
3 changes: 1 addition & 2 deletions src/app-layout/__tests__/skeleton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable simple-import-sort/imports */
import React from 'react';

import { describeEachAppLayout, renderComponent } from './utils';
import AppLayout from '../../../lib/components/app-layout';
import BreadcrumbGroup from '../../../lib/components/breadcrumb-group';
import { getFunnelKeySelector } from '../../internal/analytics/selectors';
import { describeEachAppLayout, renderComponent } from './utils';

let widgetMockEnabled = false;
function createWidgetizedComponentMock(Implementation: React.ComponentType, Skeleton: React.ComponentType) {
Expand Down
4 changes: 2 additions & 2 deletions src/app-layout/__tests__/slots.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React from 'react';
import { describeEachAppLayout, renderComponent } from './utils';

import AppLayout from '../../../lib/components/app-layout';
import { describeEachAppLayout, renderComponent } from './utils';

describeEachAppLayout(() => {
describe.each([true, false])('stickyNotifications=%s', stickyNotifications => {
Expand Down
29 changes: 5 additions & 24 deletions src/app-layout/__tests__/split-panel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React, { useState } from 'react';
import { screen } from '@testing-library/react';

import AppLayout from '../../../lib/components/app-layout';
import { AppLayoutProps } from '../../../lib/components/app-layout/interfaces';
import SplitPanel from '../../../lib/components/split-panel';
import { KeyCode } from '../../../lib/components/internal/keycode';
import { useVisualRefresh } from '../../../lib/components/internal/hooks/use-visual-mode';
import { describeEachAppLayout, renderComponent, splitPanelI18nStrings } from './utils';
import applayoutTools from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';
import SplitPanel from '../../../lib/components/split-panel';
import { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
import { describeEachAppLayout, renderComponent, splitPanelI18nStrings } from './utils';

import applayoutTools from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';
import testUtilStyles from '../../../lib/components/split-panel/test-classes/styles.selectors.js';

const defaultSplitPanel = (
Expand All @@ -30,17 +29,6 @@ const fakeComputedStyle: Window['getComputedStyle'] = (...args) => {
return result;
};

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
useVisualRefresh: jest.fn().mockReturnValue(false),
}));

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isMotionDisabled: jest.fn().mockReturnValue(true),
useDensityMode: jest.fn().mockReturnValue('comfortable'),
useReducedMotion: jest.fn().mockReturnValue(true),
}));

let isMocked = false;

jest.mock('@cloudscape-design/component-toolkit', () => {
Expand Down Expand Up @@ -261,14 +249,7 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
});
});

describe('Visual refresh only features', () => {
beforeEach(() => {
(useVisualRefresh as jest.Mock).mockReturnValue(true);
});
afterEach(() => {
(useVisualRefresh as jest.Mock).mockReset();
});

describeEachAppLayout({ themes: ['refresh'], sizes: ['desktop'] }, () => {
function isDrawersBarDisplayed(wrapper: AppLayoutWrapper) {
return !!wrapper.findByClassName(applayoutTools['has-tools-form']);
}
Expand Down
Loading
Loading