summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2023-10-07 19:53:29 +0200
committerSamantaz Fox <coding@samantaz.fr>2023-10-07 19:53:29 +0200
commit1caaf63c8abb64babd72f75081130163325caf19 (patch)
tree3f432c7c6e231a0e36898b6573e63bdc66535fdc /spec
parenteddb54adb11c36760d56c00b0eddc1c16f4e6b31 (diff)
parentbe2feba17c2f3b9d8e043825beff57568df46f2e (diff)
downloadinvidious-1caaf63c8abb64babd72f75081130163325caf19.tar.gz
invidious-1caaf63c8abb64babd72f75081130163325caf19.tar.bz2
invidious-1caaf63c8abb64babd72f75081130163325caf19.zip
Refactor WebVTT building logic into WebVTT::Builder (#4070)
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/vtt/builder_spec.cr64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/helpers/vtt/builder_spec.cr b/spec/helpers/vtt/builder_spec.cr
new file mode 100644
index 00000000..7b543ddc
--- /dev/null
+++ b/spec/helpers/vtt/builder_spec.cr
@@ -0,0 +1,64 @@
+require "../../spec_helper.cr"
+
+MockLines = [
+ {
+ "start_time": Time::Span.new(seconds: 1),
+ "end_time": Time::Span.new(seconds: 2),
+ "text": "Line 1",
+ },
+
+ {
+ "start_time": Time::Span.new(seconds: 2),
+ "end_time": Time::Span.new(seconds: 3),
+ "text": "Line 2",
+ },
+]
+
+Spectator.describe "WebVTT::Builder" do
+ it "correctly builds a vtt file" do
+ result = WebVTT.build do |vtt|
+ MockLines.each do |line|
+ vtt.cue(line["start_time"], line["end_time"], line["text"])
+ end
+ end
+
+ expect(result).to eq([
+ "WEBVTT",
+ "",
+ "00:00:01.000 --> 00:00:02.000",
+ "Line 1",
+ "",
+ "00:00:02.000 --> 00:00:03.000",
+ "Line 2",
+ "",
+ "",
+ ].join('\n'))
+ end
+
+ it "correctly builds a vtt file with setting fields" do
+ setting_fields = {
+ "Kind" => "captions",
+ "Language" => "en",
+ }
+
+ result = WebVTT.build(setting_fields) do |vtt|
+ MockLines.each do |line|
+ vtt.cue(line["start_time"], line["end_time"], line["text"])
+ end
+ end
+
+ expect(result).to eq([
+ "WEBVTT",
+ "Kind: captions",
+ "Language: en",
+ "",
+ "00:00:01.000 --> 00:00:02.000",
+ "Line 1",
+ "",
+ "00:00:02.000 --> 00:00:03.000",
+ "Line 2",
+ "",
+ "",
+ ].join('\n'))
+ end
+end