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

IntegrationsSettings.browser.test.tsx

146 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 serverConfig: config,
63 },
64];
65const projects: Project[] = [
66 {
67 id: ProjectId.make("browser-project"),
68 environmentId,
69 title: "Browser project",
70 workspaceRoot: "/workspace/browser",
71 repositoryIdentity: null,
72 defaultModelSelection: null,
73 scripts: [],
74 createdAt: "2026-11-14T00:00:00.000Z",
75 updatedAt: "2026-11-14T00:00:00.000Z",
76 },
77];
78​
79// Profiles, link target and the advanced rows only work in the desktop app.
80vi.mock(import("../../env"), async (original) => ({ ...(await original()), isElectron: true }));
81vi.mock(import("../../state/environments"), async (original) => ({
82 ...(await original()),
83 useEnvironments: () => ({
84 isReady: true,
85 networkStatus: "online" as const,
86 environments,
87 presentationById: new Map(),
88 }),
89 usePrimaryEnvironmentId: () => environmentId,
90 usePrimaryEnvironment: () => environments[0]!,
91 readEnvironment: () => environments[0]!,
92}));
93vi.mock(import("../../state/session"), async (original) => ({
94 ...(await original()),
95 useEnvironmentScope: () => true,
96 useEnvironmentsWithScope: () => new Set([environmentId]),
97}));
98vi.mock(import("../../state/entities"), async (original) => ({
99 ...(await original()),
100 useProjects: () => projects,
101 useServerConfigs: () => new Map([[environmentId, config]]),
102}));
103​
104import { BrowserSettingsPanel } from "./IntegrationsSettings";
105import { SettingsScopeProvider } from "./SettingsScopeContext";
106​
107const [group] = buildSidebarProjectSnapshots({
108 projects,
109 settings: DEFAULT_CLIENT_SETTINGS,
110 primaryEnvironmentId: environmentId,
111 resolveEnvironmentLabel: () => "Desk",
112});
113const isInert = (element: Element) => element.closest("[inert]") !== null;
114​
115it.each([
116 { scope: "a project", search: { project: group!.projectKey } },
117 {
118 scope: "a checkout",
119 search: { project: group!.projectKey, checkout: group!.memberProjects[0]!.physicalProjectKey },
120 },
121])("shows device preferences read-only for $scope", async ({ search }) => {
122 await ensureClientSettingsHydrated();
123 await persistClientSettingsPatch(
124 { browserProfiles: [{ id: "work", name: "Work", kind: "persistent" }] },
125 async () => {},
126 );
127 await using screen = await render(
128 <SettingsScopeProvider search={search} onChange={() => {}}>
129 <BrowserSettingsPanel />
130 </SettingsScopeProvider>,
131 { router: "/settings/browser" },
132 );
133​
134 for (const name of ["Search engine", "Open links in"]) {
135 expect(isInert(screen.getByRole("combobox", { name }).element())).toBe(true);
136 }
137 expect(isInert(screen.getByRole("switch", { name: "Agent browser access" }).element())).toBe(
138 false,
139 );
140 // Profiles save for this device in every scope, but the default profile is a device preference.
141 await expect.element(screen.getByRole("button", { name: "Add profile" })).toBeEnabled();
142 await userEvent.click(screen.getByRole("button", { name: "Work options" }));
143 await expect
144 .element(page.getByRole("menuitem", { name: "Set as default" }))
145 .toHaveAttribute("aria-disabled", "true");
146});