38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
daysFromToday,
|
|
dueLabel,
|
|
dueTone,
|
|
nextFriday,
|
|
untilMidnight,
|
|
} from "../src/lib/due";
|
|
|
|
describe("due helpers read the day they are given", () => {
|
|
it("labels against the given today, not the wall clock", () => {
|
|
expect(dueLabel("2026-08-23", "2026-08-23")).toBe("today");
|
|
expect(dueLabel("2026-08-24", "2026-08-23")).toBe("tomorrow");
|
|
expect(dueLabel("2026-08-22", "2026-08-23")).toBe("yesterday");
|
|
expect(dueLabel("2026-08-23", "2026-08-30")).toBe("Aug 23");
|
|
});
|
|
|
|
it("tones against the given today", () => {
|
|
expect(dueTone("2026-08-22", "2026-08-23")).toBe("overdue");
|
|
expect(dueTone("2026-08-24", "2026-08-23")).toBe("soon");
|
|
expect(dueTone("2026-09-24", "2026-08-23")).toBe("normal");
|
|
expect(daysFromToday("2026-09-02", "2026-08-23")).toBe(10);
|
|
});
|
|
|
|
it("finds the friday after the given day, never the same one", () => {
|
|
expect(nextFriday("2026-08-23")).toBe("2026-08-28");
|
|
expect(nextFriday("2026-08-28")).toBe("2026-09-04");
|
|
});
|
|
|
|
it("arms the midnight timer for the coming midnight", () => {
|
|
const late = new Date(2026, 7, 23, 23, 59, 0);
|
|
expect(untilMidnight(late)).toBeGreaterThan(60_000);
|
|
expect(untilMidnight(late)).toBeLessThan(62_000);
|
|
const early = new Date(2026, 7, 23, 0, 0, 1);
|
|
expect(untilMidnight(early)).toBeGreaterThan(23 * 3_600_000);
|
|
});
|
|
});
|