mirror of
https://github.com/coder/coder.git
synced 2026-11-17 09:00:16 +08:00
Related to https://github.com/coder/coder/issues/20214 This PR aims to add only the FE component for capturing user feedback from tasks. Once the BE work is completed (in a separate PR), this component will be triggered after a task is deleted. The goal is to develop this feature in parallel. **Screenshot:** <img width="1206" height="727" alt="Screenshot 2025-10-09 at 14 31 53" src="https://github.com/user-attachments/assets/1f92026c-8f05-4535-bbd6-85c4b107c037" />
121 lines
3.2 KiB
TypeScript
121 lines
3.2 KiB
TypeScript
import { MockTask, mockApiError } from "testHelpers/entities";
|
|
import { withGlobalSnackbar } from "testHelpers/storybook";
|
|
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
import { API } from "api/api";
|
|
import { expect, spyOn, userEvent, within } from "storybook/test";
|
|
import { TaskFeedbackDialog } from "./TaskFeedbackDialog";
|
|
|
|
const meta: Meta<typeof TaskFeedbackDialog> = {
|
|
title: "modules/tasks/TaskFeedbackDialog",
|
|
component: TaskFeedbackDialog,
|
|
args: {
|
|
taskId: MockTask.id,
|
|
open: true,
|
|
},
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof TaskFeedbackDialog>;
|
|
|
|
export const Idle: Story = {};
|
|
|
|
export const Submitting: Story = {
|
|
beforeEach: async () => {
|
|
spyOn(API.experimental, "createTaskFeedback").mockImplementation(() => {
|
|
return new Promise(() => {});
|
|
});
|
|
},
|
|
play: async ({ canvasElement, step }) => {
|
|
const body = within(canvasElement.ownerDocument.body);
|
|
|
|
step("fill and submit the form", async () => {
|
|
const regularOption = body.getByLabelText(
|
|
"It sort of worked, but struggled a lot",
|
|
);
|
|
userEvent.click(regularOption);
|
|
|
|
const commentTextarea = body.getByRole("textbox", {
|
|
name: "Additional comments",
|
|
});
|
|
await userEvent.type(commentTextarea, "This is my comment");
|
|
|
|
const submitButton = body.getByRole("button", {
|
|
name: "Submit Feedback",
|
|
});
|
|
await userEvent.click(submitButton);
|
|
});
|
|
},
|
|
};
|
|
|
|
export const Success: Story = {
|
|
args: {
|
|
open: true,
|
|
},
|
|
decorators: [withGlobalSnackbar],
|
|
beforeEach: async () => {
|
|
spyOn(API.experimental, "createTaskFeedback").mockResolvedValue();
|
|
},
|
|
play: async ({ canvasElement, step }) => {
|
|
const body = within(canvasElement.ownerDocument.body);
|
|
|
|
step("fill and submit the form", async () => {
|
|
const regularOption = body.getByLabelText(
|
|
"It sort of worked, but struggled a lot",
|
|
);
|
|
userEvent.click(regularOption);
|
|
|
|
const commentTextarea = body.getByRole("textbox", {
|
|
name: "Additional comments",
|
|
});
|
|
await userEvent.type(commentTextarea, "This is my comment");
|
|
|
|
const submitButton = body.getByRole("button", {
|
|
name: "Submit Feedback",
|
|
});
|
|
await userEvent.click(submitButton);
|
|
});
|
|
|
|
step("submitted successfully", async () => {
|
|
await body.findByText("Feedback submitted successfully");
|
|
expect(API.experimental.createTaskFeedback).toHaveBeenCalledWith(
|
|
MockTask.id,
|
|
{
|
|
rate: "regular",
|
|
comment: "This is my comment",
|
|
},
|
|
);
|
|
});
|
|
},
|
|
};
|
|
|
|
export const Failure: Story = {
|
|
beforeEach: async () => {
|
|
spyOn(API.experimental, "createTaskFeedback").mockRejectedValue(
|
|
mockApiError({
|
|
message: "Failed to submit feedback",
|
|
detail: "Server is down",
|
|
}),
|
|
);
|
|
},
|
|
play: async ({ canvasElement, step }) => {
|
|
const body = within(canvasElement.ownerDocument.body);
|
|
|
|
step("fill and submit the form", async () => {
|
|
const regularOption = body.getByLabelText(
|
|
"It sort of worked, but struggled a lot",
|
|
);
|
|
userEvent.click(regularOption);
|
|
|
|
const commentTextarea = body.getByRole("textbox", {
|
|
name: "Additional comments",
|
|
});
|
|
await userEvent.type(commentTextarea, "This is my comment");
|
|
|
|
const submitButton = body.getByRole("button", {
|
|
name: "Submit Feedback",
|
|
});
|
|
await userEvent.click(submitButton);
|
|
});
|
|
},
|
|
};
|