Skip to content

Conversation

@just-boris
Copy link
Member

Description

Remove a lot of jest.mock calls

Related links, issue #, if available: n/a

How has this been tested?

Test-only changes

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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

Comment on lines -22 to -24
jest.mock('../../../lib/components/internal/hooks/use-mobile', () => ({
useMobile: jest.fn().mockReturnValue(true),
}));
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

Comment on lines -18 to 17

// 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();
});
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

@codecov
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.42%. Comparing base (6038d56) to head (e91f1d3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3277      +/-   ##
==========================================
- Coverage   96.44%   96.42%   -0.03%     
==========================================
  Files         791      791              
  Lines       22569    22573       +4     
  Branches     7733     7794      +61     
==========================================
- Hits        21766    21765       -1     
- Misses        750      801      +51     
+ Partials       53        7      -46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -31 to -34
jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isMotionDisabled: jest.fn().mockReturnValue(true),
}));
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)

Comment on lines +12 to +15
const forceMobileMode = (globalThis as any)[forceMobileModeSymbol];
if (typeof forceMobileMode !== 'undefined') {
return forceMobileMode;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This follows our VR flags idea: cloudscape-design/component-toolkit#79

Currently this is used only internally, but we might make it our official test util to allow our consumers write unit tests on mobile use-cases

Comment on lines +66 to +67
// remove after this is released: https://github.com/cloudscape-design/component-toolkit/pull/118
document.body.classList.remove('awsui-visual-refresh');
Copy link
Member Author

Choose a reason for hiding this comment

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

@just-boris just-boris marked this pull request as ready for review February 11, 2025 12:39
@just-boris just-boris requested a review from a team as a code owner February 11, 2025 12:39
@just-boris just-boris requested review from gethinwebster and removed request for a team February 11, 2025 12:39
@just-boris just-boris added this pull request to the merge queue Feb 11, 2025
Merged via the queue into main with commit ded9233 Feb 11, 2025
38 checks passed
@just-boris just-boris deleted the app-layout-tests-remove-mocks branch February 11, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants