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 {JSON.stringify(value)}; } // @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( } /> , ); expect(JSON.parse(screen.getByRole("status").textContent!)).toEqual({ work_id: work, chapter_id: chapter, branch, }); });