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

Docs: Add docs for mounting inside the play function #28444

Merged
merged 24 commits into from
Jul 10, 2024
Merged

Conversation

kasperpeulen
Copy link
Contributor

Closes #

What I did

Add docs for mounting inside the play function

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!

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>

@kasperpeulen kasperpeulen added documentation ci:docs Run the CI jobs for documentation checks only. labels Jul 3, 2024
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.

PR Summary

  • Added docs/_snippets/before-each-in-preview.md for beforeEach function usage in preview files.
  • Added docs/_snippets/mount-advanced.md with advanced mounting examples for React, Svelte, and Vue3.
  • Added docs/_snippets/mount-basic.md with basic mounting examples using MockDate.
  • Updated docs/api/doc-blocks/doc-block-story.mdx to include a Callout about autoplay requirement for mount.
  • Enhanced docs/writing-tests/interaction-testing.mdx with detailed guidance on mounting inside the play function.

5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

nx-cloud bot commented Jul 3, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 3e0adbd. 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.

@kasperpeulen kasperpeulen requested a review from yannbf July 3, 2024 22:23
Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

Looks good! I added a few comments, please check them out.
Would be nice to have @kylegach take a look at this after he is back!

docs/_snippets/mount-basic.md Outdated Show resolved Hide resolved
docs/_snippets/mount-basic.md Outdated Show resolved Hide resolved
docs/_snippets/mount-basic.md Outdated Show resolved Hide resolved
docs/_snippets/mount-advanced.md Show resolved Hide resolved
docs/_snippets/mount-advanced.md Show resolved Hide resolved
docs/writing-tests/interaction-testing.mdx Outdated Show resolved Hide resolved
docs/writing-tests/interaction-testing.mdx Outdated Show resolved Hide resolved
docs/writing-tests/interaction-testing.mdx Outdated Show resolved Hide resolved
docs/writing-tests/interaction-testing.mdx Outdated Show resolved Hide resolved
docs/writing-tests/interaction-testing.mdx Outdated Show resolved Hide resolved
Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

Changes look good but I'd love for @kylegach to take a pass at them

docs/api/doc-blocks/doc-block-story.mdx Outdated Show resolved Hide resolved
docs/writing-tests/interaction-testing.mdx Outdated Show resolved Hide resolved
@valentinpalkovic
Copy link
Contributor

I think we should call out that when the mount function is used to actually pass in a new JSXElement with modified arguments, these are NOT synced to the controls panel. Is this a limitation we want to document or actually a bug?

@kasperpeulen
Copy link
Contributor Author

@valentinpalkovic A custom render function has the exact same limitation right?

The mount args are really implemented as lazy render function, so every limitation with the render function will also apply to the mount args.

@valentinpalkovic
Copy link
Contributor

That's correct. Still, this limitation should be highlighted and mentioned.

@kasperpeulen
Copy link
Contributor Author

@valentinpalkovic But do you mean in both the render and mount docs then?

@valentinpalkovic
Copy link
Contributor

Yes, if it isn't part of the render docs, then for sure!

- Prose tweaks, adding links for context
- Use `If` blocks for conditional content
- Restructure content to be story, component, project-ordered
- Update headings to be problem-oriented
@@ -56,24 +56,71 @@ Once the story loads in the UI, it simulates the user's behavior and verifies th

<Video src="../_assets/writing-tests/addon-interaction-example-optimized.mp4" />

### Run code before each test
<If notRenderer="angular">
Copy link
Contributor

Choose a reason for hiding this comment

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

I opted to conditionally render this content so that Angular viewers don't even see this feature they cannot use.

But should we render fallback content showing them how to use story-level beforeEach? @kasperpeulen

Copy link
Contributor Author

@kasperpeulen kasperpeulen Jul 9, 2024

Choose a reason for hiding this comment

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

I like this! My feeling is that displaying the current 'beforeEach' docs for Angular is sufficient. I'm collaborating with the vitest team to enhance the regex for Angular compatibility.

2. Your Storybook framework or builder must be configured to transpile to ES2017 or newer. This is because destructuring statements and async/await usages are otherwise transpiled away, which prevents Storybook from recognizing your usage of `mount`.
</Callout>

<If renderer={['react', 'vue', 'svelte']}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the snippets are only available for these renderers, it seemed like the feature itself only worked for these, so I conditionally rendered this section.

Is there appropriate fallback content for the others? @kasperpeulen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fallback is kind of the basic-mount example, which will be displayed above this, so I think this is fine!

Comment on lines +69 to +74
<Callout variant="warning">
There are two requirements to use the `mount` function:

1. You *must* destructure the mount property from the `context` (the argument passed to your play function). This makes sure that Storybook does not start rendering the story before the play function begins.
2. Your Storybook framework or builder must be configured to transpile to ES2017 or newer. This is because destructuring statements and async/await usages are otherwise transpiled away, which prevents Storybook from recognizing your usage of `mount`.
</Callout>
Copy link
Contributor

Choose a reason for hiding this comment

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

If you like the way I reworded this, I suggest updating the error message changed in the PR to match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this, but I feel that the error message in Storybook should still explicitly point out Angular.

@kylegach kylegach merged commit c226334 into next Jul 10, 2024
11 checks passed
@kylegach kylegach deleted the kasper/mount-docs branch July 10, 2024 19:00
@github-actions github-actions bot mentioned this pull request Jul 10, 2024
33 tasks
kylegach added a commit that referenced this pull request Jul 10, 2024
Docs: Add docs for mounting inside the play function
@kylegach kylegach mentioned this pull request Jul 10, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:docs Run the CI jobs for documentation checks only. documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants