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
Reverted to automatic height
  • Loading branch information
mszylkowski committed Oct 5, 2021
commit 2636c3a500e7038e094c81e9721758eae7c07d2c
19 changes: 6 additions & 13 deletions extensions/amp-story/1.0/test/test-amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 @@ -51,7 +52,7 @@ describes.realWin(
* @param {Array<string>=} ids
* @return {!Array<!Element>}
*/
function createStoryWithPages(count, ids = [], autoAdvance = false) {
async function createStoryWithPages(count, ids = [], autoAdvance = false) {
element = win.document.createElement('amp-story');
element.getAmpDoc = () => env.ampdoc;

Expand All @@ -68,7 +69,7 @@ describes.realWin(
});

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

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

AmpStory.isBrowserSupported = () => true;

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

afterEach(() => {
Expand All @@ -127,15 +131,12 @@ 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 @@ -165,8 +166,6 @@ describes.realWin(
await createStoryWithPages(2);

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

await story.buildCallback();
await story.layoutCallback();
expect(buildShareMenuStub).to.have.been.calledOnce;
});
Expand All @@ -189,8 +188,6 @@ 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 @@ -242,8 +239,6 @@ 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 @@ -256,8 +251,6 @@ 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