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( {}} /> , ); 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(); });