Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Story Preview] Allow all story pages and grid layers to be rendered in preview mode #38030

Merged
merged 9 commits into from
Apr 18, 2022
5 changes: 5 additions & 0 deletions extensions/amp-story/1.0/amp-story-grid-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class AmpStoryGridLayer extends AmpStoryBaseLayer {
return isPrerenderActivePage(element.parentElement);
}

/** @override */
static previewAllowed() {
return true;
}

/** @param {!AmpElement} element */
constructor(element) {
super(element);
Expand Down
5 changes: 5 additions & 0 deletions extensions/amp-story/1.0/amp-story-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ export class AmpStoryPage extends AMP.BaseElement {
return isPrerenderActivePage(element);
}

/** @override */
static previewAllowed() {
return true;
}

/** @param {!AmpElement} element */
constructor(element) {
super(element);
Expand Down
25 changes: 24 additions & 1 deletion extensions/amp-story/1.0/test/test-amp-story-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describes.realWin('amp-story-page', {amp: {extensions}}, (env) => {
let html;
let gridLayerEl;
let page;
let story;
let storeService;
let isPerformanceTrackingOn;

Expand Down Expand Up @@ -67,7 +68,7 @@ describes.realWin('amp-story-page', {amp: {extensions}}, (env) => {
};
});

const story = win.document.createElement('amp-story');
story = win.document.createElement('amp-story');
story.getImpl = () => Promise.resolve(mediaPoolRoot);
// Makes whenUpgradedToCustomElement() resolve immediately.
story.createdCallback = Promise.resolve();
Expand Down Expand Up @@ -713,4 +714,26 @@ describes.realWin('amp-story-page', {amp: {extensions}}, (env) => {

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

it('should only allow the prerender visibility state if it is the first page', async () => {
const pageElement2 = win.document.createElement('amp-story-page');
const pageElement3 = win.document.createElement('amp-story-page');
story.appendChild(pageElement2);
story.appendChild(pageElement3);

expect(AmpStoryPage.prerenderAllowed(element)).to.be.true;
expect(AmpStoryPage.prerenderAllowed(pageElement2)).to.be.false;
expect(AmpStoryPage.prerenderAllowed(pageElement3)).to.be.false;
});

it('should always allow the preview visibility state', async () => {
const pageElement2 = win.document.createElement('amp-story-page');
const pageElement3 = win.document.createElement('amp-story-page');
story.appendChild(pageElement2);
story.appendChild(pageElement3);

expect(AmpStoryPage.previewAllowed(element)).to.be.true;
expect(AmpStoryPage.previewAllowed(pageElement2)).to.be.true;
expect(AmpStoryPage.previewAllowed(pageElement3)).to.be.true;
});
});