- 资源 → 站点:卡片 / 列表切换(URL ?view= + localStorage 记住),筛选全部 / 已启用 / 需处理, 按分享率 / 上传 / 上次登录排序;卡片显示账号状态、凭证类型、上次登录、上传 / 下载 / 分享率、 等级 / VIP、做种、健康检测结果与时间、快照、限流 - 操作:检测健康、刷新登录(wait:true 同步结果)、更新凭证、编辑(限流 / 快照 / 代理)、启停、 删除(确认框列出影响) - 添加站点向导:按适配器分组选 23 个定义(未实测标注)→ 名称 / 域名覆盖 / 凭证三选一 (馒头默认 API Key)→ 保存并测试(刷新登录 + 健康检测);验证码 / 二次验证提示改用 Cookie 并链接待处理 - 站点详情:概览(用户数据磁贴 + 30 天上传 / 下载与分享率折线,recharts,无彩)/ 资源 / 快照与 Feed / 账号(凭证管理、Passkey、登录历史) - 设置"站点与账号"改为"站点默认"(限流、快照周期、UA、代理、做种页数) - 侧栏改名"站点";smoke 补站点路由;依赖新增 recharts Co-Authored-By: Claude Opus 5.5 <[email protected]>
77 lines
3.4 KiB
TypeScript
77 lines
3.4 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, 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("7 组 18 项(另加系统组的定时任务),路径唯一且都在 /console 下", () => {
|
|
expect(NAV_GROUPS.map((g) => g.title)).toEqual(["概览", "资源", "订阅", "下载", "整理", "Agent", "系统"]);
|
|
const core = NAV_ITEMS.filter((i) => i.to !== "/console/schedules");
|
|
expect(core).toHaveLength(18);
|
|
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);
|
|
for (const g of NAV_GROUPS) expect(g.items.length).toBeLessThanOrEqual(4);
|
|
});
|
|
|
|
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/engine/r1")?.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/tasks/abc")?.label).toBe("业务任务");
|
|
expect(findNavItem("/console/sites/abc")?.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)).toBeNull();
|
|
}
|
|
});
|
|
|
|
it("不相关的 query 不跳转", () => {
|
|
expect(legacyRedirect("/console/tasks", "?kind=submitDownload")).toBeNull();
|
|
expect(legacyRedirect("/console/subscriptions", "")).toBeNull();
|
|
expect(legacyRedirect("/console/sources", "?health=failing")).toBeNull();
|
|
});
|
|
});
|