| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { assert, it } from "@effect/vitest"; |
| 3 | |
| 4 | import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types"; |
| 5 | import { |
| 6 | applyShowcaseLocalEnvironmentDisplayUrls, |
| 7 | resolveShowcaseEnvironmentUpdateDisplayUrl, |
| 8 | } from "./showcaseEnvironmentRows"; |
| 9 | |
| 10 | function environment( |
| 11 | environmentId: string, |
| 12 | environmentLabel: string, |
| 13 | displayUrl = "http://127.0.0.1:3773/", |
| 14 | ): ConnectedEnvironmentSummary { |
| 15 | return { |
| 16 | environmentId: EnvironmentId.make(environmentId), |
| 17 | environmentLabel, |
| 18 | displayUrl, |
| 19 | isRelayManaged: false, |
| 20 | isEnabled: true, |
| 21 | connectionState: "connected", |
| 22 | connectionError: null, |
| 23 | connectionErrorTraceId: null, |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | it("presents showcase transports as remote endpoints", () => { |
| 28 | const environments = applyShowcaseLocalEnvironmentDisplayUrls([ |
| 29 | environment("runtime-id-1", "Moonbase Terminal"), |
| 30 | environment("runtime-id-2", "Suspense Station"), |
| 31 | environment("runtime-id-3", "Kernel Cabin"), |
| 32 | ]); |
| 33 | |
| 34 | assert.deepStrictEqual( |
| 35 | environments.map(({ displayUrl }) => displayUrl), |
| 36 | [ |
| 37 | "https://moonbase.tail9f3a.ts.net/", |
| 38 | "https://suspense-vps.hel1.t3.sh/", |
| 39 | "http://100.82.16.5:3773/", |
| 40 | ], |
| 41 | ); |
| 42 | }); |
| 43 | |
| 44 | it("leaves environments outside the showcase fixture unchanged", () => { |
| 45 | const original = environment( |
| 46 | "runtime-id-4", |
| 47 | "My Workstation", |
| 48 | "https://workstation.example.test/", |
| 49 | ); |
| 50 | |
| 51 | assert.deepStrictEqual(applyShowcaseLocalEnvironmentDisplayUrls([original]), [original]); |
| 52 | }); |
| 53 | |
| 54 | it("does not persist a cosmetic showcase URL when only the label is saved", () => { |
| 55 | assert.equal( |
| 56 | resolveShowcaseEnvironmentUpdateDisplayUrl({ |
| 57 | actualDisplayUrl: "http://127.0.0.1:3773/", |
| 58 | presentedDisplayUrl: "https://moonbase.tail9f3a.ts.net/", |
| 59 | submittedDisplayUrl: "https://moonbase.tail9f3a.ts.net/", |
| 60 | }), |
| 61 | "http://127.0.0.1:3773/", |
| 62 | ); |
| 63 | assert.equal( |
| 64 | resolveShowcaseEnvironmentUpdateDisplayUrl({ |
| 65 | actualDisplayUrl: "http://127.0.0.1:3773/", |
| 66 | presentedDisplayUrl: "https://moonbase.tail9f3a.ts.net/", |
| 67 | submittedDisplayUrl: "https://new-host.example.com/", |
| 68 | }), |
| 69 | "https://new-host.example.com/", |
| 70 | ); |
| 71 | }); |