| ... | ... | @@ -1,11 +1,7 @@ |
| 1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | 2 | |
| 3 | 3 | import type { WorkspaceState } from "../../state/workspaceModel"; |
| 4 | | import { |
| 5 | | shouldShowWorkspaceConnectionStatus, |
| 6 | | workspaceConnectionStatusLabel, |
| 7 | | workspaceConnectionStatusPresentation, |
| 8 | | } from "./workspace-connection-status"; |
| 4 | import { workspaceConnectionStatusPresentation } from "./workspace-connection-status"; |
| 9 | 5 | |
| 10 | 6 | function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState { |
| 11 | 7 | return { |
| ... | ... | @@ -27,14 +23,16 @@ function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState |
| 27 | 23 | |
| 28 | 24 | describe("workspace connection status", () => { |
| 29 | 25 | it("stays hidden while a ready environment is connected", () => { |
| 30 | | expect(shouldShowWorkspaceConnectionStatus(workspaceState())).toBe(false); |
| 26 | expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull(); |
| 31 | 27 | }); |
| 32 | 28 | |
| 33 | 29 | it("surfaces offline snapshots", () => { |
| 34 | 30 | const state = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false }); |
| 35 | 31 | |
| 36 | | expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true); |
| 37 | | expect(workspaceConnectionStatusLabel(state)).toBe("You are offline"); |
| 32 | expect(workspaceConnectionStatusPresentation(state)).toEqual({ |
| 33 | label: "You are offline", |
| 34 | showsProgress: false, |
| 35 | }); |
| 38 | 36 | }); |
| 39 | 37 | |
| 40 | 38 | it("names the environment while reconnecting", () => { |
| ... | ... | @@ -54,8 +52,10 @@ describe("workspace connection status", () => { |
| 54 | 52 | ], |
| 55 | 53 | }); |
| 56 | 54 | |
| 57 | | expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true); |
| 58 | | expect(workspaceConnectionStatusLabel(state)).toBe("Reconnecting to Julius’s Mac mini"); |
| 55 | expect(workspaceConnectionStatusPresentation(state)).toEqual({ |
| 56 | label: "Reconnecting to Julius’s Mac mini", |
| 57 | showsProgress: true, |
| 58 | }); |
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | 61 | it("surfaces connection errors before the generic disconnected fallback", () => { |
| ... | ... | @@ -65,15 +65,19 @@ describe("workspace connection status", () => { |
| 65 | 65 | hasReadyEnvironment: false, |
| 66 | 66 | }); |
| 67 | 67 | |
| 68 | | expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true); |
| 69 | | expect(workspaceConnectionStatusLabel(state)).toBe("Could not reach Julius’s Mac mini"); |
| 68 | expect(workspaceConnectionStatusPresentation(state)).toEqual({ |
| 69 | label: "Could not reach Julius’s Mac mini", |
| 70 | showsProgress: false, |
| 71 | }); |
| 70 | 72 | }); |
| 71 | 73 | |
| 72 | 74 | it("shows shell catch-up while cached threads remain visible", () => { |
| 73 | 75 | const state = workspaceState({ hasPendingShellSnapshot: true }); |
| 74 | 76 | |
| 75 | | expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true); |
| 76 | | expect(workspaceConnectionStatusLabel(state)).toBe("Syncing threads..."); |
| 77 | expect(workspaceConnectionStatusPresentation(state)).toEqual({ |
| 78 | label: "Syncing threads...", |
| 79 | showsProgress: true, |
| 80 | }); |
| 77 | 81 | }); |
| 78 | 82 | |
| 79 | 83 | it("distinguishes initial shell loading from cached catch-up", () => { |
| ... | ... | @@ -82,39 +86,9 @@ describe("workspace connection status", () => { |
| 82 | 86 | hasPendingShellSnapshot: true, |
| 83 | 87 | }); |
| 84 | 88 | |
| 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", |
| 89 | expect(workspaceConnectionStatusPresentation(state)).toEqual({ |
| 90 | label: "Loading threads...", |
| 111 | 91 | showsProgress: true, |
| 112 | 92 | }); |
| 113 | | |
| 114 | | const offline = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false }); |
| 115 | | expect(workspaceConnectionStatusPresentation(offline)).toEqual({ |
| 116 | | label: "You are offline", |
| 117 | | showsProgress: false, |
| 118 | | }); |
| 119 | 93 | }); |
| 120 | 94 | }); |