feat: 支持配置全局网页元素等待
This commit is contained in:
1 parent
5e9f0df57f
commit
bec3d9daa4
8 files changed
+210
-12
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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 });
|
||||
});
|
||||
|
||||
it("persists and clamps a user-adjustable element wait", async () => {
|
||||
const saved = updateSettings({ browserElementWaitMs: 12500 });
|
||||
expect(saved).toEqual({ browserElementWaitMs: 12500 });
|
||||
expect(JSON.parse(await readFile(path.join(electronState.userData, "settings.json"), "utf8"))).toEqual(saved);
|
||||
expect(updateSettings({ browserElementWaitMs: -5 })).toEqual({ browserElementWaitMs: 0 });
|
||||
expect(loadSettings()).toEqual({ browserElementWaitMs: 0 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user