Skip to content
← Public packages

@kody/mailroom

Offline-first PWA for your Kody mailbox: sent and received threads, copy-prompt for agents, no send.

src/ui/update-check.node.test.ts

83 lines · 1.4 KB · TypeScript
import assert from 'node:assert/strict'
import test from 'node:test'
import {
	describeAvailableUpdate,
	shouldRunUpdateCheck,
} from './update-check.ts'

test('update check runs on focus and skips stacked pageshow plus visibilitychange', () => {
	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,
	)
	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,
	)
})

test('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,
	)
})