Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

workspaceModel.test.ts

107 lines3.7 KB

1import {
2 EMPTY_SHELL_STATE,
3 type EnvironmentShellSummary,
4} from "@t3tools/client-runtime/state/shell";
5import {
6 BearerConnectionProfile,
7 BearerConnectionTarget,
8} from "@t3tools/client-runtime/connection";
9import { EnvironmentId } from "@t3tools/contracts";
10import { describe, expect, it } from "@effect/vitest";
11import * as Option from "effect/Option";
12​
13import { isEnvironmentShellPending, projectWorkspaceState } from "./workspaceModel";
14import { projectEnvironmentConnectionSummary as projectWorkspaceEnvironment } from "@t3tools/client-runtime/state/presentation";
15import type { EnvironmentPresentation } from "./environments";
16​
17const ENVIRONMENT_ID = EnvironmentId.make("environment-1");
18​
19function environment(
20 phase: EnvironmentPresentation["connection"]["phase"],
21): EnvironmentPresentation {
22 const connectionId = `bearer:${ENVIRONMENT_ID}`;
23 return {
24 environmentId: ENVIRONMENT_ID,
25 label: "Julius's MacBook Pro",
26 displayUrl: "https://environment.example.test",
27 relayManaged: false,
28 entry: {
29 target: new BearerConnectionTarget({
30 environmentId: ENVIRONMENT_ID,
31 label: "Julius's MacBook Pro",
32 connectionId,
33 }),
34 profile: Option.some(
35 new BearerConnectionProfile({
36 connectionId,
37 environmentId: ENVIRONMENT_ID,
38 label: "Julius's MacBook Pro",
39 httpBaseUrl: "https://environment.example.test",
40 wsBaseUrl: "wss://environment.example.test",
41 }),
42 ),
43 enabled: true,
44 },
45 connection: {
46 phase,
47 error: phase === "error" ? "Connection failed." : null,
48 traceId: phase === "error" ? "trace-1" : null,
49 },
50 serverConfig: null,
51 };
53​
54const EMPTY_SHELL_SUMMARY: EnvironmentShellSummary = {
55 hasSnapshot: false,
56 hasSynchronizingShell: false,
57 firstError: null,
58};
59​
60const CACHED_SHELL_SUMMARY: EnvironmentShellSummary = {
61 ...EMPTY_SHELL_SUMMARY,
62 hasSnapshot: true,
63 hasSynchronizingShell: true,
64};
65​
66describe("mobile workspace projection", () => {
67 it("reports offline before stale connected presentations", () => {
68 const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("connected"))];
69 const state = projectWorkspaceState({
70 isReady: true,
71 networkStatus: "offline",
72 environments,
73 shellSummary: EMPTY_SHELL_SUMMARY,
74 hasSyncingConnectedEnvironment: false,
75 });
76​
77 expect(state.connectionState).toBe("offline");
78 expect(state.networkStatus).toBe("offline");
79 expect(state.hasReadyEnvironment).toBe(false);
80 });
81​
82 it("waits for shell cache initialization and synchronization, but not completed reads", () => {
83 expect(isEnvironmentShellPending(EMPTY_SHELL_STATE)).toBe(true);
84 expect(isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, status: "synchronizing" })).toBe(true);
85 expect(isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, status: "cached" })).toBe(false);
86 expect(
87 isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, error: Option.some("Cache failed.") }),
88 ).toBe(false);
89 });
90​
91 it("keeps retained snapshots visible while reconnecting without claiming readiness", () => {
92 const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("reconnecting"))];
93 const state = projectWorkspaceState({
94 isReady: true,
95 networkStatus: "online",
96 environments,
97 shellSummary: CACHED_SHELL_SUMMARY,
98 hasSyncingConnectedEnvironment: false,
99 });
100​
101 expect(state.hasLoadedShellSnapshot).toBe(true);
102 expect(state.hasPendingShellSnapshot).toBe(true);
103 expect(state.hasSyncingConnectedEnvironment).toBe(false);
104 expect(state.hasReadyEnvironment).toBe(false);
105 expect(state.connectionState).toBe("reconnecting");
106 });
107});