import assert from 'node:assert/strict' import { describe, it } from 'node:test' import { describeAvailableUpdate, shouldRunUpdateCheck } from './update-check.ts' describe('update check on open', () => { it('runs when the app becomes visible and nothing is in flight', () => { assert.equal( shouldRunUpdateCheck({ visible: true, inFlight: false, lastStartedAt: null, now: 10_000, }), true, ) assert.equal( shouldRunUpdateCheck({ visible: false, inFlight: false, lastStartedAt: null, now: 10_000, }), false, ) assert.equal( shouldRunUpdateCheck({ visible: true, inFlight: true, lastStartedAt: null, now: 10_000, }), false, ) }) it('collapses pageshow and visibilitychange that fire together', () => { assert.equal( shouldRunUpdateCheck({ visible: true, inFlight: false, lastStartedAt: 10_000, now: 11_000, minIntervalMs: 3000, }), false, ) assert.equal( shouldRunUpdateCheck({ visible: true, inFlight: false, lastStartedAt: 10_000, now: 14_000, minIntervalMs: 3000, }), true, ) }) it('toasts for a waiting worker or a newer published sha', () => { assert.equal( describeAvailableUpdate({ runningSha: 'aaa', latestSha: 'aaa', hasWaitingWorker: true, }), 'worker', ) assert.equal( describeAvailableUpdate({ runningSha: 'aaa1111', latestSha: 'bbb2222', hasWaitingWorker: false, }), 'published', ) assert.equal( describeAvailableUpdate({ runningSha: 'aaa1111', latestSha: 'aaa1111', hasWaitingWorker: false, }), null, ) }) })