Skip to content

Commit f74133b

Browse files
refactor(mobile): test final connection status presentation
1 parent 044a6e1 commit f74133b

2 files changed

Lines changed: 22 additions & 48 deletions

File tree

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { describe, expect, it } from "vite-plus/test";
22

33
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";
95

106
function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState {
117
return {
@@ -27,14 +23,16 @@ function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState
2723

2824
describe("workspace connection status", () => {
2925
it("stays hidden while a ready environment is connected", () => {
30-
expect(shouldShowWorkspaceConnectionStatus(workspaceState())).toBe(false);
26+
expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull();
3127
});
3228

3329
it("surfaces offline snapshots", () => {
3430
const state = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
3531

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+
});
3836
});
3937

4038
it("names the environment while reconnecting", () => {
@@ -54,8 +52,10 @@ describe("workspace connection status", () => {
5452
],
5553
});
5654

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+
});
5959
});
6060

6161
it("surfaces connection errors before the generic disconnected fallback", () => {
@@ -65,15 +65,19 @@ describe("workspace connection status", () => {
6565
hasReadyEnvironment: false,
6666
});
6767

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+
});
7072
});
7173

7274
it("shows shell catch-up while cached threads remain visible", () => {
7375
const state = workspaceState({ hasPendingShellSnapshot: true });
7476

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+
});
7781
});
7882

7983
it("distinguishes initial shell loading from cached catch-up", () => {
@@ -82,39 +86,9 @@ describe("workspace connection status", () => {
8286
hasPendingShellSnapshot: true,
8387
});
8488

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...",
11191
showsProgress: true,
11292
});
113-
114-
const offline = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
115-
expect(workspaceConnectionStatusPresentation(offline)).toEqual({
116-
label: "You are offline",
117-
showsProgress: false,
118-
});
11993
});
12094
});

‎apps/mobile/src/features/home/workspace-connection-status.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface WorkspaceConnectionStatusPresentation {
66
readonly showsProgress: boolean;
77
}
88

9-
export function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
9+
function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
1010
return (
1111
state.networkStatus === "offline" ||
1212
state.connectionError !== null ||
@@ -16,7 +16,7 @@ export function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): bool
1616
);
1717
}
1818

19-
export function workspaceConnectionStatusLabel(state: WorkspaceState): string {
19+
function workspaceConnectionStatusLabel(state: WorkspaceState): string {
2020
if (state.networkStatus === "offline") return "You are offline";
2121
if (state.connectingEnvironments.length === 1) {
2222
return `Reconnecting to ${state.connectingEnvironments[0]!.environmentLabel}`;

0 commit comments

Comments
 (0)