From 76cee8ce21db486e756e0980610ace7a2d8e9d86 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Wed, 24 Jun 2026 16:08:03 +0200 Subject: [PATCH] test: add vtt parser tests for invalid timestamps, cue settings and multiline cues --- static/player/subtitles/vtt.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/static/player/subtitles/vtt.test.ts b/static/player/subtitles/vtt.test.ts index 388242e..b81b1b1 100644 --- a/static/player/subtitles/vtt.test.ts +++ b/static/player/subtitles/vtt.test.ts @@ -28,4 +28,31 @@ World { start: 2, end: 3, text: "World" }, ]); }); + + test("returns zero for invalid timestamps", () => { + assert.equal(parseVttTime(""), 0); + assert.equal(parseVttTime("not a timestamp"), 0); + assert.equal(parseVttTime("00:bad"), 0); + }); + + test("ignores cue settings and strips html tags", () => { + const cues = parseVtt(`WEBVTT + +00:10.000 --> 00:12.000 align:start position:0% +Bold & plain +`); + + assert.deepEqual(cues, [{ start: 10, end: 12, text: "Bold & plain" }]); + }); + + test("joins multiline cue text", () => { + const cues = parseVtt(`WEBVTT + +00:00.000 --> 00:03.000 +First line +Second line +`); + + assert.deepEqual(cues, [{ start: 0, end: 3, text: "First line\nSecond line" }]); + }); });