Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const meta = {
ok: true,
data: createExampleCandidates().slice(0, command.count),
})),
regenerateDirectReading: fn<GrammarExampleManagerProps["regenerateDirectReading"]>(
async ({ sentence }) => ({
ok: true,
data: [{ start: 0, end: sentence.length, korean: "수정한 문장의 뜻입니다" }],
}),
),
save: fn<GrammarExampleManagerProps["save"]>(async () => ({
ok: true,
data: { ...note, version: 2 },
Expand Down Expand Up @@ -80,10 +86,59 @@ export const EditCandidate: Story = {
const canvas = within(canvasElement);

await userEvent.click(canvas.getByRole("button", { name: "예문 3개 생성" }));
await userEvent.click(canvas.getAllByRole("button", { name: "이 예문 수정" })[0]);
const input = (await canvas.findAllByLabelText("한국어 뜻"))[0];

await userEvent.clear(input);
await userEvent.type(input, "그는 운전사가 아니라 교사입니다.");
await expect(input).toHaveValue("그는 운전사가 아니라 교사입니다.");
},
};

export const EditEnglishAndRegenerate: Story = {
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole("button", { name: "예문 3개 생성" }));
await userEvent.click(canvas.getAllByRole("button", { name: "이 예문 수정" })[0]);
const english = canvas.getAllByLabelText("영어 예문")[0];
await userEvent.clear(english);
await userEvent.type(english, "My edited sentence.");
await expect(canvas.getAllByRole("checkbox")[0]).toBeDisabled();
await userEvent.click(canvas.getByRole("button", { name: "직독직해 다시 생성" }));
await expect(args.regenerateDirectReading).toHaveBeenCalledWith(
expect.objectContaining({ sentence: "My edited sentence." }),
);
await expect(canvas.getAllByRole("checkbox")[0]).toBeEnabled();
},
};

export const EditCancelAfterFailure: Story = {
play: async ({ canvasElement, args }) => {
args.regenerateDirectReading.mockResolvedValueOnce({ ok: false, code: "RATE_LIMITED" });
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole("button", { name: "예문 3개 생성" }));
await userEvent.click(canvas.getAllByRole("button", { name: "이 예문 수정" })[0]);
const english = canvas.getAllByLabelText("영어 예문")[0];
const original = (english as HTMLTextAreaElement).value;
await userEvent.clear(english);
await userEvent.type(english, "My edited sentence.");
await userEvent.click(canvas.getByRole("button", { name: "직독직해 다시 생성" }));
await expect(await canvas.findByRole("alert")).toHaveTextContent("요청 한도");
await userEvent.click(canvas.getAllByRole("button", { name: "수정 취소" })[0]);
await expect(english).toHaveValue(original);
await expect(canvas.getAllByRole("checkbox")[0]).toBeEnabled();
},
};

export const LoginRequired: Story = {
play: async ({ canvasElement, args }) => {
args.generate.mockResolvedValueOnce({ ok: false, code: "UNAUTHORIZED" });
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole("button", { name: "예문 3개 생성" }));
await expect(await canvas.findByRole("alert")).toHaveTextContent("로그인이 필요");
await expect(canvas.getByRole("link", { name: "로그인 페이지로 이동" })).toHaveAttribute(
"href",
"/login",
);
},
};
25 changes: 24 additions & 1 deletion src/_storybook/views/grammar-detail/GrammarDetail.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { Meta, StoryObj } from "@storybook/nextjs-vite";
import { expect, userEvent, within } from "storybook/test";
import { expect, fn, userEvent, within } from "storybook/test";
import { GrammarDetail } from "@/views/grammar-detail/ui/GrammarDetail";
import { GrammarAnalysisReader } from "@/features/grammar-analysis-edit";
import { createEditorNote } from "@/_tests/features/grammar-note-editor/fixtures";
import { createExampleCandidates } from "@/_tests/features/grammar-example-generation/fixtures";
import { GrammarExamplesSection } from "@/views/grammar-detail/ui/GrammarExamplesSection";

const note = createEditorNote();

Expand Down Expand Up @@ -45,3 +47,24 @@ export const Reading: Story = {
);
},
};

export const DirectReading: Story = {
args: {
examples: (
<GrammarExamplesSection
note={{ ...note, examples: [createExampleCandidates()[0]] }}
manageButton={null}
generateAudio={fn()}
/>
),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(canvas.getByText("그는 운전사가 아니라 교사입니다.")).toBeVisible();
await userEvent.click(canvas.getByRole("button", { name: "직독직해" }));
await expect(canvas.getByText("그는 운전사가 아니라 교사입니다")).toBeVisible();
await expect(canvas.queryByText("그는 운전사가 아니라 교사입니다.")).not.toBeInTheDocument();
await userEvent.click(canvas.getByRole("button", { name: "자연스러운 해석" }));
await expect(canvas.getByText("그는 운전사가 아니라 교사입니다.")).toBeVisible();
},
};
Loading
Loading