Skip to content

Commit

Permalink
✨ Render page level CTA when amp-story-shopping-attachment exists (am…
Browse files Browse the repository at this point in the history
…pproject#36721)

* Add shopping attachment to list of attachment elements with CTA UI.

* Add visual test

* Remove whitespace

* Use amp-story-draggable-drawer-root

* Add dark theme page to example.

* Update ID

* use shopping attachment.

* remove empty space

* Update diff path.
  • Loading branch information
processprocess authored and rileyajones committed Nov 4, 2021
1 parent 38c5634 commit 111a668
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
10 changes: 9 additions & 1 deletion examples/amp-story/amp-story-shopping.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
publisher="AMP Story Shopping"
publisher-logo-src="example.com/logo.png"
poster-portrait-src="example.com/poster.jpg">
<amp-story-page id="example">
<amp-story-page id="default">
<amp-story-shopping-config layout='nodisplay'></amp-story-shopping-config>
<amp-story-grid-layer template="vertical">
<amp-story-shopping-tag></amp-story-shopping-tag>
</amp-story-grid-layer>
<amp-story-shopping-attachment layout='nodisplay'></amp-story-shopping-attachment>
</amp-story-page>

<amp-story-page id="dark-theme">
<amp-story-shopping-config layout='nodisplay'></amp-story-shopping-config>
<amp-story-grid-layer template="vertical">
<amp-story-shopping-tag></amp-story-shopping-tag>
</amp-story-grid-layer>
<amp-story-shopping-attachment layout='nodisplay' theme="dark"></amp-story-shopping-attachment>
</amp-story-page>
</amp-story>
</body>
</html>
44 changes: 44 additions & 0 deletions examples/visual-tests/amp-story/amp-story-shopping.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-story" src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script>
<script async custom-element="amp-story-shopping" src="https://cdn.ampproject.org/v0/amp-story-shopping-0.1.js"></script>
<title>AMP Story Shopping</title>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="canonical" href="index.html">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
.i-amphtml-story-spinner-container {
/* Hide the spinner for loading pages, since this causes flakes */
display: none;
}
</style>
</head>

<body>
<amp-story standalone publisher="AMP Team" title="Visual Diff Test"
publisher-logo-src="/examples/visual-tests/photos/120.png"
poster-portrait-src="/examples/visual-tests/picsum.photos/image981_900x1600.jpg"
poster-landscape-src="/examples/visual-tests/picsum.photos/image981_1600x900.jpg"
poster-square-src="/examples/visual-tests/picsum.photos/image981_1600x1600.jpg"
supports-landscape>
<amp-story-page id="default">
<amp-story-shopping-config layout='nodisplay'></amp-story-shopping-config>
<amp-story-grid-layer template="vertical">
<amp-story-shopping-tag></amp-story-shopping-tag>
</amp-story-grid-layer>
<amp-story-shopping-attachment layout='nodisplay'></amp-story-shopping-attachment>
</amp-story-page>

<amp-story-page id="dark-theme">
<amp-story-shopping-config layout='nodisplay'></amp-story-shopping-config>
<amp-story-grid-layer template="vertical">
<amp-story-shopping-tag></amp-story-shopping-tag>
</amp-story-grid-layer>
<amp-story-shopping-attachment layout='nodisplay' theme="dark"></amp-story-shopping-attachment>
</amp-story-page>
</amp-story>
</body>
</html>
19 changes: 19 additions & 0 deletions examples/visual-tests/amp-story/amp-story-shopping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const {
verifySelectorsVisible,
} = require('../../../build-system/tasks/visual-diff/verifiers');

module.exports = {
'dark theme - shopping CTA UI should display': async (page, name) => {
const pageID = 'dark-theme';
const url = await page.url();
await page.goto(`${url}#page=${pageID}`);
await page.waitForSelector(
`amp-story-page#${pageID}[active][distance="0"]`
);
await verifySelectorsVisible(page, name, [
'.i-amphtml-story-page-open-attachment[active]',
]);
},
};
6 changes: 3 additions & 3 deletions extensions/amp-story/1.0/amp-story-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -1719,9 +1719,9 @@ export class AmpStoryPage extends AMP.BaseElement {
* @private
*/
renderOpenAttachmentUI_() {
// AttachmentEl can be either amp-story-page-attachment or amp-story-page-outlink
// AttachmentEl can be any component that extends draggable drawer.
const attachmentEl = this.element.querySelector(
'amp-story-page-attachment, amp-story-page-outlink'
'amp-story-page-attachment, amp-story-page-outlink, amp-story-shopping-attachment'
);
if (!attachmentEl) {
return;
Expand Down Expand Up @@ -1775,7 +1775,7 @@ export class AmpStoryPage extends AMP.BaseElement {
*/
openAttachment(shouldAnimate = true) {
const attachmentEl = this.element.querySelector(
'amp-story-page-attachment, amp-story-page-outlink'
'amp-story-page-attachment, amp-story-page-outlink, amp-story-shopping-attachment'
);

if (!attachmentEl) {
Expand Down
9 changes: 8 additions & 1 deletion test/visual-diff/visual-tests.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,13 @@
"viewport": {"width": 1440, "height": 900},
"loading_complete_selectors": [".i-amphtml-story-loaded"],
"interactive_tests": "examples/visual-tests/amp-story/amp-story-page-attachment.js"
}
},
{
"url": "examples/visual-tests/amp-story/amp-story-shopping.html",
"name": "amp-story-shopping UI",
"viewport": {"width": 320, "height": 480},
"loading_complete_selectors": [".i-amphtml-story-loaded"],
"interactive_tests": "examples/visual-tests/amp-story/amp-story-shopping.js"
}
]
}

0 comments on commit 111a668

Please sign in to comment.