import { describe, expect, test } from "bun:test"; import { parseVideoPath, scrubFrameAt, type ScrubManifest } from "./video"; describe("parseVideoPath", () => { test("accepts the prepared layout", () => { for (const asset of [ "master.m3u8", "poster.jpg", "720/index.m3u8", "720/init.mp4", "720/00012.m4s", "scrub/manifest.json", "scrub/sheet-003.webp", ]) { expect(parseVideoPath(`/videos/intro/v1/${asset}`)).toEqual({ id: "intro", version: "v1", asset }); } }); test("refuses anything else", () => { for (const path of [ "/videos/intro/v1/", "/videos/intro/v1/../x", "/videos/Intro/v1/master.m3u8", "/videos/intro/v1/prepared.json", "/videos/intro/master.m3u8", "/other", ]) { expect(parseVideoPath(path)).toBeNull(); } }); }); describe("scrubFrameAt", () => { const manifest: ScrubManifest = { interval: 2, count: 150, frameWidth: 256, frameHeight: 144, columns: 10, rows: 10, sheets: ["scrub/sheet-000.webp", "scrub/sheet-001.webp"], }; test("maps time to tile", () => { expect(scrubFrameAt(manifest, 0)).toEqual({ sheet: "scrub/sheet-000.webp", x: 0, y: 0 }); expect(scrubFrameAt(manifest, 26)).toEqual({ sheet: "scrub/sheet-000.webp", x: 768, y: 144 }); expect(scrubFrameAt(manifest, 210)).toEqual({ sheet: "scrub/sheet-001.webp", x: 1280, y: 0 }); }); test("clamps past the end", () => { expect(scrubFrameAt(manifest, 10_000)).toEqual({ sheet: "scrub/sheet-001.webp", x: 2304, y: 576 }); expect(scrubFrameAt(manifest, -5).x).toBe(0); }); });