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

[UI v2] Setup Storybook #16003

Merged
merged 2 commits into from
Nov 15, 2024
Merged

[UI v2] Setup Storybook #16003

merged 2 commits into from
Nov 15, 2024

Conversation

evan-liu
Copy link
Contributor

closes #15998

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

@github-actions github-actions bot added the enhancement An improvement of an existing feature label Nov 13, 2024
@evan-liu evan-liu changed the title Setup Storybook for v2 UI [UI v2] Setup Storybook Nov 13, 2024
Comment on lines +43 to +66
export const TestAddRemove: Story = {
name: "Test: Add and remove",
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
const tagsInput: HTMLInputElement = canvas.getByRole("textbox");

await step("Add testTag", async () => {
await userEvent.type(tagsInput, "testTag");
await expect(tagsInput.value).toBe("testTag");
await userEvent.type(tagsInput, "{enter}");
await expect(tagsInput.value).toBe("");
await expect(canvas.queryByText("testTag")).not.toBeNull();
});

await step("Add testTag2", async () => {
await userEvent.type(tagsInput, "testTag2{enter}");
});

await step("Delete testTag", async () => {
await userEvent.click(canvas.getAllByRole("button")[0]);
await expect(canvas.queryByText("testTag")).toBeNull();
});
},
};
Copy link
Member

Choose a reason for hiding this comment

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

This is neat! I haven't seen tests written with Storybook before. Does this have any advantages over our current vitest + testing-library setup?

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 didn't set up the test runner for it on CI (I can add it to this PR or another PR if you're interested), so it is more for development than testing.

  • The play function further reduces the feedback loop on local-dev
  • The time travel feature helps with debugging

Please see the live version here.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the Storybook test also uses vitest + testing-library, here’s one potential workflow without a test runner for the Storybook tests:

  1. Use the Storybook play function to facilitate local development.
  2. Once development is completed, copy the Storybook test into the test suite.
  3. Clean up the Storybook stories and tests, keep only the stories/tests for documentation purposes.

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!

@desertaxle desertaxle merged commit 5877a75 into PrefectHQ:main Nov 15, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storybook for UI V2?
2 participants