The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | BearerConnectionProfile, |
| 3 | BearerConnectionTarget, |
| 4 | type ConnectionCatalogEntry, |
| 5 | type ConnectionRoute, |
| 6 | } from "@t3tools/client-runtime/connection"; |
| 7 | import { EnvironmentId } from "@t3tools/contracts"; |
| 8 | import * as Option from "effect/Option"; |
| 9 | import { expect, it, vi } from "vite-plus/test"; |
| 10 | import { userEvent } from "vite-plus/test/browser"; |
| 11 | |
| 12 | vi.mock(import("~/state/session"), async (importOriginal) => ({ |
| 13 | ...(await importOriginal()), |
| 14 | usePreparedConnection: (() => Option.none()) as never, |
| 15 | })); |
| 16 | |
| 17 | vi.mock(import("~/state/use-atom-command"), async (importOriginal) => ({ |
| 18 | ...(await importOriginal()), |
| 19 | useAtomCommand: (() => async () => ({ _tag: "Success" })) as never, |
| 20 | })); |
| 21 | |
| 22 | import { render } from "../../../test/render"; |
| 23 | import type { EnvironmentPresentation } from "~/state/environments"; |
| 24 | import { EnvironmentRoutesList } from "./EnvironmentRoutesList"; |
| 25 | |
| 26 | const ENVIRONMENT_ID = EnvironmentId.make("environment-1"); |
| 27 | |
| 28 | function direct(id: string, httpBaseUrl: string): ConnectionRoute { |
| 29 | return { |
| 30 | target: new BearerConnectionTarget({ |
| 31 | environmentId: ENVIRONMENT_ID, |
| 32 | label: "Desk", |
| 33 | connectionId: id, |
| 34 | }), |
| 35 | profile: Option.some( |
| 36 | new BearerConnectionProfile({ |
| 37 | connectionId: id, |
| 38 | environmentId: ENVIRONMENT_ID, |
| 39 | label: "Desk", |
| 40 | httpBaseUrl, |
| 41 | wsBaseUrl: httpBaseUrl.replace(/^http/, "ws"), |
| 42 | }), |
| 43 | ), |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | const LAN = direct("lan", "http://192.168.1.10:3773/"); |
| 48 | const TAILNET = direct("tailnet", "https://desk.tail1234.ts.net/"); |
| 49 | const PUBLIC = direct("public", "https://desk.example.com/"); |
| 50 | |
| 51 | function routesList(routes: ReadonlyArray<ConnectionRoute>) { |
| 52 | const [first, ...rest] = routes; |
| 53 | const entry: ConnectionCatalogEntry = { |
| 54 | target: first!.target, |
| 55 | profile: first!.profile, |
| 56 | alternateRoutes: rest, |
| 57 | enabled: true, |
| 58 | }; |
| 59 | const environment: EnvironmentPresentation = { |
| 60 | environmentId: ENVIRONMENT_ID, |
| 61 | label: "Desk", |
| 62 | displayUrl: null, |
| 63 | relayManaged: false, |
| 64 | entry, |
| 65 | connection: { phase: "available", error: null, traceId: null }, |
| 66 | serverConfig: null, |
| 67 | refusedRouteIds: [], |
| 68 | }; |
| 69 | return <EnvironmentRoutesList environment={environment} onAddRoute={() => undefined} />; |
| 70 | } |
| 71 | |
| 72 | it("shows a route added after a reorder was saved, once another route is removed", async () => { |
| 73 | await using screen = await render(routesList([LAN, TAILNET])); |
| 74 | await userEvent.click(screen.getByRole("button", { name: "Reorder LAN, position 1" })); |
| 75 | await userEvent.keyboard(" "); |
| 76 | await userEvent.keyboard("{ArrowDown}"); |
| 77 | await userEvent.keyboard(" "); |
| 78 | await expect |
| 79 | .element(screen.getByRole("button", { name: "Reorder Tailscale HTTPS, position 1" })) |
| 80 | .toBeVisible(); |
| 81 | |
| 82 | await screen.rerender(routesList([TAILNET, LAN])); |
| 83 | await screen.rerender(routesList([TAILNET, LAN, PUBLIC])); |
| 84 | await screen.rerender(routesList([TAILNET, PUBLIC])); |
| 85 | |
| 86 | await expect |
| 87 | .element(screen.getByRole("button", { name: "Reorder desk.example.com, position 2" })) |
| 88 | .toBeVisible(); |
| 89 | expect(screen.getByRole("listitem").elements()).toHaveLength(2); |
| 90 | await expect |
| 91 | .element(screen.getByRole("button", { name: "Remove desk.example.com route" })) |
| 92 | .toBeVisible(); |
| 93 | }); |