import { test } from "node:test"; import assert from "node:assert/strict"; import { msUntilTextChanges } from "../src/ui/relative-time/next-change.ts"; test("an age under a minute changes every second", () => { assert.equal(msUntilTextChanges(0, false), 1000); assert.equal(msUntilTextChanges(2500, false), 500); }); test("an age in minutes changes at the next minute", () => { assert.equal(msUntilTextChanges(60_000, false), 60_000); assert.equal(msUntilTextChanges(90_000, false), 30_000); }); test("an age in hours changes at the next hour", () => { assert.equal(msUntilTextChanges(3_600_000 + 1_000, false), 3_599_000); }); test("an age in days changes at the next day", () => { assert.equal(msUntilTextChanges(86_400_000, false), 86_400_000); }); test("a countdown drops a step when the time left falls below it", () => { // 5m 30s left reads "in 5m" until 5m, then "in 4m". assert.equal(msUntilTextChanges(-330_000, true), 30_001); // 20.5s left reads "in 20s" until 20s. assert.equal(msUntilTextChanges(-20_500, true), 501); }); test("a clock ahead of an age waits for it to catch up", () => { assert.equal(msUntilTextChanges(-4000, false), 5000); }); test("the wait never goes under the floor", () => { assert.equal(msUntilTextChanges(999_990, false) >= 50, true); assert.equal(msUntilTextChanges(-10, true) >= 50, true); });