muse-agent-example/web/tests/编辑/历史回退.test.tsx
zizi ae02fd1732 前端:工作台页面、事件标签与旅程用例
- 上下文清单、任务列表与详情、恢复控制、运行观察、创作对话与消息流、正式变更决策面板、正文写作与候选审阅、资料研究等页面同步本轮后端能力。
- 事件标签表补齐后端事件类型;查询键与生成客户端随 HTTP 契约重新生成。
- 依赖调整后 lockfile 同步;交互用例与浏览器旅程 spec 一并更新。
- 证据:make 前端检查(lint + typecheck + Pi 工具桥 tsc)exit 0;make 前端测试 37 文件 / 120 用例通过。
2026-09-18 01:15:07 +08:00

73 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { afterEach, expect, it, vi } from "vitest";
import {
cleanup,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { Ui依赖装配 } from "../../src/应用/依赖装配";
import { Ui版本历史 } from "../../src/功能/正文写作/版本分支";
import type { 正文记录 } from "../../src/功能/正文写作/数据";
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});
// @muse-case {"case_id":"NC-editor-restore-conflict","environment":"离线组件/实际编辑器;HTTP响应替身不计真实链路","given":"打开历史后正文基线改变","when":"回退返回明确409","then":["解除编辑器只读,提示重新读取基线而非重试旧版本"],"contract":"docs/系统架构/新版设计/接口契约/正文结构与中文选区.md"}
it("NC-editor-restore-conflict:明确回退冲突解除只读并要求重新核对", async () => {
const record: 正文记录 = {
work_id: "w",
chapter_id: "c",
branch_id: "main",
document_id: "d",
revision: 2,
state: "saved",
document: {
format_version: 1,
paragraphs: [{ paragraph_id: "p", content: [] }],
},
visible_text: "",
document_hash: "h",
visible_text_hash: "t",
};
vi.stubGlobal(
"fetch",
vi.fn(
async (request: Request) =>
new Response(
JSON.stringify(
request.method === "POST"
? { code: "REVISION_CONFLICT", message: "版本已更新" }
: new URL(request.url).pathname.endsWith("history")
? [{ revision: 1 }]
: { ...record, revision: 1 },
),
{
status: request.method === "POST" ? 409 : 200,
headers: { "Content-Type": "application/json" },
},
),
),
);
const busy = vi.fn();
render(
<Ui依赖装配>
<Ui版本历史
current={record}
canRestore
onBusy={busy}
onRestored={async () => {}}
/>
</Ui依赖装配>,
);
fireEvent.click(screen.getByRole("button", { name: "查看版本记录" }));
fireEvent.click(await screen.findByRole("button", { name: "版本 1" }));
fireEvent.click(
await screen.findByRole("button", { name: "将版本 1 恢复为新版本" }),
);
await screen.findByText("版本已更新");
await waitFor(() => expect(busy).toHaveBeenLastCalledWith(false));
expect(screen.getByRole("button", { name: "重新打开当前版本" })).toBeTruthy();
});