-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFeedbackComment.stories.tsx
More file actions
71 lines (67 loc) · 2.46 KB
/
Copy pathFeedbackComment.stories.tsx
File metadata and controls
71 lines (67 loc) · 2.46 KB
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
import type { Meta, StoryObj } from "@storybook/react";
import { expect, fn } from "storybook/test";
import { FeedbackComment } from "./FeedbackComment";
const meta = {
title: "Profile/Review runs/Feedback comment",
component: FeedbackComment,
parameters: {
layout: "padded",
docs: {
description: {
component:
"The written half of a developer's response to feedback. The draft stays local until it is " +
"saved, so abandoning it leaves the recorded comment untouched — and disputing an " +
"observation is the one case where the server insists on an explanation.",
},
},
},
tags: ["autodocs"],
args: { isRequired: false, onSave: fn() },
decorators: [
(Story) => (
<div className="max-w-lg">
<Story />
</div>
),
],
} satisfies Meta<typeof FeedbackComment>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Empty: Story = {
play: async ({ canvas }) => {
await expect(canvas.getByRole("button", { name: "Save comment" })).toBeDisabled();
await expect(canvas.queryByRole("button", { name: "Cancel" })).toBeNull();
},
};
export const Recorded: Story = {
args: { comment: "Split into two commits so the reasoning reads on its own." },
play: async ({ canvas }) => {
await expect(canvas.getByRole("button", { name: "Save comment" })).toBeDisabled();
},
};
export const Editing: Story = {
args: { comment: "Split into two commits." },
play: async ({ canvas, userEvent }) => {
const field = canvas.getByRole("textbox");
await userEvent.type(field, " The second one is the fix.");
await expect(canvas.getByRole("button", { name: "Save comment" })).toBeEnabled();
await userEvent.click(canvas.getByRole("button", { name: "Cancel" }));
await expect(field).toHaveValue("Split into two commits.");
},
};
export const RequiredForDispute: Story = {
args: { isRequired: true },
play: async ({ args, canvas, userEvent }) => {
const field = canvas.getByRole("textbox");
await expect(field).toHaveAttribute("aria-invalid", "true");
await expect(canvas.getByRole("button", { name: "Save comment" })).toBeDisabled();
await userEvent.type(field, "The timeout was raised on purpose; the comment above says why.");
await userEvent.click(canvas.getByRole("button", { name: "Save comment" }));
await expect(args.onSave).toHaveBeenCalledWith(
"The timeout was raised on purpose; the comment above says why.",
);
},
};
export const Saving: Story = {
args: { comment: "Handled in the follow-up.", isPending: true },
};