@playpilot/tpi 5.14.0 → 5.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.
@@ -2,18 +2,23 @@ import { fireEvent, render } from '@testing-library/svelte'
2
2
  import { describe, expect, it, vi } from 'vitest'
3
3
 
4
4
  import Playlink from '../../../routes/components/Playlink.svelte'
5
+ import { hasConsentedTo } from '$lib/consent'
5
6
 
6
7
  vi.mock('$lib/tracking', () => ({
7
8
  track: vi.fn(),
8
9
  }))
9
10
 
11
+ vi.mock('$lib/consent', () => ({
12
+ hasConsentedTo: vi.fn(() => true),
13
+ }))
14
+
10
15
  vi.mock('svelte', async (importActual) => ({
11
16
  ...(await importActual()),
12
17
  getContext: vi.fn(),
13
18
  }))
14
19
 
15
20
  describe('Playlink.svelte', () => {
16
- const playlink = { name: 'Some playlink', logo_url: 'logo', extra_info: { category: 'SVOD' } }
21
+ const playlink = { name: 'Some playlink', logo_url: 'logo', url: 'https://playpilot.com/', extra_info: { category: 'SVOD' } }
17
22
 
18
23
  it('Should render category as words', () => {
19
24
  // @ts-ignore
@@ -93,6 +98,22 @@ describe('Playlink.svelte', () => {
93
98
  expect(getByText('Some action text')).toBeTruthy()
94
99
  })
95
100
 
101
+ it('Should render as link when user has consented to affiliate', () => {
102
+ // @ts-ignore
103
+ const { getByRole } = render(Playlink, { playlink })
104
+
105
+ expect(getByRole('link')).toBeTruthy()
106
+ })
107
+
108
+ it('Should not render as link when user has not consented to affiliate', () => {
109
+ vi.mocked(hasConsentedTo).mockImplementation(() => false)
110
+
111
+ // @ts-ignore
112
+ const { queryByRole } = render(Playlink, { playlink })
113
+
114
+ expect(queryByRole('link')).not.toBeTruthy()
115
+ })
116
+
96
117
  it('Should not render disclaimer when not given', () => {
97
118
  // @ts-ignore
98
119
  const { queryByTestId } = render(Playlink, { disclaimer: '', playlink })
@@ -5,6 +5,11 @@ import TitleModal from '../../../routes/components/TitleModal.svelte'
5
5
  import { title } from '$lib/fakeData'
6
6
  import { track } from '$lib/tracking'
7
7
  import { TrackingEvent } from '$lib/enums/TrackingEvent'
8
+ import { hasConsentedTo } from '$lib/consent'
9
+
10
+ vi.mock('$lib/consent', () => ({
11
+ hasConsentedTo: vi.fn(() => true),
12
+ }))
8
13
 
9
14
  vi.mock('$lib/tracking', () => ({
10
15
  track: vi.fn(),
@@ -13,6 +18,7 @@ vi.mock('$lib/tracking', () => ({
13
18
  describe('TitleModal.svelte', () => {
14
19
  beforeEach(() => {
15
20
  vi.resetAllMocks()
21
+ vi.mocked(hasConsentedTo).mockImplementation(() => true)
16
22
  })
17
23
 
18
24
  afterEach(() => {
@@ -5,6 +5,11 @@ import TitlePopover from '../../../routes/components/TitlePopover.svelte'
5
5
  import { title } from '$lib/fakeData'
6
6
  import { track } from '$lib/tracking'
7
7
  import { TrackingEvent } from '$lib/enums/TrackingEvent'
8
+ import { hasConsentedTo } from '$lib/consent'
9
+
10
+ vi.mock('$lib/consent', () => ({
11
+ hasConsentedTo: vi.fn(() => true),
12
+ }))
8
13
 
9
14
  vi.mock('$lib/tracking', () => ({
10
15
  track: vi.fn(),
@@ -13,6 +18,7 @@ vi.mock('$lib/tracking', () => ({
13
18
  describe('TitlePopover.svelte', () => {
14
19
  beforeEach(() => {
15
20
  vi.resetAllMocks()
21
+ vi.mocked(hasConsentedTo).mockImplementation(() => true)
16
22
  })
17
23
 
18
24
  afterEach(() => {
@@ -1,7 +1,12 @@
1
1
  import { render } from '@testing-library/svelte'
2
- import { describe, expect, it } from 'vitest'
2
+ import { describe, expect, it, vi } from 'vitest'
3
3
 
4
4
  import TrackingPixels from '../../../routes/components/TrackingPixels.svelte'
5
+ import { hasConsentedTo } from '$lib/consent'
6
+
7
+ vi.mock('$lib/consent', () => ({
8
+ hasConsentedTo: vi.fn(() => true),
9
+ }))
5
10
 
6
11
  describe('TrackingPixels.svelte', () => {
7
12
  it('Should render all given pixels', () => {
@@ -12,4 +17,13 @@ describe('TrackingPixels.svelte', () => {
12
17
  expect(/** @type {HTMLImageElement} */ (getAllByRole('presentation')[0]).src).toBe('https://image.com/a.jpg')
13
18
  expect(/** @type {HTMLImageElement} */ (getAllByRole('presentation')[1]).src).toBe('https://image.com/b.jpg')
14
19
  })
20
+
21
+ it('Should not render any pixels when user has not consented', () => {
22
+ vi.mocked(hasConsentedTo).mockImplementation(() => false)
23
+
24
+ const pixels = ['https://image.com/a.jpg', 'https://image.com/b.jpg']
25
+ const { queryByRole } = render(TrackingPixels, { pixels })
26
+
27
+ expect(queryByRole('presentation')).not.toBeTruthy()
28
+ })
15
29
  })
@@ -73,7 +73,20 @@ beforeAll(() => {
73
73
 
74
74
  beforeEach(() => {
75
75
  // @ts-ignore
76
- window.PlayPilotLinkInjections = { token: 'some-token' }
76
+ window.PlayPilotLinkInjections = { token: 'some-token', require_consent: false }
77
+
78
+ // Enable all consent
79
+ // @ts-ignore
80
+ window.__tcfapi = (command, _version, callback) => {
81
+ if (command !== 'addEventListener') return
82
+
83
+ setTimeout(() => callback({
84
+ purpose: { consents: { 1: true, 2: true, 7: true, 8: true, 9: true, 10: true } },
85
+ eventStatus: 'tcloaded',
86
+ }, true), 0)
87
+
88
+ return 1
89
+ }
77
90
 
78
91
  // Reset cookies
79
92
  document.cookie.split(';').forEach((cookie) => document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, '=;'))