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

SettingsPanels.logic.test.ts

90 lines2.9 KB

1import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts";
2import * as Duration from "effect/Duration";
3import { describe, expect, it } from "vite-plus/test";
4import {
5 backgroundActivitySharedPolicySettings,
6 getChangedBrowserSettingLabels,
7 hasChangedBackgroundActivitySettings,
8} from "./SettingsPanels.logic";
9​
10describe("background activity settings restore", () => {
11 it("detects legacy interval values even when the structured setting is at its default", () => {
12 expect(
13 hasChangedBackgroundActivitySettings({
14 backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
15 backgroundActivityProfile: DEFAULT_UNIFIED_SETTINGS.backgroundActivityProfile,
16 automaticGitFetchInterval: Duration.seconds(45),
17 providerHealthRefreshInterval: DEFAULT_UNIFIED_SETTINGS.providerHealthRefreshInterval,
18 }),
19 ).toBe(true);
20 expect(
21 hasChangedBackgroundActivitySettings({
22 backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
23 backgroundActivityProfile: DEFAULT_UNIFIED_SETTINGS.backgroundActivityProfile,
24 automaticGitFetchInterval: DEFAULT_UNIFIED_SETTINGS.automaticGitFetchInterval,
25 providerHealthRefreshInterval: Duration.minutes(7),
26 }),
27 ).toBe(true);
28 expect(hasChangedBackgroundActivitySettings(DEFAULT_UNIFIED_SETTINGS)).toBe(false);
29 });
30​
31 it("preserves advanced overrides when the shared policy changes", () => {
32 const automaticGitFetchInterval = Duration.seconds(42);
33 expect(
34 backgroundActivitySharedPolicySettings(
35 {
36 ...DEFAULT_UNIFIED_SETTINGS,
37 backgroundActivity: {
38 schemaVersion: 1,
39 profile: "custom",
40 baseProfile: "balanced",
41 overrides: {
42 automaticGitFetchInterval,
43 pauseWhenOnBattery: true,
44 },
45 },
46 },
47 "performance",
48 ),
49 ).toEqual({
50 schemaVersion: 1,
51 profile: "custom",
52 baseProfile: "performance",
53 overrides: {
54 automaticGitFetchInterval,
55 pauseWhenOnBattery: true,
56 },
57 });
58 });
59​
60 it("materializes legacy advanced overrides before changing the shared policy", () => {
61 const automaticGitFetchInterval = Duration.seconds(42);
62 expect(
63 backgroundActivitySharedPolicySettings(
64 {
65 ...DEFAULT_UNIFIED_SETTINGS,
66 automaticGitFetchInterval,
67 },
68 "battery-saver",
69 ),
70 ).toEqual({
71 schemaVersion: 1,
72 profile: "custom",
73 baseProfile: "battery-saver",
74 overrides: {
75 automaticGitFetchInterval,
76 },
77 });
78 });
79});
80​
81describe("getChangedBrowserSettingLabels", () => {
82 it("counts a retained custom search URL so restore clears it", () => {
83 expect(
84 getChangedBrowserSettingLabels({
85 ...DEFAULT_UNIFIED_SETTINGS,
86 browserCustomSearchUrl: "https://search.example/?q=%s",
87 }),
88 ).toEqual(["Search engine"]);
89 });
90});