-
Notifications
You must be signed in to change notification settings - Fork 209
chore: Fix mocks application in app layout tests #3277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and in many places below – removed direct mock applications, because |
||
| import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js'; | ||
|
|
||
| const testIf = (condition: boolean) => (condition ? test : test.skip); | ||
|
|
||
|
|
||
| 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| test('should not create a new stacking context by default', () => { | ||
|
|
||
| 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
| 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, | ||
|
|
||
There was a problem hiding this comment.
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