|
| 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 | + }; |
| 68 | + return <EnvironmentRoutesList environment={environment} onAddRoute={() => undefined} />; |
| 69 | +} |
| 70 | + |
| 71 | +it("shows a route added after a reorder was saved, once another route is removed", async () => { |
| 72 | + await using screen = await render(routesList([LAN, TAILNET])); |
| 73 | + await userEvent.click(screen.getByRole("button", { name: "Reorder LAN, position 1" })); |
| 74 | + await userEvent.keyboard(" "); |
| 75 | + await userEvent.keyboard("{ArrowDown}"); |
| 76 | + await userEvent.keyboard(" "); |
| 77 | + await expect |
| 78 | + .element(screen.getByRole("button", { name: "Reorder Tailscale, position 1" })) |
| 79 | + .toBeVisible(); |
| 80 | + |
| 81 | + await screen.rerender(routesList([TAILNET, LAN])); |
| 82 | + await screen.rerender(routesList([TAILNET, LAN, PUBLIC])); |
| 83 | + await screen.rerender(routesList([TAILNET, PUBLIC])); |
| 84 | + |
| 85 | + await expect |
| 86 | + .element(screen.getByRole("button", { name: "Reorder desk.example.com, position 2" })) |
| 87 | + .toBeVisible(); |
| 88 | + expect(screen.getByRole("listitem").elements()).toHaveLength(2); |
| 89 | + await expect |
| 90 | + .element(screen.getByRole("button", { name: "Remove desk.example.com route" })) |
| 91 | + .toBeVisible(); |
| 92 | +}); |
0 commit comments