|
|
|
|
@ -26,17 +26,22 @@ describe("iconForTab", () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns stable icons for known tabs", () => {
|
|
|
|
|
expect(iconForTab("chat")).toBe("messageSquare");
|
|
|
|
|
expect(iconForTab("overview")).toBe("barChart");
|
|
|
|
|
expect(iconForTab("channels")).toBe("link");
|
|
|
|
|
expect(iconForTab("instances")).toBe("radio");
|
|
|
|
|
expect(iconForTab("sessions")).toBe("fileText");
|
|
|
|
|
expect(iconForTab("cron")).toBe("loader");
|
|
|
|
|
expect(iconForTab("skills")).toBe("zap");
|
|
|
|
|
expect(iconForTab("nodes")).toBe("monitor");
|
|
|
|
|
expect(iconForTab("config")).toBe("settings");
|
|
|
|
|
expect(iconForTab("debug")).toBe("bug");
|
|
|
|
|
expect(iconForTab("logs")).toBe("scrollText");
|
|
|
|
|
const cases = [
|
|
|
|
|
{ tab: "chat", icon: "messageSquare" },
|
|
|
|
|
{ tab: "overview", icon: "barChart" },
|
|
|
|
|
{ tab: "channels", icon: "link" },
|
|
|
|
|
{ tab: "instances", icon: "radio" },
|
|
|
|
|
{ tab: "sessions", icon: "fileText" },
|
|
|
|
|
{ tab: "cron", icon: "loader" },
|
|
|
|
|
{ tab: "skills", icon: "zap" },
|
|
|
|
|
{ tab: "nodes", icon: "monitor" },
|
|
|
|
|
{ tab: "config", icon: "settings" },
|
|
|
|
|
{ tab: "debug", icon: "bug" },
|
|
|
|
|
{ tab: "logs", icon: "scrollText" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(iconForTab(testCase.tab), testCase.tab).toBe(testCase.icon);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns a fallback icon for unknown tab", () => {
|
|
|
|
|
@ -56,9 +61,14 @@ describe("titleForTab", () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns expected titles", () => {
|
|
|
|
|
expect(titleForTab("chat")).toBe("Chat");
|
|
|
|
|
expect(titleForTab("overview")).toBe("Overview");
|
|
|
|
|
expect(titleForTab("cron")).toBe("Cron Jobs");
|
|
|
|
|
const cases = [
|
|
|
|
|
{ tab: "chat", title: "Chat" },
|
|
|
|
|
{ tab: "overview", title: "Overview" },
|
|
|
|
|
{ tab: "cron", title: "Cron Jobs" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(titleForTab(testCase.tab), testCase.tab).toBe(testCase.title);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -77,108 +87,96 @@ describe("subtitleForTab", () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("normalizeBasePath", () => {
|
|
|
|
|
it("returns empty string for falsy input", () => {
|
|
|
|
|
expect(normalizeBasePath("")).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("adds leading slash if missing", () => {
|
|
|
|
|
expect(normalizeBasePath("ui")).toBe("/ui");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("removes trailing slash", () => {
|
|
|
|
|
expect(normalizeBasePath("/ui/")).toBe("/ui");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns empty string for root path", () => {
|
|
|
|
|
expect(normalizeBasePath("/")).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles nested paths", () => {
|
|
|
|
|
expect(normalizeBasePath("/apps/openclaw")).toBe("/apps/openclaw");
|
|
|
|
|
it("normalizes base-path variants", () => {
|
|
|
|
|
const cases = [
|
|
|
|
|
{ input: "", expected: "" },
|
|
|
|
|
{ input: "ui", expected: "/ui" },
|
|
|
|
|
{ input: "/ui/", expected: "/ui" },
|
|
|
|
|
{ input: "/", expected: "" },
|
|
|
|
|
{ input: "/apps/openclaw", expected: "/apps/openclaw" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(normalizeBasePath(testCase.input), testCase.input).toBe(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("normalizePath", () => {
|
|
|
|
|
it("returns / for falsy input", () => {
|
|
|
|
|
expect(normalizePath("")).toBe("/");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("adds leading slash if missing", () => {
|
|
|
|
|
expect(normalizePath("chat")).toBe("/chat");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("removes trailing slash except for root", () => {
|
|
|
|
|
expect(normalizePath("/chat/")).toBe("/chat");
|
|
|
|
|
expect(normalizePath("/")).toBe("/");
|
|
|
|
|
it("normalizes paths", () => {
|
|
|
|
|
const cases = [
|
|
|
|
|
{ input: "", expected: "/" },
|
|
|
|
|
{ input: "chat", expected: "/chat" },
|
|
|
|
|
{ input: "/chat/", expected: "/chat" },
|
|
|
|
|
{ input: "/", expected: "/" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(normalizePath(testCase.input), testCase.input).toBe(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("pathForTab", () => {
|
|
|
|
|
it("returns correct path without base", () => {
|
|
|
|
|
expect(pathForTab("chat")).toBe("/chat");
|
|
|
|
|
expect(pathForTab("overview")).toBe("/overview");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("prepends base path", () => {
|
|
|
|
|
expect(pathForTab("chat", "/ui")).toBe("/ui/chat");
|
|
|
|
|
expect(pathForTab("sessions", "/apps/openclaw")).toBe("/apps/openclaw/sessions");
|
|
|
|
|
it("builds tab paths with optional bases", () => {
|
|
|
|
|
const cases = [
|
|
|
|
|
{ tab: "chat", base: undefined, expected: "/chat" },
|
|
|
|
|
{ tab: "overview", base: undefined, expected: "/overview" },
|
|
|
|
|
{ tab: "chat", base: "/ui", expected: "/ui/chat" },
|
|
|
|
|
{ tab: "sessions", base: "/apps/openclaw", expected: "/apps/openclaw/sessions" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(
|
|
|
|
|
pathForTab(testCase.tab, testCase.base),
|
|
|
|
|
`${testCase.tab}:${testCase.base ?? "root"}`,
|
|
|
|
|
).toBe(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("tabFromPath", () => {
|
|
|
|
|
it("returns tab for valid path", () => {
|
|
|
|
|
expect(tabFromPath("/chat")).toBe("chat");
|
|
|
|
|
expect(tabFromPath("/overview")).toBe("overview");
|
|
|
|
|
expect(tabFromPath("/sessions")).toBe("sessions");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns chat for root path", () => {
|
|
|
|
|
expect(tabFromPath("/")).toBe("chat");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles base paths", () => {
|
|
|
|
|
expect(tabFromPath("/ui/chat", "/ui")).toBe("chat");
|
|
|
|
|
expect(tabFromPath("/apps/openclaw/sessions", "/apps/openclaw")).toBe("sessions");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns null for unknown path", () => {
|
|
|
|
|
expect(tabFromPath("/unknown")).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("is case-insensitive", () => {
|
|
|
|
|
expect(tabFromPath("/CHAT")).toBe("chat");
|
|
|
|
|
expect(tabFromPath("/Overview")).toBe("overview");
|
|
|
|
|
it("resolves tabs from path variants", () => {
|
|
|
|
|
const cases = [
|
|
|
|
|
{ path: "/chat", base: undefined, expected: "chat" },
|
|
|
|
|
{ path: "/overview", base: undefined, expected: "overview" },
|
|
|
|
|
{ path: "/sessions", base: undefined, expected: "sessions" },
|
|
|
|
|
{ path: "/", base: undefined, expected: "chat" },
|
|
|
|
|
{ path: "/ui/chat", base: "/ui", expected: "chat" },
|
|
|
|
|
{ path: "/apps/openclaw/sessions", base: "/apps/openclaw", expected: "sessions" },
|
|
|
|
|
{ path: "/unknown", base: undefined, expected: null },
|
|
|
|
|
{ path: "/CHAT", base: undefined, expected: "chat" },
|
|
|
|
|
{ path: "/Overview", base: undefined, expected: "overview" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(
|
|
|
|
|
tabFromPath(testCase.path, testCase.base),
|
|
|
|
|
`${testCase.path}:${testCase.base ?? "root"}`,
|
|
|
|
|
).toBe(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("inferBasePathFromPathname", () => {
|
|
|
|
|
it("returns empty string for root", () => {
|
|
|
|
|
expect(inferBasePathFromPathname("/")).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns empty string for direct tab path", () => {
|
|
|
|
|
expect(inferBasePathFromPathname("/chat")).toBe("");
|
|
|
|
|
expect(inferBasePathFromPathname("/overview")).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("infers base path from nested paths", () => {
|
|
|
|
|
expect(inferBasePathFromPathname("/ui/chat")).toBe("/ui");
|
|
|
|
|
expect(inferBasePathFromPathname("/apps/openclaw/sessions")).toBe("/apps/openclaw");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles index.html suffix", () => {
|
|
|
|
|
expect(inferBasePathFromPathname("/index.html")).toBe("");
|
|
|
|
|
expect(inferBasePathFromPathname("/ui/index.html")).toBe("/ui");
|
|
|
|
|
it("infers base-path variants from pathname", () => {
|
|
|
|
|
const cases = [
|
|
|
|
|
{ path: "/", expected: "" },
|
|
|
|
|
{ path: "/chat", expected: "" },
|
|
|
|
|
{ path: "/overview", expected: "" },
|
|
|
|
|
{ path: "/ui/chat", expected: "/ui" },
|
|
|
|
|
{ path: "/apps/openclaw/sessions", expected: "/apps/openclaw" },
|
|
|
|
|
{ path: "/index.html", expected: "" },
|
|
|
|
|
{ path: "/ui/index.html", expected: "/ui" },
|
|
|
|
|
] as const;
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
expect(inferBasePathFromPathname(testCase.path), testCase.path).toBe(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("TAB_GROUPS", () => {
|
|
|
|
|
it("contains all expected groups", () => {
|
|
|
|
|
const labels = TAB_GROUPS.map((g) => g.label);
|
|
|
|
|
expect(labels).toContain("Chat");
|
|
|
|
|
expect(labels).toContain("Control");
|
|
|
|
|
expect(labels).toContain("Agent");
|
|
|
|
|
expect(labels).toContain("Settings");
|
|
|
|
|
const labels = TAB_GROUPS.map((g) => g.label.toLowerCase());
|
|
|
|
|
for (const expected of ["chat", "control", "agent", "settings"]) {
|
|
|
|
|
expect(labels).toContain(expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("all tabs are unique", () => {
|
|
|
|
|
|