Skip to content

Commit

Permalink
✅ [Story analytics] Add test to check sharing happens with the right …
Browse files Browse the repository at this point in the history
…tag and eventType (ampproject#37488)

* Added tasts

* Undo

* Adding share examples for analytics

* Using share menu for analytics

* Added test

* Fixed linting

* Fix linting again

* Added comment to retrigger CLA
  • Loading branch information
mszylkowski authored and samouri committed Feb 2, 2022
1 parent 9667d4c commit 9add5a6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions extensions/amp-story/1.0/test/test-amp-story-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ import {expect} from 'chai';

import {Services} from '#service';

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

import {registerServiceBuilder} from '../../../../src/service-helpers';
import {AmpStoryShare} from '../amp-story-share';
import {
Action,
AmpStoryStoreService,
StateProperty,
} from '../amp-story-store-service';
import {StoryAnalyticsEvent, getAnalyticsService} from '../story-analytics';

describes.realWin('amp-story-share', {amp: true}, (env) => {
let ampStoryShare;
let ampStory;
let storeService;
let win;
let installExtensionForDoc;
let analyticsTriggerStub;

beforeEach(() => {
win = env.win;
Expand All @@ -42,6 +46,7 @@ describes.realWin('amp-story-share', {amp: true}, (env) => {
ampStory = win.document.createElement('amp-story');
win.document.body.appendChild(ampStory);
ampStoryShare = new AmpStoryShare(win, ampStory);
getAnalyticsService(win, ampStory);
});

it('should build the sharing menu if native sharing is unsupported', () => {
Expand Down Expand Up @@ -88,4 +93,23 @@ describes.realWin('amp-story-share', {amp: true}, (env) => {
text: 'AMP',
});
});

it('should send correct analytics tagName and eventType when opening the share menu', () => {
analyticsTriggerStub = env.sandbox.stub(
analyticsApi,
'triggerAnalyticsEvent'
);
env.sandbox.stub(ampStoryShare, 'isSystemShareSupported_').returns(false);

storeService.dispatch(Action.TOGGLE_SHARE_MENU, true);

// tagName should be amp-story-share-menu as per extensions/amp-story/amp-story-analytics.md
expect(analyticsTriggerStub).to.be.calledWith(
ampStory,
StoryAnalyticsEvent.OPEN,
env.sandbox.match(
(val) => val.eventDetails.tagName === 'amp-story-share-menu'
)
);
});
});

0 comments on commit 9add5a6

Please sign in to comment.