muse-agent-example/web/tests/编辑/历史回退.test.tsx
zizi 98530437f2 W11 编辑器、动态表单与人审工作台:编辑器、动态表单与人审工作台(确认前正文不落正式库)。
按 R2 串行阶段整理提交;包内文件为该阶段交付(含后续小增量),状态以工作包清单为准。
2026-09-10 19:25:41 +08:00

72 lines
2.1 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();
});
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();
});