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

cloudEnvironmentConnectionPresentation.test.ts

55 lines1.9 KB

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 };
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 ["offline", "Offline", "Offline", "idle"],
44 ["available", "Not connected", "Available", "idle"],
45 ] as const)(
46 "presents %s without claiming the environment is connected",
47 (phase, buttonLabel, statusText, tone) => {
48 expect(
49 presentSavedCloudEnvironmentConnection(
50 connection(phase, phase === "error" ? "Access denied." : null),
51 ),
52 ).toEqual({ buttonLabel, statusText, tone });
53 },
54 );
55});