Open History to see the last commit
1import {
2 DEFAULT_CLIENT_SETTINGS,
3 DEFAULT_UNIFIED_SETTINGS,
4 type DeviceServiceState,
5} from "@t3tools/contracts";
6import {
7 createMemoryHistory,
8 createRootRoute,
9 createRouter,
10 RouterProvider,
11} from "@tanstack/react-router";
12import { act, StrictMode, type ReactNode } from "react";
13import { create, type ReactTestRenderer } from "react-test-renderer";
14import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
15
16const { listBrowserImportSources } = vi.hoisted(() => ({
17 listBrowserImportSources: vi.fn().mockResolvedValue([]),
18}));
19
20vi.mock("../preview/previewBridge", () => ({
21 previewBridge: { listBrowserImportSources },
22}));
23vi.mock("../../env", () => ({ isElectron: true }));
24vi.mock("../../state/environments", () => ({
25 useEnvironments: () => ({ environments: [], isReady: true }),
26 usePrimaryEnvironment: () => null,
27}));
28vi.mock("../../hooks/useSettings", () => ({
29 PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE: "Connect to an environment",
30 useClientSettings: (selector: (settings: typeof DEFAULT_CLIENT_SETTINGS) => unknown) =>
31 selector(DEFAULT_CLIENT_SETTINGS),
32 useClientSettingsHydrated: () => true,
33 usePrimarySettingsAvailable: () => true,
34 usePrimarySettings: () => DEFAULT_UNIFIED_SETTINGS,
35 useUpdatePrimarySettings: () => vi.fn(),
36}));
37vi.mock("./settingsLayout", async (importOriginal) => ({
38 ...(await importOriginal<typeof import("./settingsLayout")>()),
39 SettingsPageContainer: ({ children }: { children: ReactNode }) => children,
40}));
41// The scoped agent-access rows need the settings layout's scope provider;
42// this test covers the device-local browser sections only.
43vi.mock("./ProjectDefaultsSettings", () => ({ ProjectDefaultsSettings: () => null }));
44vi.mock("./SettingsScopeContext", () => ({
45 useSettingsScope: () => ({
46 scope: { kind: "all", environmentIds: [] },
47 environment: null,
48 connectedEnvironments: [],
49 targets: [],
50 }),
51 useOptionalSettingsScope: () => null,
52}));
53
54import { IntegrationsSettingsPanel } from "./IntegrationsSettings";
55import { platformSetupStatus } from "../device/DeviceSetup";
56
57let renderer: ReactTestRenderer | undefined;
58
59beforeEach(() => {
60 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
61 listBrowserImportSources.mockClear();
62});
63
64afterEach(async () => {
65 await act(() => renderer?.unmount());
66 vi.unstubAllGlobals();
67});
68
69async function openSettings() {
70 const router = createRouter({
71 routeTree: createRootRoute({ component: IntegrationsSettingsPanel }),
72 history: createMemoryHistory(),
73 });
74 await router.load();
75 await act(() => {
76 renderer = create(
77 <StrictMode>
78 <RouterProvider router={router} />
79 </StrictMode>,
80 );
81 });
82 expect(renderer!.root.findByType(IntegrationsSettingsPanel)).toBeDefined();
83}
84
85describe("Integrations browser discovery", () => {
86 it("does not scan browser files when entering or revisiting settings", async () => {
87 await openSettings();
88 expect(listBrowserImportSources).not.toHaveBeenCalled();
89
90 await act(() => renderer?.unmount());
91 await openSettings();
92 expect(listBrowserImportSources).not.toHaveBeenCalled();
93 });
94
95 it("places device settings directly after browser settings", async () => {
96 await openSettings();
97 const sections = renderer!.root
98 .findAll((node) => node.type === "section")
99 .map((node) => node.props.id)
100 .filter(Boolean);
101 expect(sections.indexOf("devices")).toBeGreaterThan(sections.indexOf("browser"));
102 });
103});
104
105const deviceState = (overrides: Partial<DeviceServiceState> = {}): DeviceServiceState => ({
106 hosts: [
107 {
108 id: "local",
109 kind: "local",
110 label: "This machine",
111 hubInstalled: false,
112 agentDeviceInstalled: false,
113 platforms: [
114 { platform: "ios", available: true },
115 { platform: "android", available: true },
116 ],
117 },
118 ],
119 hostStatus: "ready",
120 hostStatuses: {},
121 devices: [],
122 sessions: [],
123 onboardingCompleted: false,
124 agentAccessEnabled: false,
125 hubBasePath: "/api/device-hub",
126 revision: 0,
127 ...overrides,
128});
129
130describe("device setup guidance", () => {
131 it("directs users to install an iOS runtime and create an Android virtual device", () => {
132 expect(platformSetupStatus(deviceState(), "ios").message).toContain("Xcode Settings");
133 expect(platformSetupStatus(deviceState(), "android").message).toContain("Device Manager");
134 });
135
136 it("preserves a specific missing-tool explanation from the server", () => {
137 const state = deviceState({
138 hosts: [
139 {
140 ...deviceState().hosts[0]!,
141 platforms: [
142 { platform: "ios", available: true },
143 { platform: "android", available: false, reason: "Android Emulator is missing." },
144 ],
145 },
146 ],
147 });
148 expect(platformSetupStatus(state, "android").message).toBe("Android Emulator is missing.");
149 });
150});