返回 DeepSeek-Reasonix
project-tree-diagnostics.test.ts
根目录 / desktop / frontend / src / __tests__ / project-tree-diagnostics.test.ts
1 import assert from "node:assert/strict";
2 import { summarizeProjectTreeSessions } from "../lib/projectTreeDiagnostics";
3 import type { ProjectNode } from "../lib/types";
4
5 const topic = (id: string, extra: Partial<ProjectNode> = {}): ProjectNode => ({
6 key: `topic-${id}`,
7 kind: "topic",
8 label: id,
9 topicId: id,
10 ...extra,
11 });
12
13 const tree: ProjectNode[] = [{
14 key: "project-a",
15 kind: "project",
16 label: "Project A",
17 root: "private-root",
18 children: [
19 topic("one"),
20 topic("two"),
21 topic("three"),
22 topic("four"),
23 topic("five"),
24 topic("six", { runtimeOnly: true, recoveryCopyCount: 2, running: true }),
25 ],
26 }, {
27 key: "global",
28 kind: "global_folder",
29 label: "Global",
30 children: [topic("global-one", { kind: "global_topic", topicId: "global-one", pinned: true })],
31 }];
32
33 const summary = summarizeProjectTreeSessions({
34 tree,
35 visibleTree: tree,
36 expanded: new Set(["project-a"]),
37 queryActive: false,
38 folderProjection: (_folder, children) => ({ visible: children.slice(0, 5) }),
39 projectNodeKey: (node) => node.key,
40 isActive: (node) => node.topicId === "one",
41 isUnread: (node) => node.topicId === "two",
42 });
43
44 assert.equal(summary.workspaceSessions, 7);
45 assert.equal(summary.visibleSessions, 5, "classic preview plus collapsed global folder hides two rows");
46 assert.equal(summary.hiddenSessions, 2);
47 assert.equal(summary.hiddenByTruncation, 1);
48 assert.equal(summary.hiddenByCollapsed, 1);
49 assert.equal(summary.runtimeOnlySessions, 1);
50 assert.equal(summary.recoveryCopySessions, 0, "ordinary-tree diagnostics ignore deprecated physical-copy counts");
51 assert.equal(summary.recoveryCopies, 0, "ordinary-tree diagnostics do not expose hidden recovery storage");
52 assert.equal(summary.runningSessions, 1);
53 assert.equal(summary.unreadSessions, 1);
54 assert.equal(summary.pinnedSessions, 1);
55 assert.equal(summary.activeSessions, 1);
56 assert.equal(summary.activeVisibleSessions, 1);
57
58 const filtered = summarizeProjectTreeSessions({
59 tree,
60 visibleTree: [{ ...tree[0], children: [tree[0].children?.[0] ?? topic("one")] }],
61 expanded: new Set(["project-a"]),
62 queryActive: true,
63 projectNodeKey: (node) => node.key,
64 });
65 assert.equal(filtered.workspaceSessions, 7);
66 assert.equal(filtered.visibleSessions, 1);
67 assert.equal(filtered.hiddenByFilter, 6);
68 assert.equal(filtered.hiddenByCollapsed, 0);
69 assert.equal(filtered.hiddenByTruncation, 0);
70
71 console.log("project tree diagnostics tests passed");
72
72 lines TYPESCRIPT