Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Custom Browser Event Tracker End-to-End Test #35354

Merged
merged 13 commits into from
Aug 5, 2021
25 changes: 9 additions & 16 deletions extensions/amp-analytics/0.1/test-e2e/test-cbe.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ describes.endtoend(

// Sleep 1 second for the blur event to be sent
await sleep(1000);
await expect(
'https://foo.com/event?type=blur&eventId='
).to.have.been.sent;
await expect('https://foo.com/event?type=blur&eventId=inputText2').to.have
.been.sent;
});

it('click on dropdown menu to focus and then blur', async () => {

const focusedDropdown = await controller.findElement('#numChild');
const blurredDropdown = await controller.findElement('#numChild2');
kalemuw marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -56,9 +54,8 @@ describes.endtoend(

// Sleep 1 second for the blur event to be sent
await sleep(1000);
await expect(
'https://foo.com/event?type=blur&eventId='
).to.have.been.sent;
await expect('https://foo.com/event?type=blur&eventId=numChild2').to.have
.been.sent;
});

it('change the content of the input field to trigger on change event', async () => {
Expand All @@ -71,10 +68,8 @@ describes.endtoend(

// Sleep 1 second for the change event to be sent
await sleep(1000);
await expect(
'https://foo.com/event?type=change&eventId='
).to.have.been.sent;

await expect('https://foo.com/event?type=change&eventId=inputText').to
.have.been.sent;
});

it('change drop down option selected to trigger on change event', async () => {
Expand All @@ -84,11 +79,9 @@ describes.endtoend(
await controller.type(changedDropdown, '1');
await controller.type(changedDropdown, Key.Enter);
// Sleep 1 second for the change event to be sent
await sleep(1000);
await expect(
'https://foo.com/event?type=change&eventId='
).to.have.been.sent;

await sleep(5000);
await expect('https://foo.com/event?type=change&eventId=numChild').to.have
.been.sent;
});
}
);
35 changes: 31 additions & 4 deletions test/fixtures/e2e/amp-analytics/custom-browser-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script>
(self.AMP = self.AMP || []).push(function (AMP) {
AMP.toggleExperiment('analytics-browser-events', true);
});
</script>
</head>
<body>
<div style="display: flex; flex-direction: column; height: 100vh">
Expand Down Expand Up @@ -116,23 +121,45 @@ <h1>AMP Form</h1>
"genericTrigger-1":{
"on": "change",
"request": "event",
"selector": ["#inputText","#numChild"],
"selector": "#inputText",
"vars": {
"eventType": "change"
},
"extraUrlParams":{
"eventId": "${id}"
kalemuw marked this conversation as resolved.
Show resolved Hide resolved
"eventId": "inputText"
}
},
"genericTrigger-2":{
"on": "change",
"request": "event",
"selector": "#numChild",
"vars": {
"eventType": "change"
},
"extraUrlParams":{
"eventId": "numChild"
}
},
"genericTrigger-3":{
"on": "blur",
"request": "event",
"selector": "#inputText2",
"vars": {
"eventType": "blur"
},
"extraUrlParams":{
"eventId": "inputText2"
}
},
"genericTrigger-4":{
"on": "blur",
"request": "event",
"selector": ["#inputText2", "#numChild2"],
"selector": "#numChild2",
"vars": {
"eventType": "blur"
},
"extraUrlParams":{
"eventId": "${id}"
"eventId": "numChild2"
}
}
}
Expand Down