import { describe, it, expect } from "vitest"; import { describeJob, etaLabel, timeAgo } from "./status"; describe("etaLabel", () => { it("formats seconds, minutes, and hours", () => { expect(etaLabel(45)).toBe("~45s left"); expect(etaLabel(240)).toBe("~4m left"); expect(etaLabel(3900)).toBe("~1h 5m left"); }); it("returns null for missing or non-positive input", () => { expect(etaLabel(null)).toBeNull(); expect(etaLabel(undefined)).toBeNull(); expect(etaLabel(0)).toBeNull(); expect(etaLabel(-5)).toBeNull(); }); }); describe("describeJob", () => { it("maps pipeline states to literal labels + severity kind", () => { expect(describeJob("requested", "intake")).toMatchObject({ label: "Queued", kind: "idle" }); expect(describeJob("matching", "match")).toMatchObject({ label: "Searching", kind: "working" }); expect(describeJob("matched", "match")).toMatchObject({ label: "Searching", kind: "working" }); expect(describeJob("downloading", "download")).toMatchObject({ label: "Downloading", kind: "working" }); expect(describeJob("tagging", "tag")).toMatchObject({ label: "Finishing", kind: "verify" }); expect(describeJob("imported", "import")).toMatchObject({ label: "Pressed", kind: "done" }); expect(describeJob("needs_attention", "download")).toMatchObject({ label: "Needs attention", kind: "attention" }); }); it("falls back gracefully for unknown states", () => { expect(describeJob("weird", "intake").kind).toBe("idle"); expect(describeJob("weird", "intake").label).toBe("Weird"); }); }); describe("timeAgo", () => { const now = new Date("2026-07-13T12:00:00Z").getTime(); it("returns 'just now' for deltas under 60s", () => { expect(timeAgo(new Date(now - 30_000).toISOString(), now)).toBe("just now"); }); it("returns minutes for sub-hour deltas", () => { expect(timeAgo(new Date(now - 5 * 60_000).toISOString(), now)).toBe("5m"); }); it("returns hours for sub-day deltas", () => { expect(timeAgo(new Date(now - 2 * 3600_000).toISOString(), now)).toBe("2h"); }); it("returns days for multi-day deltas", () => { expect(timeAgo(new Date(now - 3 * 86_400_000).toISOString(), now)).toBe("3d"); }); it("returns empty string for null/undefined/invalid input", () => { expect(timeAgo(null, now)).toBe(""); expect(timeAgo(undefined, now)).toBe(""); expect(timeAgo("not-a-date", now)).toBe(""); }); });