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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9b9b8d5
fixture for cbe
kalemuw e8779fe
e2e tests
kalemuw cc46b62
fixed typo
kalemuw 5e1835e
add id to request
kalemuw 3a684be
year change
kalemuw af1f5f6
Merge branch 'main' into CBE-e2e-test
kalemuw 23462d0
resync changes
kalemuw 4c991c2
resync event.js
kalemuw 468bdcc
renaming
kalemuw 024c016
update events.js
kalemuw 70ad199
Merge branch 'main' into CBE-e2e-test
kalemuw 45f6daa
merge with main branch
kalemuw bd65945
allow list invalid files
kalemuw File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
extensions/amp-analytics/0.1/test-e2e/test-browser-event.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright 2021 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import {Key} from '../../../../build-system/tasks/e2e/e2e-types'; | ||
|
||
describes.endtoend( | ||
'custom browser events', | ||
{ | ||
fixture: 'amp-analytics/browser-events.html', | ||
environments: ['single'], | ||
}, | ||
(env) => { | ||
let controller; | ||
|
||
beforeEach(async () => { | ||
controller = env.controller; | ||
}); | ||
|
||
function sleep(ms) { | ||
return new Promise((res) => setTimeout(res, ms)); | ||
} | ||
|
||
it('click on input field to focus and then blur', async () => { | ||
const focusedInputField = await controller.findElement('#inputText'); | ||
const blurredInputField = await controller.findElement('#inputText2'); | ||
|
||
await controller.click(blurredInputField); | ||
await controller.click(focusedInputField); | ||
|
||
// Sleep 1 second for the blur event to be sent | ||
await sleep(1000); | ||
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('#dropDown'); | ||
const blurredDropdown = await controller.findElement('#dropDown2'); | ||
|
||
await controller.click(blurredDropdown); | ||
await controller.click(focusedDropdown); | ||
|
||
// Sleep 1 second for the blur event to be sent | ||
await sleep(1000); | ||
await expect('https://foo.com/event?type=blur&eventId=dropDown2').to.have | ||
.been.sent; | ||
}); | ||
|
||
it('change the content of the input field to trigger on change event', async () => { | ||
const changedInputField = await controller.findElement('#inputText'); | ||
|
||
await controller.click(changedInputField); | ||
await sleep(300); | ||
await controller.type(changedInputField, 'test-text'); | ||
await controller.type(changedInputField, Key.Enter); | ||
|
||
// Sleep 1 second for the change event to be sent | ||
await sleep(1000); | ||
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 () => { | ||
const changedDropdown = await controller.findElement('#dropDown'); | ||
|
||
await controller.click(changedDropdown); | ||
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=dropDown').to.have | ||
.been.sent; | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<!doctype html> | ||
<html ⚡ lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Custom Browser Events</title> | ||
<link rel="canonical" href="amps.html" > | ||
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
<style amp-custom> | ||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; | ||
font-size: 14px; | ||
} | ||
|
||
[fallback] { | ||
display: block; | ||
/* @alternative */ display: flex; | ||
flex-direction: column; | ||
flex-wrap: nowrap; | ||
justify-content: center; | ||
align-items: center; | ||
background: rgba(0, 0, 0, 0.5); | ||
color: #fff; | ||
} | ||
|
||
.main { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.main, h1, .wrap { | ||
max-width: 960px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
|
||
.input-container { | ||
flex: 1; | ||
} | ||
|
||
.form-container { | ||
flex: 1; | ||
} | ||
|
||
h1 { | ||
font-weight: bold; | ||
margin: 40px auto 20px; | ||
font-size: 24px; | ||
} | ||
|
||
</style> | ||
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> | ||
<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"> | ||
<div> | ||
<h1>Custom Browser Events</h1> | ||
<h1>AMP Input</h1> | ||
<div class="main"> | ||
<div class="input-container"> | ||
Enter any text: <input type="text" id="inputText"> | ||
</div> | ||
<div class="input-container"> | ||
Enter any text: <input type="text" id="inputText2"> | ||
</div> | ||
</div> | ||
</div> | ||
<div> | ||
<h1>AMP Form</h1> | ||
<div class="main"> | ||
<div class="form-container"> | ||
<form method="post" | ||
class="p1" | ||
action-xhr="wololo" | ||
custom-validation-reporting="show-all-on-submit" | ||
target="_top"> | ||
<label for="numChild">Child (0-17)</label> | ||
<div class="custom-select sg__select-wrapper"> | ||
<select name="numChild" id="dropDown"> | ||
<option data-vars-num-child="0" value="0">0</option> | ||
<option data-vars-num-child="1" value="1">1</option> | ||
<option data-vars-num-child="2" value="2">2</option> | ||
<option data-vars-num-child="3" value="3">3</option> | ||
<option data-vars-num-child="4" value="4">4</option> | ||
</select> | ||
</div> | ||
<div class="custom-select sg__select-wrapper"> | ||
<select name="numChild2" id="dropDown2"> | ||
<option data-vars-num-child="0" value="0">0</option> | ||
<option data-vars-num-child="1" value="1">1</option> | ||
<option data-vars-num-child="2" value="2">2</option> | ||
<option data-vars-num-child="3" value="3">3</option> | ||
<option data-vars-num-child="4" value="4">4</option> | ||
</select> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
<amp-analytics> | ||
<script type="application/json"> | ||
{ | ||
"requests": { | ||
"event": "https://foo.com/event?type=${eventType}" | ||
}, | ||
"transport": { | ||
"beacon": false, | ||
"image": false, | ||
"xhrpost": true | ||
}, | ||
"triggers": { | ||
"genericTrigger-1":{ | ||
"on": "change", | ||
"request": "event", | ||
"selector": "#inputText", | ||
"vars": { | ||
"eventType": "change" | ||
}, | ||
"extraUrlParams":{ | ||
"eventId": "inputText" | ||
} | ||
}, | ||
"genericTrigger-2":{ | ||
"on": "change", | ||
"request": "event", | ||
"selector": "#dropDown", | ||
"vars": { | ||
"eventType": "change" | ||
}, | ||
"extraUrlParams":{ | ||
"eventId": "dropDown" | ||
} | ||
}, | ||
"genericTrigger-3":{ | ||
"on": "blur", | ||
"request": "event", | ||
"selector": "#inputText2", | ||
"vars": { | ||
"eventType": "blur" | ||
}, | ||
"extraUrlParams":{ | ||
"eventId": "inputText2" | ||
} | ||
}, | ||
"genericTrigger-4":{ | ||
"on": "blur", | ||
"request": "event", | ||
"selector": "#dropDown2", | ||
"vars": { | ||
"eventType": "blur" | ||
}, | ||
"extraUrlParams":{ | ||
"eventId": "dropDown2" | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
</amp-analytics> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rsimha This PR is currently blocked on approval from
wg-approvers
, which is a quite authoritative group.What do you think about moving this glob set to a different file, so that we can set a more permissive list of OWNERS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can currently be approved by anyone on infra or performance. Totally fine with adding other wgs to the list of owners.
amphtml/build-system/test-configs/OWNERS
Lines 6 to 11 in c491d6f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea with extracting the
.html
example list is that modifying it is lower risk than other configuration objects in this file. I would feel more comfortable allowing a wider set of people to modify the.html
list only. What do you think?(In the meantime, your approval of this PR would be appreciated since you have
wg-approvers
powers that I don't. 🙂)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, for which there already is precedent 👍
Once the html list is moved to its own file, we can give everyone permissions to edit it, similar to this file:
amphtml/build-system/test-configs/OWNERS
Lines 12 to 15 in c491d6f