import { describe, it, expect } from "vitest"; import { describeProgress } from "./downloadProgress"; const base = { status: "downloading" as const, progress: 0, bytesDownloaded: 0, fileSize: undefined as number | undefined, fileSizeEstimated: false, }; // TRACES: UR-071 | DR-290 | UT-254 describe("describeProgress", () => { it("shows an indeterminate bar, not 0%, when the size is unknown", () => { // A transcode has no Content-Length and (before the estimate) no total: // 200 MB in, the bar read "0%". That is not progress information. const view = describeProgress({ ...base, bytesDownloaded: 200 * 1024 * 1024 }); expect(view.kind).toBe("indeterminate"); expect(view.percent).toBeNull(); expect(view.label).toBe("200.0 MB"); }); it("marks an estimated total as approximate", () => { const view = describeProgress({ ...base, progress: 0.42, bytesDownloaded: 420, fileSize: 1000, fileSizeEstimated: true, }); expect(view.kind).toBe("estimated"); expect(view.percent).toBe(42); expect(view.percentLabel).toBe("~42%"); expect(view.label).toBe("420 B / ~1000 B"); }); it("reports an exact total plainly", () => { const view = describeProgress({ ...base, progress: 0.5, bytesDownloaded: 512, fileSize: 1024, }); expect(view.kind).toBe("exact"); expect(view.percent).toBe(50); expect(view.percentLabel).toBe("50%"); expect(view.label).toBe("512 B / 1.0 KB"); }); it("keeps a paused download's bar where it stopped", () => { const view = describeProgress({ ...base, status: "paused", progress: 0.25, bytesDownloaded: 256, fileSize: 1024, }); expect(view.kind).toBe("exact"); expect(view.percent).toBe(25); }); });