Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/resources/extensions/quarto/video/_tests/test-suite.lua
12923 views
1
package.path = package.path .. ';../?.lua'
2
lu = require('luaunit')
3
4
video = require('video')
5
helpers = video['video-helpers']
6
VIDEO_TYPES = helpers.VIDEO_TYPES
7
8
TestModules = {}
9
function TestModules:testVideoExists()
10
lu.assertNotIsNil(video.video)
11
end
12
13
function TestModules:testHelpersExist()
14
lu.assertNotIsNil(helpers)
15
end
16
17
TestCheckMatchStart = {}
18
function TestCheckMatchStart:testEmpty()
19
local result = helpers.checkMatchStart('', '')
20
lu.assertEquals(result, '')
21
end
22
23
function TestCheckMatchStart:testSimple()
24
local result = helpers.checkMatchStart('fake-src', 'fake')
25
lu.assertEquals(result, '-src')
26
end
27
28
function TestCheckMatchStart:testNoMatch()
29
local result = helpers.checkMatchStart('123', '456')
30
lu.assertEquals(result, nil)
31
end
32
33
function TestCheckMatchStart:testNoStartMatch()
34
local result = helpers.checkMatchStart('123456', '456')
35
lu.assertEquals(result, nil)
36
end
37
38
function TestCheckMatchStart:testPartialMatch()
39
local result = helpers.checkMatchStart('456', '4')
40
lu.assertEquals(result, '56')
41
end
42
43
TestYouTubeBuilder = {}
44
local checkYouTubeBuilder = function(params, expected)
45
result = helpers.youTubeBuilder(params)
46
lu.assertEquals(result, expected)
47
end
48
49
function TestYouTubeBuilder:testemptySource()
50
local params = nil
51
local expected = nil
52
checkYouTubeBuilder(params, expected)
53
end
54
55
function TestYouTubeBuilder:testnoSrcTable()
56
local params = { }
57
local expected = nil
58
checkYouTubeBuilder(params, expected)
59
end
60
61
function TestYouTubeBuilder:testbadSrc()
62
local params = { src='faifail' }
63
local expected = nil
64
checkYouTubeBuilder(params, expected)
65
end
66
67
function TestYouTubeBuilder:testvimeoSrc()
68
local params = { src='https://vimeo.com/548291210' }
69
local expected = nil
70
checkYouTubeBuilder(params, expected)
71
end
72
73
local SIMPLE_YOUTUBE_EXPECTED = {
74
snippet = '<iframe data-external="1" src="https://www.youtube.com/embed/wo9vZccmqwc" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
75
type = VIDEO_TYPES.YOUTUBE,
76
src = 'https://www.youtube.com/embed/wo9vZccmqwc',
77
videoId="wo9vZccmqwc"}
78
79
function TestYouTubeBuilder:testEmbedURL()
80
local params = {
81
src = 'https://www.youtube.com/embed/wo9vZccmqwc'
82
}
83
local expected = SIMPLE_YOUTUBE_EXPECTED
84
checkYouTubeBuilder(params, expected)
85
end
86
87
function TestYouTubeBuilder:testShareURL()
88
local params = {
89
src = 'https://youtu.be/wo9vZccmqwc'
90
}
91
local expected = SIMPLE_YOUTUBE_EXPECTED
92
checkYouTubeBuilder(params, expected)
93
end
94
95
function TestYouTubeBuilder:testShareURL()
96
local params = {
97
src = 'https://youtu.be/wo9vZccmqwc'
98
}
99
local expected = SIMPLE_YOUTUBE_EXPECTED
100
checkYouTubeBuilder(params, expected)
101
end
102
103
function TestYouTubeBuilder:testWebURL()
104
local params = {
105
src = 'https://www.youtube.com/watch?v=wo9vZccmqwc&ab_channel=CERN'
106
}
107
local expected = SIMPLE_YOUTUBE_EXPECTED
108
checkYouTubeBuilder(params, expected)
109
end
110
111
function TestYouTubeBuilder:testTitle()
112
local params = {
113
src = 'https://www.youtube.com/embed/wo9vZccmqwc',
114
title = 'fake-title',
115
}
116
local expected = {snippet = '<iframe data-external="1" src="https://www.youtube.com/embed/wo9vZccmqwc" title="fake-title" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
117
type = VIDEO_TYPES.YOUTUBE, src='https://www.youtube.com/embed/wo9vZccmqwc', videoId = 'wo9vZccmqwc'
118
}
119
checkYouTubeBuilder(params, expected)
120
end
121
122
function TestYouTubeBuilder:testStartTime()
123
local params = {
124
src = 'https://www.youtube.com/embed/wo9vZccmqwc',
125
start = 10,
126
}
127
local expected = {snippet = '<iframe data-external="1" src="https://www.youtube.com/embed/wo9vZccmqwc?start=10" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', type = VIDEO_TYPES.YOUTUBE, src='https://www.youtube.com/embed/wo9vZccmqwc', videoId = 'wo9vZccmqwc'}
128
checkYouTubeBuilder(params, expected)
129
end
130
131
function TestYouTubeBuilder:testHeightWidth()
132
local params = {
133
src = 'https://www.youtube.com/embed/wo9vZccmqwc',
134
height = 100,
135
width = 200,
136
}
137
local expected = {snippet = '<iframe data-external="1" src="https://www.youtube.com/embed/wo9vZccmqwc" width="200" height="100" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', type = VIDEO_TYPES.YOUTUBE,
138
src = 'https://www.youtube.com/embed/wo9vZccmqwc', videoId = 'wo9vZccmqwc'}
139
checkYouTubeBuilder(params, expected)
140
end
141
142
function TestYouTubeBuilder:testAriaLabel()
143
local params = {
144
src = 'https://www.youtube.com/embed/wo9vZccmqwc',
145
ariaLabel = 'Video demonstration of features',
146
}
147
local expected = {snippet = '<iframe data-external="1" src="https://www.youtube.com/embed/wo9vZccmqwc" title="" aria-label="Video demonstration of features" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', type = VIDEO_TYPES.YOUTUBE, src='https://www.youtube.com/embed/wo9vZccmqwc', videoId = 'wo9vZccmqwc'}
148
checkYouTubeBuilder(params, expected)
149
end
150
151
TestBrightcoveBuilder = {}
152
local checkBrightcoveBuilder = function(params, expected)
153
result = helpers.brightcoveBuilder(params)
154
lu.assertEquals(result, expected)
155
end
156
157
function TestBrightcoveBuilder:testemptySource()
158
local params = nil
159
local expected = nil
160
checkBrightcoveBuilder(params, expected)
161
end
162
163
function TestBrightcoveBuilder:testnoSrcTable()
164
local params = { }
165
local expected = nil
166
checkBrightcoveBuilder(params, expected)
167
end
168
169
function TestBrightcoveBuilder:testbadSrc()
170
local params = { src='faifail' }
171
local expected = nil
172
checkBrightcoveBuilder(params, expected)
173
end
174
175
function TestBrightcoveBuilder:testvimeoSrc()
176
local params = { src='https://vimeo.com/548291210' }
177
local expected = nil
178
checkBrightcoveBuilder(params, expected)
179
end
180
181
function TestBrightcoveBuilder:testBasic()
182
local params = {
183
src = 'https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001'
184
}
185
local expected = {
186
snippet = '<iframe data-external="1" src="https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001" allowfullscreen="" title="" allow="encrypted-media"></iframe>',
187
type = VIDEO_TYPES.BRIGHTCOVE, src='https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001' }
188
checkBrightcoveBuilder(params, expected)
189
end
190
191
function TestBrightcoveBuilder:testYouTubeShareURL()
192
local params = {
193
src = 'https://youtu.be/wo9vZccmqwc'
194
}
195
local expected = nil
196
checkBrightcoveBuilder(params, expected)
197
end
198
199
function TestBrightcoveBuilder:testTitle()
200
local params = {
201
src = 'https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001',
202
title = 'fake-title',
203
}
204
local expected = {snippet = '<iframe data-external="1" src="https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001" allowfullscreen="" title="fake-title" allow="encrypted-media"></iframe>', type = VIDEO_TYPES.BRIGHTCOVE, src='https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001' }
205
checkBrightcoveBuilder(params, expected)
206
end
207
208
function TestBrightcoveBuilder:testHeightWidth()
209
local params = {
210
src = 'https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001',
211
height = 100,
212
width = 200,
213
}
214
local expected = {snippet = '<iframe data-external="1" src="https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001" width="200" height="100" allowfullscreen="" title="" allow="encrypted-media"></iframe>', type = VIDEO_TYPES.BRIGHTCOVE, src='https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001' }
215
checkBrightcoveBuilder(params, expected)
216
end
217
218
function TestBrightcoveBuilder:testAriaLabel()
219
local params = {
220
src = 'https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001',
221
ariaLabel = 'Video demonstration of features',
222
}
223
local expected = {snippet = '<iframe data-external="1" src="https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001" allowfullscreen="" title="" aria-label="Video demonstration of features" allow="encrypted-media"></iframe>', type = VIDEO_TYPES.BRIGHTCOVE, src='https://players.brightcove.net/1460825906/default_default/index.html?videoId=5988531335001' }
224
checkBrightcoveBuilder(params, expected)
225
end
226
227
TestVimeoBuilder = {}
228
local checkVimeoBuilder = function(params, expected)
229
result = helpers.vimeoBuilder(params)
230
lu.assertEquals(result, expected)
231
end
232
233
function TestVimeoBuilder:testemptySource()
234
local params = nil
235
local expected = nil
236
checkVimeoBuilder(params, expected)
237
end
238
239
function TestVimeoBuilder:testnoSrcTable()
240
local params = { }
241
local expected = nil
242
checkVimeoBuilder(params, expected)
243
end
244
245
function TestVimeoBuilder:testbadSrc()
246
local params = { src='faifail' }
247
local expected = nil
248
checkVimeoBuilder(params, expected)
249
end
250
251
function TestVimeoBuilder:testYouTubeSrc()
252
local params = { src='https://www.youtube.com/embed/wo9vZccmqwc' }
253
local expected = nil
254
checkVimeoBuilder(params, expected)
255
end
256
257
function TestVimeoBuilder:testBasic()
258
local params = {
259
src = 'https://vimeo.com/548291210'
260
}
261
local expected = {
262
snippet = '<iframe data-external="1" src="https://player.vimeo.com/video/548291210" frameborder="0" allow="autoplay; title="" fullscreen; picture-in-picture" allowfullscreen></iframe>',
263
type = VIDEO_TYPES.VIMEO, src='https://player.vimeo.com/video/548291210', videoId = '548291210' }
264
265
checkVimeoBuilder(params, expected)
266
end
267
268
function TestVimeoBuilder:testInternal()
269
local params = {
270
src = 'https://vimeo.com/548291210/fdcc90d662'
271
}
272
local expected = {
273
snippet = '<iframe data-external="1" src="https://player.vimeo.com/video/548291210?h=fdcc90d662" frameborder="0" allow="autoplay; title="" fullscreen; picture-in-picture" allowfullscreen></iframe>',
274
type = VIDEO_TYPES.VIMEO, src='https://player.vimeo.com/video/548291210?h=fdcc90d662', videoId = '548291210' }
275
276
checkVimeoBuilder(params, expected)
277
end
278
279
function TestVimeoBuilder:testInternal_shareCopy()
280
local params = {
281
src = 'https://vimeo.com/548291210/fdcc90d662?share=copy'
282
}
283
local expected = {
284
snippet = '<iframe data-external="1" src="https://player.vimeo.com/video/548291210?h=fdcc90d662" frameborder="0" allow="autoplay; title="" fullscreen; picture-in-picture" allowfullscreen></iframe>',
285
type = VIDEO_TYPES.VIMEO, src='https://player.vimeo.com/video/548291210?h=fdcc90d662', videoId = '548291210' }
286
287
checkVimeoBuilder(params, expected)
288
end
289
290
function TestVimeoBuilder:testTitle()
291
local params = {
292
src = 'https://vimeo.com/548291210',
293
title = 'fake-title'
294
}
295
local expected = {snippet = '<iframe data-external="1" src="https://player.vimeo.com/video/548291210" frameborder="0" allow="autoplay; title="fake-title" fullscreen; picture-in-picture" allowfullscreen></iframe>', type = VIDEO_TYPES.VIMEO, src='https://player.vimeo.com/video/548291210', videoId = '548291210' }
296
checkVimeoBuilder(params, expected)
297
end
298
299
function TestVimeoBuilder:testHeightWidth()
300
local params = {
301
src = 'https://vimeo.com/548291210',
302
height = 100,
303
width = 200,
304
}
305
local expected = {snippet = '<iframe data-external="1" src="https://player.vimeo.com/video/548291210" width="200" height="100" frameborder="0" allow="autoplay; title="" fullscreen; picture-in-picture" allowfullscreen></iframe>', type = VIDEO_TYPES.VIMEO, src='https://player.vimeo.com/video/548291210', videoId = '548291210' }
306
checkVimeoBuilder(params, expected)
307
end
308
309
function TestVimeoBuilder:testAriaLabel()
310
local params = {
311
src = 'https://vimeo.com/548291210',
312
ariaLabel = 'Video demonstration of features',
313
}
314
local expected = {snippet = '<iframe data-external="1" src="https://player.vimeo.com/video/548291210" frameborder="0" title="" aria-label="Video demonstration of features" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>', type = VIDEO_TYPES.VIMEO, src='https://player.vimeo.com/video/548291210', videoId = '548291210' }
315
checkVimeoBuilder(params, expected)
316
end
317
318
TestVideoJSBuilder = {}
319
local checkVideoJSBuilder = function(params, expected)
320
VIDEO_SHORTCODE_NUM_VIDEOJS = 0 -- Reset Counter
321
result = helpers.videoJSBuilder(params)
322
lu.assertEquals(result, expected)
323
end
324
325
function TestVideoJSBuilder:testemptySource()
326
local params = nil
327
local expected = nil
328
checkVideoJSBuilder(params, expected)
329
end
330
331
function TestVideoJSBuilder:testnoSrcTable()
332
local params = { }
333
local expected = nil
334
checkVideoJSBuilder(params, expected)
335
end
336
337
function TestVideoJSBuilder:testBasic()
338
local params = {
339
id = 1,
340
src = './intro-cern.mp4'
341
}
342
local expected = {
343
id="video_shortcode_videojs_video1",
344
snippet="<video id=\"video_shortcode_videojs_video1\" class=\"video-js vjs-default-skin vjs-fluid\" controls preload=\"auto\" data-setup='{}' title=\"\"><source src=\"./intro-cern.mp4\"></video>",
345
type="VIDEOJS",
346
src='./intro-cern.mp4'
347
}
348
349
checkVideoJSBuilder(params, expected)
350
end
351
352
function TestVideoJSBuilder:testDropBox()
353
local params = {
354
id = 1,
355
src = 'https://www.dropbox.com/s/h3ezvnpyn8xe5ch/Section1_4_c.mp4?raw=1'
356
}
357
local expected = {
358
id="video_shortcode_videojs_video1",
359
snippet="<video id=\"video_shortcode_videojs_video1\" class=\"video-js vjs-default-skin vjs-fluid\" controls preload=\"auto\" data-setup='{}' title=\"\"><source src=\"https://www.dropbox.com/s/h3ezvnpyn8xe5ch/Section1_4_c.mp4?raw=1\"></video>",
360
type="VIDEOJS",
361
src='https://www.dropbox.com/s/h3ezvnpyn8xe5ch/Section1_4_c.mp4?raw=1'
362
}
363
364
checkVideoJSBuilder(params, expected)
365
end
366
367
function TestVideoJSBuilder:testTitle()
368
local params = {
369
title = 'test-title',
370
src = './intro-cern.mp4'
371
}
372
local expected = {
373
snippet="<video id=\"video_shortcode_videojs_video1\" class=\"video-js vjs-default-skin vjs-fluid\" controls preload=\"auto\" data-setup='{}' title=\"test-title\"><source src=\"./intro-cern.mp4\"></video>",
374
type="VIDEOJS",
375
src='./intro-cern.mp4',
376
id="video_shortcode_videojs_video1"
377
}
378
checkVideoJSBuilder(params, expected)
379
end
380
381
function TestVideoJSBuilder:testHeightWidth()
382
local params = {
383
id = 1,
384
height = 100,
385
width = 200,
386
src = './intro-cern.mp4'
387
}
388
local expected = {
389
id="video_shortcode_videojs_video1",
390
snippet="<video id=\"video_shortcode_videojs_video1\" width=\"200\" height=\"100\" class=\"video-js vjs-default-skin \" controls preload=\"auto\" data-setup='{}' title=\"\"><source src=\"./intro-cern.mp4\"></video>",
391
type="VIDEOJS",
392
src="./intro-cern.mp4"
393
}
394
395
checkVideoJSBuilder(params, expected)
396
end
397
398
function TestVideoJSBuilder:testAriaLabel()
399
local params = {
400
ariaLabel = 'Video demonstration of features',
401
src = './intro-cern.mp4'
402
}
403
local expected = {
404
snippet="<video id=\"video_shortcode_videojs_video1\" class=\"video-js vjs-default-skin vjs-big-play-centered vjs-fluid\" controls preload=\"auto\" data-setup='{}' title=\"\" aria-label=\"Video demonstration of features\"><source src=\"./intro-cern.mp4\"></video>",
405
type="VIDEOJS",
406
src='./intro-cern.mp4',
407
id="video_shortcode_videojs_video1"
408
}
409
checkVideoJSBuilder(params, expected)
410
end
411
412
TestVideoResponsive = {}
413
function TestVideoResponsive:testNoResponsive()
414
result = helpers.wrapWithDiv('fake-to-wrap')
415
expected = '<div class="quarto-video">fake-to-wrap</div>'
416
lu.assertEquals(result, expected)
417
end
418
419
function TestVideoResponsive:testValid()
420
result = helpers.wrapWithDiv('fake-to-wrap', nil, true)
421
expected = '<div class="quarto-video ratio ratio-16x9">fake-to-wrap</div>'
422
lu.assertEquals(result, expected)
423
end
424
425
function TestVideoResponsive:testValid_43()
426
result = helpers.wrapWithDiv('fake-to-wrap', '4x3', true)
427
expected = '<div class="quarto-video ratio ratio-4x3">fake-to-wrap</div>'
428
lu.assertEquals(result, expected)
429
end
430
431
function TestVideoResponsive:testValid_11()
432
result = helpers.wrapWithDiv('fake-to-wrap', '1x1', true)
433
expected = '<div class="quarto-video ratio ratio-1x1">fake-to-wrap</div>'
434
lu.assertEquals(result, expected)
435
end
436
437
function TestVideoResponsive:testValid_219()
438
result = helpers.wrapWithDiv('fake-to-wrap', '21x9', true)
439
expected = '<div class="quarto-video ratio ratio-21x9">fake-to-wrap</div>'
440
lu.assertEquals(result, expected)
441
end
442
443
TestHelperConvertURL = {}
444
function TestHelperConvertURL:testCanLoadModule()
445
--helper.helloWorld()
446
end
447
448
TestAsciidocVideo = {}
449
function TestAsciidocVideo:testYoutube()
450
result = formatAsciiDocVideo('qItugh-fFgg', 'youtube')
451
expected = 'video::qItugh-fFgg[youtube]'
452
lu.assertEquals(result, expected)
453
end
454
455
function TestAsciidocVideo:testVimeo()
456
result = formatAsciiDocVideo('783455773', 'vimeo')
457
expected = 'video::783455773[vimeo]'
458
lu.assertEquals(result, expected)
459
end
460
461
function TestAsciidocVideo:textLocal()
462
result = formatAsciiDocVideo('foo/bar.mp4', '')
463
expected = 'video::foo/bar.mp4[]'
464
lu.assertEquals(result, expected)
465
end
466
467
os.exit(lu.LuaUnit.run())
468
469