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

33 lines
1.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 } from "vitest";
import { cleanup, render, screen } from "@testing-library/react";
import { MemoryRouter, Routes, Route } from "react-router-dom";
import { useMuse正文路由, 正文路由 } from "../../src/功能/正文写作/路由参数";
afterEach(cleanup);
function Probe() {
const value = useMuse正文路由();
return <output>{JSON.stringify(value)}</output>;
}
// @muse-case {"case_id": "O01-route-raw-identity", "environment": "离线路由单元", "given": "作品、章、分支含中文与保留字符", "when": "构造正文与候选路由并渲染链接", "then": ["路由使用解码身份", "构造链接只编码一次"], "contract": "docs/系统架构/新版设计/工作台设计.md"}
it("O01-route-raw-identity:正文与候选路由使用解码身份且构造链接只编码一次", () => {
const work = "作品:甲%一",
chapter = "章#二 空格",
branch = "分支/B?%末";
const url = 正文路由(work, chapter, branch, "candidates");
expect(url).toContain(encodeURIComponent(chapter));
render(
<MemoryRouter initialEntries={[url]}>
<Routes>
<Route
path="/works/:work_id/candidates/:chapter_id"
element={<Probe />}
/>
</Routes>
</MemoryRouter>,
);
expect(JSON.parse(screen.getByRole("status").textContent!)).toEqual({
work_id: work,
chapter_id: chapter,
branch,
});
});