1import type { EnvironmentId } from "@t3tools/contracts";
2import type { RelayClientEnvironmentRecord } from "@t3tools/contracts/relay";
3import { renderToStaticMarkup } from "react-dom/server";
4import { describe, expect, it, vi } from "vite-plus/test";
5
6import { T3ConnectEnvironmentRow } from "./T3ConnectUserProfilePage";
7
8const environment: RelayClientEnvironmentRecord = {
9 environmentId: "environment-1" as EnvironmentId,
10 label: "Studio Mac",
11 endpoint: {
12 httpBaseUrl: "https://studio.example.com",
13 wsBaseUrl: "wss://studio.example.com",
14 providerKind: "cloudflare_tunnel",
15 },
16 linkedAt: "2026-08-12T12:00:00.000Z",
17};
18
19function renderRow({
20 confirmationOpen = false,
21 mutationPending = false,
22}: {
23 readonly confirmationOpen?: boolean;
24 readonly mutationPending?: boolean;
25} = {}) {
26 return renderToStaticMarkup(
27 <T3ConnectEnvironmentRow
28 environment={environment}
29 confirmationOpen={confirmationOpen}
30 mutationPending={mutationPending}
31 onConfirmationChange={vi.fn()}
32 onDeregister={vi.fn()}
33 />,
34 );
35}
36
37describe("T3 Connect environment row", () => {
38 it("keeps deregistration confirmation inline and collapsed by default", () => {
39 const markup = renderRow();
40
41 expect(markup).toContain("Studio Mac");
42 expect(markup).toContain("Deregister");
43 expect(markup).not.toContain("Deregister server");
44 expect(markup).not.toContain("Confirm deregistration of Studio Mac");
45 });
46
47 it("expands Clerk-style confirmation content beneath the environment row", () => {
48 const markup = renderRow({ confirmationOpen: true });
49
50 expect(markup).toContain("Deregister server");
51 expect(markup).toContain("“Studio Mac” will be removed from this account.");
52 expect(markup).toContain("Confirm deregistration of Studio Mac");
53 expect(markup).toContain("Local connections on your devices are not changed.");
54 expect(markup).toContain("Cancel");
55 });
56
57 it("locks the confirmation actions while deregistration is pending", () => {
58 const markup = renderRow({ confirmationOpen: true, mutationPending: true });
59
60 expect(markup).toContain("Deregistering…");
61 expect(markup.match(/ disabled=""/g)).toHaveLength(3);
62 });
63});