Skip to content
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

Addon Test: Support viewport globals #29319

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Oct 10, 2024

Closes #29324

What I did

This PR adds support for the new globals API for viewports, so that users that use the new test addon can get Playwright to use the correct dimensions respecting the viewports addon, both via parameters (legacy) API as well as globals (new) API

To make this work, I had to update portable stories to also include globals as part of its return type.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

There are tests for all use cases, but to test it manually you can use a story like the following (using both parameters and globals apis):

const customViewports = {
  sized: {
    name: 'Sized',
    styles: {
      width: '380px',
      height: '500px',
    },
  },
};
const parametersApi = {
  defaultViewport: 'sized',
  viewports: customViewports,
}
const globalsApi = {
  options: customViewports,
}

export const ExpectedSuccess = {
  parameters: {
    viewport: {
      ...parametersApi,
      ...globalsApi
    },
  },
  globals: { viewport: { value: 'sized' } },
};

Then run Vitest browser mode tests visually, and notice the viewport changing in size.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.7 MB 78.7 MB 6 B 0.69 0%
initSize 147 MB 147 MB 22 B -1.08 0%
diffSize 68.3 MB 68.3 MB 16 B -1.08 0%
buildSize 7.1 MB 7.1 MB 28 B -0.66 0%
buildSbAddonsSize 1.79 MB 1.79 MB 30 B -0.72 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.85 MB 1.85 MB 0 B -0.73 0%
buildSbPreviewSize 271 kB 271 kB -2 B -0.76 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.1 MB 4.1 MB 28 B -0.73 0%
buildPreviewSize 3 MB 3 MB 0 B 1.09 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 5.9s 5.6s -233ms -1.28 -4.1%
generateTime 22.1s 19.2s -2s -861ms -0.93 -14.9%
initTime 14.7s 12.7s -2s -5ms -1.69 🔰-15.7%
buildTime 10.7s 7.8s -2s -904ms -1.7 🔰-37.1%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6s 6.1s 19ms -0.42 0.3%
devManagerResponsive 4s 3.9s -118ms -0.63 -3%
devManagerHeaderVisible 589ms 602ms 13ms 0.09 2.2%
devManagerIndexVisible 620ms 636ms 16ms 0.08 2.5%
devStoryVisibleUncached 809ms 894ms 85ms -0.75 9.5%
devStoryVisible 619ms 638ms 19ms 0.1 3%
devAutodocsVisible 568ms 533ms -35ms -0.4 -6.6%
devMDXVisible 573ms 528ms -45ms -0.13 -8.5%
buildManagerHeaderVisible 572ms 526ms -46ms -0.72 -8.7%
buildManagerIndexVisible 638ms 594ms -44ms 0.18 -7.4%
buildStoryVisible 639ms 594ms -45ms -0.2 -7.6%
buildAutodocsVisible 542ms 547ms 5ms 0.4 0.9%
buildMDXVisible 690ms 464ms -226ms -1.13 -48.7%

Greptile Summary

This PR adds support for viewport globals in the Storybook addon testing framework, enhancing the ability to test responsive designs across different viewport sizes.

  • Updated setViewport function in viewports.ts to handle both parameters and globals for viewport settings
  • Added new tests in viewports.test.ts to cover the globals API and various viewport dimension formats
  • Modified testStory function in test-utils.ts to pass both parameters and globals to setViewport
  • Updated ComposedStoryFn type in composedStory.ts to include a globals property
  • Removed '!vitest' tags from some stories in tabs.stories.tsx and Sidebar.stories.tsx to enable testing with viewport globals

Copy link

nx-cloud bot commented Oct 10, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 27aa84b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@yannbf yannbf force-pushed the yann/support-viewport-globals-in-ps branch from 733fa26 to bba2178 Compare October 10, 2024 17:16
@yannbf yannbf marked this pull request as ready for review October 10, 2024 17:16
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

9 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +203 to +205
const viewportsParam: any = {
defaultViewport: 'nonExistentViewport',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

style: using 'any' type here might be too permissive

Comment on lines +215 to +217
const viewportsParam: any = {
viewports: INITIAL_VIEWPORTS,
// supported by default in addon viewports
Copy link
Contributor

Choose a reason for hiding this comment

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

style: using 'any' type here might be too permissive

Comment on lines 16 to +22
export interface ViewportsParam {
defaultViewport: string;
viewports: ViewportMap;
defaultViewport?: string;
viewports?: ViewportMap;
options?: ViewportMap;
disable?: boolean;
disabled?: boolean;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding JSDoc comments to explain the purpose of each property in the ViewportsParam interface

Comment on lines +24 to 27
export interface ViewportsGlobal {
value?: string;
disable?: boolean;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Add JSDoc comments to explain the purpose of the ViewportsGlobal interface and its properties

@@ -47,8 +57,18 @@ const parseDimension = (value: string, dimension: 'width' | 'height') => {
}
};

export const setViewport = async (viewportsParam: ViewportsParam = {} as ViewportsParam) => {
const defaultViewport = viewportsParam.defaultViewport;
export const setViewport = async (parameters: Parameters = {}, globals: Globals = {}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Update function signature to use more specific types instead of Parameters and Globals

Comment on lines 77 to 81
const viewports = {
...MINIMAL_VIEWPORTS,
...viewportsParam.viewports,
...viewportsParam.options,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Merging viewports might overwrite properties. Ensure this is the intended behavior

@yannbf yannbf force-pushed the yann/support-viewport-globals-in-ps branch from bba2178 to 9af9b98 Compare October 11, 2024 05:53
let defaultViewport;
const viewportsParam: ViewportsParam = parameters.viewport ?? {};
const viewportsGlobal: ViewportsGlobal = globals.viewport ?? {};
const isDisabled = viewportsParam.disable || viewportsParam.disabled;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this take viewportsGlobal.disable into account too?

Copy link
Member Author

@yannbf yannbf Oct 11, 2024

Choose a reason for hiding this comment

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

From what I can see there is no such thing as global.viewport.disable, only from parameters:

const { options = MINIMAL_VIEWPORTS, disable } = config || {};

can you show me where it's used?

@yannbf yannbf force-pushed the yann/support-viewport-globals-in-ps branch from 9af9b98 to a28553f Compare October 11, 2024 10:15
@yannbf yannbf force-pushed the yann/support-viewport-globals-in-ps branch from a28553f to 27aa84b Compare October 14, 2024 09:34
@yannbf yannbf merged commit 2ca29f8 into unified-ui-testing Oct 14, 2024
50 of 54 checks passed
@yannbf yannbf deleted the yann/support-viewport-globals-in-ps branch October 14, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants