From b52ae89ef18dfd9c08876b1f56a1cce8892623e9 Mon Sep 17 00:00:00 2001 From: Jason Long Date: Wed, 12 Feb 2025 15:20:35 -0800 Subject: [PATCH] fix most react-web storybook tests Change-Id: I5c3db102b883ab9718df3016506629c0ab3b5099 GitOrigin-RevId: 816f574410aa3f4a2fe91ee319b2466edf2516ec --- .../react-web/.storybook/{main.js => main.ts} | 10 +- .../.storybook/{preview.js => preview.ts} | 0 packages/react-web/.storybook/test-runner.ts | 9 + .../src/stories/PlasmicImg.stories.tsx | 19 +- .../src/stories/UseDollarState.stories.tsx | 507 ++++++++---------- 5 files changed, 256 insertions(+), 289 deletions(-) rename packages/react-web/.storybook/{main.js => main.ts} (61%) rename packages/react-web/.storybook/{preview.js => preview.ts} (100%) create mode 100644 packages/react-web/.storybook/test-runner.ts diff --git a/packages/react-web/.storybook/main.js b/packages/react-web/.storybook/main.ts similarity index 61% rename from packages/react-web/.storybook/main.js rename to packages/react-web/.storybook/main.ts index 7fba025285a..2db1561bcf9 100644 --- a/packages/react-web/.storybook/main.js +++ b/packages/react-web/.storybook/main.ts @@ -1,15 +1,17 @@ -module.exports = { +import type { StorybookConfig } from "@storybook/react-webpack5"; + +const config: StorybookConfig = { stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], addons: [ "@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions", + "@storybook/addon-webpack5-compiler-swc", ], framework: { name: "@storybook/react-webpack5", options: {}, }, - features: { - interactionsDebugger: true, - }, }; + +export default config; diff --git a/packages/react-web/.storybook/preview.js b/packages/react-web/.storybook/preview.ts similarity index 100% rename from packages/react-web/.storybook/preview.js rename to packages/react-web/.storybook/preview.ts diff --git a/packages/react-web/.storybook/test-runner.ts b/packages/react-web/.storybook/test-runner.ts new file mode 100644 index 00000000000..d6f417196ed --- /dev/null +++ b/packages/react-web/.storybook/test-runner.ts @@ -0,0 +1,9 @@ +import type { TestRunnerConfig } from "@storybook/test-runner"; + +const config: TestRunnerConfig = { + tags: { + skip: ["skip-test"], + }, +}; + +export default config; diff --git a/packages/react-web/src/stories/PlasmicImg.stories.tsx b/packages/react-web/src/stories/PlasmicImg.stories.tsx index dd9f9e71c94..d9f57dd209f 100644 --- a/packages/react-web/src/stories/PlasmicImg.stories.tsx +++ b/packages/react-web/src/stories/PlasmicImg.stories.tsx @@ -1,10 +1,18 @@ -import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { Meta, StoryFn } from "@storybook/react"; import React from "react"; import { PlasmicImg } from "../render/PlasmicImg"; import "../styles/plasmic.css"; -const Template: ComponentStory = (args: any) => { - const { containerWidth, containerHeight, ...rest } = args; +type PlasmicImgTemplateProps = React.ComponentProps & { + containerWidth?: number; + containerHeight?: number; +}; + +const Template: StoryFn = ({ + containerWidth, + containerHeight, + ...rest +}) => { return (
@@ -38,11 +46,10 @@ export default { }, args: { src: { - src: - "https://img.plasmic.app/img-optimizer/v1/img/07a7153536a89fef14e0075c7632d6b3.jpg", + src: "https://img.plasmic.app/img-optimizer/v1/img/07a7153536a89fef14e0075c7632d6b3.jpg", fullWidth: 3840, fullHeight: 2160, }, loader: "plasmic", }, -} as ComponentMeta; +} satisfies Meta; diff --git a/packages/react-web/src/stories/UseDollarState.stories.tsx b/packages/react-web/src/stories/UseDollarState.stories.tsx index fa4a9161d2d..060205e84f3 100644 --- a/packages/react-web/src/stories/UseDollarState.stories.tsx +++ b/packages/react-web/src/stories/UseDollarState.stories.tsx @@ -1,8 +1,9 @@ -import { expect } from "@storybook/jest"; -import { Story } from "@storybook/react"; +import { StoryFn } from "@storybook/react"; +import { expect, waitFor } from "@storybook/test"; import { userEvent, within } from "@storybook/testing-library"; import React from "react"; import { + $StateSpec, generateStateOnChangeProp, generateStateValueProp, get, @@ -10,19 +11,16 @@ import { useDollarState, } from "../states"; import { CyclicStatesReferencesError } from "../states/errors"; -import { $StateSpec } from "../states/types"; const deepClone = function (o: T): T { return JSON.parse(JSON.stringify(o)); }; -const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); - export default { title: "UseDollarState", }; -interface CounterArgs { +interface CounterProps { stateType?: "private" | "readonly" | "writable"; showCount?: boolean; onChange?: (val: number) => void; @@ -31,13 +29,13 @@ interface CounterArgs { "data-testid"?: string; title?: React.ReactNode; } -const Counter: Story = (args) => { +const Counter: StoryFn = (props) => { const { stateType = "private" as const, showCount = true, useInitalFunction, title, - } = args; + } = props; const $state = useDollarState( [ @@ -65,7 +63,7 @@ const Counter: Story = (args) => { }, ], { - $props: args, + $props: props, } ); return ( @@ -74,7 +72,7 @@ const Counter: Story = (args) => {