/** * Unit tests for the pure admission-queue formatting helpers (js/queue.js). * Covers the exact wording required by docs/QUEUE_SPECIFICATION.md §7.2 and §7.3. */ import { test, describe } from 'node:test'; import assert from 'node:assert/strict'; import { ordinal, formatEta, formatQueuedStatus, formatExitQueueLabel } from '../js/queue.js'; describe('ordinal', () => { test('handles 1st, 2nd, 3rd, 4th', () => { assert.equal(ordinal(1), '1st'); assert.equal(ordinal(2), '2nd'); assert.equal(ordinal(3), '3rd'); assert.equal(ordinal(4), '4th'); }); test('handles the 11th-13th exception to the last-digit rule', () => { assert.equal(ordinal(11), '11th'); assert.equal(ordinal(12), '12th'); assert.equal(ordinal(13), '13th'); }); test('handles 21st, 22nd, 23rd and higher tens', () => { assert.equal(ordinal(21), '21st'); assert.equal(ordinal(22), '22nd'); assert.equal(ordinal(23), '23rd'); assert.equal(ordinal(101), '101st'); assert.equal(ordinal(111), '111th'); }); }); describe('formatEta', () => { test('null or undefined reads as "estimating…"', () => { assert.equal(formatEta(null), 'estimating…'); assert.equal(formatEta(undefined), 'estimating…'); }); test('below 60s reads as "under a minute"', () => { assert.equal(formatEta(0), 'under a minute'); assert.equal(formatEta(59), 'under a minute'); }); test('60s and above rounds up to "about N min"', () => { assert.equal(formatEta(60), 'about 1 min'); assert.equal(formatEta(61), 'about 2 min'); assert.equal(formatEta(150), 'about 3 min'); assert.equal(formatEta(120), 'about 2 min'); }); }); describe('formatQueuedStatus', () => { test('position 1 reads as "You\'re next"', () => { assert.equal(formatQueuedStatus({ position: 1, eta_seconds: 40 }), "You're next · under a minute"); }); test('position > 1 uses the ordinal', () => { assert.equal(formatQueuedStatus({ position: 3, eta_seconds: 220 }), "You're 3rd in line · about 4 min"); }); test('null estimate reads as "estimating…"', () => { assert.equal(formatQueuedStatus({ position: 3, eta_seconds: null }), "You're 3rd in line · estimating…"); }); }); describe('formatExitQueueLabel', () => { test('under 1 minute waited', () => { assert.equal(formatExitQueueLabel(0), 'I will try next time'); assert.equal(formatExitQueueLabel(59_000), 'I will try next time'); }); test('1-3 minutes waited (inclusive)', () => { assert.equal(formatExitQueueLabel(60_000), "Ohhh, it's so long"); assert.equal(formatExitQueueLabel(90_000), "Ohhh, it's so long"); assert.equal(formatExitQueueLabel(180_000), "Ohhh, it's so long"); }); test('over 3 minutes waited', () => { assert.equal(formatExitQueueLabel(180_001), "I'm dying in this queue"); assert.equal(formatExitQueueLabel(600_000), "I'm dying in this queue"); }); });