-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from nus3/update-testing-library
Update testing library
- Loading branch information
Showing
10 changed files
with
3,666 additions
and
6,829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
module.exports = { | ||
framework: "@storybook/react", | ||
import { dirname, join } from "node:path"; | ||
|
||
import type { StorybookConfig } from "@storybook/react-vite"; | ||
|
||
function getAbsolutePath(value: string) { | ||
return dirname(require.resolve(join(value, "package.json"))); | ||
} | ||
|
||
const config: StorybookConfig = { | ||
framework: { | ||
// HACK: "@storybook/react-vite"しか許可されていない部分をstringも許可するように | ||
// @ts-expect-error | ||
name: getAbsolutePath("@storybook/react-vite"), | ||
options: {}, | ||
}, | ||
|
||
stories: ["../src/components/**/*.stories.@(js|jsx|ts|tsx)"], | ||
|
||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-interactions", | ||
getAbsolutePath("@storybook/addon-links"), | ||
getAbsolutePath("@storybook/addon-essentials"), | ||
getAbsolutePath("@storybook/addon-interactions"), | ||
], | ||
|
||
staticDirs: ["../public"], | ||
core: { | ||
builder: "@storybook/builder-vite", | ||
}, | ||
features: { | ||
storyStoreV7: true, | ||
}, | ||
|
||
async viteFinal(config) { | ||
return config; | ||
}, | ||
|
||
docs: { | ||
autodocs: true, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { action } from "@storybook/addon-actions"; | ||
|
||
import { fn } from "@storybook/test"; | ||
import { Button } from "./Button"; | ||
|
||
import type { ComponentStoryObj, Meta } from "@storybook/react"; | ||
import type { StoryObj, Meta } from "@storybook/react"; | ||
|
||
export default { | ||
title: "Button", | ||
const meta: Meta = { | ||
component: Button, | ||
} as Meta; | ||
} satisfies Meta<typeof Button>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: ComponentStoryObj<typeof Button> = { | ||
export const Default: Story = { | ||
args: { | ||
children: "label", | ||
onClick: action("onClick"), | ||
onClick: fn(), | ||
}, | ||
}; |
12 changes: 7 additions & 5 deletions
12
apps/react-vitest/src/components/DateText/DateText.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { DateText } from "./DateText"; | ||
|
||
import type { ComponentStoryObj, Meta } from "@storybook/react"; | ||
import type { StoryObj, Meta } from "@storybook/react"; | ||
|
||
export default { | ||
title: "DateText", | ||
const meta: Meta = { | ||
component: DateText, | ||
} as Meta; | ||
} satisfies Meta<typeof DateText>; | ||
|
||
export const Default: ComponentStoryObj<typeof DateText> = { | ||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
apps/react-vitest/src/components/SelectBox/SelectBox.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { action } from "@storybook/addon-actions"; | ||
|
||
import { SelectBox } from "./SelectBox"; | ||
|
||
import type { ComponentStoryObj, Meta } from "@storybook/react"; | ||
import type { StoryObj, Meta } from "@storybook/react"; | ||
import { fn } from "@storybook/test"; | ||
|
||
export default { | ||
title: "SelectBox", | ||
const meta: Meta = { | ||
component: SelectBox, | ||
} as Meta; | ||
} satisfies Meta<typeof SelectBox>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: ComponentStoryObj<typeof SelectBox> = { | ||
export const Default: Story = { | ||
args: { | ||
onClick: action("onClick"), | ||
onClick: fn(), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
import { userEvent, within } from "@storybook/testing-library"; | ||
import { expect, userEvent, within } from "@storybook/test"; | ||
|
||
import { Toast } from "./Toast"; | ||
import { AUTO_CLOSE_TIME, TOAST_ANIMATION_TIME, Toast } from "./Toast"; | ||
|
||
import type { ComponentStoryObj, Meta } from "@storybook/react"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
export default { | ||
title: "Toast", | ||
const meta: Meta = { | ||
component: Toast, | ||
} as Meta; | ||
} satisfies Meta<typeof Toast>; | ||
|
||
export const Default: ComponentStoryObj<typeof Toast> = { | ||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: "Hello nus3 in Storybook!!", | ||
}, | ||
play: ({ canvasElement }) => { | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const btn = canvas.getByRole("button"); | ||
userEvent.click(btn); | ||
|
||
await userEvent.click(btn); | ||
await expect(canvas.getByRole("alert")).toBeInTheDocument(); | ||
|
||
// HACK: 不安定になる気しかしない | ||
setTimeout(async () => { | ||
await expect(canvas.queryByRole("alert")).toBeNull(); | ||
}, AUTO_CLOSE_TIME + TOAST_ANIMATION_TIME); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.