← Public packages
@kody/mailroom
Offline-first PWA for your Kody mailbox: sent and received threads, copy-prompt for agents, no send.
src/ui/inbox-refresh.node.test.ts
79 lines · 1.5 KB · TypeScriptimport assert from 'node:assert/strict'
import test from 'node:test'
import {
INBOX_POLL_INTERVAL_MS,
inboxHasNewMail,
shouldRefreshInbox,
} from './inbox-refresh.ts'
test('inbox refresh skips stacked focus events and hidden tabs', () => {
assert.equal(INBOX_POLL_INTERVAL_MS, 20_000)
assert.equal(
shouldRefreshInbox({
visible: true,
inFlight: false,
lastStartedAt: null,
now: 10_000,
}),
true,
)
assert.equal(
shouldRefreshInbox({
visible: false,
inFlight: false,
lastStartedAt: null,
now: 10_000,
}),
false,
)
assert.equal(
shouldRefreshInbox({
visible: true,
inFlight: false,
lastStartedAt: 10_000,
now: 11_000,
minIntervalMs: 3000,
}),
false,
)
assert.equal(
shouldRefreshInbox({
visible: true,
inFlight: false,
lastStartedAt: 10_000,
now: 14_000,
minIntervalMs: 3000,
}),
true,
)
})
test('new mail is a higher count or a newer latest sent timestamp', () => {
assert.equal(
inboxHasNewMail({
previousTotal: 19,
nextTotal: 20,
previousLatestSentAt: '2026-08-31T16:00:00.000Z',
nextLatestSentAt: '2026-08-31T16:05:00.000Z',
}),
true,
)
assert.equal(
inboxHasNewMail({
previousTotal: 19,
nextTotal: 19,
previousLatestSentAt: '2026-08-31T16:00:00.000Z',
nextLatestSentAt: '2026-08-31T16:00:00.000Z',
}),
false,
)
assert.equal(
inboxHasNewMail({
previousTotal: 19,
nextTotal: 19,
previousLatestSentAt: '2026-08-31T16:00:00.000Z',
nextLatestSentAt: '2026-08-31T16:01:00.000Z',
}),
true,
)
})