Skip to content

Commit

Permalink
Encapsulate shopping label functionality. (#37515)
Browse files Browse the repository at this point in the history
  • Loading branch information
processprocess committed Jan 31, 2022
1 parent fad7fbc commit 0eab595
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ const ctaLabelFromAttr = (element) =>
*/
const openLabelOrFallback = (element, attachmentEl, label) => {
const localizationService = Services.localizationForDoc(element);
if (attachmentEl.parentElement.tagName === 'AMP-STORY-SHOPPING-ATTACHMENT') {
return localizationService.getLocalizedString(
LocalizedStringId_Enum.AMP_STORY_SHOPPING_CTA_LABEL
);
}
return (
label?.trim() ||
localizationService.getLocalizedString(
Expand Down
20 changes: 12 additions & 8 deletions extensions/amp-story-shopping/0.1/amp-story-shopping-attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ export class AmpStoryShoppingAttachment extends AMP.BaseElement {
/** @override */
buildCallback() {
loadFonts(this.win, FONTS_TO_LOAD);
this.attachmentEl_ = (
<amp-story-page-attachment
layout="nodisplay"
theme={this.element.getAttribute('theme')}
></amp-story-page-attachment>
);
this.element.appendChild(this.attachmentEl_);
this.attachmentEl_.appendChild(this.plpContainer_);

return Promise.all([
Services.storyStoreServiceForOrNull(this.win),
Services.localizationServiceForOrNull(this.element),
]).then(([storeService, localizationService]) => {
this.storeService_ = storeService;
this.localizationService_ = localizationService;

this.attachmentEl_ = (
<amp-story-page-attachment
layout="nodisplay"
theme={this.element.getAttribute('theme')}
cta-text={this.localizationService_.getLocalizedString(
LocalizedStringId_Enum.AMP_STORY_SHOPPING_CTA_LABEL
)}
></amp-story-page-attachment>
);
this.element.appendChild(this.attachmentEl_);
this.attachmentEl_.appendChild(this.plpContainer_);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ describes.realWin(
expect(() => shoppingImpl.layoutCallback()).to.not.throw();
});

it('should build CTA with i18n shopping label text', async () => {
await dispatchTestShoppingData();
const attachmentChildEl = shoppingEl.querySelector(
'amp-story-page-attachment'
);
expect(attachmentChildEl.getAttribute('cta-text')).to.equal('Shop Now');
});

it('should open attachment', async () => {
await dispatchTestShoppingData();
const attachmentChildEl = shoppingEl.querySelector(
Expand Down

0 comments on commit 0eab595

Please sign in to comment.