控制台导航最多两层(侧栏一项 = 一页,页内最多一层页签 / 分段);从列表打开的
记录改成列表页上的右侧抽屉,打开的记录写在 ?open=,刷新、分享、前进后退都能还原,
后退就是关抽屉。标准写在 docs/design/console-ia.md §9,ui-controls.md 引用。
- DetailSheet 加 xl 宽度、标题下操作行;抽屉里再开的 DetailSheet 在同一抽屉里换成子视图(返回 / Esc)
- record-sheet.tsx:useRecordSheet / RecordLink / useOpenRecord / recordPath / taskPath
- 整理记录、订阅、站点(含页签)、下载、日志任务改成抽屉;旧业务任务 / 下载任务 id 在任务抽屉里换算
- 回收站并进文件管理右侧视图(?view=trash);设置左栏只列分区
- 规则组、策略版本、媒体库未识别 / 外部身份、设置实例编辑走 ?open=
- 旧地址 /console/{organize,subscriptions,sites,downloads}/:id、/tasks/:id、/files/trash 跳到列表页抽屉
- 站内链接、铃铛、命令面板、任务时间线改拼新地址;冒烟按 ?open= 检查抽屉
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
147 lines
6.8 KiB
TypeScript
147 lines
6.8 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";
|
|
import { recordPath, taskPath } from "./record-sheet.tsx";
|
|
|
|
/** 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(13);
|
|
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",
|
|
"/console/tasks",
|
|
"/console/audit",
|
|
"/console/schedules",
|
|
])
|
|
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(pageTitle("/console/tasks/r1")).toBe("日志");
|
|
expect(findNavItem("/console/logs")?.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("downloaders", "cache")).toBe("/console/settings#downloaders/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);
|
|
expect(legacyRedirect(u.pathname, u.search), to).toBeNull();
|
|
}
|
|
});
|
|
|
|
it("任务 / 审计 / 计划的旧地址一律落到日志页;任务详情落到日志页的任务抽屉", () => {
|
|
expect(legacyRedirect("/console/tasks", "?kind=submitDownload")).toBe("/console/logs?type=task");
|
|
expect(legacyRedirect("/console/tasks", "?tab=failed")).toBe("/console/logs?type=task&level=error");
|
|
expect(legacyRedirect("/console/tasks/r1", "")).toBe("/console/logs?type=task&run=r1");
|
|
expect(legacyRedirect("/console/logs", "?type=task")).toBeNull();
|
|
});
|
|
|
|
it("记录详情的旧地址落到列表页的抽屉(?open=),其余参数跟在后面", () => {
|
|
expect(legacyRedirect("/console/organize/r%201", "")).toBe("/console/organize?open=r+1");
|
|
expect(legacyRedirect("/console/sites/abc", "?tab=accounts")).toBe("/console/sites?open=abc&tab=accounts");
|
|
expect(legacyRedirect("/console/sites/abc/", "?open=x")).toBe("/console/sites?open=abc");
|
|
expect(legacyRedirect("/console/downloads/plans", "")).toBe("/console/downloads");
|
|
expect(legacyRedirect("/console/files/trash", "")).toBe("/console/files?view=trash");
|
|
// 列表页本身和作品页不跳
|
|
expect(legacyRedirect("/console/organize", "?open=r1")).toBeNull();
|
|
expect(legacyRedirect("/console/library/abc", "")).toBeNull();
|
|
});
|
|
|
|
it("站内拼的记录地址都是列表页 + ?open=", () => {
|
|
expect(recordPath("subscriptions", "s 1")).toBe("/console/subscriptions?open=s+1");
|
|
expect(recordPath("sites", "abc", { tab: "rss", feed: null })).toBe("/console/sites?open=abc&tab=rss");
|
|
expect(taskPath("run-1")).toBe("/console/logs?type=task&run=run-1");
|
|
for (const to of [recordPath("organize", "x"), recordPath("downloads", "x"), taskPath("x")]) {
|
|
const u = new URL(to, "http://x");
|
|
expect(matchesRoute(u.pathname), to).toBe(true);
|
|
expect(legacyRedirect(u.pathname, u.search), to).toBeNull();
|
|
}
|
|
});
|
|
|
|
it("不相关的 query 不跳转", () => {
|
|
expect(legacyRedirect("/console/library", "?filter=unidentified")).toBeNull();
|
|
expect(legacyRedirect("/console/subscriptions", "")).toBeNull();
|
|
// 旧 RSS 页的 ?feed= 由 sources.tsx 查所属站点后跳转
|
|
expect(legacyRedirect("/console/sources", "?feed=f1")).toBeNull();
|
|
});
|
|
});
|