整页表格的分页放进 17rem 左栏和抽屉历史弹层会折成三行,弹层只露出 3 条会话。 改成「共 N 条 · ‹ 1/3 ›」一行,每页条数沿用全站设置,翻页时列表回到顶部。 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
87 lines
4.3 KiB
TypeScript
87 lines
4.3 KiB
TypeScript
import { createElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
import { runGroup } from "~/api/agent.ts";
|
|
import { agentListHref, agentRunHref, groupFromSearch, resolveGroup, revealScrollTop } from "./agent-nav.ts";
|
|
import { CompactPager } from "./agent-session-list.tsx";
|
|
import { isAgentPage, outletKey } from "./agent-store.ts";
|
|
|
|
// 智能体页面切换的状态逻辑:整页重挂载 key、分栏与 URL、草稿、滚动策略、快捷键在智能体页面的行为。
|
|
|
|
describe("主内容区重挂载 key", () => {
|
|
it("列表页与各会话页共用一个 key,切换会话不重挂载", () => {
|
|
expect(outletKey("/console/agent")).toBe("/console/agent");
|
|
expect(outletKey("/console/agent/0b1c")).toBe("/console/agent");
|
|
expect(outletKey("/console/agent/9f2e")).toBe(outletKey("/console/agent/0b1c"));
|
|
});
|
|
it("其它页面仍按路径重挂载", () => {
|
|
expect(outletKey("/console/library")).toBe("/console/library");
|
|
expect(outletKey("/console/agents-x")).toBe("/console/agents-x");
|
|
expect(isAgentPage("/console/agentx")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("分栏:对话 / 自动巡检", () => {
|
|
it("会话所在分栏:巡检 / 事件在自动巡检,子会话随父会话,父会话未知归对话", () => {
|
|
expect(runGroup({ trigger: "schedule" })).toBe("auto");
|
|
expect(runGroup({ trigger: "event" })).toBe("auto");
|
|
expect(runGroup({ trigger: "user" })).toBe("conversation");
|
|
expect(runGroup({ trigger: "subagent" }, { trigger: "schedule" })).toBe("auto");
|
|
expect(runGroup({ trigger: "subagent" }, { trigger: "user" })).toBe("conversation");
|
|
expect(runGroup({ trigger: "subagent" })).toBe("conversation");
|
|
});
|
|
it("URL 的 tab 只认两个取值", () => {
|
|
expect(groupFromSearch("?tab=auto&mock=1")).toBe("auto");
|
|
expect(groupFromSearch("?tab=conversation")).toBe("conversation");
|
|
expect(groupFromSearch("?tab=xx")).toBeNull();
|
|
expect(groupFromSearch("")).toBeNull();
|
|
});
|
|
it("取值顺序:URL > 当前会话 > 上次 > 对话", () => {
|
|
expect(resolveGroup({ fromUrl: "conversation", activeRun: "auto", remembered: "auto" })).toBe("conversation");
|
|
expect(resolveGroup({ fromUrl: null, activeRun: "auto", remembered: "conversation" })).toBe("auto");
|
|
// 打开巡检会话、快照还没到:沿用点它时所在的分栏,不先闪到「对话」
|
|
expect(resolveGroup({ fromUrl: null, activeRun: null, remembered: "auto" })).toBe("auto");
|
|
expect(resolveGroup({ fromUrl: null })).toBe("conversation");
|
|
});
|
|
it("链接:会话页不带 tab(由会话决定),列表页只在自动巡检时带,保留演示开关", () => {
|
|
expect(agentRunHref("r1")).toBe("/console/agent/r1");
|
|
expect(agentRunHref("r1", true)).toBe("/console/agent/r1?mock=1");
|
|
expect(agentListHref()).toBe("/console/agent");
|
|
expect(agentListHref("auto")).toBe("/console/agent?tab=auto");
|
|
expect(agentListHref("auto", true)).toBe("/console/agent?tab=auto&mock=1");
|
|
expect(agentListHref("conversation", true)).toBe("/console/agent?mock=1");
|
|
});
|
|
});
|
|
|
|
describe("当前会话滚进可见区", () => {
|
|
const vp = { scrollTop: 200, height: 300 };
|
|
it("已经完整可见不滚", () => {
|
|
expect(revealScrollTop({ top: 250, height: 40 }, vp)).toBeNull();
|
|
});
|
|
it("在上方:滚到顶边对齐;在下方:滚到底边刚好露出", () => {
|
|
expect(revealScrollTop({ top: 120, height: 40 }, vp)).toBe(120);
|
|
expect(revealScrollTop({ top: 600, height: 40 }, vp)).toBe(340);
|
|
});
|
|
});
|
|
|
|
describe("会话列表分页(窄列表一行)", () => {
|
|
const pager = (p: Partial<Parameters<typeof CompactPager>[0]>) =>
|
|
renderToStaticMarkup(
|
|
createElement(CompactPager, { page: 1, pageSize: 20, total: 0, onPageChange: () => {}, ...p }),
|
|
);
|
|
it("只有一页不显示", () => {
|
|
expect(pager({ total: 12 })).toBe("");
|
|
});
|
|
it("多页:总数 + 当前页 / 页数,没有每页条数选择", () => {
|
|
const html = pager({ total: 48, page: 2 });
|
|
expect(html).toContain("共 48 条");
|
|
expect(html).toContain("2 / 3");
|
|
expect(html).not.toContain("每页");
|
|
});
|
|
it("还能往后加载时标出已加载条数和「+」", () => {
|
|
const html = pager({ total: 20, hasMore: true });
|
|
expect(html).toContain("已加载 20 条");
|
|
expect(html).toContain("1 / 1+");
|
|
});
|
|
});
|