返回 DeepSeek-Reasonix
RemoteNavigationHarness.tsx
根目录 / desktop / frontend / src / __tests__ / helpers / RemoteNavigationHarness.tsx
1 import React, { useRef, type ReactNode } from "react";
2 import { useDesktopNavigation } from "../../app-runtime/useDesktopNavigation";
3 import { RemoteNavigationContext } from "../../lib/remoteNavigationCommands";
4 import { app } from "../../lib/bridge";
5 import { useNavigationIntentFence } from "../../lib/useNavigationIntentFence";
6 import { useT } from "../../lib/i18n";
7
8 const noop = () => {};
9 const unavailable = async (): Promise<never> => { throw new Error("unexpected local navigation in remote fixture"); };
10 /** Component fixtures use the production owner and registration fence, not a second navigation implementation. */
11 export function RemoteNavigationHarness({ children }: { children: ReactNode }) {
12 const sequence = useRef(0);
13 const fence = useNavigationIntentFence();
14 const { openRemoteProject } = useDesktopNavigation({ visible: { tabId: "fixture", sessionKey: "fixture" },
15 noteIntent: () => { const seq = ++sequence.current; fence.registerNavigationIntent(seq); return seq; },
16 beginSurface: noop, settleSurface: noop, showChat: noop,
17 setTabRevealSignal: noop, setProjectRevision: noop, setHistory: noop, t: useT(), showToast: noop,
18 ports: { registeredNavigationIntent: fence.registeredNavigationIntent, isNavigationIntentCurrent: seq => seq === sequence.current,
19 openRemoteProject: app.OpenRemoteProjectTab, switchRemoteTab: async () => {},
20 activateTopic: unavailable, openTopicSession: unavailable, openGlobalTab: unavailable, openProjectTab: unavailable,
21 ensureBlankSurface: unavailable, ensureBlankTab: unavailable, createIsolatedWorktree: unavailable,
22 openChannelSession: unavailable, resumeSession: unavailable,
23 listTabs: async () => [], listSessions: async () => [], applyTabs: noop, seedTab: noop,
24 },
25 });
26 return <RemoteNavigationContext.Provider value={openRemoteProject}>{children}</RemoteNavigationContext.Provider>;
27 }
28
28 lines Plain Text