返回 DeepSeek-Reasonix
session-experience.test.ts
根目录 / desktop / frontend / src / __tests__ / session-experience.test.ts
1 import { JSDOM } from "jsdom";
2 import {
3 applySessionExperience,
4 getSessionExperience,
5 hydrateSessionExperience,
6 resolveWorkProcessPresentation,
7 } from "../lib/sessionExperience";
8
9 const dom = new JSDOM("<!doctype html><html><body></body></html>", {
10 url: "http://localhost/",
11 });
12 globalThis.window = dom.window as unknown as Window & typeof globalThis;
13 globalThis.localStorage = dom.window.localStorage;
14 globalThis.CustomEvent = dom.window.CustomEvent;
15
16 let passed = 0;
17 let failed = 0;
18 function check(value: boolean, message: string): void {
19 if (value) {
20 passed += 1;
21 console.log(` PASS ${message}`);
22 } else {
23 failed += 1;
24 console.log(` FAIL ${message}`);
25 }
26 }
27
28 console.log("\nsession experience");
29 localStorage.clear();
30 localStorage.setItem("reasonix-session-experience", "deep");
31 check(getSessionExperience() === "standard", "startup ignores stale localStorage before the backend snapshot");
32 hydrateSessionExperience("invalid");
33 check(getSessionExperience() === "standard", "invalid startup values normalize to standard");
34 check(resolveWorkProcessPresentation("standard").keepExpandedAfterCompletion === false, "standard collapses completed work");
35 check(resolveWorkProcessPresentation("deep").showWhileRunning === true, "deep shows work while running");
36 check(resolveWorkProcessPresentation("deep").keepExpandedAfterCompletion === true, "deep keeps completed work expanded");
37
38 applySessionExperience("deep");
39 check(getSessionExperience() === "deep", "apply persists deep");
40 check(localStorage.getItem("reasonix-session-experience") === "deep", "canonical localStorage key stores deep");
41 check(localStorage.getItem("reasonix-display-mode") === "standard", "compatibility density mirror stays standard");
42 check(localStorage.getItem("reasonix-process-fold") === "expanded", "deep mirrors the old expanded fold value");
43
44 // An authoritative startup snapshot must win over a stale local optimistic value.
45 hydrateSessionExperience("standard");
46 check(getSessionExperience() === "standard", "authoritative hydrate wins over stale localStorage");
47 check(localStorage.getItem("reasonix-session-experience") === "standard", "hydrate rewrites the canonical localStorage value");
48
49 if (failed > 0) {
50 throw new Error(`${failed} session experience checks failed`);
51 }
52 console.log(` ${passed} checks passed`);
53
53 lines TYPESCRIPT