1import { describe, expect, it } from "vite-plus/test";
2
3import type { WorkspaceState } from "../../state/workspaceModel";
4import { workspaceConnectionStatusPresentation } from "./workspace-connection-status";
5
6function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState {
7 return {
8 isLoadingConnections: false,
9 hasConnections: true,
10 hasLoadedShellSnapshot: true,
11 hasPendingShellSnapshot: false,
12 hasReadyEnvironment: true,
13 hasConnectingEnvironment: false,
14 connectingEnvironments: [],
15 connectionState: "connected",
16 connectionError: null,
17 shellSnapshotError: null,
18 networkStatus: "online",
19 ...overrides,
20 };
21}
22
23describe("workspace connection status", () => {
24 it("stays hidden while a ready environment is connected", () => {
25 expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull();
26 });
27
28 it("surfaces offline snapshots", () => {
29 const state = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
30
31 expect(workspaceConnectionStatusPresentation(state)).toEqual({
32 label: "You are offline",
33 showsProgress: false,
34 });
35 });
36
37 it("names the environment while reconnecting", () => {
38 const state = workspaceState({
39 hasConnectingEnvironment: true,
40 hasReadyEnvironment: false,
41 connectingEnvironments: [
42 {
43 environmentId: "environment-1" as never,
44 environmentLabel: "Julius’s Mac mini",
45 displayUrl: "",
46 isRelayManaged: false,
47 isEnabled: true,
48 connectionState: "reconnecting",
49 connectionError: null,
50 connectionErrorTraceId: null,
51 },
52 ],
53 });
54
55 expect(workspaceConnectionStatusPresentation(state)).toEqual({
56 label: "Reconnecting to Julius’s Mac mini",
57 showsProgress: true,
58 });
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(workspaceConnectionStatusPresentation(state)).toEqual({
69 label: "Could not reach Julius’s Mac mini",
70 showsProgress: false,
71 });
72 });
73
74 it("shows shell catch-up while cached threads remain visible", () => {
75 const state = workspaceState({ hasPendingShellSnapshot: true });
76
77 expect(workspaceConnectionStatusPresentation(state)).toEqual({
78 label: "Syncing threads...",
79 showsProgress: true,
80 });
81 });
82
83 it("distinguishes initial shell loading from cached catch-up", () => {
84 const state = workspaceState({
85 hasLoadedShellSnapshot: false,
86 hasPendingShellSnapshot: true,
87 });
88
89 expect(workspaceConnectionStatusPresentation(state)).toEqual({
90 label: "Loading threads...",
91 showsProgress: true,
92 });
93 });
94});