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