Skip to content
Merged
Changes from 1 commit
Commits
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
Started changing tests to use AmpStory
  • Loading branch information
mszylkowski committed Sep 24, 2021
commit 4d8805c29cae7e5f82ba0d89e53b014423604389
16 changes: 10 additions & 6 deletions extensions/amp-story/1.0/test/test-amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {createElementWithAttributes} from '#core/dom';
import {registerServiceBuilder} from '../../../../src/service-helpers';
import {toggleExperiment} from '#experiments';
import {waitFor} from '#testing/test-helper';
import {setImportantStyles} from '#core/dom/style';

// Represents the correct value of KeyboardEvent.which for the Right Arrow
const KEYBOARD_EVENT_WHICH_RIGHT_ARROW = 39;
Expand Down Expand Up @@ -52,8 +51,9 @@ describes.realWin(
* @param {Array<string>=} ids
* @return {!Array<!Element>}
*/
async function createStoryWithPages(count, ids = [], autoAdvance = false) {
function createStoryWithPages(count, ids = [], autoAdvance = false) {
element = win.document.createElement('amp-story');
element.getAmpDoc = () => env.ampdoc;

const pageArray = Array(count)
.fill(undefined)
Expand All @@ -68,7 +68,7 @@ describes.realWin(
});

win.document.body.appendChild(element);
story = await element.getImpl();
story = new AmpStory(element);

return pageArray;
}
Expand Down Expand Up @@ -118,9 +118,6 @@ describes.realWin(
});

AmpStory.isBrowserSupported = () => true;

/** Control element lifecycle by preventing automatic callback calls. */
setImportantStyles(win.document.documentElement, {'height': 'auto'});
});

afterEach(() => {
Expand All @@ -130,13 +127,15 @@ describes.realWin(
it('should build with the expected number of pages', async () => {
const pagesCount = 2;
await createStoryWithPages(pagesCount, ['cover', 'page-1']);
await story.buildCallback();
await story.layoutCallback();
expect(story.getPageCount()).to.equal(pagesCount);
});

it('should activate the first page when built', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.buildCallback();
await story.layoutCallback();
// Getting all the AmpStoryPage objets.
const pageElements = story.element.getElementsByTagName('amp-story-page');
Expand Down Expand Up @@ -167,12 +166,14 @@ describes.realWin(

const buildShareMenuStub = env.sandbox.stub(story.shareMenu_, 'build');

await story.buildCallback();
await story.layoutCallback();
expect(buildShareMenuStub).to.have.been.calledOnce;
});

it('should return a valid page index', async () => {
await createStoryWithPages(4, ['cover', 'page-1', 'page-2', 'page-3']);
await story.buildCallback();
await story.layoutCallback();
// Getting all the AmpStoryPage objets.
const pageElements = story.element.getElementsByTagName('amp-story-page');
Expand All @@ -189,6 +190,7 @@ describes.realWin(
it('should pause/resume pages when switching pages', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.buildCallback();
await story.layoutCallback();
// Getting all the AmpStoryPage objects.
const pageElements = story.element.getElementsByTagName('amp-story-page');
Expand Down Expand Up @@ -241,6 +243,7 @@ describes.realWin(
it('lock body when amp-story is initialized', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.buildCallback();
await story.layoutCallback();
story.lockBody_();
expect(win.document.body.style.getPropertyValue('overflow')).to.be.equal(
Expand All @@ -254,6 +257,7 @@ describes.realWin(
it('checks if pagination buttons exist ', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

await story.buildCallback();
await story.layoutCallback();
expect(
story.element.querySelectorAll('.i-amphtml-story-button-container')
Expand Down