From 8956fbed0f231f51c13fd30a3fbd803b724ef2ce Mon Sep 17 00:00:00 2001 From: Axel Cureno Basurto Date: Wed, 4 Sep 2024 12:34:14 -0700 Subject: [PATCH 1/3] MWPW-157761: Tab preselect in external modals [catalog] (#2828) --- libs/blocks/merch/merch.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index 98631793cc..fd49281731 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -364,6 +364,8 @@ async function openExternalModal(url, getModal) { }); } +const isInternalModal = (url) => /\/fragments\//.test(url); + export async function openModal(e, url, offerType) { e.preventDefault(); e.stopImmediatePropagation(); @@ -371,7 +373,7 @@ export async function openModal(e, url, offerType) { await import('../modal/modal.merch.js'); const offerTypeClass = offerType === OFFER_TYPE_TRIAL ? 'twp' : 'crm'; let modal; - if (/\/fragments\//.test(url)) { + if (isInternalModal(url)) { const fragmentPath = url.split(/hlx.(page|live)/).pop(); modal = await openFragmentModal(fragmentPath, getModal); } else { @@ -398,7 +400,8 @@ export async function getModalAction(offers, options) { const columnName = (offerType === OFFER_TYPE_TRIAL) ? FREE_TRIAL_PATH : BUY_NOW_PATH; let url = checkoutLinkConfig[columnName]; if (!url) return undefined; - url = localizeLink(checkoutLinkConfig[columnName]); + url = isInternalModal(url) + ? localizeLink(checkoutLinkConfig[columnName]) : checkoutLinkConfig[columnName]; return { url, handler: (e) => openModal(e, url, offerType) }; } From f7dc1e2a2f31520cf978b6d1ed015bfa5998d3b6 Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Wed, 4 Sep 2024 12:34:21 -0700 Subject: [PATCH 2/3] MWPW-155720: Dynamic nav ignore values (#2739) * Working, needs refactoring and tests * Tests and mocks added * Removing sinon and stub * Clarifying the test statement * Changes to some instead of reduce, tests not working * Refactored logic, tests working, additional test * Some test cleanup * Clarifying function name --------- Co-authored-by: milo-pr-merge[bot] <169241390+milo-pr-merge[bot]@users.noreply.github.com> --- libs/features/dynamic-navigation.js | 13 ++++++++ test/features/dynamic-nav/dynamicNav.test.js | 32 ++++++++++++++++++- .../mocks/on-ignore-does-not-match.html | 3 ++ .../dynamic-nav/mocks/on-ignore-match.html | 3 ++ .../mocks/on-ignore-misspelled.html | 3 ++ .../mocks/on-ignore-no-content.html | 3 ++ .../mocks/on-ignore-some-matches.html | 5 +++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/features/dynamic-nav/mocks/on-ignore-does-not-match.html create mode 100644 test/features/dynamic-nav/mocks/on-ignore-match.html create mode 100644 test/features/dynamic-nav/mocks/on-ignore-misspelled.html create mode 100644 test/features/dynamic-nav/mocks/on-ignore-no-content.html create mode 100644 test/features/dynamic-nav/mocks/on-ignore-some-matches.html diff --git a/libs/features/dynamic-navigation.js b/libs/features/dynamic-navigation.js index e959365e2e..7f901a2629 100644 --- a/libs/features/dynamic-navigation.js +++ b/libs/features/dynamic-navigation.js @@ -1,6 +1,19 @@ import { getMetadata } from '../utils/utils.js'; +function isDynamicNavDisabled() { + const dynamicNavDisableValues = getMetadata('dynamic-nav-disable'); + if (!dynamicNavDisableValues) return false; + + const metadataPairsMap = dynamicNavDisableValues.split(',').map((pair) => pair.split(';')); + return metadataPairsMap.some(([metadataKey, metadataContent]) => { + const metaTagContent = getMetadata(metadataKey.toLowerCase()); + return (metaTagContent + && metaTagContent.toLowerCase() === metadataContent.toLowerCase()); + }); +} + export default function dynamicNav(url, key) { + if (isDynamicNavDisabled()) return url; const metadataContent = getMetadata('dynamic-nav'); if (metadataContent === 'entry') { diff --git a/test/features/dynamic-nav/dynamicNav.test.js b/test/features/dynamic-nav/dynamicNav.test.js index 47b168ccfa..909abd9a44 100644 --- a/test/features/dynamic-nav/dynamicNav.test.js +++ b/test/features/dynamic-nav/dynamicNav.test.js @@ -39,10 +39,40 @@ describe('Dynamic nav', () => { expect(url).to.equal('some-source-string'); }); - it('Returns the pprovided url if it does not find an item in sessionStorage and dynamic nav is on', async () => { + it('Returns the provided url if it does not find an item in sessionStorage and dynamic nav is on', async () => { document.head.innerHTML = await readFile({ path: './mocks/on.html' }); window.sessionStorage.removeItem('gnavSource'); const url = dynamicNav('gnav/aem-sites', 'bacom'); expect(url).to.equal('gnav/aem-sites'); }); + + it('Returns the provided url if it finds a metadata that matches items in the ignore list', async () => { + document.head.innerHTML = await readFile({ path: './mocks/on-ignore-match.html' }); + const url = dynamicNav('gnav/aem-sites', 'bacom'); + expect(url).to.equal('gnav/aem-sites'); + }); + + it('Returns the provided url when ignore items match some metadata but not all', async () => { + document.head.innerHTML = await readFile({ path: './mocks/on-ignore-some-matches.html' }); + const url = dynamicNav('gnav/aem-sites', 'bacom'); + expect(url).to.equal('gnav/aem-sites'); + }); + + it('Returns the sessionStorage url when dynamic nav ignore items are present but do not match the metadata', async () => { + document.head.innerHTML = await readFile({ path: './mocks/on-ignore-does-not-match.html' }); + const url = dynamicNav('gnav/aem-sites', 'bacom'); + expect(url).to.equal('some-source-string'); + }); + + it('Returns the sessionStorage url when dynamic nav ignore metadata is not found', async () => { + document.head.innerHTML = await readFile({ path: './mocks/on-ignore-misspelled.html' }); + const url = dynamicNav('gnav/aem-sites', 'bacom'); + expect(url).to.equal('some-source-string'); + }); + + it('Returns the sessionStorage url when dynamic nav ignore metadata content is empty', async () => { + document.head.innerHTML = await readFile({ path: './mocks/on-ignore-no-content.html' }); + const url = dynamicNav('gnav/aem-sites', 'bacom'); + expect(url).to.equal('some-source-string'); + }); }); diff --git a/test/features/dynamic-nav/mocks/on-ignore-does-not-match.html b/test/features/dynamic-nav/mocks/on-ignore-does-not-match.html new file mode 100644 index 0000000000..5db732ec1f --- /dev/null +++ b/test/features/dynamic-nav/mocks/on-ignore-does-not-match.html @@ -0,0 +1,3 @@ + + + diff --git a/test/features/dynamic-nav/mocks/on-ignore-match.html b/test/features/dynamic-nav/mocks/on-ignore-match.html new file mode 100644 index 0000000000..54f5df6e5d --- /dev/null +++ b/test/features/dynamic-nav/mocks/on-ignore-match.html @@ -0,0 +1,3 @@ + + + diff --git a/test/features/dynamic-nav/mocks/on-ignore-misspelled.html b/test/features/dynamic-nav/mocks/on-ignore-misspelled.html new file mode 100644 index 0000000000..365044aa08 --- /dev/null +++ b/test/features/dynamic-nav/mocks/on-ignore-misspelled.html @@ -0,0 +1,3 @@ + + + diff --git a/test/features/dynamic-nav/mocks/on-ignore-no-content.html b/test/features/dynamic-nav/mocks/on-ignore-no-content.html new file mode 100644 index 0000000000..0a58c9a003 --- /dev/null +++ b/test/features/dynamic-nav/mocks/on-ignore-no-content.html @@ -0,0 +1,3 @@ + + + diff --git a/test/features/dynamic-nav/mocks/on-ignore-some-matches.html b/test/features/dynamic-nav/mocks/on-ignore-some-matches.html new file mode 100644 index 0000000000..56ff79f5a7 --- /dev/null +++ b/test/features/dynamic-nav/mocks/on-ignore-some-matches.html @@ -0,0 +1,5 @@ + + + + + From 264c9981ff5f21b55f85547a3d06fe77eb5e6413 Mon Sep 17 00:00:00 2001 From: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:34:27 -0600 Subject: [PATCH 3/3] MWPW-157693 [MEP] Action area simplified selector does not work well with hero-marquee block (#2827) * Make action-area more flexible * unit test update --- libs/features/personalization/personalization.js | 2 +- test/features/personalization/modifyNonFragmentSelector.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 29cfddd65d..d32285ed41 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -358,7 +358,7 @@ function modifySelectorTerm(termParam) { section: 'main > div', 'primary-cta': 'p strong a', 'secondary-cta': 'p em a', - 'action-area': 'p:has(em a, strong a)', + 'action-area': '*:has(> em a, > strong a)', }; const otherSelectors = ['row', 'col']; const htmlEls = ['main', 'div', 'a', 'p', 'strong', 'em', 'picture', 'source', 'img', 'h']; diff --git a/test/features/personalization/modifyNonFragmentSelector.test.js b/test/features/personalization/modifyNonFragmentSelector.test.js index 56db63e300..7b977c3874 100644 --- a/test/features/personalization/modifyNonFragmentSelector.test.js +++ b/test/features/personalization/modifyNonFragmentSelector.test.js @@ -4,7 +4,7 @@ import { modifyNonFragmentSelector } from '../../../libs/features/personalizatio const values = [ { b: 'main section1 marquee action-area', - a: 'main > div:nth-child(1) .marquee p:has(em a, strong a)', + a: 'main > div:nth-child(1) .marquee *:has(> em a, > strong a)', }, { b: 'main > section1 .marquee h2',