@playpilot/tpi 8.14.0 → 8.15.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 +8 -8
- package/package.json +1 -1
- package/src/lib/api/externalPages.ts +0 -7
- package/src/lib/api/titles.ts +10 -0
- package/src/lib/data/translations.ts +5 -0
- package/src/lib/injection.ts +13 -3
- package/src/lib/routes.ts +4 -0
- package/src/lib/types/config.d.ts +5 -0
- package/src/lib/types/explore.d.ts +1 -0
- package/src/routes/components/Description.svelte +1 -0
- package/src/routes/components/Explore/ExploreRouter.svelte +38 -2
- package/src/routes/components/Explore/Routes/ExploreModal.svelte +38 -0
- package/src/routes/components/Explore/Routes/ExploreResults.svelte +12 -2
- package/src/routes/components/Explore/Routes/ExploreTitle.svelte +94 -0
- package/src/routes/components/Modals/Modal.svelte +3 -1
- package/src/routes/components/Modals/RailModal.svelte +4 -3
- package/src/routes/components/Modals/TitlesRailModal.svelte +5 -4
- package/src/routes/components/Playlinks/Playlinks.svelte +1 -0
- package/src/routes/components/Title.svelte +12 -4
- package/src/routes/explore/+page.svelte +4 -0
- package/src/tests/lib/api/titles.test.js +23 -1
- package/src/tests/lib/injection.test.js +44 -3
- package/src/tests/lib/routes.test.js +14 -2
- package/src/tests/routes/components/Explore/Routes/ExploreTitle.test.js +87 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { titleUrl } from '$lib/routes'
|
|
2
|
+
import { exploreTitleUrl, titleUrl } from '$lib/routes'
|
|
3
3
|
import { playPilotBaseUrl } from '$lib/constants'
|
|
4
|
+
import { title } from '$lib/fakeData'
|
|
4
5
|
|
|
5
6
|
describe('$lib/routes', () => {
|
|
6
|
-
describe('
|
|
7
|
+
describe('titleUrl', () => {
|
|
7
8
|
it('Should return url for given title', () => {
|
|
8
9
|
// @ts-ignore
|
|
9
10
|
expect(titleUrl({ type: 'series', slug: 'some-slug' })).toBe(`${playPilotBaseUrl}/series/some-slug/`)
|
|
@@ -12,4 +13,15 @@ describe('$lib/routes', () => {
|
|
|
12
13
|
expect(titleUrl({ type: 'movie', slug: 'some-other-slug' })).toBe(`${playPilotBaseUrl}/movie/some-other-slug/`)
|
|
13
14
|
})
|
|
14
15
|
})
|
|
16
|
+
|
|
17
|
+
describe('exploreTitleUrl', () => {
|
|
18
|
+
it('Should return url for given title', () => {
|
|
19
|
+
window.PlayPilotLinkInjections.config = {
|
|
20
|
+
open_tpi_links_in_explore: true,
|
|
21
|
+
explore_navigation_path: 'https://some-path.com/explore',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
expect(exploreTitleUrl(title)).toBe(`https://some-path.com/explore?route=title&sid=${title.sid}`)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
15
27
|
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { render, waitFor, fireEvent } from '@testing-library/svelte'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import TitleDetail from '../../../../../routes/components/Explore/Routes/ExploreTitle.svelte'
|
|
5
|
+
import { fetchTitleBySid } from '$lib/api/titles'
|
|
6
|
+
import { title } from '$lib/fakeData'
|
|
7
|
+
|
|
8
|
+
vi.mock('$lib/api/titles', () => ({
|
|
9
|
+
fetchTitleBySid: vi.fn(),
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
vi.mock('/src/routes/components/Title.svelte', () => ({
|
|
13
|
+
default: vi.fn(),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe('ExploreTitle.svelte', () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
vi.resetAllMocks()
|
|
19
|
+
vi.mocked(fetchTitleBySid).mockResolvedValue(title)
|
|
20
|
+
|
|
21
|
+
history.pushState({}, '', '/')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('Should render empty state when no sid is in the URL', async () => {
|
|
25
|
+
const { getByText } = render(TitleDetail)
|
|
26
|
+
|
|
27
|
+
await waitFor(() => {
|
|
28
|
+
expect(getByText('Page not found')).toBeTruthy()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Should call fetchTitleBySid with sid from URL', async () => {
|
|
33
|
+
history.pushState({}, '', '?sid=some-sid')
|
|
34
|
+
|
|
35
|
+
render(TitleDetail)
|
|
36
|
+
|
|
37
|
+
expect(fetchTitleBySid).toHaveBeenCalledWith('some-sid')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('Should render loading state while fetching', async () => {
|
|
41
|
+
history.pushState({}, '', '?sid=some-sid')
|
|
42
|
+
vi.mocked(fetchTitleBySid).mockReturnValue(new Promise(() => {}))
|
|
43
|
+
|
|
44
|
+
const { getByText } = render(TitleDetail)
|
|
45
|
+
|
|
46
|
+
expect(getByText('Loading...')).toBeTruthy()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('Should render the title when fetchTitleBySid resolves', async () => {
|
|
50
|
+
history.pushState({}, '', '?sid=some-sid')
|
|
51
|
+
|
|
52
|
+
const { getByTestId } = render(TitleDetail)
|
|
53
|
+
|
|
54
|
+
await waitFor(() => {
|
|
55
|
+
expect(getByTestId('title')).toBeTruthy()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('Should render empty state when fetchTitleBySid rejects', async () => {
|
|
60
|
+
history.pushState({}, '', '?sid=some-sid')
|
|
61
|
+
vi.mocked(fetchTitleBySid).mockRejectedValue(new Error('Not found'))
|
|
62
|
+
|
|
63
|
+
const { getByText } = render(TitleDetail)
|
|
64
|
+
|
|
65
|
+
await waitFor(() => {
|
|
66
|
+
expect(getByText('Page not found')).toBeTruthy()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('Should call navigate with "home" when back button is clicked', async () => {
|
|
71
|
+
history.pushState({}, '', '?sid=some-sid')
|
|
72
|
+
|
|
73
|
+
const navigate = vi.fn()
|
|
74
|
+
|
|
75
|
+
const { getByText } = render(TitleDetail, { navigate })
|
|
76
|
+
|
|
77
|
+
await fireEvent.click(getByText('Home'))
|
|
78
|
+
|
|
79
|
+
expect(navigate).toHaveBeenCalledWith('home')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('Should not call fetchTitleBySid when no sid is in the URL', async () => {
|
|
83
|
+
render(TitleDetail)
|
|
84
|
+
|
|
85
|
+
expect(fetchTitleBySid).not.toHaveBeenCalled()
|
|
86
|
+
})
|
|
87
|
+
})
|