Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Enriqe committed Mar 12, 2020
1 parent 2a32f0b commit d86c273
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/amp-story-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ const IframePosition = {
* @enum {number}
*/
const SwipingState = {
SWIPING_TO_LEFT: 0,
SWIPING_TO_RIGHT: 1,
NOT_SWIPING: 0,
SWIPING_TO_LEFT: 1,
SWIPING_TO_RIGHT: 2,
};

/** @const {number} */
Expand Down Expand Up @@ -111,8 +112,8 @@ export class AmpStoryPlayer {
/** @private {number} */
this.currentIdx_ = 0;

/** @private {?SwipingState} */
this.swipingState_ = null;
/** @private {!SwipingState} */
this.swipingState_ = SwipingState.NOT_SWIPING;

/** @private {!Object} */
this.touchEventState_ = {
Expand Down Expand Up @@ -538,6 +539,7 @@ export class AmpStoryPlayer {
this.touchEventState_.startY = 0;
this.touchEventState_.lastX = 0;
this.touchEventState_.isSwipeX = null;
this.swipingState_ = SwipingState.NOT_SWIPING;
}

/**
Expand Down
24 changes: 15 additions & 9 deletions test/unit/test-amp-story-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ describes.realWin('AmpStoryPlayer', {amp: false}, env => {
const fakeData = {next: true};
fireHandler['selectDocument']('selectDocument', fakeData);

const iframes = playerEl.shadowRoot.querySelectorAll('iframe');
expect(iframes[0].getAttribute('i-amphtml-iframe-position')).to.eql('-1');
expect(iframes[1].getAttribute('i-amphtml-iframe-position')).to.eql('0');
win.requestAnimationFrame(() => {
const iframes = playerEl.shadowRoot.querySelectorAll('iframe');
expect(iframes[0].getAttribute('i-amphtml-iframe-position')).to.eql('-1');
expect(iframes[1].getAttribute('i-amphtml-iframe-position')).to.eql('0');
});
});

it('should navigate when swiping', async () => {
Expand All @@ -204,9 +206,11 @@ describes.realWin('AmpStoryPlayer', {amp: false}, env => {

swipeLeft();

const iframes = playerEl.shadowRoot.querySelectorAll('iframe');
expect(iframes[0].getAttribute('i-amphtml-iframe-position')).to.eql('-1');
expect(iframes[1].getAttribute('i-amphtml-iframe-position')).to.eql('0');
win.requestAnimationFrame(() => {
const iframes = playerEl.shadowRoot.querySelectorAll('iframe');
expect(iframes[0].getAttribute('i-amphtml-iframe-position')).to.eql('-1');
expect(iframes[1].getAttribute('i-amphtml-iframe-position')).to.eql('0');
});
});

it('should not navigate when swiping last story', async () => {
Expand All @@ -217,8 +221,10 @@ describes.realWin('AmpStoryPlayer', {amp: false}, env => {
swipeLeft();
swipeLeft();

const iframes = playerEl.shadowRoot.querySelectorAll('iframe');
expect(iframes[0].getAttribute('i-amphtml-iframe-position')).to.eql('-1');
expect(iframes[1].getAttribute('i-amphtml-iframe-position')).to.eql('0');
win.requestAnimationFrame(() => {
const iframes = playerEl.shadowRoot.querySelectorAll('iframe');
expect(iframes[0].getAttribute('i-amphtml-iframe-position')).to.eql('-1');
expect(iframes[1].getAttribute('i-amphtml-iframe-position')).to.eql('0');
});
});
});

0 comments on commit d86c273

Please sign in to comment.