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

コンポーネントのStoryの調整・不足分の追加 #2333

Merged
merged 17 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
5 changes: 5 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const preview: Preview = {
value: "#333",
},
],
grid: {
cellSize: 8,
cellAmount: 4,
opacity: 0.1,
},
},
},
decorators: [
Expand Down
15 changes: 11 additions & 4 deletions src/components/Base/BaseCheckbox.stories.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { ref } from "vue";
import BaseCheckbox from "./BaseCheckbox.vue";

const meta: Meta<typeof BaseCheckbox> = {
component: BaseCheckbox,
render: (args) => ({
components: { BaseCheckbox },
setup() {
const checked = ref(Boolean(args.checked));
return { args, checked };
},
template: `<BaseCheckbox v-bind="args" v-model:checked="checked"></BaseCheckbox>`,
}),
};

export default meta;
type Story = StoryObj<typeof BaseCheckbox>;

export const Default: Story = {
export const Unchecked: Story = {
args: {
label: "Default",
checked: false,
label: "Unchecked",
},
};

export const Checked: Story = {
...Default,
args: {
label: "Checked",
checked: true,
Expand Down
46 changes: 46 additions & 0 deletions src/components/Base/BaseSelect.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ref } from "vue";
import type { Meta, StoryObj } from "@storybook/vue3";

import BaseSelect from "./BaseSelect.vue";
import BaseSelectItem from "./BaseSelectItem.vue";

const meta: Meta<typeof BaseSelect> = {
component: BaseSelect,
render: (args) => ({
components: { BaseSelect, BaseSelectItem },
setup() {
const modelValue = ref(
args.modelValue ? String(args.modelValue) : undefined,
);
return { args, modelValue };
},
template: `
<BaseSelect v-bind="args" v-model="modelValue">
<BaseSelectItem label="A" value="a" />
<BaseSelectItem label="B" value="b" />
<BaseSelectItem label="C" value="c" />
</BaseSelect>`,
}),
};

export default meta;
type Story = StoryObj<typeof BaseSelect>;

export const Default: Story = {
args: {
modelValue: "a",
},
};

export const Placeholder: Story = {
args: {
placeholder: "placeholder",
},
};

export const Disabled: Story = {
args: {
modelValue: "a",
disabled: true,
},
};
9 changes: 9 additions & 0 deletions src/components/Base/BaseSwitch.stories.ts
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { ref } from "vue";
import BaseSwitch from "./BaseSwitch.vue";

const meta: Meta<typeof BaseSwitch> = {
component: BaseSwitch,
render: (args) => ({
components: { BaseSwitch },
setup() {
const checked = ref(Boolean(args.checked));
return { args, checked };
},
template: `<BaseSwitch v-bind="args" v-model:checked="checked"></BaseSwitch>`,
}),
};

export default meta;
Expand Down
36 changes: 36 additions & 0 deletions src/components/Base/BaseTooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { TooltipProvider } from "radix-vue";
import BaseTooltip from "./BaseTooltip.vue";

const meta: Meta<typeof BaseTooltip> = {
component: BaseTooltip,
render: (args) => ({
components: { BaseTooltip, TooltipProvider },
setup() {
return { args };
},
template: `
<TooltipProvider>
<BaseTooltip v-bind="args">
<span>Hover</span>
</BaseTooltip>
</TooltipProvider>`,
}),
};

export default meta;
type Story = StoryObj<typeof BaseTooltip>;

export const Default: Story = {
args: {
label: "Default",
},
};

export const Disabled: Story = {
args: {
label: "Default",
disabled: true,
},
};
65 changes: 65 additions & 0 deletions src/components/Dialog/AcceptDialog/AcceptDialog.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { userEvent, within, expect, fn } from "@storybook/test";

import { Meta, StoryObj } from "@storybook/vue3";
import AcceptDialog from "./AcceptDialog.vue";

const meta: Meta<typeof AcceptDialog> = {
component: AcceptDialog,
args: {
modelValue: false,
title: "タイトル",
heading: "見出し",
terms: "# 見出し1\n文章文章文章\n## 見出し2\n文章文章文章",
rejectLabel: "拒否",
acceptLabel: "承諾",
"onUpdate:modelValue": fn(),
onAccept: fn(),
onReject: fn(),
},
tags: ["!autodocs"], // ダイアログ系はautodocsのプレビューが正しく表示されないので無効化
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Opened: Story = {
name: "開いている",
args: {
modelValue: true,
},
};

export const Accept: Story = {
name: "承諾ボタンを押す",
args: { ...Opened.args },
play: async ({ args }) => {
const canvas = within(document.body); // ダイアログなので例外的にdocument.bodyを使う

const button = canvas.getByRole("button", { name: /承諾/ });
await userEvent.click(button);

// 承諾イベントが呼ばれる
await expect(args["onAccept"]).toBeCalledWith();
},
};

export const Reject: Story = {
name: "拒否ボタンを押す",
args: {
...Opened.args,
},
play: async ({ args }) => {
const canvas = within(document.body); // ダイアログなので例外的にdocument.bodyを使う

const button = canvas.getByRole("button", { name: /拒否/ });
await userEvent.click(button);

// 拒否イベントが呼ばれる
await expect(args["onReject"]).toBeCalledWith();
},
};

export const Closed: Story = {
name: "閉じている",
tags: ["skip-screenshot"],
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading