-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathindex.js
156 lines (137 loc) · 4.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {
ATI_PAGE_VIEW,
getATIParamsFromURL,
interceptATIAnalyticsBeacons,
} from '../helpers';
const assertATIPageViewEventParamsExist = ({
params,
contentType,
applicationType,
}) => {
expect(params).to.have.property('s'); // destination
expect(params).to.have.property('s2'); // producer
expect(params).to.have.property('p'); // page identifier
expect(params).to.have.property('x2'); // application type
expect(params).to.have.property('x3'); // application name
expect(params).to.have.property('x4'); // language
expect(params).to.have.property('x7'); // content type
expect(params).to.have.property('x8'); // library version
expect(params).to.have.property('x9'); // page title
if (['responsive', 'amp'].includes(applicationType)) {
expect(params).to.have.property('r'); // screen resolution & colour depth
expect(params).to.have.property('re'); // browser/viewport resolution
expect(params).to.have.property('hl'); // timestamp
expect(params).to.have.property('lng'); // device language
expect(params).to.have.property('x5'); // url
}
if (contentType !== 'list-datadriven') {
expect(params).to.have.property('x1'); // content ID
}
if (contentType === 'article') {
expect(params).to.have.property('x11'); // first published
expect(params).to.have.property('x12'); // last published
expect(params).to.have.property('x13'); // ldp things
expect(params).to.have.property('x17'); // category
}
};
const assertATIComponentViewEventParamsExist = params => {
expect(params).to.have.property('s'); // destination
expect(params).to.have.property('s2'); // producer
expect(params).to.have.property('p'); // page identifier
expect(params).to.have.property('ati'); // view event
expect(params).to.have.property('type');
expect(params.type).to.equal('AT', 'params.type');
};
const assertATIComponentClickEventParamsExist = params => {
expect(params).to.have.property('s'); // destination
expect(params).to.have.property('s2'); // producer
expect(params).to.have.property('p'); // page identifier
expect(params).to.have.property('atc'); // click event
expect(params).to.have.property('type');
expect(params.type).to.equal('AT', 'params.type');
};
export const assertPageView = ({
pageIdentifier,
applicationType,
contentType,
service,
}) => {
it(`should send a page view event with service = ${service}, page identifier = ${pageIdentifier}, application type = ${applicationType} and content type = ${contentType}`, () => {
cy.url().then(url => {
interceptATIAnalyticsBeacons();
cy.visit(url);
cy.wait(`@${ATI_PAGE_VIEW}`).then(({ request }) => {
const params = getATIParamsFromURL(request.url);
assertATIPageViewEventParamsExist({
params,
contentType,
applicationType,
});
expect(params.p).to.equal(pageIdentifier, 'params.p (page identifier)');
expect(params.x2).to.equal(
`[${applicationType}]`,
'params.x2 (application type)',
);
expect(params.x3).to.equal(
`[news-${service}]`,
'params.x3 (application name)',
);
expect(params.x7).to.equal(
`[${contentType}]`,
'params.x7 (content type)',
);
});
});
});
};
const getViewClickDetailsRegex = ({ contentType, component, pageIdentifier }) =>
new RegExp(
`PUB-\\[${contentType}.*?\\]-\\[${component}.*?\\]-\\[.*?\\]-\\[.*?\\]-\\[${pageIdentifier}\\]-\\[.*?\\]-\\[.*?\\]-\\[.*?\\]`,
'g',
);
export const assertATIComponentViewEvent = ({
component,
pageIdentifier,
contentType,
}) =>
cy
.wait(`@${component}-ati-view`)
.its('request.url')
.then(url => {
const params = getATIParamsFromURL(url);
assertATIComponentViewEventParamsExist(params);
expect(params.p).to.equal(pageIdentifier, 'params.p (page identifier)');
expect(params.ati).to.match(
getViewClickDetailsRegex({
contentType,
component,
pageIdentifier,
}),
'params.ati (publisher impression)',
);
});
export const assertATIComponentClickEvent = ({
component,
contentType,
pageIdentifier,
applicationType,
}) =>
cy
.wait(`@${component}-ati-click`)
.its('request.url')
.then(url => {
const params = getATIParamsFromURL(url);
assertATIComponentClickEventParamsExist(params);
if (applicationType === 'lite') {
expect(params.app_type).to.equal(applicationType, 'params.app_type');
}
expect(params.p).to.equal(pageIdentifier, 'params.p (page identifier)');
expect(params.atc).to.match(
getViewClickDetailsRegex({
contentType,
pageIdentifier,
component,
}),
'params.atc (publisher click)',
);
});