@playpilot/tpi 5.32.3 → 5.33.0-beta.explore.10
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/link-injections.js +25 -10
- package/package.json +1 -1
- package/src/lib/afterArticle.ts +40 -0
- package/src/lib/api/api.ts +1 -1
- package/src/lib/api/titles.ts +13 -1
- package/src/lib/color.ts +19 -0
- package/src/lib/data/countries.json +216 -0
- package/src/lib/data/translations.ts +5 -0
- package/src/lib/disclaimer.ts +27 -0
- package/src/lib/enums/SplitTest.ts +5 -0
- package/src/lib/explore.ts +59 -0
- package/src/lib/fakeData.ts +1 -0
- package/src/lib/images/titles-list.webp +0 -0
- package/src/lib/injection.ts +41 -147
- package/src/lib/modal.ts +38 -7
- package/src/lib/popover.ts +71 -0
- package/src/lib/scss/global.scss +39 -2
- package/src/lib/trailer.ts +22 -0
- package/src/lib/types/api.d.ts +6 -0
- package/src/lib/types/config.d.ts +12 -0
- package/src/lib/types/filter.d.ts +2 -0
- package/src/lib/types/title.d.ts +4 -1
- package/src/routes/+page.svelte +13 -4
- package/src/routes/components/Ads/TopScroll.svelte +4 -18
- package/src/routes/components/Button.svelte +101 -0
- package/src/routes/components/Debugger.svelte +36 -0
- package/src/routes/components/Explore/Explore.svelte +226 -0
- package/src/routes/components/Explore/ExploreCallToAction.svelte +58 -0
- package/src/routes/components/Explore/ExploreModal.svelte +15 -0
- package/src/routes/components/Explore/Filter/Dropdown.svelte +72 -0
- package/src/routes/components/Explore/Filter/Filter.svelte +79 -0
- package/src/routes/components/Explore/Filter/FilterItem.svelte +57 -0
- package/src/routes/components/Explore/Filter/FilterSorting.svelte +70 -0
- package/src/routes/components/Explore/Filter/Search.svelte +56 -0
- package/src/routes/components/Explore/Filter/TogglesWithSearch.svelte +142 -0
- package/src/routes/components/GridTitle.svelte +122 -0
- package/src/routes/components/GridTitleSkeleton.svelte +36 -0
- package/src/routes/components/Icons/IconArrow.svelte +10 -2
- package/src/routes/components/Icons/IconClose.svelte +9 -1
- package/src/routes/components/Icons/IconFilter.svelte +5 -0
- package/src/routes/components/Icons/IconPlay.svelte +3 -0
- package/src/routes/components/Icons/IconSearch.svelte +3 -0
- package/src/routes/components/ListTitle.svelte +10 -68
- package/src/routes/components/ListTitleSkeleton.svelte +42 -0
- package/src/routes/components/Modal.svelte +27 -29
- package/src/routes/components/Participant.svelte +0 -2
- package/src/routes/components/ParticipantModal.svelte +1 -1
- package/src/routes/components/Playlinks/PlaylinkIcon.svelte +1 -1
- package/src/routes/components/Playlinks/PlaylinksCompact.svelte +71 -0
- package/src/routes/components/Share.svelte +5 -23
- package/src/routes/components/Title.svelte +22 -22
- package/src/routes/components/TitleModal.svelte +4 -1
- package/src/routes/components/Trailer.svelte +18 -0
- package/src/routes/components/YouTubeEmbedOverlay.svelte +96 -0
- package/src/routes/elements/+page.svelte +39 -2
- package/src/routes/explore/+page.svelte +60 -0
- package/src/tests/lib/afterArticle.test.js +108 -0
- package/src/tests/lib/api/ads.test.js +0 -1
- package/src/tests/lib/api/titles.test.js +55 -0
- package/src/tests/lib/disclaimer.test.js +90 -0
- package/src/tests/lib/explore.test.js +139 -0
- package/src/tests/lib/injections.test.js +5 -157
- package/src/tests/lib/modal.test.js +64 -1
- package/src/tests/lib/popover.test.js +70 -0
- package/src/tests/lib/trailer.test.js +56 -0
- package/src/tests/routes/components/Button.test.js +28 -0
- package/src/tests/routes/components/Explore/Explore.test.js +133 -0
- package/src/tests/routes/components/Explore/Filter/Dropdown.test.js +16 -0
- package/src/tests/routes/components/Explore/Filter/Filter.test.js +20 -0
- package/src/tests/routes/components/Explore/Filter/FilterItem.test.js +50 -0
- package/src/tests/routes/components/Explore/Filter/FilterSorting.test.js +34 -0
- package/src/tests/routes/components/Explore/Filter/Search.test.js +26 -0
- package/src/tests/routes/components/Explore/Filter/TogglesWithSearch.test.js +53 -0
- package/src/tests/routes/components/GridTitle.test.js +42 -0
- package/src/tests/routes/components/ListTitle.test.js +1 -1
- package/src/tests/routes/components/Playlinks/PlaylinksCompact.test.js +42 -0
- package/src/tests/routes/components/Share.test.js +12 -12
- package/src/tests/routes/components/Title.test.js +13 -0
- package/src/tests/routes/components/Trailer.test.js +20 -0
- package/src/tests/routes/components/YouTubeEmbedOverlay.test.js +31 -0
- package/src/tests/setup.js +2 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { generateInjection } from '../helpers'
|
|
4
|
+
import { clearLinkInjections, getLinkInjectionElements } from '$lib/injection'
|
|
5
|
+
import { insertAfterArticlePlaylinks } from '$lib/afterArticle'
|
|
6
|
+
import { mount } from 'svelte'
|
|
7
|
+
|
|
8
|
+
vi.mock('svelte', () => ({
|
|
9
|
+
mount: vi.fn(),
|
|
10
|
+
unmount: vi.fn(),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
describe('afterArticle.js', () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.resetAllMocks()
|
|
16
|
+
clearLinkInjections()
|
|
17
|
+
|
|
18
|
+
vi.mocked(mount).mockReturnValueOnce({})
|
|
19
|
+
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
window.PlayPilotLinkInjections = {}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('insertAfterArticlePlaylinks', () => {
|
|
25
|
+
it('Should insert component after given elements', () => {
|
|
26
|
+
document.body.innerHTML = `<section>
|
|
27
|
+
<p>Some text</p>
|
|
28
|
+
<p>Some other text</p>
|
|
29
|
+
</section>
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
33
|
+
|
|
34
|
+
const elements = getLinkInjectionElements(document.body)
|
|
35
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
36
|
+
|
|
37
|
+
expect(mount).toHaveBeenCalled()
|
|
38
|
+
expect(document.querySelector('p:last-of-type + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('Should not insert component if no linkInjections were given', () => {
|
|
42
|
+
document.body.innerHTML = `<section>
|
|
43
|
+
<div>Some text</div>
|
|
44
|
+
<div>Some other text</div>
|
|
45
|
+
</section>
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
const elements = getLinkInjectionElements(document.body)
|
|
49
|
+
insertAfterArticlePlaylinks(elements, [])
|
|
50
|
+
|
|
51
|
+
expect(mount).not.toHaveBeenCalled()
|
|
52
|
+
expect(document.querySelector('[data-playpilot-after-article-playlinks]')).not.toBeTruthy()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('Should insert after the given element if selector is given in config object', () => {
|
|
56
|
+
window.PlayPilotLinkInjections.after_article_selector = 'hr'
|
|
57
|
+
|
|
58
|
+
document.body.innerHTML = `<section>
|
|
59
|
+
<div>Some text</div>
|
|
60
|
+
<hr>
|
|
61
|
+
<div>Some other text</div>
|
|
62
|
+
</section>
|
|
63
|
+
`
|
|
64
|
+
|
|
65
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
66
|
+
const elements = getLinkInjectionElements(document.body)
|
|
67
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
68
|
+
|
|
69
|
+
expect(document.querySelector('hr + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('Should insert in given position if position is given in config object', () => {
|
|
73
|
+
window.PlayPilotLinkInjections.after_article_insert_position = 'beforebegin'
|
|
74
|
+
|
|
75
|
+
document.body.innerHTML = `<section>
|
|
76
|
+
<div>Some text</div>
|
|
77
|
+
<hr>
|
|
78
|
+
<div>Some other text</div>
|
|
79
|
+
</section>
|
|
80
|
+
`
|
|
81
|
+
|
|
82
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
83
|
+
const elements = getLinkInjectionElements(document.body)
|
|
84
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
85
|
+
|
|
86
|
+
expect(document.querySelector('hr + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('Should insert in given position for the given element if selector and position are given in config object', () => {
|
|
90
|
+
window.PlayPilotLinkInjections.after_article_selector = 'hr'
|
|
91
|
+
window.PlayPilotLinkInjections.after_article_insert_position = 'beforebegin'
|
|
92
|
+
|
|
93
|
+
document.body.innerHTML = `<section>
|
|
94
|
+
<div>Some text</div>
|
|
95
|
+
<hr>
|
|
96
|
+
<div>Some other text</div>
|
|
97
|
+
</section>
|
|
98
|
+
`
|
|
99
|
+
|
|
100
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
101
|
+
const elements = getLinkInjectionElements(document.body)
|
|
102
|
+
|
|
103
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
104
|
+
|
|
105
|
+
expect(document.querySelector('[data-playpilot-after-article-playlinks] + hr')).toBeTruthy()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { api } from '$lib/api/api'
|
|
4
|
+
import { fetchSimilarTitles, fetchTitles } from '$lib/api/titles'
|
|
5
|
+
import { title } from '$lib/fakeData'
|
|
6
|
+
import { getApiToken } from '$lib/token'
|
|
7
|
+
|
|
8
|
+
vi.mock('$lib/token', () => ({
|
|
9
|
+
getApiToken: vi.fn(),
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
vi.mock('$lib/api/api', () => ({
|
|
13
|
+
api: vi.fn(),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe('$lib/api/ads', () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
vi.resetAllMocks()
|
|
19
|
+
vi.mocked(getApiToken).mockReturnValue('some-token')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('fetchTitles', () => {
|
|
23
|
+
it('Should call api with given parameters and return response', async () => {
|
|
24
|
+
vi.mocked(api).mockResolvedValueOnce({ results: [title] })
|
|
25
|
+
|
|
26
|
+
const response = await fetchTitles({ some: 'thing' })
|
|
27
|
+
|
|
28
|
+
expect(api).toHaveBeenCalledWith('/titles/browse?api-token=some-token&some=thing')
|
|
29
|
+
expect(response).toEqual({ results: [title] })
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Should throw when api returns error', async () => {
|
|
33
|
+
vi.mocked(api).mockRejectedValueOnce({ error: 'message' })
|
|
34
|
+
|
|
35
|
+
await expect(async () => await fetchTitles()).rejects.toThrow()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe('fetchSimilarTitles', () => {
|
|
40
|
+
it('Should call api with with sid for given title and return array of titles', async () => {
|
|
41
|
+
vi.mocked(api).mockResolvedValueOnce({ results: [title] })
|
|
42
|
+
|
|
43
|
+
const response = await fetchSimilarTitles(title)
|
|
44
|
+
|
|
45
|
+
expect(api).toHaveBeenCalledWith(`/titles/browse?api-token=some-token&related_to_sid=${title.sid}`)
|
|
46
|
+
expect(response).toEqual([title])
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('Should throw when api returns error', async () => {
|
|
50
|
+
vi.mocked(api).mockRejectedValueOnce({ error: 'message' })
|
|
51
|
+
|
|
52
|
+
await expect(async () => await fetchSimilarTitles(title)).rejects.toThrow()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { clearLinkInjections, getLinkInjectionElements } from '$lib/injection'
|
|
4
|
+
import { mount } from 'svelte'
|
|
5
|
+
import { insertInTextDisclaimer } from '$lib/disclaimer'
|
|
6
|
+
|
|
7
|
+
vi.mock('svelte', () => ({
|
|
8
|
+
mount: vi.fn(),
|
|
9
|
+
unmount: vi.fn(),
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
describe('disclaimer.js', () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
vi.resetAllMocks()
|
|
15
|
+
clearLinkInjections()
|
|
16
|
+
|
|
17
|
+
vi.mocked(mount).mockReturnValueOnce({})
|
|
18
|
+
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
window.PlayPilotLinkInjections = {}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('insertInTextDisclaimer', () => {
|
|
24
|
+
it('Should not insert component before the first element in_text_disclaimer_enabled is not given', () => {
|
|
25
|
+
window.PlayPilotLinkInjections.config = {}
|
|
26
|
+
|
|
27
|
+
document.body.innerHTML = `<section>
|
|
28
|
+
<p>Some text</p>
|
|
29
|
+
<p>Some other text</p>
|
|
30
|
+
</section>
|
|
31
|
+
`
|
|
32
|
+
|
|
33
|
+
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
34
|
+
|
|
35
|
+
expect(mount).not.toHaveBeenCalled()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('Should insert component before the first element if config is valid', () => {
|
|
39
|
+
window.PlayPilotLinkInjections.config = {
|
|
40
|
+
in_text_disclaimer_enabled: true,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
document.body.innerHTML = `<section>
|
|
44
|
+
<p>Some text</p>
|
|
45
|
+
<p>Some other text</p>
|
|
46
|
+
</section>
|
|
47
|
+
`
|
|
48
|
+
|
|
49
|
+
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
50
|
+
|
|
51
|
+
expect(mount).toHaveBeenCalled()
|
|
52
|
+
expect(document.querySelector('[data-playpilot-in-text-disclaimer] + p')).toBeTruthy()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('Should insert component before the given selector element if selector is present in config', () => {
|
|
56
|
+
window.PlayPilotLinkInjections.config = {
|
|
57
|
+
in_text_disclaimer_enabled: true,
|
|
58
|
+
in_text_disclaimer_selector: 'strong',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
document.body.innerHTML = `<section>
|
|
62
|
+
<p>Some text</p>
|
|
63
|
+
<strong>Some other text</strong>
|
|
64
|
+
</section>
|
|
65
|
+
`
|
|
66
|
+
|
|
67
|
+
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
68
|
+
|
|
69
|
+
expect(document.querySelector('[data-playpilot-in-text-disclaimer] + strong')).toBeTruthy()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('Should insert component in the given position for the given selector element if position is present in config', () => {
|
|
73
|
+
window.PlayPilotLinkInjections.config = {
|
|
74
|
+
in_text_disclaimer_enabled: true,
|
|
75
|
+
in_text_disclaimer_selector: 'strong',
|
|
76
|
+
in_text_disclaimer_insert_position: 'afterend',
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
document.body.innerHTML = `<section>
|
|
80
|
+
<p>Some text</p>
|
|
81
|
+
<strong>Some other text</strong>
|
|
82
|
+
</section>
|
|
83
|
+
`
|
|
84
|
+
|
|
85
|
+
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
86
|
+
|
|
87
|
+
expect(document.querySelector('strong + [data-playpilot-in-text-disclaimer]')).toBeTruthy()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
+
import { destroyExplore, insertExplore, insertExploreIntoNavigation } from '$lib/explore'
|
|
3
|
+
import { mount, unmount } from 'svelte'
|
|
4
|
+
vi.mock('svelte', () => ({
|
|
5
|
+
mount: vi.fn(() => true),
|
|
6
|
+
unmount: vi.fn(),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
describe('explore.js', () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
destroyExplore()
|
|
12
|
+
|
|
13
|
+
vi.resetAllMocks()
|
|
14
|
+
vi.mocked(mount).mockReturnValue({})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('insertExplore', () => {
|
|
18
|
+
it('Should not call mount when no target element is found', () => {
|
|
19
|
+
insertExplore()
|
|
20
|
+
|
|
21
|
+
expect(mount).not.toHaveBeenCalled()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('Should call mount when target is found', () => {
|
|
25
|
+
document.body.innerHTML = '<div data-playpilot-explore></div>'
|
|
26
|
+
|
|
27
|
+
insertExplore()
|
|
28
|
+
|
|
29
|
+
expect(mount).toHaveBeenCalled()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Should clear any html inside of the element before mount', () => {
|
|
33
|
+
document.body.innerHTML = '<div data-playpilot-explore><span></span></div>'
|
|
34
|
+
|
|
35
|
+
insertExplore()
|
|
36
|
+
|
|
37
|
+
expect(document.querySelector('span')).not.toBeTruthy()
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('destroyExplore', () => {
|
|
42
|
+
it('Should not call unmount if component was not previously mounted', () => {
|
|
43
|
+
destroyExplore()
|
|
44
|
+
|
|
45
|
+
expect(unmount).not.toHaveBeenCalled()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('Should call unmount if component was previously mounted', () => {
|
|
49
|
+
insertExplore()
|
|
50
|
+
destroyExplore()
|
|
51
|
+
|
|
52
|
+
expect(unmount).toHaveBeenCalled()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('insertExploreIntoNavigation', () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
document.body.innerHTML = ''
|
|
59
|
+
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
window.PlayPilotLinkInjections = {}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('Should not insert if config object is not present', () => {
|
|
65
|
+
expect(insertExploreIntoNavigation()).toBe(false)
|
|
66
|
+
|
|
67
|
+
expect(document.body.innerHTML).toBe('')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('Should not insert if config object is present but explore_navigation_selector is not given', () => {
|
|
71
|
+
window.PlayPilotLinkInjections.config = {
|
|
72
|
+
explore_navigation_selector: null,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
expect(insertExploreIntoNavigation()).toBe(false)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('Should not insert if explore_navigation_selector is given but selector captures nothing', () => {
|
|
79
|
+
document.body.innerHTML = '<nav></nav>'
|
|
80
|
+
|
|
81
|
+
window.PlayPilotLinkInjections.config = {
|
|
82
|
+
explore_navigation_selector: 'a',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
expect(insertExploreIntoNavigation()).toBe(false)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('Should insert if explore_navigation_selector is given and selector is valid', () => {
|
|
89
|
+
document.body.innerHTML = '<nav><a></a></nav>'
|
|
90
|
+
|
|
91
|
+
window.PlayPilotLinkInjections.config = {
|
|
92
|
+
explore_navigation_selector: 'a',
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
expect(insertExploreIntoNavigation()).toBe(true)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('Should copy element matching given selector with the given path', () => {
|
|
99
|
+
document.body.innerHTML = '<nav><a></a></nav>'
|
|
100
|
+
|
|
101
|
+
window.PlayPilotLinkInjections.config = {
|
|
102
|
+
explore_navigation_selector: 'a',
|
|
103
|
+
explore_navigation_path: '/explore',
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
insertExploreIntoNavigation()
|
|
107
|
+
|
|
108
|
+
expect(document.body.innerHTML).toBe('<nav><a></a><a class="" href="/explore" data-playpilot-explore-navigation-element="true">Streaming Guide</a></nav>')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('Should copy element matching given selector with text equal to explore_navigation_label', () => {
|
|
112
|
+
document.body.innerHTML = '<nav><a></a></nav>'
|
|
113
|
+
|
|
114
|
+
window.PlayPilotLinkInjections.config = {
|
|
115
|
+
explore_navigation_selector: 'a',
|
|
116
|
+
explore_navigation_label: 'Some label',
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
insertExploreIntoNavigation()
|
|
120
|
+
|
|
121
|
+
const link = document.querySelector('[data-playpilot-explore-navigation-element]')
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
expect(link.innerText).toBe('Some label')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('Should copy element and change link inside of element if the selector was not a link', () => {
|
|
127
|
+
document.body.innerHTML = '<ul><li><a>Link</a></li></ul>'
|
|
128
|
+
|
|
129
|
+
window.PlayPilotLinkInjections.config = {
|
|
130
|
+
explore_navigation_selector: 'li',
|
|
131
|
+
explore_navigation_path: '/explore',
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
insertExploreIntoNavigation()
|
|
135
|
+
|
|
136
|
+
expect(document.body.innerHTML).toBe('<ul><li><a>Link</a></li><li data-playpilot-explore-navigation-element="true"><a class="" href="/explore">Streaming Guide</a></li></ul>')
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { fireEvent } from '@testing-library/svelte'
|
|
2
2
|
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { injectLinksInDocument, clearLinkInjections, clearLinkInjection, getLinkInjectionElements,
|
|
4
|
+
import { injectLinksInDocument, clearLinkInjections, clearLinkInjection, getLinkInjectionElements, getLinkInjectionsParentElement, isAvailableAsManualInjection, filterRemovedAndInactiveInjections, isEquivalentInjection, filterInvalidInTextInjections, filterInvalidAfterArticleInjections, isValidInjection, isValidPlaylinkType, removePlayPilotTitleLinks } from '$lib/injection'
|
|
5
5
|
import { mount, unmount } from 'svelte'
|
|
6
6
|
import { fakeFetch, generateInjection } from '../helpers'
|
|
7
|
-
import {
|
|
8
|
-
import { track } from '$lib/tracking'
|
|
7
|
+
import { openModalForInjectedLink } from '$lib/modal'
|
|
9
8
|
|
|
10
9
|
vi.mock('svelte', () => ({
|
|
11
10
|
mount: vi.fn(),
|
|
@@ -17,6 +16,7 @@ vi.mock('$lib/modal', () => ({
|
|
|
17
16
|
destroyAllModals: vi.fn(),
|
|
18
17
|
getPreviousModal: vi.fn(),
|
|
19
18
|
goBackToPreviousModal: vi.fn(),
|
|
19
|
+
openModalForInjectedLink: vi.fn(),
|
|
20
20
|
}))
|
|
21
21
|
|
|
22
22
|
vi.mock('$lib/tracking', () => ({
|
|
@@ -33,7 +33,7 @@ function mockMatchMedia(matches = false) {
|
|
|
33
33
|
})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
describe('
|
|
36
|
+
describe('injections.js', () => {
|
|
37
37
|
beforeEach(() => {
|
|
38
38
|
vi.resetAllMocks()
|
|
39
39
|
clearLinkInjections()
|
|
@@ -401,7 +401,7 @@ describe('linkInjection.js', () => {
|
|
|
401
401
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('a'))
|
|
402
402
|
await fireEvent.click(link)
|
|
403
403
|
|
|
404
|
-
expect(
|
|
404
|
+
expect(openModalForInjectedLink).toHaveBeenCalled()
|
|
405
405
|
})
|
|
406
406
|
|
|
407
407
|
it('Should not fire given onclick function when clicked with modifier keys or not left click', async () => {
|
|
@@ -1184,158 +1184,6 @@ describe('linkInjection.js', () => {
|
|
|
1184
1184
|
})
|
|
1185
1185
|
})
|
|
1186
1186
|
|
|
1187
|
-
describe('insertAfterArticlePlaylinks', () => {
|
|
1188
|
-
it('Should insert component after given elements', () => {
|
|
1189
|
-
document.body.innerHTML = `<section>
|
|
1190
|
-
<p>Some text</p>
|
|
1191
|
-
<p>Some other text</p>
|
|
1192
|
-
</section>
|
|
1193
|
-
`
|
|
1194
|
-
|
|
1195
|
-
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
1196
|
-
|
|
1197
|
-
const elements = getLinkInjectionElements(document.body)
|
|
1198
|
-
insertAfterArticlePlaylinks(elements, [injection])
|
|
1199
|
-
|
|
1200
|
-
expect(mount).toHaveBeenCalled()
|
|
1201
|
-
expect(document.querySelector('p:last-of-type + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
1202
|
-
})
|
|
1203
|
-
|
|
1204
|
-
it('Should not insert component if no linkInjections were given', () => {
|
|
1205
|
-
document.body.innerHTML = `<section>
|
|
1206
|
-
<div>Some text</div>
|
|
1207
|
-
<div>Some other text</div>
|
|
1208
|
-
</section>
|
|
1209
|
-
`
|
|
1210
|
-
|
|
1211
|
-
const elements = getLinkInjectionElements(document.body)
|
|
1212
|
-
insertAfterArticlePlaylinks(elements, [])
|
|
1213
|
-
|
|
1214
|
-
expect(mount).not.toHaveBeenCalled()
|
|
1215
|
-
expect(document.querySelector('[data-playpilot-after-article-playlinks]')).not.toBeTruthy()
|
|
1216
|
-
})
|
|
1217
|
-
|
|
1218
|
-
it('Should insert after the given element if selector is given in config object', () => {
|
|
1219
|
-
window.PlayPilotLinkInjections.after_article_selector = 'hr'
|
|
1220
|
-
|
|
1221
|
-
document.body.innerHTML = `<section>
|
|
1222
|
-
<div>Some text</div>
|
|
1223
|
-
<hr>
|
|
1224
|
-
<div>Some other text</div>
|
|
1225
|
-
</section>
|
|
1226
|
-
`
|
|
1227
|
-
|
|
1228
|
-
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
1229
|
-
const elements = getLinkInjectionElements(document.body)
|
|
1230
|
-
insertAfterArticlePlaylinks(elements, [injection])
|
|
1231
|
-
|
|
1232
|
-
expect(document.querySelector('hr + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
1233
|
-
})
|
|
1234
|
-
|
|
1235
|
-
it('Should insert in given position if position is given in config object', () => {
|
|
1236
|
-
window.PlayPilotLinkInjections.after_article_insert_position = 'beforebegin'
|
|
1237
|
-
|
|
1238
|
-
document.body.innerHTML = `<section>
|
|
1239
|
-
<div>Some text</div>
|
|
1240
|
-
<hr>
|
|
1241
|
-
<div>Some other text</div>
|
|
1242
|
-
</section>
|
|
1243
|
-
`
|
|
1244
|
-
|
|
1245
|
-
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
1246
|
-
const elements = getLinkInjectionElements(document.body)
|
|
1247
|
-
insertAfterArticlePlaylinks(elements, [injection])
|
|
1248
|
-
|
|
1249
|
-
expect(document.querySelector('hr + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
1250
|
-
})
|
|
1251
|
-
|
|
1252
|
-
it('Should insert in given position for the given element if selector and position are given in config object', () => {
|
|
1253
|
-
window.PlayPilotLinkInjections.after_article_selector = 'hr'
|
|
1254
|
-
window.PlayPilotLinkInjections.after_article_insert_position = 'beforebegin'
|
|
1255
|
-
|
|
1256
|
-
document.body.innerHTML = `<section>
|
|
1257
|
-
<div>Some text</div>
|
|
1258
|
-
<hr>
|
|
1259
|
-
<div>Some other text</div>
|
|
1260
|
-
</section>
|
|
1261
|
-
`
|
|
1262
|
-
|
|
1263
|
-
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
1264
|
-
const elements = getLinkInjectionElements(document.body)
|
|
1265
|
-
insertAfterArticlePlaylinks(elements, [injection])
|
|
1266
|
-
|
|
1267
|
-
expect(document.querySelector('[data-playpilot-after-article-playlinks] + hr')).toBeTruthy()
|
|
1268
|
-
})
|
|
1269
|
-
})
|
|
1270
|
-
|
|
1271
|
-
describe('insertInTextDisclaimer', () => {
|
|
1272
|
-
it('Should not insert component before the first element in_text_disclaimer_enabled is not given', () => {
|
|
1273
|
-
window.PlayPilotLinkInjections.config = {}
|
|
1274
|
-
|
|
1275
|
-
document.body.innerHTML = `<section>
|
|
1276
|
-
<p>Some text</p>
|
|
1277
|
-
<p>Some other text</p>
|
|
1278
|
-
</section>
|
|
1279
|
-
`
|
|
1280
|
-
|
|
1281
|
-
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
1282
|
-
|
|
1283
|
-
expect(mount).not.toHaveBeenCalled()
|
|
1284
|
-
})
|
|
1285
|
-
|
|
1286
|
-
it('Should insert component before the first element if config is valid', () => {
|
|
1287
|
-
window.PlayPilotLinkInjections.config = {
|
|
1288
|
-
in_text_disclaimer_enabled: true,
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
document.body.innerHTML = `<section>
|
|
1292
|
-
<p>Some text</p>
|
|
1293
|
-
<p>Some other text</p>
|
|
1294
|
-
</section>
|
|
1295
|
-
`
|
|
1296
|
-
|
|
1297
|
-
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
1298
|
-
|
|
1299
|
-
expect(mount).toHaveBeenCalled()
|
|
1300
|
-
expect(document.querySelector('[data-playpilot-in-text-disclaimer] + p')).toBeTruthy()
|
|
1301
|
-
})
|
|
1302
|
-
|
|
1303
|
-
it('Should insert component before the given selector element if selector is present in config', () => {
|
|
1304
|
-
window.PlayPilotLinkInjections.config = {
|
|
1305
|
-
in_text_disclaimer_enabled: true,
|
|
1306
|
-
in_text_disclaimer_selector: 'strong',
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
document.body.innerHTML = `<section>
|
|
1310
|
-
<p>Some text</p>
|
|
1311
|
-
<strong>Some other text</strong>
|
|
1312
|
-
</section>
|
|
1313
|
-
`
|
|
1314
|
-
|
|
1315
|
-
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
1316
|
-
|
|
1317
|
-
expect(document.querySelector('[data-playpilot-in-text-disclaimer] + strong')).toBeTruthy()
|
|
1318
|
-
})
|
|
1319
|
-
|
|
1320
|
-
it('Should insert component in the given position for the given selector element if position is present in config', () => {
|
|
1321
|
-
window.PlayPilotLinkInjections.config = {
|
|
1322
|
-
in_text_disclaimer_enabled: true,
|
|
1323
|
-
in_text_disclaimer_selector: 'strong',
|
|
1324
|
-
in_text_disclaimer_insert_position: 'afterend',
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
document.body.innerHTML = `<section>
|
|
1328
|
-
<p>Some text</p>
|
|
1329
|
-
<strong>Some other text</strong>
|
|
1330
|
-
</section>
|
|
1331
|
-
`
|
|
1332
|
-
|
|
1333
|
-
insertInTextDisclaimer(getLinkInjectionElements(document.body))
|
|
1334
|
-
|
|
1335
|
-
expect(document.querySelector('strong + [data-playpilot-in-text-disclaimer]')).toBeTruthy()
|
|
1336
|
-
})
|
|
1337
|
-
})
|
|
1338
|
-
|
|
1339
1187
|
describe('isAvailableAsManualInjection', () => {
|
|
1340
1188
|
it('Should return true if the ai injection has a matching manual injection', () => {
|
|
1341
1189
|
const aiInjection = generateInjection('Some sentence', 'Some title')
|