muse-agent-example/web/tests/交互/具体改进.test.tsx
zizi 9e6f1c4481 R2 改造交付:新版模块化单体全量成果
- src/muse 新版全模块(装配/共享/上下文/任务运行/作品规划/故事世界/正文写作/审校修订/知识方法/作者经验/效果评测/交付连载/资料研究/正式变更/元数据/接入/基础设施/编排)+ 测试树(单元/契约/集成/架构/迁移/端到端/夹具)
- 129 项功能全部实现与自动验证(功能覆盖.json/矩阵),含 W31 补齐的规则与代价/节奏安排/伏笔与承诺
- 旧实现按处置清单退出(702 条中 324 删,保护合同与未迁移条目留存有据);web/app.py 旧工作台退役,新工作台为唯一写入口
- 数据库/旧库迁移:真实旧库内容批次迁移链(端点守卫/PG作品正文映射/质量资产缺省投影)
- 运行手册 docs/运行手册.md;W30 本机服务阶段一已运行(infra PG 为正式内容权威)
- R2 执行证据与私有运行材料在 .agents.local/改造/R2-20260909/(不入库)
2026-09-15 12:47:42 +08:00

141 lines
4.3 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 { beforeEach, afterEach, expect, it, vi } from "vitest";
import {
cleanup,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MemoryRouter, Routes, Route } from "react-router-dom";
import { Ui改进提案页 } from "../../src/功能/作者经验/改进提案页";
const api = vi.hoisted(() => ({ read: vi.fn(), check: vi.fn(), act: vi.fn() }));
vi.mock("../../src/功能/作者经验/数据", () => ({
读取改进: api.read,
核对方法凭据: api.check,
请求改进启停: api.act,
提出改进: vi.fn(),
读取反馈: vi.fn(),
读取观察: async () => ({ groups: [], observations: [] }),
记录观察: vi.fn(),
}));
vi.mock("../../src/功能/知识方法/数据", () => ({
useMuse方法列表: () => ({ data: [] }),
}));
const point = {
improvement_id: "improvement",
revision: 1,
content_hash: "hash",
};
function row() {
return {
...point,
payload: {
title: "具体方法改进",
rationale: "检验承接",
target: {
target_ref: "B04.method:method",
version: "1",
content_hash: "method-hash",
},
feedback_ids: ["feedback"],
},
target_state: "confirmed",
is_current_target: true,
actions: [],
};
}
function mount() {
render(
<MemoryRouter initialEntries={["/improvements/improvement"]}>
<QueryClientProvider
client={
new QueryClient({ defaultOptions: { queries: { retry: false } } })
}
>
<Routes>
<Route
path="/improvements/:improvement_id"
element={<Ui改进提案页 />}
/>
</Routes>
</QueryClientProvider>
</MemoryRouter>,
);
}
beforeEach(() => {
vi.clearAllMocks();
api.read.mockResolvedValue(row());
api.check.mockResolvedValue({ receipt_id: "proof" });
api.act.mockResolvedValue({});
});
afterEach(cleanup);
it("NC-ui-improvement-retry:核对后明确启用且网络重试复用原命令", async () => {
api.act.mockRejectedValueOnce(new Error("连接中断"));
mount();
await screen.findByRole("heading", { name: "具体方法改进" });
const button = screen.getByRole("button", {
name: "确认启用已测版本",
}) as HTMLButtonElement;
expect(button.disabled).toBe(true);
fireEvent.change(screen.getByLabelText("已测版本凭据"), {
target: { value: "proof" },
});
fireEvent.click(screen.getByRole("button", { name: "核对启用依据" }));
await waitFor(() => expect(button.disabled).toBe(false));
expect(api.act).not.toHaveBeenCalled();
fireEvent.click(button);
await screen.findByText("连接中断");
expect(button.disabled).toBe(true);
fireEvent.click(screen.getByRole("button", { name: "核对启用依据" }));
await waitFor(() => expect(button.disabled).toBe(false));
fireEvent.click(button);
await waitFor(() => expect(api.act).toHaveBeenCalledTimes(2));
expect(api.act.mock.calls[0]).toEqual(api.act.mock.calls[1]);
expect(api.act.mock.calls[0].slice(1)).toEqual([point, "enable", "proof"]);
});
it("NC-ui-improvement-recover:刷新后保留请求仍用原版本与命令恢复", async () => {
api.read.mockResolvedValue({
...row(),
target_state: "enabled",
actions: [
{
action_id: "action",
command_id: "persisted-command",
kind: "enable",
revision: 1,
payload: { selection: point, proof_id: "original-proof" },
receipt: null,
},
],
});
mount();
fireEvent.click(await screen.findByRole("button", { name: "恢复这次请求" }));
await waitFor(() =>
expect(api.act).toHaveBeenCalledWith(
"persisted-command",
point,
"enable",
"original-proof",
),
);
expect(api.check).not.toHaveBeenCalled();
});
it("NC-ui-improvement-version:已改变目标不继续当前启停", async () => {
api.read.mockResolvedValue({
...row(),
is_current_target: false,
target_state: "enabled",
});
mount();
await screen.findByRole("heading", { name: "具体方法改进" });
for (const name of ["核对启用依据", "确认启用已测版本", "停用目标方法"])
expect(
(screen.getByRole("button", { name }) as HTMLButtonElement).disabled,
).toBe(true);
expect(api.act).not.toHaveBeenCalled();
});