| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { mkdtemp, writeFile, readFile } from "node:fs/promises"; |
| 4 | import { tmpdir } from "node:os"; |
| 5 | import { join } from "node:path"; |
| 6 | import { AppZoomStore, normalizeAppZoom } from "./zoomStore.js"; |
| 7 | |
| 8 | test("normalizes app zoom and defaults safely", () => { |
| 9 | assert.equal(normalizeAppZoom(Number.NaN), 1); |
| 10 | assert.equal(normalizeAppZoom(0.71), 0.7); |
| 11 | assert.equal(normalizeAppZoom(3), 2); |
| 12 | }); |
| 13 | |
| 14 | test("migrates only explicitly user-owned legacy zoom", async () => { |
| 15 | const root = await mkdtemp(join(tmpdir(), "reasonix-zoom-")); |
| 16 | const legacy = join(root, "desktop-zoom.json"); |
| 17 | await writeFile(legacy, JSON.stringify({ zoomFactor: 0.7 })); |
| 18 | const store = new AppZoomStore(join(root, "electron-app-zoom.json"), legacy); |
| 19 | assert.equal((await store.load()).appZoomFactor, 1); |
| 20 | await writeFile(legacy, JSON.stringify({ zoomFactor: 0.7, source: "user" })); |
| 21 | const second = new AppZoomStore(join(root, "electron-app-zoom-2.json"), legacy); |
| 22 | assert.equal((await second.load()).appZoomFactor, 0.7); |
| 23 | }); |
| 24 | |
| 25 | test("persists user value and reset", async () => { |
| 26 | const root = await mkdtemp(join(tmpdir(), "reasonix-zoom-")); |
| 27 | const file = join(root, "nested", "zoom.json"); |
| 28 | const store = new AppZoomStore(file); |
| 29 | await store.set(0.85); |
| 30 | assert.equal((await store.load()).appZoomFactor, 0.85); |
| 31 | await store.reset(); |
| 32 | assert.deepEqual(JSON.parse(await readFile(file, "utf8")), { version: 1, appZoomFactor: 1, source: "user" }); |
| 33 | }); |
| 34 |