| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { type DesktopSettingsView, KEPT, checkFailed, hostOf, sectionOf, settingsOf, updateLine } from "./desktop-settings.ts"; |
| 5 | |
| 6 | function view(over: Partial<DesktopSettingsView> = {}): DesktopSettingsView { |
| 7 | return { |
| 8 | startHidden: true, |
| 9 | closeToTray: true, |
| 10 | notifications: true, |
| 11 | flash: true, |
| 12 | badge: true, |
| 13 | systemTitleBar: false, |
| 14 | zoom: 1.1, |
| 15 | developerTools: false, |
| 16 | autoUpdate: true, |
| 17 | runner: true, |
| 18 | runnerBackend: "sandboxed", |
| 19 | runnerWorkspace: "acme", |
| 20 | runnerCapabilities: { linux: true, windows: false, macos: true }, |
| 21 | openAtLogin: true, |
| 22 | version: "0.3.6", |
| 23 | platform: "windows", |
| 24 | server: "https://g1t.sh/", |
| 25 | updateReady: null, |
| 26 | checkedAt: null, |
| 27 | titleBarChanged: false, |
| 28 | customFrame: true, |
| 29 | developerToolsChanged: false, |
| 30 | runnerView: {} as DesktopSettingsView["runnerView"], |
| 31 | ...over, |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | test("a change is saved over the settings as the app has them, and nothing else", () => { |
| 36 | // The zoom changed from the menu while the dialog was open: turning the badge off keeps it. |
| 37 | const saved = settingsOf(view({ zoom: 1.5 }), { badge: false }); |
| 38 | assert.equal(saved.badge, false); |
| 39 | assert.equal(saved.zoom, 1.5); |
| 40 | assert.deepEqual(saved.runnerCapabilities, { linux: true, windows: false, macos: true }); |
| 41 | // Only what the app keeps goes back: not what it only shows. |
| 42 | assert.deepEqual(Object.keys(saved).sort(), [...KEPT].sort()); |
| 43 | }); |
| 44 | |
| 45 | test("the app opens the section it names, or the first", () => { |
| 46 | assert.equal(sectionOf("updates"), "updates"); |
| 47 | assert.equal(sectionOf("runner"), "runner"); |
| 48 | assert.equal(sectionOf("plan9"), "general"); |
| 49 | assert.equal(sectionOf(null), "general"); |
| 50 | }); |
| 51 | |
| 52 | test("updates say where this copy stands", () => { |
| 53 | assert.match(updateLine(view({ updateReady: "0.3.7" })), /^Version 0\.3\.7 is downloaded/); |
| 54 | assert.match(updateLine(view({ checkedAt: Date.now() })), /^Up to date\. Last checked today at /); |
| 55 | assert.match(updateLine(view()), /checks on its own shortly/); |
| 56 | assert.equal(updateLine(view({ autoUpdate: false })), "Checking on its own is off."); |
| 57 | }); |
| 58 | |
| 59 | test("a failed check says why in a line", () => { |
| 60 | assert.match(checkFailed("error sending request for url"), /Could not reach g1t\.sh/); |
| 61 | assert.match(checkFailed(new Error("")), /Could not reach g1t\.sh/); |
| 62 | assert.equal(checkFailed("the signature is wrong"), "Could not check: the signature is wrong"); |
| 63 | assert.equal(hostOf("https://g1t.example.com/"), "g1t.example.com"); |
| 64 | }); |