refactor(mobile): test final connection status presentation (#10007)
This commit is contained in:
1 parent
4e5e17fd9e
commit
1449deca0a
2 files changed
+22
-48
No files matched your search
@@ -1,11 +1,7 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import type { WorkspaceState } from "../../state/workspaceModel";
|
||||
import {
|
||||
shouldShowWorkspaceConnectionStatus,
|
||||
workspaceConnectionStatusLabel,
|
||||
workspaceConnectionStatusPresentation,
|
||||
} from "./workspace-connection-status";
|
||||
import { workspaceConnectionStatusPresentation } from "./workspace-connection-status";
|
||||
|
||||
function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState {
|
||||
return {
|
||||
@@ -27,14 +23,16 @@ function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState
|
||||
|
||||
describe("workspace connection status", () => {
|
||||
it("stays hidden while a ready environment is connected", () => {
|
||||
expect(shouldShowWorkspaceConnectionStatus(workspaceState())).toBe(false);
|
||||
expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull();
|
||||
});
|
||||
|
||||
it("surfaces offline snapshots", () => {
|
||||
const state = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
|
||||
|
||||
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
|
||||
expect(workspaceConnectionStatusLabel(state)).toBe("You are offline");
|
||||
expect(workspaceConnectionStatusPresentation(state)).toEqual({
|
||||
label: "You are offline",
|
||||
showsProgress: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("names the environment while reconnecting", () => {
|
||||
@@ -54,8 +52,10 @@ describe("workspace connection status", () => {
|
||||
],
|
||||
});
|
||||
|
||||
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
|
||||
expect(workspaceConnectionStatusLabel(state)).toBe("Reconnecting to Julius’s Mac mini");
|
||||
expect(workspaceConnectionStatusPresentation(state)).toEqual({
|
||||
label: "Reconnecting to Julius’s Mac mini",
|
||||
showsProgress: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("surfaces connection errors before the generic disconnected fallback", () => {
|
||||
@@ -65,15 +65,19 @@ describe("workspace connection status", () => {
|
||||
hasReadyEnvironment: false,
|
||||
});
|
||||
|
||||
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
|
||||
expect(workspaceConnectionStatusLabel(state)).toBe("Could not reach Julius’s Mac mini");
|
||||
expect(workspaceConnectionStatusPresentation(state)).toEqual({
|
||||
label: "Could not reach Julius’s Mac mini",
|
||||
showsProgress: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("shows shell catch-up while cached threads remain visible", () => {
|
||||
const state = workspaceState({ hasPendingShellSnapshot: true });
|
||||
|
||||
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
|
||||
expect(workspaceConnectionStatusLabel(state)).toBe("Syncing threads...");
|
||||
expect(workspaceConnectionStatusPresentation(state)).toEqual({
|
||||
label: "Syncing threads...",
|
||||
showsProgress: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("distinguishes initial shell loading from cached catch-up", () => {
|
||||
@@ -82,39 +86,9 @@ describe("workspace connection status", () => {
|
||||
hasPendingShellSnapshot: true,
|
||||
});
|
||||
|
||||
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
|
||||
expect(workspaceConnectionStatusLabel(state)).toBe("Loading threads...");
|
||||
});
|
||||
|
||||
it("presents nothing while connected", () => {
|
||||
expect(workspaceConnectionStatusPresentation(workspaceState())).toBeNull();
|
||||
});
|
||||
|
||||
it("presents progress while reconnecting but not while offline", () => {
|
||||
const reconnecting = workspaceState({
|
||||
hasConnectingEnvironment: true,
|
||||
hasReadyEnvironment: false,
|
||||
connectingEnvironments: [
|
||||
{
|
||||
environmentId: "environment-1" as never,
|
||||
environmentLabel: "Julius’s Mac mini",
|
||||
displayUrl: "",
|
||||
isRelayManaged: false,
|
||||
connectionState: "reconnecting",
|
||||
connectionError: null,
|
||||
connectionErrorTraceId: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(workspaceConnectionStatusPresentation(reconnecting)).toEqual({
|
||||
label: "Reconnecting to Julius’s Mac mini",
|
||||
expect(workspaceConnectionStatusPresentation(state)).toEqual({
|
||||
label: "Loading threads...",
|
||||
showsProgress: true,
|
||||
});
|
||||
|
||||
const offline = workspaceState({ networkStatus: "offline", hasReadyEnvironment: false });
|
||||
expect(workspaceConnectionStatusPresentation(offline)).toEqual({
|
||||
label: "You are offline",
|
||||
showsProgress: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@ export interface WorkspaceConnectionStatusPresentation {
|
||||
readonly showsProgress: boolean;
|
||||
}
|
||||
|
||||
export function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
|
||||
function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
|
||||
return (
|
||||
state.networkStatus === "offline" ||
|
||||
state.connectionError !== null ||
|
||||
@@ -16,7 +16,7 @@ export function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): bool
|
||||
);
|
||||
}
|
||||
|
||||
export function workspaceConnectionStatusLabel(state: WorkspaceState): string {
|
||||
function workspaceConnectionStatusLabel(state: WorkspaceState): string {
|
||||
if (state.networkStatus === "offline") return "You are offline";
|
||||
if (state.connectingEnvironments.length === 1) {
|
||||
return `Reconnecting to ${state.connectingEnvironments[0]!.environmentLabel}`;
|
||||
|
||||
Reference in new issue
Block a user