@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.29.0",
3
+ "version": "8.29.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -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
 
@@ -19,6 +19,7 @@
19
19
  explore_navigation_path: '/explore',
20
20
  explore_custom_style: 'main { border: 2px solid white }',
21
21
  explore_use_router: true,
22
+ open_tpi_links_in_explore: true,
22
23
  },
23
24
  require_consent: false,
24
25
  }
@@ -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
- document.body.innerHTML = ''
26
- })
27
-
28
- it('Should render each given participant', async () => {
29
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
30
-
31
- const { getByText } = render(ParticipantsRail, { title })
32
-
33
- await waitFor(() => {
34
- expect(getByText(participants[0].name)).toBeTruthy()
35
- expect(getByText(participants[1].name)).toBeTruthy()
36
- })
37
- })
38
-
39
- it('Should render image only for participants with image', async () => {
40
- const participantsWithImage = [...participants]
41
- participantsWithImage[0].image = 'some-image.jpg'
42
-
43
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participantsWithImage)
44
-
45
- const { getAllByRole } = render(ParticipantsRail, { title })
46
-
47
- await waitFor(() => {
48
- expect(getAllByRole('presentation')).toHaveLength(1)
49
- })
50
- })
51
-
52
- it('Should order participants by their number of occurrences on the page', async () => {
53
- document.body.innerHTML = `<main>${participants[1].name}. ${participants[2].name}, ${participants[2].name}</main>`
54
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
55
-
56
- const { getAllByTestId } = render(ParticipantsRail, { title })
57
-
58
- await waitFor(() => {
59
- expect(getAllByTestId('participant')[0].innerText).toContain(participants[2].name)
60
- expect(getAllByTestId('participant')[1].innerText).toContain(participants[1].name)
61
- expect(getAllByTestId('participant')[2].innerText).toContain(participants[0].name)
62
- })
63
- })
64
-
65
- it('Should not render when no participants are returned', async () => {
66
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce([])
67
-
68
- const { container } = render(ParticipantsRail)
69
-
70
- await waitFor(() => {
71
- expect(container.querySelectorAll('.participant').length).toBe(0)
72
- })
73
- })
74
-
75
- it('Should open modal on click of participant', async () => {
76
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
77
-
78
- const { getAllByTestId } = render(ParticipantsRail, { title })
79
-
80
- await waitFor(async () => {
81
- await fireEvent.click(getAllByTestId('participant')[0])
82
- })
83
-
84
- expect(openModal).toHaveBeenCalledWith({ event: expect.any(Object), type: 'participant', data: participants[0] })
85
- })
86
-
87
- it('Should fire track event on click of participant', async () => {
88
- vi.mocked(fetchParticipantsForTitle).mockResolvedValueOnce(participants)
89
-
90
- const { getAllByTestId } = render(ParticipantsRail, { title })
91
-
92
- await waitFor(async () => {
93
- await fireEvent.click(getAllByTestId('participant')[0])
94
- })
95
-
96
- expect(track).toHaveBeenCalledWith(TrackingEvent.ParticipantClick, null, { title_source: title.original_title, participant: participants[0].name })
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
+ })