Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
test(web): add getActiveCaptionText unit tests
Richie McIlroy1a936a285d23
diff --git a/apps/web/__tests__/unit/caption-cues.test.ts b/apps/web/__tests__/unit/caption-cues.test.tsnew file mode 100644index 000000000..daecbe46f--- /dev/null+++ b/apps/web/__tests__/unit/caption-cues.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it } from "vitest";+import { getActiveCaptionText } from "@/app/s/[videoId]/_components/caption-cues";++function createCueList(+ cues: { startTime: number; text: string }[],+): TextTrackCueList {+ return {+ length: cues.length,+ item: (index: number) => cues[index] ?? null,+ getCueById: () => null,+ } as unknown as TextTrackCueList;+}++describe("getActiveCaptionText", () => {+ it("returns an empty caption when no cue is active", () => {+ expect(getActiveCaptionText(null)).toBe("");+ expect(getActiveCaptionText(createCueList([]))).toBe("");+ });++ it("uses the latest active cue when cues overlap", () => {+ const activeCues = createCueList([+ { startTime: 0, text: "First caption" },+ { startTime: 3.199, text: "<v Speaker>Second caption</v>" },+ ]);++ expect(getActiveCaptionText(activeCues)).toBe("Second caption");+ });+});