| 1 | import assert from "node:assert/strict"; |
| 2 | import { readFileSync } from "node:fs"; |
| 3 | import { test } from "node:test"; |
| 4 | import { fileURLToPath } from "node:url"; |
| 5 | import { startupPresentation } from "./startupPresentation.js"; |
| 6 | |
| 7 | test("a healthy first boot stays hidden", () => { |
| 8 | assert.equal(startupPresentation({ serviceReady: false, hasWindow: false, lifecycle: "starting" }), "none"); |
| 9 | }); |
| 10 | |
| 11 | test("a second click while starting does not open the wait page", () => { |
| 12 | assert.equal(startupPresentation({ serviceReady: false, hasWindow: false, lifecycle: "starting" }), "none"); |
| 13 | }); |
| 14 | |
| 15 | test("a second click focuses an existing window instead of replacing it", () => { |
| 16 | assert.equal(startupPresentation({ serviceReady: false, hasWindow: true, lifecycle: "starting" }), "focus"); |
| 17 | assert.equal(startupPresentation({ serviceReady: true, hasWindow: true, lifecycle: "ready" }), "focus"); |
| 18 | }); |
| 19 | |
| 20 | test("a failed or timed-out startup still shows the recovery page", () => { |
| 21 | assert.equal(startupPresentation({ serviceReady: false, hasWindow: false, lifecycle: "failed" }), "diagnostic"); |
| 22 | assert.equal(startupPresentation({ serviceReady: false, hasWindow: true, lifecycle: "failed" }), "diagnostic"); |
| 23 | }); |
| 24 | |
| 25 | test("whenReady does not create or show a provisional diagnostic window", () => { |
| 26 | const source = readFileSync(fileURLToPath(new URL("./index.ts", import.meta.url)), "utf8"); |
| 27 | const end = source.indexOf("return service.start()"); |
| 28 | const start = source.lastIndexOf("void app.whenReady()", end); |
| 29 | assert.ok(start >= 0 && end > start, "index.ts must still start the service from whenReady"); |
| 30 | const boot = source.slice(start, end); |
| 31 | assert.equal(boot.includes("showFailure"), false, "first boot must not show the diagnostic wait page"); |
| 32 | assert.equal(boot.includes("mainWindow.create("), false, "first boot must not create a window just to flash a wait page"); |
| 33 | assert.equal(source.includes('status.lifecycle === "starting" ? startingPage'), false, "second clicks must not load the wait page while still starting"); |
| 34 | }); |
| 35 |