Files
UHD_Media_Tool/apps/web/app/components/console/nav.test.ts
T
rootandClaude Opus 5.5 57ce40168d refactor(web): 技术信息折叠铺到媒体库 / 审计 / 运行状态,清理正常态徽章与解释型页描述(DEAI-2)
- 媒体库详情:作品 UUID 进技术信息;「实际路径与库根」改「文件位置」,正常态(已核验、
  可访问、主位置)不加徽章;外部身份显示「TMDB 90228 · 你确认的 / 自动匹配」,修订号进悬停;
  元数据字段来源默认收起(「显示来源」,跟随界面设置);别名默认只列中英文与手动加的;
  「内容单元」→「季与集」,「临时单元」→「编号待确认」;侧栏与页标题统一「媒体库」
- 审计:动作列不再重复英文码,对象列显示中文类型 / 能力名,ID 只在详情;补 capability.denied
- 运行状态:进程、已下线实例、趋势图与最大表收进折叠区;图例同名序列加序号,不再拼接
- 站点卡:账号正常与登录方式不加徽章,健康不显示毫秒,限流移出卡片
- 文件管理:目录「正常」徽章与重复的剩余空间去掉;已登记 → 已入库,临时文件 → 未完成
- 规则:「修订」列改「最后修改」;不支持的关键字合成一行;页签改「默认规则 / 自动收新作品 / 已忽略」;
  默认规则说明去掉「带层」等算法描述
- 站点 Passkey 与登录用通行密钥区分命名;命令面板提示去重
- 删解释型页描述(审计、搜索、下载、下载计划、RSS、规则、媒体库、运行状态、站点、任务、计划、整理)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-29 20:58:38 +08:00

93 lines
4.2 KiB
TypeScript

import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { LEGACY_REDIRECTS, legacyRedirect } from "../../routes/console/redirects.ts";
import { consolePath, findNavItem, NAV_GROUPS, NAV_ITEMS, pageTitle, settingsPath } from "./nav.ts";
/** routes.ts 里登记的控制台路由(相对 /console) */
const ROUTE_PATTERNS = [
"",
...[...readFileSync(new URL("../../routes.ts", import.meta.url), "utf8").matchAll(/route\("([^"*]+)",/g)].map(
(m) => m[1] as string,
),
];
const matchesRoute = (pathname: string) => {
const rest = pathname.replace(/^\/console\/?/, "");
return ROUTE_PATTERNS.some((p) => new RegExp(`^${p.replace(/:[^/]+/g, "[^/]+")}$`).test(rest));
};
describe("控制台导航", () => {
it("IA-3:5 组,按定稿清单逐项列出,路径唯一且都在 /console 下", () => {
expect(NAV_GROUPS.map((g) => g.title)).toEqual(["概览", "资源", "订阅", "整理", "系统"]);
expect(NAV_GROUPS.map((g) => g.items.map((i) => i.label))).toEqual([
["首页", "任务", "计划", "智能体会话"],
["站点", "RSS"],
["订阅", "规则"],
["下载面板", "整理记录", "文件管理", "媒体库"],
["设置", "审计", "运行状态"],
]);
// IA-3 逐项清单 14 项 + FE-6 计划页
expect(NAV_ITEMS).toHaveLength(15);
expect(new Set(NAV_ITEMS.map((i) => i.to)).size).toBe(NAV_ITEMS.length);
expect(NAV_ITEMS.every((i) => i.to.startsWith("/console"))).toBe(true);
});
it("取消的入口不在侧栏:待处理走顶栏收件箱,引擎面板 / 身份并入别处", () => {
const paths = NAV_ITEMS.map((i) => i.to);
for (const p of ["/console/inbox", "/console/engine", "/console/identity"]) expect(paths).not.toContain(p);
expect(pageTitle("/console/inbox")).toBe("待处理");
});
it("每个导航项都有路由", () => {
for (const i of NAV_ITEMS) expect(matchesRoute(i.to), i.to).toBe(true);
});
it("按最长前缀匹配当前项", () => {
expect(findNavItem("/console")?.label).toBe("首页");
expect(findNavItem("/console/")?.label).toBe("首页");
expect(findNavItem("/console/library/abc")?.label).toBe("媒体库");
expect(findNavItem("/console/tasks/r1")?.label).toBe("任务");
expect(findNavItem("/console/schedules")?.label).toBe("计划");
expect(findNavItem("/console/downloads")?.label).toBe("下载面板");
expect(findNavItem("/console/downloads/plans")?.label).toBe("下载面板");
expect(findNavItem("/console/downloads/abc")?.label).toBe("下载面板");
expect(findNavItem("/console/sites/abc")?.label).toBe("站点");
expect(findNavItem("/console/status")?.label).toBe("运行状态");
expect(findNavItem("/nope")).toBeUndefined();
});
it("consolePath 拼路径并编码", () => {
expect(consolePath()).toBe("/console");
expect(consolePath("library", "a b")).toBe("/console/library/a%20b");
expect(consolePath("downloads", "plans")).toBe("/console/downloads/plans");
});
it("settingsPath 只认新分区名", () => {
expect(settingsPath("automation", "cache")).toBe("/console/settings#automation/cache");
expect(settingsPath("agent")).toBe("/console/settings#agent");
});
});
describe("旧链接重定向", () => {
it.each(LEGACY_REDIRECTS)("$from → $to", ({ from, to }) => {
const u = new URL(from, "http://x");
expect(legacyRedirect(u.pathname, u.search)).toBe(to);
});
it("新地址都有路由,且不会再次跳转", () => {
for (const { to } of LEGACY_REDIRECTS) {
const u = new URL(to, "http://x");
expect(matchesRoute(u.pathname), to).toBe(true);
if (u.pathname !== "/console/sites/abc") expect(legacyRedirect(u.pathname, u.search), to).toBeNull();
}
});
it("不相关的 query 不跳转", () => {
expect(legacyRedirect("/console/tasks", "?kind=submitDownload")).toBeNull();
expect(legacyRedirect("/console/schedules", "?job=trash.purge")).toBeNull();
expect(legacyRedirect("/console/tasks", "?tab=failed")).toBeNull();
expect(legacyRedirect("/console/library", "?filter=unidentified")).toBeNull();
expect(legacyRedirect("/console/subscriptions", "")).toBeNull();
expect(legacyRedirect("/console/sources", "?health=failing")).toBeNull();
});
});