1import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection";
2import { describe, expect, it } from "vite-plus/test";
3
4import { presentSavedCloudEnvironmentConnection } from "./cloudEnvironmentConnectionPresentation";
5
6function connection(
7 phase: EnvironmentConnectionPresentation["phase"],
8 error: string | null = null,
9): EnvironmentConnectionPresentation {
10 return { phase, error, traceId: null };
11}
12
13describe("saved cloud environment connection presentation", () => {
14 it("only labels a live connection as connected", () => {
15 expect(presentSavedCloudEnvironmentConnection(connection("connected"))).toEqual({
16 buttonLabel: "Connected",
17 statusText: "Connected",
18 tone: "connected",
19 });
20
21 expect(presentSavedCloudEnvironmentConnection(connection("connecting"))).toEqual({
22 buttonLabel: "Connecting…",
23 statusText: "Connecting...",
24 tone: "connecting",
25 });
26 });
27
28 it("surfaces a failed attempt while the supervisor reconnects", () => {
29 expect(
30 presentSavedCloudEnvironmentConnection(
31 connection("reconnecting", "Relay environment endpoint is unavailable."),
32 ),
33 ).toEqual({
34 buttonLabel: "Reconnecting…",
35 statusText:
36 "Failed to connect. Reconnecting... Reason: Relay environment endpoint is unavailable.",
37 tone: "connecting",
38 });
39 });
40
41 it.each([
42 ["error", "Connection failed", "Connection failed. Reason: Access denied.", "error"],
43 ["unsupported", "Client not supported", "Client not supported", "idle"],
44 ["offline", "Offline", "Offline", "idle"],
45 ["available", "Not connected", "Available", "idle"],
46 ] as const)(
47 "presents %s without claiming the environment is connected",
48 (phase, buttonLabel, statusText, tone) => {
49 expect(
50 presentSavedCloudEnvironmentConnection(
51 connection(phase, phase === "error" ? "Access denied." : null),
52 ),
53 ).toEqual({ buttonLabel, statusText, tone });
54 },
55 );
56});