Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6aabe91
Added tasts
mszylkowski Dec 21, 2021
dc1fa87
Undo
mszylkowski Dec 21, 2021
d707e5b
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Dec 28, 2021
0e3df75
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Dec 28, 2021
a3f7bd0
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 4, 2022
8c5119c
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 6, 2022
77f8435
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 10, 2022
16e712e
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 19, 2022
8088eb7
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 25, 2022
3858b2a
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 28, 2022
e12d2f6
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 31, 2022
2a29105
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Feb 1, 2022
a5b781f
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Feb 10, 2022
b8006ee
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 8, 2022
b570e86
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 10, 2022
6b7e456
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 22, 2022
50bdff8
Merge branch 'ampproject:main' into main
mszylkowski Mar 24, 2022
267ae0e
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 29, 2022
c7edd8c
Merge branch 'main' of github.com:mszylkowski/amphtml
mszylkowski Mar 29, 2022
ca057da
Removed timeout of 10s
mszylkowski Mar 29, 2022
4139fa3
Reverted past change and added visibility wait
mszylkowski Mar 29, 2022
94e9cfc
Merge branch 'main' of github.com:ampproject/amphtml into fixPrerende…
mszylkowski Mar 30, 2022
a34b4fc
Fixed unit tests
mszylkowski Mar 30, 2022
6e22c0c
Remove unused import in test
mszylkowski Mar 30, 2022
4159d64
Merge branch 'main' of github.com:ampproject/amphtml into fixPrerende…
mszylkowski Mar 30, 2022
1bd423e
Test analytics not sent if not visible
mszylkowski Mar 30, 2022
9b86704
Fixed test index value
mszylkowski Mar 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed unit tests
  • Loading branch information
mszylkowski committed Mar 30, 2022
commit a34b4fcc8fb86d199c096fb10373edc3d1f6441d
22 changes: 17 additions & 5 deletions extensions/amp-story/1.0/test/test-amp-story-embedded-component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {VisibilityState_Enum} from '#core/constants/visibility-state';
import {addAttributesToElement} from '#core/dom';

import {Services} from '#service';
import {LocalizationService} from '#service/localization';

import * as analyticsApi from '#utils/analytics';

