import { test } from "node:test"; import assert from "node:assert/strict"; import { matchesVideoQuery, type VideoRow } from "./videoRows"; // The one predicate behind BOTH the list's search box (VideoListPane) and the // server's `?q=` ordering for the detail pane's prev/next (videos/page.tsx). function row(id: string, title?: string): VideoRow { return { id, ...(title ? { title } : {}), downloaded: false, transcribed: false, untranscribable: false, partial: false, corruptSource: false, corruptFullSource: false, failedTranscription: false, wrongFormatAudio: false, excluded: false, incompleteTranscript: false, digestWarnings: false, shortAudio: false, running: false, status: "not_downloaded", }; } test("matches the id, case-insensitively", () => { assert.equal(matchesVideoQuery(row("AbC123xyz"), "abc123"), true); assert.equal(matchesVideoQuery(row("AbC123xyz"), " XYZ "), true); assert.equal(matchesVideoQuery(row("AbC123xyz"), "nope"), false); }); test("matches the title, case-insensitively", () => { const r = row("vid00000001", "Moonlit Harbor Interview"); assert.equal(matchesVideoQuery(r, "harbor"), true); assert.equal(matchesVideoQuery(r, "HARBOR interview"), true); assert.equal(matchesVideoQuery(r, "vid0000"), true); assert.equal(matchesVideoQuery(r, "sunrise"), false); }); test("a row with no title matches on the id only; a blank query matches all", () => { assert.equal(matchesVideoQuery(row("vid1"), "harbor"), false); assert.equal(matchesVideoQuery(row("vid1"), ""), true); assert.equal(matchesVideoQuery(row("vid1", "Anything"), " "), true); });