Files
UHD_Media_Tool/apps/web/app/components/console/nav.test.ts
T
rootandClaude Opus 5.5 fa76d7563c feat(控制台): 去掉待处理中心,问题回到发生处
- 侧栏与命令面板没有「待处理」;/console/inbox?kind= 按问题类型跳到整理记录「需要处理」、下载面板、运行状态或订阅
- 整理记录加「需要处理」筛选,行内写原因与推荐动作(指定作品 / 重新整理 / 让智能体识别 / 替换·保留两者·跳过 / 忽略),
  详情页同样可处理;处理按钮从原待处理页抽成 components/decisions/decision-actions.tsx 复用
- 铃铛只放等你批准的智能体操作与系统健康;首页「要我处理」与运行状态「需要关注」放汇总计数,运行状态加智能体用量
- 设置 → 智能体:预算卡改为「用量与限制」(只剩单次工具调用与时长,附花费统计),自动调查卡加「整理识别不到作品时叫智能体识别」
- 集数待确认的原因显示在作品页集数映射(可确认建议规则 / 智能体建议)与订阅详情;未识别资源在媒体库「未识别」里直接选候选或指定
- 下载、站点、任务里指向待处理的链接改到对应页面

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
2026-10-06 16:47:25 +08:00

110 lines
5.0 KiB
TypeScript

import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { LEGACY_REDIRECTS, legacyRedirect } from "../../routes/console/redirects.ts";
import {
ACQUIRE_GROUP_TITLE,
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-2:4 组,任务归系统,站点 / 订阅 / 规则合为「获取」,没有独立 RSS 项", () => {
expect(NAV_GROUPS.map((g) => g.title)).toEqual(["概览", ACQUIRE_GROUP_TITLE, "整理", "系统"]);
expect(ACQUIRE_GROUP_TITLE).toBe("获取");
expect(NAV_GROUPS.map((g) => g.items.map((i) => i.label))).toEqual([
["首页", "计划", "智能体会话"],
["站点", "发现", "订阅", "规则"],
["下载面板", "整理记录", "文件管理", "媒体库"],
["任务", "设置", "审计", "运行状态"],
]);
expect(NAV_ITEMS).toHaveLength(15);
expect(NAV_ITEMS.map((i) => i.to)).not.toContain("/console/sources");
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(NAV_ITEMS.map((i) => i.label)).not.toContain("待处理");
expect(pageTitle("/console/inbox")).toBeUndefined();
});
it("旧待处理链接按问题类型落到对应页面", () => {
expect(legacyRedirect("/console/inbox", "?kind=path_conflict")).toBe("/console/organize?tab=records&attention=1");
expect(legacyRedirect("/console/inbox", "?kind=download_failed")).toBe("/console/downloads");
expect(legacyRedirect("/console/inbox", "?kind=space_insufficient")).toBe("/console/status#attention");
expect(legacyRedirect("/console/inbox", "?kind=unknown_kind")).toBe("/console/organize?tab=records&attention=1");
});
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();
// 旧 RSS 页的 ?feed= 由 sources.tsx 查所属站点后跳转
expect(legacyRedirect("/console/sources", "?feed=f1")).toBeNull();
});
});