Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import { DEFAULT_BROWSER_PROFILE_ID, INCOGNITO_BROWSER_PROFILE_ID } from "@t3tools/contracts";
3
4const settings = vi.hoisted(() => ({ current: {} as Record<string, unknown> }));
5
6vi.mock("~/hooks/useSettings", () => ({
7 getClientSettings: () => settings.current,
8 useClientSettings: () => undefined,
9 ensureClientSettingsHydrated: () => Promise.resolve(),
10}));
11
12const { getBrowserDefaults } = await import("./browserDefaults");
13
14const withDefaultProfile = (browserDefaultProfileId: string) => {
15 settings.current = {
16 browserDefaultViewport: { _tag: "fill" },
17 browserDefaultZoomFactor: 1,
18 browserDefaultAppearance: "system",
19 browserAutoShowFloatingPreview: true,
20 browserProfiles: [{ id: "work", name: "Work", kind: "persistent" }],
21 browserDefaultProfileId,
22 };
23 return getBrowserDefaults();
24};
25
26describe("getBrowserDefaults profile resolution", () => {
27 it("keeps a configured persistent profile", () => {
28 expect(withDefaultProfile("work").profileId).toBe("work");
29 });
30
31 it("falls back for an unknown profile", () => {
32 expect(withDefaultProfile("deleted").profileId).toBe(DEFAULT_BROWSER_PROFILE_ID);
33 });
34
35 it("refuses incognito as the default", () => {
36 // A stored incognito default would open every new tab into storage that is
37 // discarded on close, and the settings list no longer offers it — so the
38 // row badged "Default" must be the one tabs actually open under.
39 expect(withDefaultProfile(INCOGNITO_BROWSER_PROFILE_ID).profileId).toBe(
40 DEFAULT_BROWSER_PROFILE_ID,
41 );
42 });
43});