Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import type { WorkspaceState } from "../../state/workspaceModel";
4import {
5 shouldShowWorkspaceConnectionStatus,
6 workspaceConnectionStatusLabel,
7 workspaceConnectionStatusPresentation,
8} from "./workspace-connection-status";
9
10function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState {
11 return {
12 isLoadingConnections: false,
13 hasConnections: true,
14 hasLoadedShellSnapshot: true,
15 hasPendingShellSnapshot: false,
16 hasReadyEnvironment: true,
17 hasConnectingEnvironment: false,
18 connectingEnvironments: [],
19 connectionState: "connected",
20 connectionError: null,
21 shellSnapshotError: null,
22 latestCachedSnapshotReceivedAt: null,
23 networkStatus: "online",
24 ...overrides,
25 };
26}
27
28describe("workspace connection status", () => {
29 it("stays hidden while a ready environment is connected", () => {
30 expect(shouldShowWorkspaceConnectionStatus(workspaceState())).toBe(false);
31 });
32
33 it("surfaces offline snapshots", () => {
34 const state = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
35
36 expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
37 expect(workspaceConnectionStatusLabel(state)).toBe("You are offline");
38 });
39
40 it("names the environment while reconnecting", () => {
41 const state = workspaceState({
42 hasConnectingEnvironment: true,
43 hasReadyEnvironment: false,
44 connectingEnvironments: [
45 {
46 environmentId: "environment-1" as never,
47 environmentLabel: "Julius’s Mac mini",
48 displayUrl: "",
49 isRelayManaged: false,
50 connectionState: "reconnecting",
51 connectionError: null,
52 connectionErrorTraceId: null,
53 },
54 ],
55 });
56
57 expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
58 expect(workspaceConnectionStatusLabel(state)).toBe("Reconnecting to Julius’s Mac mini");
59 });
60
61 it("surfaces connection errors before the generic disconnected fallback", () => {
62 const state = workspaceState({
63 connectionError: "Could not reach Julius’s Mac mini",
64 hasLoadedShellSnapshot: false,
65 hasReadyEnvironment: false,
66 });
67
68 expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
69 expect(workspaceConnectionStatusLabel(state)).toBe("Could not reach Julius’s Mac mini");
70 });
71
72 it("shows shell catch-up while cached threads remain visible", () => {
73 const state = workspaceState({ hasPendingShellSnapshot: true });
74
75 expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
76 expect(workspaceConnectionStatusLabel(state)).toBe("Syncing threads...");
77 });
78
79 it("distinguishes initial shell loading from cached catch-up", () => {
80 const state = workspaceState({
81 hasLoadedShellSnapshot: false,
82 hasPendingShellSnapshot: true,
83 });
84
85 expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
86 expect(workspaceConnectionStatusLabel(state)).toBe("Loading threads...");
87 });
88
89 it("presents nothing while connected", () => {
90 expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull();
91 });
92
93 it("presents progress while reconnecting but not while offline", () => {
94 const reconnecting = workspaceState({
95 hasConnectingEnvironment: true,
96 hasReadyEnvironment: false,
97 connectingEnvironments: [
98 {
99 environmentId: "environment-1" as never,
100 environmentLabel: "Julius’s Mac mini",
101 displayUrl: "",
102 isRelayManaged: false,
103 connectionState: "reconnecting",
104 connectionError: null,
105 connectionErrorTraceId: null,
106 },
107 ],
108 });
109 expect(workspaceConnectionStatusPresentation(reconnecting)).toEqual({
110 label: "Reconnecting to Julius’s Mac mini",
111 showsProgress: true,
112 });
113
114 const offline = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
115 expect(workspaceConnectionStatusPresentation(offline)).toEqual({
116 label: "You are offline",
117 showsProgress: false,
118 });
119 });
120});