import {registerServiceBuilder} from '../../../../src/service-helpers';
import {
getAmpdoc,
registerServiceBuilder,
} from '../../../../src/service-helpers';
import {AmpStoryEmbeddedComponent} from '../amp-story-embedded-component';
import {
Action,
Expand Down Expand Up @@ -224,20 +228,22 @@ describes.realWin('amp-story-embedded-component', {amp: true}, (env) => {
expect(tooltipTextEl.textContent).to.equal('google.com');
});

it('should fire analytics event when entering a tooltip', () => {
it('should fire analytics event when entering a tooltip', async () => {
fakePage.appendChild(clickableEl);
storeService.dispatch(Action.TOGGLE_INTERACTIVE_COMPONENT, {
element: clickableEl,
state: EmbeddedComponentState.FOCUSED,
});

await getAmpdoc(win.document).whenFirstVisible();

expect(analyticsTriggerStub).to.be.calledWith(
parentEl,
StoryAnalyticsEvent.FOCUS
);
});

it('should send data-var specified by publisher in analytics event', () => {
it('should send data-var specified by publisher in analytics event', async () => {
addAttributesToElement(clickableEl, {
'data-vars-tooltip-id': '1234',
});
Expand All @@ -248,6 +254,8 @@ describes.realWin('amp-story-embedded-component', {amp: true}, (env) => {
state: EmbeddedComponentState.FOCUSED,
});

await getAmpdoc(win.document).whenFirstVisible();

expect(analyticsTriggerStub).to.be.calledWithMatch(
parentEl,
StoryAnalyticsEvent.FOCUS,
Expand All @@ -257,7 +265,7 @@ describes.realWin('amp-story-embedded-component', {amp: true}, (env) => {
);
});

it('should fire analytics event when clicking on the tooltip of a link', () => {
it('should fire analytics event when clicking on the tooltip of a link', async () => {
fakePage.appendChild(clickableEl);
storeService.dispatch(Action.TOGGLE_INTERACTIVE_COMPONENT, {
element: clickableEl,
Expand All @@ -273,13 +281,15 @@ describes.realWin('amp-story-embedded-component', {amp: true}, (env) => {

tooltip.click();

await getAmpdoc(win.document).whenFirstVisible();

expect(analyticsTriggerStub).to.be.calledWith(
parentEl,
StoryAnalyticsEvent.CLICK_THROUGH
);
});

it('should fire analytics event when clicking on the tooltip of a tweet', () => {
it('should fire analytics event when clicking on the tooltip of a tweet', async () => {
clickableEl = win.document.createElement('amp-twitter');
addAttributesToElement(clickableEl, {
'data-tweetid': '1166723359696130049',
Expand All @@ -300,6 +310,8 @@ describes.realWin('amp-story-embedded-component', {amp: true}, (env) => {

tooltip.click();

await getAmpdoc(win.document).whenFirstVisible();

expect(analyticsTriggerStub).to.be.calledWith(
parentEl,
StoryAnalyticsEvent.FOCUS
Expand Down
9 changes: 7 additions & 2 deletions extensions/amp-story/1.0/test/test-amp-story-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {Services} from '#service';

import * as analyticsApi from '#utils/analytics';

import {registerServiceBuilder} from '../../../../src/service-helpers';
import {
getAmpdoc,
registerServiceBuilder,
} from '../../../../src/service-helpers';
import {AmpStoryShare} from '../amp-story-share';
import {
Action,
Expand Down Expand Up @@ -94,7 +97,7 @@ describes.realWin('amp-story-share', {amp: true}, (env) => {
});
});

it('should send correct analytics tagName and eventType when opening the share menu', () => {
it('should send correct analytics tagName and eventType when opening the share menu', async () => {
analyticsTriggerStub = env.sandbox.stub(
analyticsApi,
'triggerAnalyticsEvent'
Expand All @@ -103,6 +106,8 @@ describes.realWin('amp-story-share', {amp: true}, (env) => {

storeService.dispatch(Action.TOGGLE_SHARE_MENU, true);

await getAmpdoc(win.document).whenFirstVisible();

// tagName should be amp-story-share-menu as per extensions/amp-story/amp-story-analytics.md
expect(analyticsTriggerStub).to.be.calledWith(
ampStory,
Expand Down
20 changes: 16 additions & 4 deletions extensions/amp-story/1.0/test/test-story-analytics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as analytics from '#utils/analytics';

import {getAmpdoc} from 'src/service-helpers';

import {Action, getStoreService} from '../amp-story-store-service';
import {StoryAnalyticsService} from '../story-analytics';
import {getAnalyticsService} from '../story-analytics';

describes.realWin('amp-story-analytics', {amp: true}, (env) => {
let el;
Expand All @@ -10,11 +12,12 @@ describes.realWin('amp-story-analytics', {amp: true}, (env) => {
beforeEach(() => {
const {win} = env;
el = win.document.createElement('amp-story');
win.document.body.appendChild(el);
storeService = getStoreService(win);
new StoryAnalyticsService(env.win, el);
getAnalyticsService(win, el);
});

it('sends story-page-visible on current page change', () => {
it('sends story-page-visible on current page change', async () => {
const triggerAnalyticsStub = env.sandbox.stub(
analytics,
'triggerAnalyticsEvent'
Expand All @@ -23,6 +26,9 @@ describes.realWin('amp-story-analytics', {amp: true}, (env) => {
id: 'page-1',
index: 0,
});

await getAmpdoc(env.win.document).whenFirstVisible();

expect(triggerAnalyticsStub).to.have.been.calledOnceWithExactly(
el,
'story-page-visible',
Expand All @@ -43,7 +49,7 @@ describes.realWin('amp-story-analytics', {amp: true}, (env) => {
expect(triggerAnalyticsStub).not.to.be.called;
});

it('sends story-page-visible on content page after ad page', () => {
it('sends story-page-visible on content page after ad page', async () => {
const triggerAnalyticsStub = env.sandbox.stub(
analytics,
'triggerAnalyticsEvent'
Expand All @@ -52,6 +58,9 @@ describes.realWin('amp-story-analytics', {amp: true}, (env) => {
id: 'page-1',
index: 0,
});

await getAmpdoc(env.win.document).whenFirstVisible();

expect(triggerAnalyticsStub).to.have.been.calledOnceWithExactly(
el,
'story-page-visible',
Expand All @@ -68,6 +77,9 @@ describes.realWin('amp-story-analytics', {amp: true}, (env) => {
id: 'page-2',
index: 2,
});

await getAmpdoc(env.win.document).whenFirstVisible();

expect(triggerAnalyticsStub).to.have.been.calledTwice;
expect(triggerAnalyticsStub.secondCall).to.have.been.calledWithExactly(
el,
Expand Down