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

workspaceModel.test.ts

108 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 refusedRouteIds: [],
52 };
54​
55const EMPTY_SHELL_SUMMARY: EnvironmentShellSummary = {
56 hasSnapshot: false,
57 hasSynchronizingShell: false,
58 firstError: null,
59};
60​
61const CACHED_SHELL_SUMMARY: EnvironmentShellSummary = {
62 ...EMPTY_SHELL_SUMMARY,
63 hasSnapshot: true,
64 hasSynchronizingShell: true,
65};
66​
67describe("mobile workspace projection", () => {
68 it("reports offline before stale connected presentations", () => {
69 const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("connected"))];
70 const state = projectWorkspaceState({
71 isReady: true,
72 networkStatus: "offline",
73 environments,
74 shellSummary: EMPTY_SHELL_SUMMARY,
75 hasSyncingConnectedEnvironment: false,
76 });
77​
78 expect(state.connectionState).toBe("offline");
79 expect(state.networkStatus).toBe("offline");
80 expect(state.hasReadyEnvironment).toBe(false);
81 });
82​
83 it("waits for shell cache initialization and synchronization, but not completed reads", () => {
84 expect(isEnvironmentShellPending(EMPTY_SHELL_STATE)).toBe(true);
85 expect(isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, status: "synchronizing" })).toBe(true);
86 expect(isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, status: "cached" })).toBe(false);
87 expect(
88 isEnvironmentShellPending({ ...EMPTY_SHELL_STATE, error: Option.some("Cache failed.") }),
89 ).toBe(false);
90 });
91​
92 it("keeps retained snapshots visible while reconnecting without claiming readiness", () => {
93 const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("reconnecting"))];
94 const state = projectWorkspaceState({
95 isReady: true,
96 networkStatus: "online",
97 environments,
98 shellSummary: CACHED_SHELL_SUMMARY,
99 hasSyncingConnectedEnvironment: false,
100 });
101​
102 expect(state.hasLoadedShellSnapshot).toBe(true);
103 expect(state.hasPendingShellSnapshot).toBe(true);
104 expect(state.hasSyncingConnectedEnvironment).toBe(false);
105 expect(state.hasReadyEnvironment).toBe(false);
106 expect(state.connectionState).toBe("reconnecting");
107 });
108});