From 7971880200e6d19d330c6263855c23f34a63aac9 Mon Sep 17 00:00:00 2001 From: Nicolas Peltier <1032754+npeltier@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:16:24 +0200 Subject: [PATCH] MWPW-146326 introduce promo text for all cards (#2483) * MWPW-146326 refactor merch-card unit tests * MWPW-146326 introduce promo text for all merch cards except special offer cards. Also get rid of Devices text in slot['detail-m'] as per ticket decision * MWPW-146326 first set of feedbacks * MWPW-146326 removing only * MWPW-146326 some more changes * MWPW-146326 fixed new lint issues * MWPW-146326 make card UT more talkative * MWPW-146326 rename TEXT_STYLES * MWPW-146326 last changes * MWPW-146326 final commit from mas main --- libs/blocks/merch-card/merch-card.js | 10 +- libs/deps/merch-card.js | 38 +- test/blocks/merch-card/merch-card.test.js | 414 ++++++++---------- test/blocks/merch-card/mocks/catalog.html | 8 +- .../merch-card/mocks/intro-pricing.html | 1 + .../merch-card/mocks/mini-compare-chart.html | 1 + test/blocks/merch-card/mocks/plans-card.html | 4 +- .../blocks/merch-card/mocks/segment-card.html | 1 + 8 files changed, 215 insertions(+), 262 deletions(-) diff --git a/libs/blocks/merch-card/merch-card.js b/libs/blocks/merch-card/merch-card.js index 189f65db38..e247b9127d 100644 --- a/libs/blocks/merch-card/merch-card.js +++ b/libs/blocks/merch-card/merch-card.js @@ -28,13 +28,15 @@ const CARD_TYPES = [ const CARD_SIZES = ['wide', 'super-wide']; -const TEXT_STYLES = { - H5: 'detail-m', +const SLOT_MAP_DEFAULT = { + H5: 'promo-text', H4: 'body-xxs', H3: 'heading-xs', H2: 'heading-m', }; +const SLOT_MAP = { 'special-offers': { H5: 'detail-m' } }; + const HEADING_MAP = { 'special-offers': { H5: 'H4', @@ -153,9 +155,7 @@ const parseContent = async (el, merchCard) => { if (merchCard.variant === MINI_COMPARE_CHART) { bodySlotName = 'body-m'; - const promoText = el.querySelectorAll('h5'); const priceSmallType = el.querySelectorAll('h6'); - appendSlot(promoText, 'promo-text', merchCard); appendSlot(priceSmallType, 'price-commitment', merchCard); } @@ -171,7 +171,7 @@ const parseContent = async (el, merchCard) => { innerElements.forEach((element) => { let { tagName } = element; if (isHeadingTag(tagName)) { - let slotName = TEXT_STYLES[tagName]; + let slotName = SLOT_MAP[merchCard.variant]?.[tagName] || SLOT_MAP_DEFAULT[tagName]; if (slotName) { if (['H2', 'H3', 'H4', 'H5'].includes(tagName)) { element.classList.add('card-heading'); diff --git a/libs/deps/merch-card.js b/libs/deps/merch-card.js index 48a7f7b1b7..397c18271c 100644 --- a/libs/deps/merch-card.js +++ b/libs/deps/merch-card.js @@ -1,4 +1,4 @@ -// branch: develop commit: 074fea3f15242a36834be88bb51eaec58799ee75 Fri, 14 Jun 2024 14:18:48 GMT +// branch: main commit: fbbefe1b71216b73b1e41d50997927fbc7340473 Tue, 25 Jun 2024 15:33:55 GMT import{html as a,LitElement as j}from"/libs/deps/lit-all.min.js";import{LitElement as q,html as T,css as F}from"/libs/deps/lit-all.min.js";var s=class extends q{static properties={size:{type:String,attribute:!0},src:{type:String,attribute:!0},alt:{type:String,attribute:!0},href:{type:String,attribute:!0}};constructor(){super(),this.size="m",this.alt=""}render(){let{href:e}=this;return e?T` ${this.alt} `:T` ${this.alt}`}static styles=F` @@ -414,7 +414,6 @@ import{html as a,LitElement as j}from"/libs/deps/lit-all.min.js";import{LitEleme } `),p};var[_,M,O,L,N,te]=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter","Tab"];var P=document.createElement("style");P.innerHTML=` :root { - --consonant-merch-card-detail-font-size: 12px; --consonant-merch-card-detail-font-weight: 500; --consonant-merch-card-detail-letter-spacing: 0.8px; @@ -425,7 +424,7 @@ import{html as a,LitElement as j}from"/libs/deps/lit-all.min.js";import{LitEleme --consonant-merch-card-heading-secondary-font-size: 14px; --consonant-merch-card-body-font-size: 14px; --consonant-merch-card-body-line-height: 21px; - --consonant-merch-card-promo-text-height: 17px; + --consonant-merch-card-promo-text-height: var(--consonant-merch-card-body-font-size); /* responsive width */ --consonant-merch-card-mobile-width: 300px; @@ -828,7 +827,14 @@ merch-card [slot="promo-text"] { padding: 0; } + +merch-card[variant="mini-compare-chart"] [slot="body-xxs"] { + font-size: var(--consonant-merch-card-body-xs-font-size); + padding: var(--consonant-merch-spacing-xs) var(--consonant-merch-spacing-s) 0; +} + merch-card[variant="mini-compare-chart"] [slot="promo-text"] { + font-size: var(--consonant-merch-card-body-m-font-size); padding: var(--consonant-merch-spacing-xs) var(--consonant-merch-spacing-s) 0; } @@ -910,9 +916,14 @@ merch-card[variant="mini-compare-chart"] .footer-row-cell-description a { padding: 0 var(--consonant-merch-spacing-xs); } + merch-card[variant="mini-compare-chart"] [slot="body-xxs"] { + font-size: var(--consonant-merch-card-body-xs-font-size); + padding: 0 var(--consonant-merch-spacing-xs); + } + merch-card[variant="mini-compare-chart"] [slot="promo-text"] { font-size: var(--consonant-merch-card-body-xs-font-size); - padding: var(--consonant-merch-spacing-xs); + padding: 0 var(--consonant-merch-spacing-xs); } merch-card[variant="mini-compare-chart"] .footer-row-cell { @@ -1387,7 +1398,7 @@ body.merch-modal { scrollbar-gutter: stable; height: 100vh; } -`;document.head.appendChild(P);var H="merch-offer-select:ready",D="merch-card:ready";var C="merch-storage:change",z="merch-quantity-selector:change";function B(p){let e=[];function t(r){r.nodeType===Node.TEXT_NODE?e.push(r):r.childNodes.forEach(t)}return t(p),e}var l="MERCH-CARD",g="merch-card",W=32,S="mini-compare-chart",I=p=>`--consonant-merch-card-footer-row-${p}-min-height`,d=class extends j{static properties={name:{type:String,attribute:"name",reflect:!0},variant:{type:String,reflect:!0},size:{type:String,attribute:"size",reflect:!0},badgeColor:{type:String,attribute:"badge-color"},badgeBackgroundColor:{type:String,attribute:"badge-background-color"},badgeText:{type:String,attribute:"badge-text"},actionMenu:{type:Boolean,attribute:"action-menu"},actionMenuContent:{type:String,attribute:"action-menu-content"},customHr:{type:Boolean,attribute:"custom-hr"},detailBg:{type:String,attribute:"detail-bg"},secureLabel:{type:String,attribute:"secure-label"},checkboxLabel:{type:String,attribute:"checkbox-label"},selected:{type:Boolean,attribute:"aria-selected",reflect:!0},storageOption:{type:String,attribute:"storage",reflect:!0},stockOfferOsis:{type:Object,attribute:"stock-offer-osis",converter:{fromAttribute:e=>{let[t,r,n]=e.split(",");return{PUF:t,ABM:r,M2M:n}}}},filters:{type:String,reflect:!0,converter:{fromAttribute:e=>Object.fromEntries(e.split(",").map(t=>{let[r,n,o]=t.split(":"),m=Number(n);return[r,{order:isNaN(m)?void 0:m,size:o}]})),toAttribute:e=>Object.entries(e).map(([t,{order:r,size:n}])=>[t,r,n].filter(o=>o!=null).join(":")).join(",")}},types:{type:String,attribute:"types",reflect:!0},merchOffer:{type:Object}};static styles=[A,...R()];customerSegment;marketSegment;constructor(){super(),this.filters={},this.types="",this.selected=!1}#e;updated(e){e.has("badgeBackgroundColor")&&this.variant!=="twp"&&(this.style.border=`1px solid ${this.badgeBackgroundColor}`),this.updateComplete.then(async()=>{let t=Array.from(this.querySelectorAll('span[is="inline-price"][data-wcs-osi]'));await Promise.all(t.map(r=>r.onceSettled())),this.adjustTitleWidth(),this.adjustMiniCompareBodySlots(),this.adjustMiniCompareFooterRows()})}get evergreen(){return this.classList.contains("intro-pricing")}get stockCheckbox(){return this.checkboxLabel?a`