Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 1,740 Bytes
a8fb296 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import { describe, expect, it } from 'vitest'
import { clockTime, youtubeEmbedUrl, youtubeVideoId } from './youtubeEmbed'
describe('youtubeVideoId (#972)', () => {
it('reads watch, short and embed URLs', () => {
expect(youtubeVideoId('https://www.youtube.com/watch?v=7VghnjHd_1w&t=7747s')).toBe('7VghnjHd_1w')
expect(youtubeVideoId('https://youtu.be/7VghnjHd_1w?t=12')).toBe('7VghnjHd_1w')
expect(youtubeVideoId('https://m.youtube.com/embed/7VghnjHd_1w')).toBe('7VghnjHd_1w')
})
it('is null for anything that is not a YouTube recording', () => {
expect(youtubeVideoId(null)).toBeNull()
expect(youtubeVideoId('not a url')).toBeNull()
expect(youtubeVideoId('https://example.gov/agenda.pdf')).toBeNull()
expect(youtubeVideoId('https://youtube.com.evil.net/watch?v=7VghnjHd_1w')).toBeNull()
expect(youtubeVideoId('https://www.youtube.com/watch?v=bad')).toBeNull()
})
})
describe('youtubeEmbedUrl (#972)', () => {
it('starts at the quoted moment, in whole seconds, on the no-cookie host', () => {
const u = new URL(youtubeEmbedUrl('7VghnjHd_1w', 7747.466))
expect(u.origin + u.pathname).toBe('https://www.youtube-nocookie.com/embed/7VghnjHd_1w')
expect(u.searchParams.get('start')).toBe('7747')
expect(u.searchParams.get('autoplay')).toBe('1')
})
it('starts at the beginning when the passage has no timing', () => {
expect(new URL(youtubeEmbedUrl('7VghnjHd_1w', null)).searchParams.has('start')).toBe(false)
expect(new URL(youtubeEmbedUrl('7VghnjHd_1w', -3)).searchParams.has('start')).toBe(false)
})
})
describe('clockTime', () => {
it('formats minutes and hours', () => {
expect(clockTime(247)).toBe('4:07')
expect(clockTime(7747.4)).toBe('2:09:07')
})
})
|