-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
// SPDX-FileCopyrightText: 2025 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import { Button } from "@radix-ui/themes";
import { action } from "@storybook/addon-actions";
import type { Meta, StoryObj } from "@storybook/react";
import { expect, userEvent, waitFor, within } from "@storybook/test";
import { withMockedBackend } from "../../../.storybook/decorators/withMockedBackend.tsx";
import { DeleteCustomAttributeDefinition } from "../../mocks/yamori/workspace/v2/workspace_service.ts";
import * as DeleteDialog from "./DeleteDialog.tsx";
export default {
component: DeleteDialog.Content,
args: {
id: { value: "cf-foo" },
onDeleteError: action("onDeleteError"),
onDeleteStart: action("onDeleteStart"),
onDeleted: action("onDeleted"),
},
render(args) {
return (
<DeleteDialog.Root>
<DeleteDialog.Trigger>
<Button data-testid="trigger">開く</Button>
</DeleteDialog.Trigger>
<DeleteDialog.Content {...args} />
</DeleteDialog.Root>
);
},
} satisfies Meta<typeof DeleteDialog.Content>;
type Story = StoryObj<typeof DeleteDialog.Content>;
export const Demo: Story = {
decorators: [withMockedBackend([DeleteCustomAttributeDefinition()])],
async play({ canvas }) {
await userEvent.click(canvas.getByTestId("trigger"));
},
};
export const Success: Story = {
decorators: [withMockedBackend([DeleteCustomAttributeDefinition()])],
async play({ canvas }) {
await userEvent.click(canvas.getByTestId("trigger"));
const root = within(document.documentElement);
await userEvent.click(root.getByRole("button", { name: /削除する/ }));
await waitFor(() => expect(root.getByText(/削除しました/)).toBeInTheDocument());
},
};
export const SlowLoad: Story = {
decorators: [withMockedBackend([DeleteCustomAttributeDefinition({ delayMs: 2_000 })])],
async play({ canvas }) {
await userEvent.click(canvas.getByTestId("trigger"));
const root = within(document.documentElement);
await userEvent.click(root.getByRole("button", { name: /削除する/ }));
},
};
export const SystemError: Story = {
decorators: [
withMockedBackend([
DeleteCustomAttributeDefinition({
failureRate: 1,
}),
]),
],
async play({ canvas }) {
await userEvent.click(canvas.getByTestId("trigger"));
const root = within(document.documentElement);
await userEvent.click(root.getByRole("button", { name: /削除する/ }));
await waitFor(() => expect(root.getByText(/失敗しました/)).toBeInTheDocument());
},
};