|
| 1 | +// @vitest-environment jsdom |
| 2 | +/** |
| 3 | + * GoalPlanApprovalDialog.test.tsx — 草案确认流关键交互(v0.18.2 审查修复回归: |
| 4 | + * 标题编辑不回弹(展开顺序)/勾选排除/确认提交契约)。 |
| 5 | + */ |
| 6 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 7 | +import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react"; |
| 8 | +import GoalPlanApprovalDialog from "./GoalPlanApprovalDialog"; |
| 9 | +import type { GoalPlanView } from "../types/goals"; |
| 10 | + |
| 11 | +const view: GoalPlanView = { |
| 12 | + proposal: { |
| 13 | + milestones: [ |
| 14 | + { title: "基础入门", dueWeeks: 4, criteriaType: "manual", refGroupId: null, note: "" }, |
| 15 | + { title: "项目实战", dueWeeks: 12, criteriaType: "group_settled", refGroupId: 5, note: "" }, |
| 16 | + ], |
| 17 | + groups: [{ groupId: 5, reason: "素材命中" }], |
| 18 | + systems: [{ action: "create", systemId: null, name: "Python 基础", coreQuestion: "怎么把语法变成工具?", domainEntries: ["语言基础"], concepts: [], reason: "" }], |
| 19 | + weeklyContract: { targetDays: 3, targetCards: 20 }, |
| 20 | + summary: "8 周从基础到项目", |
| 21 | + }, |
| 22 | + dropped: { droppedMilestones: [], droppedGroups: [], droppedSystems: [] }, |
| 23 | + honestNote: "", |
| 24 | + costYuan: 0.1, |
| 25 | + model: "m", |
| 26 | +}; |
| 27 | + |
| 28 | +afterEach(() => cleanup()); |
| 29 | + |
| 30 | +describe("GoalPlanApprovalDialog 确认流", () => { |
| 31 | + it("标题编辑不回弹(仅修改 draft 对应项)", () => { |
| 32 | + render(<GoalPlanApprovalDialog view={view} onConfirm={vi.fn()} onClose={vi.fn()} onUseRules={vi.fn()} />); |
| 33 | + const input = screen.getByTestId("plan-milestone-0") as HTMLInputElement; |
| 34 | + fireEvent.change(input, { target: { value: "修改后的标题" } }); |
| 35 | + expect((screen.getByTestId("plan-milestone-0") as HTMLInputElement).value).toBe("修改后的标题"); |
| 36 | + expect((screen.getByTestId("plan-milestone-1") as HTMLInputElement).value).toBe("项目实战"); |
| 37 | + }); |
| 38 | + |
| 39 | + it("取消勾选后确认提交排除该项", async () => { |
| 40 | + const onConfirm = vi.fn().mockResolvedValue(undefined); |
| 41 | + render(<GoalPlanApprovalDialog view={view} onConfirm={onConfirm} onClose={vi.fn()} onUseRules={vi.fn()} />); |
| 42 | + // 取消第 2 条里程碑 |
| 43 | + fireEvent.click(screen.getAllByRole("checkbox")[1]); |
| 44 | + fireEvent.click(screen.getByTestId("plan-confirm")); |
| 45 | + await waitFor(() => expect(onConfirm).toHaveBeenCalledTimes(1)); |
| 46 | + const req = onConfirm.mock.calls[0][0]; |
| 47 | + expect(req.milestones).toHaveLength(1); |
| 48 | + expect(req.milestones[0].title).toBe("基础入门"); |
| 49 | + expect(req.weeklyContract.targetDays).toBe(3); |
| 50 | + }); |
| 51 | + |
| 52 | + it("「改用规则草案」回调可用(不关闭——调用方决定)", () => { |
| 53 | + const onUseRules = vi.fn(); |
| 54 | + render(<GoalPlanApprovalDialog view={view} onConfirm={vi.fn()} onClose={vi.fn()} onUseRules={onUseRules} />); |
| 55 | + fireEvent.click(screen.getByText("改用规则草案")); |
| 56 | + expect(onUseRules).toHaveBeenCalledTimes(1); |
| 57 | + }); |
| 58 | +}); |
0 commit comments