Skip to content

Commit

Permalink
Add integration tests for <amp-analytics type=googleanalytics> (#19674)
Browse files Browse the repository at this point in the history
* Add integration tests for <amp-analytics type=googleanalytics>

* remove

* skip one failing amp-bind test.
  • Loading branch information
lannka committed Dec 7, 2018
1 parent 384cf61 commit 857fe14
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
70 changes: 70 additions & 0 deletions test/integration/test-amp-analytics.js
Expand Up @@ -15,6 +15,7 @@
*/

import {RequestBank} from '../../testing/test-helper';
import {parseQueryString} from '../../src/url';

describe.configure().skipIfPropertiesObfuscated().run('amp' +
'-analytics', function() {
Expand Down Expand Up @@ -291,4 +292,73 @@ describe.configure().skipIfPropertiesObfuscated().run('amp' +
});
});
});

describes.integration('amp-analytics type=googleanalytics', {
body: `
<script>
// initialize with a valid _ga cookie
document.cookie='_ga=GA1.2.1427830804.1524174812';
</script>
<amp-analytics type="googleanalytics">
<script type="application/json">
{
"vars": {
"account": "UA-67833617-1"
},
"requests": {
"host": "${RequestBank.getUrl()}"
},
"triggers": {
"pageview": {
"on": "visible",
"request": "pageview"
},
"performanceTiming": {
"enabled": false
},
"adwordsTiming": {
"enabled": false
}
}
}
</script>
</amp-analytics>`,
extensions: ['amp-analytics'],
}, () => {
afterEach(() => {
// clean up written _ga cookie
document.cookie = '_ga=;expires=' + new Date(0).toUTCString();
});

it('should send request', () => {
return RequestBank.withdraw().then(req => {
expect(req.url).to.match(/^\/r\/collect\?/);
const queries = parseQueryString(req.url.substr('/r/collect'.length));
// see vendors/googleanalytics.js "pageview" request for config
expect(queries).to.include({
_v: 'a1',
_r: '1',
v: '1',
cid: '1427830804.1524174812',
dr: '',
ds: 'AMP',
dt: 'AMP TEST',
tid: 'UA-67833617-1',
t: 'pageview',
});
const isNumber = /^\d+$/;
const isRandomNumber = /^0\.\d+$/;
expect(queries['dl']).to.contain('/amp4test/compose-doc?'); // ${documentLocation}
expect(queries['_s']).to.match(isNumber); // ${requestCount}
expect(queries['_utmht']).to.match(isNumber); // ${timestamp}
expect(queries['sr']).to.match(/^\d+x\d+$/); // ${screenWidth}x${screenHeight}
expect(queries['sd']).to.match(isNumber); // ${screenColorDepth}
expect(queries['ul']).to.be.ok; // ${browserLanguage}
expect(queries['de']).to.be.ok; // ${documentCharset}
expect(queries['jid']).to.match(isRandomNumber); // ${random}
expect(queries['a']).to.match(isNumber); // ${pageViewId}
expect(queries['z']).to.match(isRandomNumber); // ${random}
});
});
});
});
3 changes: 2 additions & 1 deletion test/integration/test-amp-bind.js
Expand Up @@ -231,7 +231,8 @@ describe.configure().ifNewChrome().run('amp-bind', function() {
});
});

it('should change slides when the slide attribute binding changes',
// TODO(choumx, #19647): Times out on SL Chrome 71.
it.skip('should change slides when the slide attribute binding changes',
() => {
const carousel = fixture.doc.getElementById('carousel');
const slides =
Expand Down

0 comments on commit 857fe14

Please sign in to comment.