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

Develop #81

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions .scaffdog/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,11 @@ export const Sample: Story = {
# `{{ inputs.name | pascal }}/{{ inputs.name | pascal }}.test.tsx`

```tsx
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./{{ inputs.name | pascal }}.stories";

const { ...otherStories } = composeStories(stories);

describe("{{ inputs.name | pascal }}", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const meta = {
component: Footer,
parameters: {
layout: "fullscreen",
testLevel: "snapshot",
},
} satisfies Meta<typeof Footer>;

Expand Down
19 changes: 2 additions & 17 deletions src/components/HeaderFooterTemplate/Footer/Footer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./Footer.stories";

const { ...otherStories } = composeStories(stories);

describe("Footer", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Footer renders Sample 1`] = `
exports[`Footer スナップショット Sample 1`] = `
<body>
<div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const meta = {
component: Header,
parameters: {
layout: "fullscreen",
testLevel: "snapshot",
},
} satisfies Meta<typeof Header>;

Expand Down
25 changes: 2 additions & 23 deletions src/components/HeaderFooterTemplate/Header/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./Header.stories";

const { ...otherStories } = composeStories(stories);

// TODO: 他にいい方法はないものか...理想としては storybook では追加設定不要なので jest も不要になって欲しい
// story で仮に返却値を指定したとしても適切にスナップショットを撮ることができない。
jest.mock("next/navigation", () => ({
usePathname: jest.fn().mockReturnValue("/other-path"),
}));

describe("Header", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Header renders Sample 1`] = `
exports[`Header スナップショット Sample 1`] = `
<body>
<div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const meta = {
component: HeaderFooterTemplate,
parameters: {
layout: "fullscreen",
testLevel: "snapshot",
},
} satisfies Meta<typeof HeaderFooterTemplate>;

Expand Down
23 changes: 2 additions & 21 deletions src/components/HeaderFooterTemplate/HeaderFooterTemplate.test.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./HeaderFooterTemplate.stories";

const { ...otherStories } = composeStories(stories);

jest.mock("next/navigation", () => ({
usePathname: jest.fn().mockReturnValue("/other-path"),
}));

describe("HeaderFooterTemplate", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HeaderFooterTemplate renders Sample 1`] = `
exports[`HeaderFooterTemplate スナップショット Sample 1`] = `
<body>
<div>
<div
Expand Down
1 change: 1 addition & 0 deletions src/components/PageNotFound/PageNotFound.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const meta = {
component: PageNotFound,
parameters: {
layout: "fullscreen",
testLevel: "snapshot",
},
} satisfies Meta<typeof PageNotFound>;

Expand Down
19 changes: 2 additions & 17 deletions src/components/PageNotFound/PageNotFound.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./PageNotFound.stories";

const { ...otherStories } = composeStories(stories);

describe("PageNotFound", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PageNotFound renders Sample 1`] = `
exports[`PageNotFound スナップショット Sample 1`] = `
<body>
<div>
<section>
Expand Down
1 change: 1 addition & 0 deletions src/components/SyakooLabText/SyakooLabText.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const meta = {
component: SyakooLabText,
parameters: {
layout: "centered",
testLevel: "snapshot",
},
} satisfies Meta<typeof SyakooLabText>;

Expand Down
19 changes: 2 additions & 17 deletions src/components/SyakooLabText/SyakooLabText.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./SyakooLabText.stories";

const { ...otherStories } = composeStories(stories);

describe("SyakooLabText", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SyakooLabText renders Sample 1`] = `
exports[`SyakooLabText スナップショット Sample 1`] = `
<body>
<div>
<svg
Expand Down
19 changes: 2 additions & 17 deletions src/design-system/icons/Icon.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { composeStories } from "@storybook/react";
import { act, render } from "@testing-library/react";
import { testStories } from "@/test/testStories";

import * as stories from "./Icon.stories";

const { ...otherStories } = composeStories(stories);

describe("Icon", () => {
const testCases = Object.values(otherStories).map(
(Story) => [Story.storyName, Story] as const,
);
test.each(testCases)("renders %s", async (_, Story) => {
const tree = render(<Story />);
await act(async () => {
if (Story.play) {
await Story.play({ canvasElement: tree.container });
}
});

expect(tree.baseElement).toMatchSnapshot();
});
testStories(stories);
});
Loading
Loading