返回 DeepSeek-Reasonix
sessionLoadingFixture.tsx
根目录 / desktop / frontend / src / test-support / sessionLoadingFixture.tsx
1 import { ChatPaneRegion } from "../app-shell/ChatPaneRegion";
2 import { RemoteSessionSurface } from "../components/RemoteSessionSurface";
3 import { Transcript } from "../components/Transcript";
4 import { initialState, type Item } from "../lib/useController";
5 import type { RemoteSessionApi } from "../lib/useRemoteSession";
6 import type { SessionAvailability } from "../lib/sessionAvailability";
7 import { useT } from "../lib/i18n";
8
9 export type LoadingFixtureInput = {
10 surface: "local" | "remote" | "transcript";
11 identity: string;
12 generation?: number;
13 phase: "loading" | "ready" | "error";
14 cached?: boolean;
15 source?: SessionAvailability["source"];
16 onRetry?: () => Promise<void>;
17 };
18
19 /** Real production surfaces with controlled data completion, shared by DOM/browser checks. */
20 export function SessionLoadingFixture({ surface, identity, generation = 1, phase, cached = false, source = "history", onRetry = async () => {} }: LoadingFixtureInput) {
21 const t = useT();
22 const items: Item[] = cached || phase === "ready" ? [{ kind: "user", id: `${identity}-user`, text: `Content ${identity}` }] : [];
23 const state = { ...initialState, items, hydrating: phase === "loading" && source === "history" };
24 const availability: SessionAvailability = { kind: phase, source, detail: phase === "error" ? "Fixture read failed" : undefined };
25 if (surface === "transcript") return <Transcript items={items} tabId={identity} geometrySessionKey={`${identity}:${generation}`}
26 hydrating={phase === "loading"} onPrompt={() => {}} />;
27 if (surface === "remote") {
28 const session = {
29 state: phase === "loading" && source === "connection" ? "connecting" : "ready",
30 hydrated: phase === "ready", error: phase === "error" ? "Fixture read failed" : "",
31 transcript: state, surfaceGeneration: generation, retryHydration: onRetry,
32 } as RemoteSessionApi;
33 return <RemoteSessionSurface tab={{ id: identity, scope: "project", workspaceRoot: "/fixture", workspaceName: "Fixture",
34 topicId: identity, topicTitle: identity, label: "Fixture", ready: true, running: false, mode: "normal", active: true, cwd: "/fixture",
35 remote: { hostId: "fixture", workspace: "/fixture" } }} session={session} />;
36 }
37 return <ChatPaneRegion transitioning={false} imDetail={null} remote={undefined} t={t}
38 transcript={{ state, items, tabId: identity, geometrySessionKey: `${identity}:${generation}`,
39 footerHeight: 100, transcriptHydrating: state.hydrating, navigationDataReady: phase === "ready",
40 readOnly: false, controllerReady: phase === "ready", hydratePlaceholderActive: cached && phase === "loading",
41 clearContextPending: false, availability, rewind: { stateActive: false, committing: false },
42 invocationMetadata: undefined, surfaceCommitToken: undefined, liveStore: undefined }}
43 onRetryHistory={onRetry} commands={{ onPrompt: () => {}, onFork: () => {},
44 onLoadOlderHistory: undefined, onLoadNewerHistory: undefined, onSurfacePaintReady: undefined }} />;
45 }
46
46 lines Plain Text