@playpilot/tpi 8.29.0 → 8.29.2
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 +8 -8
- package/dist/link-injections.js +1 -1
- package/dist/mount.js +6 -6
- package/package.json +1 -1
- package/src/routes/components/Rails/ParticipantsRail.svelte +11 -1
- package/src/routes/explore/+page.svelte +1 -0
- package/src/tests/routes/components/Rails/ParticipantsRail.test.js +122 -98
package/package.json
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
import { track } from '$lib/tracking'
|
|
9
9
|
import type { ParticipantData } from '$lib/types/participant'
|
|
10
10
|
import type { TitleData } from '$lib/types/title'
|
|
11
|
+
import { getContext } from 'svelte'
|
|
11
12
|
import ParticipantImage from '../Participants/ParticipantImage.svelte'
|
|
12
13
|
import Rail from './Rail.svelte'
|
|
14
|
+
import { exploreModalUrl } from '$lib/routes'
|
|
13
15
|
|
|
14
16
|
interface Props {
|
|
15
17
|
title: TitleData
|
|
@@ -18,6 +20,8 @@
|
|
|
18
20
|
|
|
19
21
|
const { title, heading = t('Cast') }: Props = $props()
|
|
20
22
|
|
|
23
|
+
const navigate: Function | undefined = getContext('navigate')
|
|
24
|
+
|
|
21
25
|
/**
|
|
22
26
|
* Order participants by how often their name appears in an the page text. This only takes into account
|
|
23
27
|
* their full name. If an actor is mentioned by first name only, which is often the case, they won't get
|
|
@@ -42,8 +46,14 @@
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
function onclick(event: MouseEvent, participant: ParticipantData): void {
|
|
45
|
-
openModal({ event, type: 'participant', data: participant })
|
|
46
49
|
track(TrackingEvent.ParticipantClick, null, { title_source: title.original_title || title.title, participant: participant.name })
|
|
50
|
+
|
|
51
|
+
if (!window.PlayPilotLinkInjections?.config?.open_tpi_links_in_explore || window.location.href.includes(window.PlayPilotLinkInjections.config.explore_navigation_path || '')) {
|
|
52
|
+
openModal({ event, type: 'participant', data: participant })
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
window.location.href = exploreModalUrl(participant.sid)
|
|
47
57
|
}
|
|
48
58
|
</script>
|
|
49
59
|
|
|
@@ -1,98 +1,122 @@
|
|
|
1
|
-
import { fireEvent, render, waitFor } from '@testing-library/svelte'
|
|
2
|
-
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import ParticipantsRail from '../../../../routes/components/Rails/ParticipantsRail.svelte'
|
|
5
|
-
import { openModal } from '$lib/modal'
|
|
6
|
-
import { participants, title } from '$lib/fakeData'
|
|
7
|
-
import { track } from '$lib/tracking'
|
|
8
|
-
import { TrackingEvent } from '$lib/enums/TrackingEvent'
|
|
9
|
-
import { fetchParticipantsForTitle } from '$lib/api/participants'
|
|
10
|
-
|
|
11
|
-
vi.mock('$lib/modal', () => ({
|
|
12
|
-
openModal: vi.fn(),
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
vi.mock('$lib/tracking', () => ({
|
|
16
|
-
track: vi.fn(),
|
|
17
|
-
}))
|
|
18
|
-
|
|
19
|
-
vi.mock('$lib/api/participants', () => ({
|
|
20
|
-
fetchParticipantsForTitle: vi.fn(),
|
|
21
|
-
}))
|
|
22
|
-
|
|
23
|
-
describe('ParticipantsRail.svelte', () => {
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
1
|
+
import { fireEvent, render, waitFor } from '@testing-library/svelte'
|
|
2
|
+
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import ParticipantsRail from '../../../../routes/components/Rails/ParticipantsRail.svelte'
|
|
5
|
+
import { openModal } from '$lib/modal'
|
|
6
|
+
import { participants, title } from '$lib/fakeData'
|
|
7
|
+
import { track } from '$lib/tracking'
|
|
8
|
+
import { TrackingEvent } from '$lib/enums/TrackingEvent'
|
|
9
|
+
import { fetchParticipantsForTitle } from '$lib/api/participants'
|
|
10
|
+
|
|
11
|
+
vi.mock('$lib/modal', () => ({
|
|
12
|
+
openModal: vi.fn(),
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
vi.mock('$lib/tracking', () => ({
|
|
16
|
+
track: vi.fn(),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
vi.mock('$lib/api/participants', () => ({
|
|
20
|
+
fetchParticipantsForTitle: vi.fn(),
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
describe('ParticipantsRail.svelte', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
vi.resetAllMocks()
|
|
26
|
+
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
window.PlayPilotLinkInjections = {}
|
|
29
|
+
document.body.innerHTML = ''
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Should render each given participant', async () => {
|
|
33
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
34
|
+
|
|
35
|
+
const { getByText } = render(ParticipantsRail, { title })
|
|
36
|
+
|
|
37
|
+
await waitFor(() => {
|
|
38
|
+
expect(getByText(participants[0].name)).toBeTruthy()
|
|
39
|
+
expect(getByText(participants[1].name)).toBeTruthy()
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('Should render image only for participants with image', async () => {
|
|
44
|
+
const participantsWithImage = [...participants]
|
|
45
|
+
participantsWithImage[0].image = 'some-image.jpg'
|
|
46
|
+
|
|
47
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participantsWithImage)
|
|
48
|
+
|
|
49
|
+
const { getAllByRole } = render(ParticipantsRail, { title })
|
|
50
|
+
|
|
51
|
+
await waitFor(() => {
|
|
52
|
+
expect(getAllByRole('presentation')).toHaveLength(1)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('Should order participants by their number of occurrences on the page', async () => {
|
|
57
|
+
document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
|
|
58
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
59
|
+
|
|
60
|
+
const { getAllByTestId } = render(ParticipantsRail, { title })
|
|
61
|
+
|
|
62
|
+
await waitFor(() => {
|
|
63
|
+
expect(getAllByTestId('participant')[0].innerText).toContain(participants[2].name)
|
|
64
|
+
expect(getAllByTestId('participant')[1].innerText).toContain(participants[1].name)
|
|
65
|
+
expect(getAllByTestId('participant')[2].innerText).toContain(participants[0].name)
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('Should not render when no participants are returned', async () => {
|
|
70
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce([])
|
|
71
|
+
|
|
72
|
+
const { container } = render(ParticipantsRail)
|
|
73
|
+
|
|
74
|
+
await waitFor(() => {
|
|
75
|
+
expect(container.querySelectorAll('.participant').length).toBe(0)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('Should open modal on click of participant', async () => {
|
|
80
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
81
|
+
|
|
82
|
+
const { getAllByTestId } = render(ParticipantsRail, { title })
|
|
83
|
+
|
|
84
|
+
await waitFor(async () => {
|
|
85
|
+
await fireEvent.click(getAllByTestId('participant')[0])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
expect(openModal).toHaveBeenCalledWith({ event: expect.any(Object), type: 'participant', data: participants[0] })
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('Should not open modal on click if if open_tpi_links_in_explore is true and instead set url', async () => {
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
window.PlayPilotLinkInjections = {
|
|
94
|
+
config: {
|
|
95
|
+
open_tpi_links_in_explore: true,
|
|
96
|
+
explore_navigation_path: 'some-explore-url.com'
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
101
|
+
|
|
102
|
+
const { getAllByTestId } = render(ParticipantsRail, { title })
|
|
103
|
+
|
|
104
|
+
await waitFor(async () => {
|
|
105
|
+
await fireEvent.click(getAllByTestId('participant')[0])
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
expect(openModal).not.toHaveBeenCalled()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('Should fire track event on click of participant', async () => {
|
|
112
|
+
vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
|
|
113
|
+
|
|
114
|
+
const { getAllByTestId } = render(ParticipantsRail, { title })
|
|
115
|
+
|
|
116
|
+
await waitFor(async () => {
|
|
117
|
+
await fireEvent.click(getAllByTestId('participant')[0])
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
expect(track).toHaveBeenCalledWith(TrackingEvent.ParticipantClick, null, { title_source: title.original_title, participant: participants[0].name })
|
|
121
|
+
})
|
|
122
|
+
})
|