36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const electronState = vi.hoisted(() => ({ userData: "" }));
|
|
vi.mock("electron", () => ({
|
|
app: {
|
|
getPath: () => electronState.userData
|
|
}
|
|
}));
|
|
|
|
import { loadSettings, updateSettings } from "./settings";
|
|
|
|
describe("app settings", () => {
|
|
beforeEach(async () => {
|
|
electronState.userData = await mkdtemp(path.join(os.tmpdir(), "rpa-settings-"));
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await rm(electronState.userData, { recursive: true, force: true });
|
|
});
|
|
|
|
it("returns the default element wait when no settings file exists", () => {
|
|
expect(loadSettings()).toEqual({ browserElementWaitMs: 5000, aiConfig: { baseUrl: "", apiKey: "", model: "" } });
|
|
});
|
|
|
|
it("persists and clamps a user-adjustable element wait", async () => {
|
|
const saved = updateSettings({ browserElementWaitMs: 12500 });
|
|
expect(saved).toEqual({ browserElementWaitMs: 12500, aiConfig: { baseUrl: "", apiKey: "", model: "" } });
|
|
expect(JSON.parse(await readFile(path.join(electronState.userData, "settings.json"), "utf8"))).toEqual(saved);
|
|
expect(updateSettings({ browserElementWaitMs: -5 })).toEqual({ browserElementWaitMs: 0, aiConfig: { baseUrl: "", apiKey: "", model: "" } });
|
|
expect(loadSettings()).toEqual({ browserElementWaitMs: 0, aiConfig: { baseUrl: "", apiKey: "", model: "" } });
|
|
});
|
|
});
|