Files
minhtrannhatandClaude Opus 5.5 9fba5de6d7 Update the app while a timer runs
When a new service worker takes control, the app shows an UPDATE
button. If the page is hidden, the app reloads into the new version.
It does not reload while the entry editor is open or while a save or
import runs. A running timer continues after the reload, because it is
stored with its start time in IndexedDB.

The app asks for a new version when it becomes visible and one time
each hour, because an installed PWA can stay open for days.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-08 14:49:29 -05:00

27 lines
909 B
TypeScript

import { describe, expect, test } from "bun:test";
import { readyToReload } from "../src/client/update.ts";
const safe = { updateReady: true, hidden: true, editing: false, busy: false };
describe("app update reload", () => {
test("reloads a hidden page when an update is ready and nothing is open", () => {
expect(readyToReload(safe)).toBe(true);
});
test("does not reload without an update", () => {
expect(readyToReload({ ...safe, updateReady: false })).toBe(false);
});
test("does not reload while the user looks at the page", () => {
expect(readyToReload({ ...safe, hidden: false })).toBe(false);
});
test("does not reload while the entry editor is open", () => {
expect(readyToReload({ ...safe, editing: true })).toBe(false);
});
test("does not reload while a save or import runs", () => {
expect(readyToReload({ ...safe, busy: true })).toBe(false);
});
});