@playpilot/tpi 8.29.10 → 8.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editorial.mount.js +9 -9
- package/dist/link-injections.js +1 -1
- package/dist/mount.js +7 -7
- package/eslint.config.js +1 -0
- package/package.json +1 -1
- package/src/lib/afterArticle.ts +1 -1
- package/src/lib/api/participants.ts +0 -1
- package/src/lib/injection.ts +1 -1
- package/src/lib/types/global.d.ts +1 -0
- package/src/routes/components/Debugger.svelte +20 -7
- package/src/routes/components/Explore/Routes/ExploreModal.svelte +107 -107
- package/src/routes/components/Modals/TitlesReelModal.svelte +3 -3
- package/src/routes/components/Rails/TitlesRail.svelte +1 -1
- package/src/routes/components/YouTubeEmbed.svelte +61 -20
- package/src/routes/components/YouTubeEmbedBackground.svelte +1 -0
- package/src/routes/components/YouTubeEmbedOverlay.svelte +1 -1
- package/src/routes/elements/+page.svelte +12 -0
- package/src/tests/lib/injection.test.js +2 -2
- package/src/tests/routes/components/YouTubeEmbed.test.js +109 -33
- package/src/tests/routes/components/YouTubeEmbedBackground.test.js +2 -3
- package/src/tests/routes/components/YouTubeEmbedOverlay.test.js +2 -3
|
@@ -1,72 +1,148 @@
|
|
|
1
1
|
import { render } from '@testing-library/svelte'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
2
|
+
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
|
|
4
3
|
import YouTubeEmbed from '../../../routes/components/YouTubeEmbed.svelte'
|
|
5
|
-
import { beforeEach } from 'node:test'
|
|
6
4
|
import { fakeFetch } from '../../helpers'
|
|
7
5
|
|
|
6
|
+
function loadPlyr() {
|
|
7
|
+
const script = document.head.querySelector('script[src*="plyr"]')
|
|
8
|
+
script?.dispatchEvent(new Event('load'))
|
|
9
|
+
}
|
|
10
|
+
|
|
8
11
|
describe('YouTubeEmbed.svelte', () => {
|
|
12
|
+
/** @type {any} */ let Plyr
|
|
13
|
+
/** @type {any} */ let player
|
|
14
|
+
/** @type {any} */ let onready
|
|
15
|
+
/** @type {any} */ let statechange
|
|
16
|
+
|
|
9
17
|
beforeEach(() => {
|
|
10
18
|
fakeFetch()
|
|
19
|
+
onready = undefined
|
|
20
|
+
statechange = undefined
|
|
21
|
+
|
|
22
|
+
player = {
|
|
23
|
+
on: vi.fn((eventName, callback) => {
|
|
24
|
+
if (eventName === 'ready') onready = callback
|
|
25
|
+
if (eventName === 'statechange') statechange = callback
|
|
26
|
+
}),
|
|
27
|
+
play: vi.fn(),
|
|
28
|
+
pause: vi.fn(),
|
|
29
|
+
muted: false,
|
|
30
|
+
volume: 1,
|
|
31
|
+
currentTime: 0,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Plyr = vi.fn(() => player)
|
|
35
|
+
window.Plyr = Plyr
|
|
11
36
|
})
|
|
12
37
|
|
|
13
|
-
|
|
14
|
-
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
delete window.Plyr
|
|
40
|
+
document.head.innerHTML = ''
|
|
41
|
+
})
|
|
15
42
|
|
|
16
|
-
|
|
43
|
+
it('Should render player element and initialize Plyr with default options', () => {
|
|
44
|
+
const { container } = render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc' })
|
|
45
|
+
loadPlyr()
|
|
46
|
+
|
|
47
|
+
/** @type {HTMLElement | null} */
|
|
48
|
+
const playerElement = container.querySelector('.player')
|
|
49
|
+
|
|
50
|
+
expect(playerElement).toBeTruthy()
|
|
51
|
+
expect(playerElement?.dataset.plyrEmbedId).toBe('abc')
|
|
52
|
+
expect(playerElement?.dataset.plyrProvider).toBe('youtube')
|
|
53
|
+
|
|
54
|
+
expect(Plyr).toHaveBeenCalledWith(
|
|
55
|
+
playerElement,
|
|
56
|
+
expect.objectContaining({
|
|
57
|
+
controls: [],
|
|
58
|
+
autoplay: true,
|
|
59
|
+
muted: false,
|
|
60
|
+
clickToPlay: false,
|
|
61
|
+
playsinline: true,
|
|
62
|
+
youtube: expect.objectContaining({ noCookie: true, cc_load_policy: 0, cc_lang_pref: 'auto' }),
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
17
65
|
})
|
|
18
66
|
|
|
19
|
-
it('Should
|
|
20
|
-
const { container } = render(YouTubeEmbed, {
|
|
67
|
+
it('Should initialize Plyr with given controls', () => {
|
|
68
|
+
const { container } = render(YouTubeEmbed, {
|
|
69
|
+
embeddable_url: 'youtube.com/watch?v=abc',
|
|
70
|
+
controls: ['fullscreen', 'mute'],
|
|
71
|
+
})
|
|
21
72
|
|
|
22
|
-
|
|
73
|
+
loadPlyr()
|
|
74
|
+
|
|
75
|
+
expect(Plyr).toHaveBeenCalledWith(
|
|
76
|
+
container.querySelector('.player'),
|
|
77
|
+
expect.objectContaining({ controls: ['fullscreen', 'mute'] }),
|
|
78
|
+
)
|
|
23
79
|
})
|
|
24
80
|
|
|
25
|
-
it('Should
|
|
81
|
+
it('Should initialize Plyr muted if given', () => {
|
|
26
82
|
const { container } = render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc', muted: true })
|
|
27
83
|
|
|
28
|
-
|
|
84
|
+
loadPlyr()
|
|
85
|
+
|
|
86
|
+
expect(Plyr).toHaveBeenCalledWith(
|
|
87
|
+
container.querySelector('.player'),
|
|
88
|
+
expect.objectContaining({ muted: true }),
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('Should set current time on ready to given fallbackStartTime', () => {
|
|
93
|
+
render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc', fallbackStartTime: 8 })
|
|
94
|
+
|
|
95
|
+
loadPlyr()
|
|
96
|
+
onready?.()
|
|
97
|
+
|
|
98
|
+
expect(player.currentTime).toBe(8)
|
|
29
99
|
})
|
|
30
100
|
|
|
31
|
-
it('Should
|
|
32
|
-
|
|
101
|
+
it('Should use stored playtime for video id, minus 1 second', () => {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
window.PlayPilotLinkInjections = {
|
|
104
|
+
video_playtimes: { abc: 5 },
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc' })
|
|
108
|
+
|
|
109
|
+
loadPlyr()
|
|
110
|
+
onready?.()
|
|
33
111
|
|
|
34
|
-
expect(
|
|
112
|
+
expect(player.currentTime).toBe(4)
|
|
35
113
|
})
|
|
36
114
|
|
|
37
|
-
it('Should
|
|
115
|
+
it('Should enable captions in youtube options if given', () => {
|
|
38
116
|
const { container } = render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc', captions: true })
|
|
117
|
+
loadPlyr()
|
|
39
118
|
|
|
40
|
-
expect(
|
|
119
|
+
expect(Plyr).toHaveBeenCalledWith(container.querySelector('.player'), expect.objectContaining({ youtube: expect.objectContaining({ cc_load_policy: 1 }) }))
|
|
41
120
|
})
|
|
42
121
|
|
|
43
|
-
it('Should
|
|
122
|
+
it('Should initialize Plyr with autoplay set to false if given', () => {
|
|
44
123
|
const { container } = render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc', autoplay: false })
|
|
45
124
|
|
|
46
|
-
|
|
125
|
+
loadPlyr()
|
|
126
|
+
|
|
127
|
+
expect(Plyr).toHaveBeenCalledWith(container.querySelector('.player'), expect.objectContaining({ autoplay: false }))
|
|
47
128
|
})
|
|
48
129
|
|
|
49
|
-
it('Should
|
|
50
|
-
|
|
130
|
+
it('Should replay and re-mute on loop when video ends', () => {
|
|
131
|
+
render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc', loop: true, muted: true })
|
|
132
|
+
|
|
133
|
+
loadPlyr()
|
|
134
|
+
global.requestAnimationFrame = (callback) => (callback(0), 0)
|
|
51
135
|
|
|
52
|
-
|
|
136
|
+
statechange?.({ detail: { code: 0 } })
|
|
137
|
+
|
|
138
|
+
expect(player.play).toHaveBeenCalled()
|
|
139
|
+
expect(player.muted).toBe(true)
|
|
53
140
|
})
|
|
54
141
|
|
|
55
142
|
it('Should render error message if embeddable_url is invalid', () => {
|
|
56
143
|
const { container, getByText } = render(YouTubeEmbed, { embeddable_url: '-' })
|
|
57
144
|
|
|
58
|
-
expect(container.querySelector('
|
|
145
|
+
expect(container.querySelector('.player')).not.toBeTruthy()
|
|
59
146
|
expect(getByText('Something went wrong')).toBeTruthy()
|
|
60
147
|
})
|
|
61
|
-
|
|
62
|
-
it('Should include start_time for given video id if present, minus 1 second', () => {
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
window.PlayPilotLinkInjections = {
|
|
65
|
-
video_playtimes: { abc: 5 },
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const { container } = render(YouTubeEmbed, { embeddable_url: 'youtube.com/watch?v=abc', captions: true })
|
|
69
|
-
|
|
70
|
-
expect(/** @type {HTMLIFrameElement} */ (container.querySelector('iframe')).src).toContain('&start_time=4')
|
|
71
|
-
})
|
|
72
148
|
})
|
|
@@ -5,9 +5,8 @@ import YouTubeEmbedBackground from '../../../routes/components/YouTubeEmbedBackg
|
|
|
5
5
|
|
|
6
6
|
describe('YouTubeEmbedBackground.svelte', () => {
|
|
7
7
|
it('Should render embed iframe with given video url', () => {
|
|
8
|
-
const {
|
|
8
|
+
const { getByTestId } = render(YouTubeEmbedBackground, { embeddable_url: 'youtube.com/watch?v=abc' })
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
expect(container.querySelector('iframe').src).toBe('https://video.playpilot.net/?video_id=abc&color=fa548a&muted=true&loop=true&captions=false&controls=&start_time=5&autoplay=true&playsinline=true')
|
|
10
|
+
expect(getByTestId('youtube.com/watch?v=abc')).toBeTruthy()
|
|
12
11
|
})
|
|
13
12
|
})
|
|
@@ -5,10 +5,9 @@ import YouTubeEmbedOverlay from '../../../routes/components/YouTubeEmbedOverlay.
|
|
|
5
5
|
|
|
6
6
|
describe('YouTubeEmbedOverlay.svelte', () => {
|
|
7
7
|
it('Should render embed iframe with given video url', () => {
|
|
8
|
-
const {
|
|
8
|
+
const { getByTestId } = render(YouTubeEmbedOverlay, { embeddable_url: 'youtube.com/watch?v=abc', onclose: () => null })
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
expect(container.querySelector('iframe').src).toBe('https://video.playpilot.net/?video_id=abc&color=fa548a&muted=false&loop=false&captions=false&controls=current-time,fullscreen,mute,play,progress&start_time=0&autoplay=true&playsinline=true')
|
|
10
|
+
expect(getByTestId('youtube.com/watch?v=abc')).toBeTruthy()
|
|
12
11
|
})
|
|
13
12
|
|
|
14
13
|
it('Should fire given onclose function on click of close button and backdrop', async () => {
|