Skip to content

Commit

Permalink
🐛 Fixing storyProgress calculation so that values are [0,1] (ampproje…
Browse files Browse the repository at this point in the history
…ct#31024)

* Fixing storyProgress calculation

* fixing breaking test
  • Loading branch information
raxsha authored and ed-bird committed Dec 10, 2020
1 parent fd3ead0 commit a30e80f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describes.fakeWin('amp-story-viewer-messaging-handler', {}, (env) => {
});

it('should return the STORY_PROGRESS', async () => {
storeService.dispatch(Action.SET_PAGE_IDS, [1, 2, 3, 4]);
storeService.dispatch(Action.SET_PAGE_IDS, [1, 2, 3, 4, 5]);
storeService.dispatch(Action.CHANGE_PAGE, {id: 3, index: 2});
const response = await fakeViewerService.receiveMessage(
'getDocumentState',
Expand Down
11 changes: 11 additions & 0 deletions extensions/amp-story/1.0/test/test-variable-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ describes.fakeWin('amp-story variable service', {}, (env) => {
const variables = variableService.get();
expect(variables['storyAdvancementMode']).to.equal('manualAdvance');
});

it('should calculate storyProgress correctly on change', () => {
storeService.dispatch(Action.SET_PAGE_IDS, ['a', 'b', 'c', 'd', 'e']);
storeService.dispatch(Action.CHANGE_PAGE, {
id: 'd',
index: 3,
});

const variables = variableService.get();
expect(variables['storyProgress']).to.equal(0.75);
});
});
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/variable-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class AmpStoryVariableService {
.length;
if (numberOfPages > 0) {
this.variables_[AnalyticsVariable.STORY_PROGRESS] =
pageIndex / numberOfPages;
pageIndex / (numberOfPages - 1);
}
},
true /* callToInitialize */
Expand Down

0 comments on commit a30e80f

Please sign in to comment.