Skip to content

Commit

Permalink
nonext story event (#30098)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enriqe committed Sep 2, 2020
1 parent 4c76c46 commit f4decd2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/amp-story-player/amp-story-player-impl.js
Expand Up @@ -1181,6 +1181,14 @@ export class AmpStoryPlayer {
* @private
*/
onSelectDocument_(data) {
if (
!this.isCircularWrappingEnabled_() &&
this.currentIdx_ + 1 === this.stories_.length
) {
this.element_.dispatchEvent(
createCustomEvent(this.win_, 'noNextStory', dict({}))
);
}
if (data.next) {
this.next_();
} else if (data.previous) {
Expand Down
30 changes: 30 additions & 0 deletions test/unit/test-amp-story-player.js
Expand Up @@ -285,6 +285,36 @@ describes.realWin('AmpStoryPlayer', {amp: false}, (env) => {
});
});

it('dispatch noNextStory when in last story', async () => {
buildStoryPlayer(1);

await manager.loadPlayers();
await nextTick();

const noNextSpy = env.sandbox.spy();
playerEl.addEventListener('noNextStory', noNextSpy);

const fakeData = {next: true};
fireHandler['selectDocument']('selectDocument', fakeData);

expect(noNextSpy).to.have.been.called;
});

it('should not dispatch noNextStory when not in last story', async () => {
buildStoryPlayer(2);

await manager.loadPlayers();
await nextTick();

const noNextSpy = env.sandbox.spy();
playerEl.addEventListener('noNextStory', noNextSpy);

const fakeData = {next: true};
fireHandler['selectDocument']('selectDocument', fakeData);

expect(noNextSpy).to.not.have.been.called;
});

it('should navigate when swiping', async () => {
buildStoryPlayer(4);
await manager.loadPlayers();
Expand Down

0 comments on commit f4decd2

Please sign in to comment.