返回 DeepSeek-Reasonix
dock-view-requests.test.tsx
根目录 / desktop / frontend / src / __tests__ / dock-view-requests.test.tsx
1 import assert from "node:assert/strict";
2 import React, { act } from "react";
3 import { createRoot } from "react-dom/client";
4 import { JSDOM } from "jsdom";
5 import { useDockViewRequests } from "../app-shell/useDockViewRequests";
6
7 const dom = new JSDOM("<div id='root'></div>");
8 Object.assign(globalThis, { window: dom.window, document: dom.window.document, IS_REACT_ACT_ENVIRONMENT: true });
9 const root = createRoot(document.getElementById("root")!);
10 let forwarded: ReturnType<typeof useDockViewRequests>;
11 function Harness({ scope, view, request }: { scope: string; view: string | null; request: { id: number; path: string } }) {
12 const props = { changeRevealRequest: { ...request } };
13 forwarded = useDockViewRequests(scope, view, props);
14 return null;
15 }
16 const first = { id: 1, path: "a.ts" };
17 const next = { id: 2, path: "b.ts" };
18 const paint = (scope: string, view: string | null, request = first) =>
19 act(async () => root.render(<React.StrictMode><Harness scope={scope} view={view} request={request} /></React.StrictMode>));
20 await paint("project-a", "view-a");
21 assert.equal(forwarded!.changeRevealRequest?.path, first.path);
22 assert.equal(forwarded!.changeRevealRequest?.acceptNavigation?.(), true);
23 assert(!("tabId" in forwarded!), "forwarding requests must not retain session data or callbacks");
24 await paint("project-a", "view-a");
25 assert.equal(forwarded!.changeRevealRequest?.path, first.path);
26 assert.equal(forwarded!.changeRevealRequest?.acceptNavigation?.(), false);
27 await paint("project-a", "view-b");
28 assert.equal(forwarded!.changeRevealRequest, null, "another view must not inherit the pending reveal");
29 await paint("project-a", "view-a");
30 assert.equal(forwarded!.changeRevealRequest, null, "returning must restore navigation rather than replay an old reveal");
31 await paint("project-a", null, next);
32 await paint("project-a", "view-b", next);
33 assert.equal(forwarded!.changeRevealRequest?.path, next.path, "a new command while closed is delivered when the panel opens");
34 await paint("project-b", "view-b", next);
35 assert.equal(forwarded!.changeRevealRequest, null, "retained command cannot cross projects");
36 await act(async () => root.unmount());
37 dom.window.close();
38 console.log("PASS view-owned reveal requests, remount and project isolation");
39
39 lines Plain Text