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

IntegrationsSettings.browser.test.tsx

147 lines5.0 KB

1import { PrimaryConnectionTarget } from "@t3tools/client-runtime/connection";
2import { EnvironmentId, ProjectId, ServerConfig } from "@t3tools/contracts";
3import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
4import * as Option from "effect/Option";
5import * as Schema from "effect/Schema";
6import { expect, it, vi } from "vite-plus/test";
7import { page, userEvent } from "vite-plus/test/browser";
8​
9import { render } from "../../../test/render";
10import { ensureClientSettingsHydrated, persistClientSettingsPatch } from "../../hooks/useSettings";
11import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping";
12import type { EnvironmentPresentation } from "../../state/environments";
13import type { Project } from "../../types";
14​
15const environmentId = EnvironmentId.make("browser-settings");
16const config = Schema.decodeSync(ServerConfig)({
17 environment: {
18 environmentId,
19 label: "Desk",
20 platform: { os: "linux", arch: "x64" },
21 serverVersion: "1.0.0",
22 orchestrationProtocolVersion: 2,
23 capabilities: {},
24 },
25 auth: {
26 policy: "loopback-browser",
27 bootstrapMethods: ["one-time-token"],
28 sessionMethods: ["browser-session-cookie"],
29 sessionCookieName: "t3_session",
30 },
31 cwd: "/workspace/browser",
32 keybindingsConfigPath: "/workspace/keybindings.json",
33 keybindings: [],
34 issues: [],
35 providers: [],
36 availableEditors: [],
37 observability: {
38 logsDirectoryPath: "/workspace/logs",
39 localTracingEnabled: false,
40 otlpTracesEnabled: false,
41 otlpMetricsEnabled: false,
42 },
43 settings: {},
44});
45const environments: EnvironmentPresentation[] = [
46 {
47 environmentId,
48 label: "Desk",
49 displayUrl: "http://localhost:12345",
50 relayManaged: false,
51 entry: {
52 target: new PrimaryConnectionTarget({
53 environmentId,
54 label: "Desk",
55 httpBaseUrl: "http://localhost:12345",
56 wsBaseUrl: "ws://localhost:12345/ws",
57 }),
58 profile: Option.none(),
59 enabled: true,
60 },
61 connection: { phase: "connected", error: null, traceId: null },
62 refusedRouteIds: [],
63 serverConfig: config,
64 },
65];
66const projects: Project[] = [
67 {
68 id: ProjectId.make("browser-project"),
69 environmentId,
70 title: "Browser project",
71 workspaceRoot: "/workspace/browser",
72 repositoryIdentity: null,
73 defaultModelSelection: null,
74 scripts: [],
75 createdAt: "2026-11-14T00:00:00.000Z",
76 updatedAt: "2026-11-14T00:00:00.000Z",
77 },
78];
79​
80// Profiles, link target and the advanced rows only work in the desktop app.
81vi.mock(import("../../env"), async (original) => ({ ...(await original()), isElectron: true }));
82vi.mock(import("../../state/environments"), async (original) => ({
83 ...(await original()),
84 useEnvironments: () => ({
85 isReady: true,
86 networkStatus: "online" as const,
87 environments,
88 presentationById: new Map(),
89 }),
90 usePrimaryEnvironmentId: () => environmentId,
91 usePrimaryEnvironment: () => environments[0]!,
92 readEnvironment: () => environments[0]!,
93}));
94vi.mock(import("../../state/session"), async (original) => ({
95 ...(await original()),
96 useEnvironmentScope: () => true,
97 useEnvironmentsWithScope: () => new Set([environmentId]),
98}));
99vi.mock(import("../../state/entities"), async (original) => ({
100 ...(await original()),
101 useProjects: () => projects,
102 useServerConfigs: () => new Map([[environmentId, config]]),
103}));
104​
105import { BrowserSettingsPanel } from "./IntegrationsSettings";
106import { SettingsScopeProvider } from "./SettingsScopeContext";
107​
108const [group] = buildSidebarProjectSnapshots({
109 projects,
110 settings: DEFAULT_CLIENT_SETTINGS,
111 primaryEnvironmentId: environmentId,
112 resolveEnvironmentLabel: () => "Desk",
113});
114const isInert = (element: Element) => element.closest("[inert]") !== null;
115​
116it.each([
117 { scope: "a project", search: { project: group!.projectKey } },
118 {
119 scope: "a checkout",
120 search: { project: group!.projectKey, checkout: group!.memberProjects[0]!.physicalProjectKey },
121 },
122])("shows device preferences read-only for $scope", async ({ search }) => {
123 await ensureClientSettingsHydrated();
124 await persistClientSettingsPatch(
125 { browserProfiles: [{ id: "work", name: "Work", kind: "persistent" }] },
126 async () => {},
127 );
128 await using screen = await render(
129 <SettingsScopeProvider search={search} onChange={() => {}}>
130 <BrowserSettingsPanel />
131 </SettingsScopeProvider>,
132 { router: "/settings/browser" },
133 );
134​
135 for (const name of ["Search engine", "Open links in"]) {
136 expect(isInert(screen.getByRole("combobox", { name }).element())).toBe(true);
137 }
138 expect(isInert(screen.getByRole("switch", { name: "Agent browser access" }).element())).toBe(
139 false,
140 );
141 // Profiles save for this device in every scope, but the default profile is a device preference.
142 await expect.element(screen.getByRole("button", { name: "Add profile" })).toBeEnabled();
143 await userEvent.click(screen.getByRole("button", { name: "Work options" }));
144 await expect
145 .element(page.getByRole("menuitem", { name: "Set as default" }))
146 .toHaveAttribute("aria-disabled", "true");
147});