@playpilot/tpi 8.41.0-beta.1 → 8.41.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.
@@ -1,166 +1,156 @@
1
- import { fireEvent, render } from '@testing-library/svelte'
2
- import { describe, expect, it, vi } from 'vitest'
3
-
4
- import Display from '../../../../routes/components/Ads/Display.svelte'
5
- import { track } from '$lib/tracking'
6
- import { TrackingEvent } from '$lib/enums/TrackingEvent'
7
-
8
- vi.mock('$lib/tracking', () => ({
9
- track: vi.fn(),
10
- }))
11
-
12
- export const campaign = {
13
- campaign_format: 'display',
14
- campaign_type: 'image',
15
- campaign_platforms: ['web', 'android_app', 'ios_app'],
16
- campaign_name: 'some_campaign_NL',
17
- campaign_start: '2025-04-24T00:00:00Z',
18
- campaign_end: '2025-04-30T23:59:00Z',
19
- campaign_region: 'nl',
20
- content: {
21
- header: 'Some top scroll header',
22
- header_logo: 'https://example.com/',
23
- header_logo_uuid: '4fb7d6ea152111f08dd20a58a9feac02',
24
- subheader: null,
25
- image: 'https://example.com/',
26
- image_uuid: '4fb7d6ea152111f08dd20a58a9feac02',
27
- video: null,
28
- format: null,
29
- },
30
- cta: {
31
- header: 'Button Label',
32
- subheader: null,
33
- image: null,
34
- image_uuid: null,
35
- url: 'https://google.com/',
36
- },
37
- content_playlist: null,
38
- provider: null,
39
- impression_trackers: [],
40
- target_title_uuid: null,
41
- target_title_sid: null,
42
- backfill_providers: [],
43
- autogenerated: false,
44
- enabled: true,
45
- hide_imdb_score: false,
46
- hide_sponsored_message: false,
47
- disclaimer: 'Some disclaimer',
48
- }
49
-
50
- describe('Display.svelte', () => {
51
- it('Should fire track event on mount', () => {
52
- /** @ts-ignore */
53
- render(Display, { campaign })
54
-
55
- expect(track).toHaveBeenCalledWith(TrackingEvent.DisplayAdView, null, { campaign_name: campaign.campaign_name })
56
- })
57
-
58
- it('Should fire track event on click', async () => {
59
- /** @ts-ignore */
60
- const { getByRole } = render(Display, { campaign })
61
-
62
- vi.resetAllMocks()
63
-
64
- await fireEvent.click(getByRole('link'))
65
- expect(track).toHaveBeenCalledWith(TrackingEvent.DisplayAdClick, null, { campaign_name: campaign.campaign_name })
66
- expect(track).toHaveBeenCalledTimes(1)
67
-
68
- await fireEvent.mouseUp(getByRole('link'), { button: 1 })
69
- expect(track).toHaveBeenCalledTimes(2)
70
- })
71
-
72
- it('Should render link without any content by default', () => {
73
- /** @ts-ignore */
74
- const { container } = render(Display, { campaign: { cta: {}, content: {} } })
75
-
76
- expect(/** @type {HTMLAnchorElement} */ (container.querySelector('a'))).toBeTruthy()
77
- expect(/** @type {HTMLAnchorElement} */ (container.querySelector('a')).children).toHaveLength(0)
78
- })
79
-
80
- it('Should render disclaimer when given', () => {
81
- /** @ts-ignore */
82
- const { getByTestId } = render(Display, { campaign: { disclaimer: 'Some disclaimer', cta: {}, content: {} } })
83
-
84
- expect(getByTestId('disclaimer')).toBeTruthy()
85
- })
86
-
87
- it('Should render content subheader when given', () => {
88
- /** @ts-ignore */
89
- const { getByText } = render(Display, { campaign: { cta: { subheader: 'Some cta subheader' }, content: {} } })
90
-
91
- expect(getByText('Some cta subheader')).toBeTruthy()
92
- })
93
-
94
- it('Should render logo when given', () => {
95
- /** @ts-ignore */
96
- const { getByRole } = render(Display, { campaign: { cta: {}, content: { header_logo: 'test' } } })
97
-
98
- expect(getByRole('presentation').getAttribute('src')).toBe('test')
99
- })
100
-
101
- it('Should render background image when given', () => {
102
- /** @ts-ignore */
103
- const { getByRole } = render(Display, { campaign: { campaign_type: 'image', cta: {}, content: { image: 'test' } } })
104
-
105
- expect(getByRole('presentation').getAttribute('src')).toBe('test')
106
- })
107
-
108
- it('Should render header when given', () => {
109
- /** @ts-ignore */
110
- const { getByText } = render(Display, { campaign: { cta: {}, content: { header: 'Some header' } } })
111
-
112
- expect(getByText('Some header')).toBeTruthy()
113
- })
114
-
115
- it('Should render subheader when given', () => {
116
- /** @ts-ignore */
117
- const { getByText } = render(Display, { campaign: { cta: {}, content: { header: 'Some subheader' } } })
118
-
119
- expect(getByText('Some subheader')).toBeTruthy()
120
- })
121
-
122
- it('Should render button when cta header is given', () => {
123
- /** @ts-ignore */
124
- const { getByText } = render(Display, { campaign: { cta: { header: 'Some button label' }, content: {} } })
125
-
126
- expect(getByText('Some button label')).toBeTruthy()
127
- })
128
-
129
- it('Should not have compact class by default', () => {
130
- /** @ts-ignore */
131
- const { getByRole } = render(Display, { campaign })
132
-
133
- expect(getByRole('link').classList).not.toContain('compact')
134
- })
135
-
136
- it('Should have compact class when prop is given', () => {
137
- /** @ts-ignore */
138
- const { getByRole } = render(Display, { campaign, compact: true })
139
-
140
- expect(getByRole('link').classList).toContain('compact')
141
- })
142
-
143
- it('Should not show disclaimer text when compact', () => {
144
- /** @ts-ignore */
145
- const { queryByText } = render(Display, { compact: true, campaign: { disclaimer: 'Some disclaimer', cta: {}, content: {} } })
146
-
147
- expect(queryByText('Some disclaimer')).not.toBeTruthy()
148
- })
149
-
150
- it('Should render video rather than image when video is given as type', () => {
151
- /** @ts-ignore */
152
- const { container } = render(Display, { campaign: { campaign_type: 'video', cta: {}, content: { video: 'abc' } } })
153
-
154
- expect(container.querySelector('video')).toBeTruthy()
155
- })
156
-
157
- it('Should render with expected content when slim variant is given', () => {
158
- /** @ts-ignore */
159
- const { container, queryByText } = render(Display, { slim: true, campaign: { campaign_type: 'video', cta: { header: 'Some header', subheader: 'Some cta subheader' }, content: { header_logo: 'dfg', video: 'abc' } } })
160
-
161
- expect(container.querySelector('.slim')).toBeTruthy()
162
- expect(container.querySelector('.logo')).toBeTruthy()
163
- expect(queryByText('Some header')).toBeTruthy()
164
- expect(queryByText('Some cta header')).not.toBeTruthy()
165
- })
166
- })
1
+ import { fireEvent, render } from '@testing-library/svelte'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+
4
+ import Display from '../../../../routes/components/Ads/Display.svelte'
5
+ import { track } from '$lib/tracking'
6
+ import { TrackingEvent } from '$lib/enums/TrackingEvent'
7
+
8
+ vi.mock('$lib/tracking', () => ({
9
+ track: vi.fn(),
10
+ }))
11
+
12
+ export const campaign = {
13
+ campaign_format: 'display',
14
+ campaign_type: 'image',
15
+ campaign_platforms: ['web', 'android_app', 'ios_app'],
16
+ campaign_name: 'some_campaign_NL',
17
+ campaign_start: '2025-04-24T00:00:00Z',
18
+ campaign_end: '2025-04-30T23:59:00Z',
19
+ campaign_region: 'nl',
20
+ content: {
21
+ header: 'Some top scroll header',
22
+ header_logo: 'https://example.com/',
23
+ header_logo_uuid: '4fb7d6ea152111f08dd20a58a9feac02',
24
+ subheader: null,
25
+ image: 'https://example.com/',
26
+ image_uuid: '4fb7d6ea152111f08dd20a58a9feac02',
27
+ video: null,
28
+ format: null,
29
+ },
30
+ cta: {
31
+ header: 'Button Label',
32
+ subheader: null,
33
+ image: null,
34
+ image_uuid: null,
35
+ url: 'https://google.com/',
36
+ },
37
+ content_playlist: null,
38
+ provider: null,
39
+ impression_trackers: [],
40
+ target_title_uuid: null,
41
+ target_title_sid: null,
42
+ backfill_providers: [],
43
+ autogenerated: false,
44
+ enabled: true,
45
+ hide_imdb_score: false,
46
+ hide_sponsored_message: false,
47
+ disclaimer: 'Some disclaimer',
48
+ }
49
+
50
+ describe('Display.svelte', () => {
51
+ it('Should fire track event on mount', () => {
52
+ /** @ts-ignore */
53
+ render(Display, { campaign })
54
+
55
+ expect(track).toHaveBeenCalledWith(TrackingEvent.DisplayAdView, null, { campaign_name: campaign.campaign_name })
56
+ })
57
+
58
+ it('Should fire track event on click', async () => {
59
+ /** @ts-ignore */
60
+ const { getByRole } = render(Display, { campaign })
61
+
62
+ vi.resetAllMocks()
63
+
64
+ await fireEvent.click(getByRole('link'))
65
+ expect(track).toHaveBeenCalledWith(TrackingEvent.DisplayAdClick, null, { campaign_name: campaign.campaign_name })
66
+ expect(track).toHaveBeenCalledTimes(1)
67
+
68
+ await fireEvent.mouseUp(getByRole('link'), { button: 1 })
69
+ expect(track).toHaveBeenCalledTimes(2)
70
+ })
71
+
72
+ it('Should render link without any content by default', () => {
73
+ /** @ts-ignore */
74
+ const { container } = render(Display, { campaign: { cta: {}, content: {} } })
75
+
76
+ expect(/** @type {HTMLAnchorElement} */ (container.querySelector('a'))).toBeTruthy()
77
+ expect(/** @type {HTMLAnchorElement} */ (container.querySelector('a')).children).toHaveLength(0)
78
+ })
79
+
80
+ it('Should render disclaimer when given', () => {
81
+ /** @ts-ignore */
82
+ const { getByTestId } = render(Display, { campaign: { disclaimer: 'Some disclaimer', cta: {}, content: {} } })
83
+
84
+ expect(getByTestId('disclaimer')).toBeTruthy()
85
+ })
86
+
87
+ it('Should render content subheader when given', () => {
88
+ /** @ts-ignore */
89
+ const { getByText } = render(Display, { campaign: { cta: { subheader: 'Some cta subheader' }, content: { } } })
90
+
91
+ expect(getByText('Some cta subheader')).toBeTruthy()
92
+ })
93
+
94
+ it('Should render logo when given', () => {
95
+ /** @ts-ignore */
96
+ const { getByRole } = render(Display, { campaign: { cta: {}, content: { header_logo: 'test' } } })
97
+
98
+ expect(getByRole('presentation').getAttribute('src')).toBe('test')
99
+ })
100
+
101
+ it('Should render background image when given', () => {
102
+ /** @ts-ignore */
103
+ const { getByRole } = render(Display, { campaign: { campaign_type: 'image', cta: {}, content: { image: 'test' } } })
104
+
105
+ expect(getByRole('presentation').getAttribute('src')).toBe('test')
106
+ })
107
+
108
+ it('Should render header when given', () => {
109
+ /** @ts-ignore */
110
+ const { getByText } = render(Display, { campaign: { cta: {}, content: { header: 'Some header' } } })
111
+
112
+ expect(getByText('Some header')).toBeTruthy()
113
+ })
114
+
115
+ it('Should render subheader when given', () => {
116
+ /** @ts-ignore */
117
+ const { getByText } = render(Display, { campaign: { cta: {}, content: { header: 'Some subheader' } } })
118
+
119
+ expect(getByText('Some subheader')).toBeTruthy()
120
+ })
121
+
122
+ it('Should render button when cta header is given', () => {
123
+ /** @ts-ignore */
124
+ const { getByText } = render(Display, { campaign: { cta: { header: 'Some button label' }, content: {} } })
125
+
126
+ expect(getByText('Some button label')).toBeTruthy()
127
+ })
128
+
129
+ it('Should not have compact class by default', () => {
130
+ /** @ts-ignore */
131
+ const { getByRole } = render(Display, { campaign })
132
+
133
+ expect(getByRole('link').classList).not.toContain('compact')
134
+ })
135
+
136
+ it('Should have compact class when prop is given', () => {
137
+ /** @ts-ignore */
138
+ const { getByRole } = render(Display, { campaign, compact: true })
139
+
140
+ expect(getByRole('link').classList).toContain('compact')
141
+ })
142
+
143
+ it('Should not show disclaimer text when compact', () => {
144
+ /** @ts-ignore */
145
+ const { queryByText } = render(Display, { compact: true, campaign: { disclaimer: 'Some disclaimer', cta: {}, content: {} } })
146
+
147
+ expect(queryByText('Some disclaimer')).not.toBeTruthy()
148
+ })
149
+
150
+ it('Should render video rather than image when video is given as type', () => {
151
+ /** @ts-ignore */
152
+ const { container } = render(Display, { campaign: { campaign_type: 'video', cta: {}, content: { video: 'abc' } } })
153
+
154
+ expect(container.querySelector('video')).toBeTruthy()
155
+ })
156
+ })