|
| 1 | +import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | +import { describe, expect, it } from "vite-plus/test"; |
| 3 | + |
| 4 | +import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspaceModel"; |
| 5 | +import { deriveHomeEmptyState } from "./home-empty-state"; |
| 6 | + |
| 7 | +function connectingEnvironment( |
| 8 | + connectionState: "connecting" | "reconnecting", |
| 9 | + connectionError: string | null, |
| 10 | +): WorkspaceEnvironment { |
| 11 | + return { |
| 12 | + environmentId: EnvironmentId.make("environment-1"), |
| 13 | + environmentLabel: "corex", |
| 14 | + displayUrl: "", |
| 15 | + isRelayManaged: false, |
| 16 | + isEnabled: true, |
| 17 | + connectionState, |
| 18 | + connectionError, |
| 19 | + connectionErrorTraceId: null, |
| 20 | + }; |
| 21 | +} |
| 22 | + |
| 23 | +function workspaceState(overrides: Partial<WorkspaceState> = {}): WorkspaceState { |
| 24 | + return { |
| 25 | + isLoadingConnections: false, |
| 26 | + hasConnections: true, |
| 27 | + hasLoadedShellSnapshot: true, |
| 28 | + hasPendingShellSnapshot: false, |
| 29 | + hasSyncingConnectedEnvironment: false, |
| 30 | + hasReadyEnvironment: true, |
| 31 | + hasConnectingEnvironment: false, |
| 32 | + connectingEnvironments: [], |
| 33 | + connectionState: "connected", |
| 34 | + connectionError: null, |
| 35 | + shellSnapshotError: null, |
| 36 | + networkStatus: "online", |
| 37 | + ...overrides, |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +const RETAINED_FAILURE = "Environment did not respond before the connection timeout."; |
| 42 | +const reconnecting = connectingEnvironment("reconnecting", RETAINED_FAILURE); |
| 43 | + |
| 44 | +describe("home empty state", () => { |
| 45 | + it.each([ |
| 46 | + [ |
| 47 | + "waits while a saved environment retries after a retained failure", |
| 48 | + workspaceState({ |
| 49 | + hasLoadedShellSnapshot: false, |
| 50 | + hasPendingShellSnapshot: true, |
| 51 | + hasReadyEnvironment: false, |
| 52 | + hasConnectingEnvironment: true, |
| 53 | + connectingEnvironments: [reconnecting], |
| 54 | + connectionState: "reconnecting", |
| 55 | + connectionError: RETAINED_FAILURE, |
| 56 | + }), |
| 57 | + 1, |
| 58 | + { title: "Connecting to environment", loading: true, showsAddEnvironment: false }, |
| 59 | + ], |
| 60 | + [ |
| 61 | + "waits for a connected environment's first shell snapshot", |
| 62 | + workspaceState({ |
| 63 | + hasLoadedShellSnapshot: false, |
| 64 | + hasPendingShellSnapshot: true, |
| 65 | + hasSyncingConnectedEnvironment: true, |
| 66 | + }), |
| 67 | + 0, |
| 68 | + { title: "Loading threads", loading: true, showsAddEnvironment: false }, |
| 69 | + ], |
| 70 | + [ |
| 71 | + "waits while another environment is still connecting after one loaded empty", |
| 72 | + workspaceState({ |
| 73 | + hasPendingShellSnapshot: true, |
| 74 | + hasConnectingEnvironment: true, |
| 75 | + connectingEnvironments: [reconnecting], |
| 76 | + connectionError: RETAINED_FAILURE, |
| 77 | + }), |
| 78 | + 0, |
| 79 | + { title: "Loading threads", loading: true, showsAddEnvironment: false }, |
| 80 | + ], |
| 81 | + [ |
| 82 | + "reports no threads once every environment has resolved", |
| 83 | + workspaceState(), |
| 84 | + 1, |
| 85 | + { title: "No threads yet", loading: false, showsAddEnvironment: false }, |
| 86 | + ], |
| 87 | + [ |
| 88 | + "does not wait on retries while the device is offline", |
| 89 | + workspaceState({ |
| 90 | + hasPendingShellSnapshot: true, |
| 91 | + hasReadyEnvironment: false, |
| 92 | + hasConnectingEnvironment: true, |
| 93 | + connectingEnvironments: [reconnecting], |
| 94 | + connectionState: "offline", |
| 95 | + networkStatus: "offline", |
| 96 | + }), |
| 97 | + 1, |
| 98 | + { title: "No threads yet", loading: false, showsAddEnvironment: true }, |
| 99 | + ], |
| 100 | + ] as const)("%s", (_name, state, projectCount, expected) => { |
| 101 | + const { title, loading, showsAddEnvironment } = deriveHomeEmptyState(state, projectCount); |
| 102 | + expect({ title, loading, showsAddEnvironment }).toEqual(expected); |
| 103 | + }); |
| 104 | +}); |
0 commit comments