From 7543e278924a825cbbb2495796a443d737a52051 Mon Sep 17 00:00:00 2001 From: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:14:30 -0600 Subject: [PATCH] MWPW-146211 [MILO][MEP] Option to select all elements (#2976) * stash * stash * stash * working well * set updated command list for inline * remove querySelector function * unit test and custom block fix * updates for in-block * merch-card-collection unit test fixed * unit test updates * more unit test repair * linting errors * more linting * Fix Invalid selector test * add coverage * force git checks to refire * remove comment * pass rootEl to getSelectedElements for use when needed (gnav) * skip if clause in codecov --------- Co-authored-by: markpadbe --- libs/blocks/fragment/fragment.js | 18 ++- .../global-navigation/utilities/utilities.js | 5 +- .../merch-card-collection.js | 4 +- .../personalization/personalization.js | 103 ++++++++++-------- test/blocks/fragment/fragment.test.js | 14 +++ .../merch-card-collection.test.js | 4 +- test/features/personalization/actions.test.js | 32 ++++-- .../actionsTargetManifestId.test.js | 8 -- .../parseNestedPlaceholders.test.js | 16 ++- .../personalization/personalization.test.js | 33 ++---- 10 files changed, 138 insertions(+), 99 deletions(-) diff --git a/libs/blocks/fragment/fragment.js b/libs/blocks/fragment/fragment.js index 7e740c50c3..dd938b4374 100644 --- a/libs/blocks/fragment/fragment.js +++ b/libs/blocks/fragment/fragment.js @@ -32,15 +32,18 @@ const updateFragMap = (fragment, a, href) => { } }; -const insertInlineFrag = (sections, a, relHref) => { +const insertInlineFrag = (sections, a, relHref, mep, handleMepCommands) => { // Inline fragments only support one section, other sections are ignored const fragChildren = [...sections[0].children]; - fragChildren.forEach((child) => child.setAttribute('data-path', relHref)); if (a.parentElement.nodeName === 'DIV' && !a.parentElement.attributes.length) { a.parentElement.replaceWith(...fragChildren); } else { a.replaceWith(...fragChildren); } + fragChildren.forEach((child) => { + child.setAttribute('data-path', relHref); + if (handleMepCommands) mep.commands = handleMepCommands(mep.commands, child); + }); }; function replaceDotMedia(path, doc) { @@ -74,7 +77,8 @@ export default async function init(a) { const path = new URL(a.href).pathname; if (mep?.fragments?.[path]) { - relHref = mep.handleFragmentCommand(mep?.fragments[path], a); + const { handleFragmentCommand } = await import('../../features/personalization/personalization.js'); + relHref = handleFragmentCommand(mep?.fragments[path], a); if (!relHref) return; } @@ -119,10 +123,16 @@ export default async function init(a) { const { updateFragDataProps } = await import('../../features/personalization/personalization.js'); updateFragDataProps(a, inline, sections, fragment); } + let handleMepCommands = false; + if (mep?.commands?.length) { + const { handleCommands } = await import('../../features/personalization/personalization.js'); + handleMepCommands = handleCommands; + } if (inline) { - insertInlineFrag(sections, a, relHref); + insertInlineFrag(sections, a, relHref, mep, handleMepCommands); } else { a.parentElement.replaceChild(fragment, a); + if (handleMepCommands) handleMepCommands(mep?.commands, fragment); await loadArea(fragment); } } diff --git a/libs/blocks/global-navigation/utilities/utilities.js b/libs/blocks/global-navigation/utilities/utilities.js index fcbd01abac..a5050ea458 100644 --- a/libs/blocks/global-navigation/utilities/utilities.js +++ b/libs/blocks/global-navigation/utilities/utilities.js @@ -321,7 +321,7 @@ export async function fetchAndProcessPlainHtml({ url, shouldDecorateLinks = true const mepGnav = getConfig()?.mep?.inBlock?.['global-navigation']; const mepFragment = mepGnav?.fragments?.[path]; if (mepFragment && mepFragment.action === 'replace') { - path = mepFragment.target; + path = mepFragment.content; } const res = await fetch(path.replace(/(\.html$|$)/, '.plain.html')); if (res.status !== 200) { @@ -338,8 +338,9 @@ export async function fetchAndProcessPlainHtml({ url, shouldDecorateLinks = true if (mepFragment?.targetManifestId) body.dataset.adobeTargetTestid = mepFragment.targetManifestId; const commands = mepGnav?.commands; if (commands?.length) { + /* c8 ignore next 4 */ const { handleCommands, deleteMarkedEls } = await import('../../../features/personalization/personalization.js'); - handleCommands(commands, body, true); + handleCommands(commands, body, true, true); deleteMarkedEls(body); } const inlineFrags = [...body.querySelectorAll('a[href*="#_inline"]')]; diff --git a/libs/blocks/merch-card-collection/merch-card-collection.js b/libs/blocks/merch-card-collection/merch-card-collection.js index dad54cb600..b6d7f90163 100644 --- a/libs/blocks/merch-card-collection/merch-card-collection.js +++ b/libs/blocks/merch-card-collection/merch-card-collection.js @@ -58,10 +58,10 @@ async function getCardsRoot(config, html) { } const fetchOverrideCard = (action, config) => new Promise((resolve, reject) => { - fetch(`${localizeLink(overrideUrlOrigin(action?.target))}.plain.html`).then((res) => { + fetch(`${localizeLink(overrideUrlOrigin(action?.content))}.plain.html`).then((res) => { if (res.ok) { res.text().then((cardContent) => { - const response = { path: action.target, cardContent: /^
(.*)<\/div>$/.exec(cardContent.replaceAll('\n', ''))[1] }; + const response = { path: action.content, cardContent: /^
(.*)<\/div>$/.exec(cardContent.replaceAll('\n', ''))[1] }; if (config?.mep?.preview) response.manifestId = action.manifestId; resolve(response); }); diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index dfc1ac354d..886acbb9b2 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -32,6 +32,10 @@ const COLUMN_NOT_OPERATOR = 'not '; const TARGET_EXP_PREFIX = 'target-'; const INLINE_HASH = '_inline'; const PAGE_URL = new URL(window.location.href); +const FLAGS = { + all: 'all', + includeFragments: 'include-fragments', +}; export const TRACKED_MANIFEST_TYPE = 'personalization'; @@ -159,7 +163,7 @@ export function replacePlaceholders(value, placeholders) { return val; } -export const createContent = (el, content, manifestId, targetManifestId, action, modifiers) => { +export const createContent = (el, { content, manifestId, targetManifestId, action, modifiers }) => { if (action === 'replace') { addIds(el, manifestId, targetManifestId); } @@ -190,19 +194,19 @@ export const createContent = (el, content, manifestId, targetManifestId, action, }; const COMMANDS = { - [COMMANDS_KEYS.remove]: ({ el, target, manifestId }) => { - if (target === 'false') return; + [COMMANDS_KEYS.remove]: (el, { content, manifestId }) => { + if (content === 'false') return; if (manifestId) { el.dataset.removedManifestId = manifestId; return; } el.classList.add(CLASS_EL_DELETE); }, - [COMMANDS_KEYS.replace]: ({ el, target, modifiers, manifestId, targetManifestId }) => { + [COMMANDS_KEYS.replace]: (el, cmd) => { if (!el || el.classList.contains(CLASS_EL_REPLACE)) return; el.insertAdjacentElement( 'beforebegin', - createContent(el, target, manifestId, targetManifestId, 'replace', modifiers), + createContent(el, cmd), ); }, }; @@ -319,20 +323,9 @@ function normalizeKeys(obj) { }, {}); } -const querySelector = (el, selector, all = false) => { - try { - return all ? el.querySelectorAll(selector) : el.querySelector(selector); - } catch (e) { - /* eslint-disable-next-line no-console */ - log('Invalid selector: ', selector); - return null; - } -}; -function registerInBlockActions(cmd, manifestId, targetManifestId) { - const { action, target, selector } = cmd; - const command = { action, target, manifestId, targetManifestId }; - - const blockAndSelector = selector.substring(IN_BLOCK_SELECTOR_PREFIX.length).trim().split(/\s+/); +function registerInBlockActions(command) { + const blockAndSelector = command.selector.substring(IN_BLOCK_SELECTOR_PREFIX.length) + .trim().split(/\s+/); const [blockName] = blockAndSelector; const config = getConfig(); @@ -340,6 +333,7 @@ function registerInBlockActions(cmd, manifestId, targetManifestId) { config.mep.inBlock[blockName] ??= {}; let blockSelector; + if (blockAndSelector.length === 1) delete command.selector; if (blockAndSelector.length > 1) { blockSelector = blockAndSelector.slice(1).join(' '); command.selector = blockSelector; @@ -351,14 +345,14 @@ function registerInBlockActions(cmd, manifestId, targetManifestId) { // eslint-disable-next-line no-restricted-syntax for (const key in fragments) { - if (fragments[key].target === blockSelector) fragments[key] = command; + if (fragments[key].content === blockSelector) fragments[key] = command; } fragments[blockSelector] = command; blockSelector = normalizePath(blockSelector); // eslint-disable-next-line no-restricted-syntax for (const key in fragments) { - if (fragments[key].target === blockSelector) fragments[key] = command; + if (fragments[key].content === blockSelector) fragments[key] = command; } fragments[blockSelector] = command; return; @@ -439,24 +433,34 @@ export function modifyNonFragmentSelector(selector) { }; } -function getSelectedElement({ selector: sel, rootEl }) { +function getSelectedElements(sel, rootEl, forceRootEl) { + const root = forceRootEl ? rootEl : document; const selector = sel.trim(); if (!selector) return {}; if (getSelectorType(selector) === 'fragment') { try { - const fragment = document.querySelector( + const fragments = root.querySelectorAll( `a[href*="${normalizePath(selector, false)}"], a[href*="${normalizePath(selector, true)}"]`, ); - if (fragment) return { el: fragment.parentNode }; - return {}; + return { els: fragments, modifiers: [FLAGS.all, FLAGS.includeFragments] }; } catch (e) { /* c8 ignore next */ - return {}; + return { els: [], modifiers: [] }; } } const { modifiedSelector, modifiers } = modifyNonFragmentSelector(selector); - return { el: querySelector(rootEl || document, modifiedSelector), modifiers }; + let els; + try { + els = root.querySelectorAll(modifiedSelector); + } catch (e) { + /* eslint-disable-next-line no-console */ + log('Invalid selector: ', selector); + return null; + } + if (modifiers.includes(FLAGS.all) || !els.length) return { els, modifiers }; + els = [els[0]]; + return { els, modifiers }; } const addHash = (url, newHash) => { if (!newHash) return url; @@ -484,29 +488,39 @@ export const updateFragDataProps = (a, inline, sections, fragment) => { } }; -export function handleCommands(commands, rootEl = document, forceInline = false) { +export function handleCommands(commands, rootEl, forceInline = false, forceRootEl = false) { commands.forEach((cmd) => { - const { manifestId, targetManifestId, action, selector, target: trgt } = cmd; - const target = forceInline ? addHash(trgt, INLINE_HASH) : trgt; + const { action, content, selector } = cmd; + cmd.content = forceInline ? addHash(content, INLINE_HASH) : content; if (selector.startsWith(IN_BLOCK_SELECTOR_PREFIX)) { - registerInBlockActions(cmd, manifestId, targetManifestId); + registerInBlockActions(cmd); + cmd.selectorType = IN_BLOCK_SELECTOR_PREFIX; return; } - const { el, modifiers } = getSelectedElement({ selector, rootEl }); + const { els, modifiers } = getSelectedElements(selector, rootEl, forceRootEl); + cmd.modifiers = modifiers; - if (!el || (!(action in COMMANDS) && !(action in CREATE_CMDS))) return; + els?.forEach((el) => { + if (!el || (!(action in COMMANDS) && !(action in CREATE_CMDS)) + || (rootEl && !rootEl.contains(el))) return; - if (action in COMMANDS) { - COMMANDS[action]({ - el, target, manifestId, targetManifestId, action, modifiers, - }); - return; + if (action in COMMANDS) { + COMMANDS[action](el, cmd); + return; + } + const insertAnchor = getSelectorType(selector) === 'fragment' ? el.parentElement : el; + insertAnchor?.insertAdjacentElement( + CREATE_CMDS[action], + createContent(el, cmd), + ); + }); + if ((els.length && !cmd.modifiers.includes(FLAGS.all)) + || !cmd.modifiers.includes(FLAGS.includeFragments)) { + cmd.completed = true; } - el?.insertAdjacentElement( - CREATE_CMDS[action], - createContent(el, target, manifestId, targetManifestId, action, modifiers), - ); }); + return commands.filter((cmd) => !cmd.completed + && cmd.selectorType !== IN_BLOCK_SELECTOR_PREFIX); } const getVariantInfo = (line, variantNames, variants, manifestPath, fTargetId) => { @@ -537,7 +551,7 @@ const getVariantInfo = (line, variantNames, variants, manifestPath, fTargetId) = action, selector, pageFilter, - target: line[vn], + content: line[vn], selectorType: getSelectorType(selector), manifestId, targetManifestId, @@ -986,7 +1000,7 @@ export async function applyPers(manifests, postLCP = false) { addIds(main, manifestId, targetManifestId); } - if (!postLCP) handleCommands(config.mep.commands); + if (!postLCP) config.mep.commands = handleCommands(config.mep.commands); deleteMarkedEls(); const pznList = results.filter((r) => (r.experiment?.manifestType === TRACKED_MANIFEST_TYPE)); @@ -1048,7 +1062,6 @@ export async function init(enablements = {}) { const config = getConfig(); if (!postLCP) { config.mep = { - handleFragmentCommand, updateFragDataProps, preview: (mepButton !== 'off' && (config.env?.name !== 'prod' || mepParam || mepParam === '' || mepButton)), diff --git a/test/blocks/fragment/fragment.test.js b/test/blocks/fragment/fragment.test.js index 2e1a7ef8a5..d77d5c1a33 100644 --- a/test/blocks/fragment/fragment.test.js +++ b/test/blocks/fragment/fragment.test.js @@ -16,6 +16,20 @@ const config = { contentRoot: `${window.location.origin}${getLocale(locales).prefix}`, decorateArea, locales, + mep: { + commands: [ + { + action: 'remove', + selector: 'aside.large p:nth-child(1):has(picture) #_include-fragments', + pageFilter: '', + content: 'true', + selectorType: 'other', + manifestId: 'manifest.json', + targetManifestId: false, + modifiers: ['include-fragments'], + }, + ], + }, }; setConfig(config); diff --git a/test/blocks/merch-card-collection/merch-card-collection.test.js b/test/blocks/merch-card-collection/merch-card-collection.test.js index e70dcda3cb..6854e6645c 100644 --- a/test/blocks/merch-card-collection/merch-card-collection.test.js +++ b/test/blocks/merch-card-collection/merch-card-collection.test.js @@ -171,12 +171,12 @@ describe('Merch Cards', async () => { { action: 'replace', manifestId: 'promo1.json', - target: '/override-photoshop', + content: '/override-photoshop', }, { action: 'replace', manifestId: 'promo2.json', - target: '/override-express', + content: '/override-express', }, ], }, diff --git a/test/features/personalization/actions.test.js b/test/features/personalization/actions.test.js index 19057fd2eb..d0a7d0dc83 100644 --- a/test/features/personalization/actions.test.js +++ b/test/features/personalization/actions.test.js @@ -40,7 +40,8 @@ describe('replace action', () => { const el = parentEl.firstElementChild.firstElementChild; expect(el.href) .to.equal('http://localhost:2000/test/features/personalization/mocks/fragments/milo-replace-content-chrome-howto-h2'); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); + const el2 = document.querySelector('a[href="/test/features/personalization/mocks/fragments/milo-replace-content-chrome-howto-h2"]'); + expect(el2.dataset.adobeTargetTestid).to.equal(undefined); // .how-to should not be changed as it is targeted to firefox expect(document.querySelector('.how-to')).to.not.be.null; }); @@ -55,7 +56,8 @@ describe('replace action', () => { expect(document.querySelector('a[href="/fragments/replaceme"]')).to.exist; expect(document.querySelector('a[href="/fragments/inline-replaceme#_inline"]')).to.exist; await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); + const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/milo-replace-content-chrome-howto-h2"]'); + expect(el.dataset.adobeTargetTestid).to.be.equal(undefined); const fragmentResp = await readFile({ path: './mocks/fragments/fragmentReplaced.plain.html' }); const inlineFragmentResp = await readFile({ path: './mocks/fragments/inlineFragReplaced.plain.html' }); @@ -139,7 +141,8 @@ describe('prependToSection action', async () => { expect(document.querySelector('a[href="/test/features/personalization/mocks/fragments/prependToSection"]')).to.be.null; await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); + const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/prependToSection"]'); + expect(el.dataset.adobeTargetTestid).to.equal(undefined); const fragment = document.querySelector('main > div:nth-child(2) > div:first-child a[href="/test/features/personalization/mocks/fragments/prependToSection"]'); expect(fragment).to.not.be.null; @@ -156,7 +159,8 @@ describe('appendToSection action', async () => { expect(document.querySelector('a[href="/test/features/personalization/mocks/fragments/appendToSection"]')).to.be.null; await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); + const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/appendToSection"]'); + expect(el.dataset.adobeTargetTestid).to.equal(undefined); const fragment = document.querySelector('main > div:nth-child(2) > div:last-child a[href="/test/features/personalization/mocks/fragments/appendToSection"]'); expect(fragment).to.not.be.null; @@ -198,7 +202,6 @@ describe('remove action', () => { setFetchResponse(manifestJson); mepSettings.mepButton = 'off'; await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); }); it('remove should remove content', async () => { expect(document.querySelector('.z-pattern')).to.be.null; @@ -221,7 +224,6 @@ describe('remove action', () => { expect(document.querySelector('.z-pattern')).to.not.be.null; mepSettings.mepButton = false; await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); expect(document.querySelector('.z-pattern')).to.not.be.null; expect(document.querySelector('.z-pattern').dataset.removedManifestId).to.not.be.null; @@ -274,7 +276,6 @@ describe('custom actions', async () => { manifestJson = JSON.parse(manifestJson); setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); expect(getConfig().mep.custom).to.be.undefined; }); @@ -288,29 +289,38 @@ describe('custom actions', async () => { 'my-block': { commands: [{ action: 'replace', - target: '/fragments/fragmentreplaced', + content: '/fragments/fragmentreplaced', manifestId: false, targetManifestId: false, + pageFilter: '', + // selector: 'in-block:my-block', + selectorType: 'in-block:', }, { action: 'replace', - target: '/fragments/new-large-menu', + content: '/fragments/new-large-menu', manifestId: false, selector: '.large-menu', targetManifestId: false, + pageFilter: '', + selectorType: 'in-block:', }], fragments: { '/fragments/sub-menu': { action: 'replace', - target: '/fragments/even-more-new-sub-menu', + content: '/fragments/even-more-new-sub-menu', manifestId: false, targetManifestId: false, + pageFilter: '', + selectorType: 'in-block:', }, '/fragments/new-sub-menu': { action: 'replace', - target: '/fragments/even-more-new-sub-menu', + content: '/fragments/even-more-new-sub-menu', manifestId: false, targetManifestId: false, + pageFilter: '', + selectorType: 'in-block:', }, }, }, diff --git a/test/features/personalization/actionsTargetManifestId.test.js b/test/features/personalization/actionsTargetManifestId.test.js index 9f649f2e58..ee247e90a9 100644 --- a/test/features/personalization/actionsTargetManifestId.test.js +++ b/test/features/personalization/actionsTargetManifestId.test.js @@ -31,7 +31,6 @@ describe('replace action', () => { manifestJson = JSON.parse(manifestJson); setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal('manifest'); const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/milo-replace-content-chrome-howto-h2"]'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); }); @@ -44,7 +43,6 @@ describe('replace action', () => { setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.fragments['/fragments/replaceme'].targetManifestId).to.equal('manifest'); const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/milo-replace-content-chrome-howto-h2"]'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); const fragmentResp = await readFile({ path: './mocks/fragments/fragmentReplaced.plain.html' }); @@ -73,7 +71,6 @@ describe('insertAfter action', async () => { setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal('manifest'); const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/insertafter"]'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); }); @@ -87,7 +84,6 @@ describe('insertBefore action', async () => { setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal('manifest'); const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/insertbefore"]'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); }); @@ -102,7 +98,6 @@ describe('prependToSection action', async () => { expect(document.querySelector('a[href="/test/features/personalization/mocks/fragments/prependToSection"]')).to.be.null; await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal('manifest'); const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/prependToSection"]'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); }); @@ -117,7 +112,6 @@ describe('appendToSection action', async () => { setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.commands[0].targetManifestId).to.equal('manifest'); const el = document.querySelector('a[href="/test/features/personalization/mocks/fragments/appendToSection"]'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); }); @@ -154,7 +148,6 @@ describe('useBlockCode action', async () => { setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.experiments[0].selectedVariant.useblockcode[0].targetManifestId).to.equal('manifest'); await addMepAnalytics(config); const el = document.querySelector('.promo'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); @@ -166,7 +159,6 @@ describe('useBlockCode action', async () => { setFetchResponse(manifestJson); await init(mepSettings); - expect(getConfig().mep.experiments[0].selectedVariant.useblockcode[0].targetManifestId).to.equal('manifest'); await addMepAnalytics(config); const el = document.querySelector('.myblock'); expect(el.dataset.adobeTargetTestid).to.equal('manifest'); diff --git a/test/features/personalization/parseNestedPlaceholders.test.js b/test/features/personalization/parseNestedPlaceholders.test.js index 43a5d05071..a6ccf6873f 100644 --- a/test/features/personalization/parseNestedPlaceholders.test.js +++ b/test/features/personalization/parseNestedPlaceholders.test.js @@ -20,12 +20,24 @@ describe('test different values for parseNestedPlaceholders', () => { describe('test createContent', () => { const el = document.createElement('div'); it('append action', () => { - const newContent = createContent(el, '{{promo-discount}}', false, false, 'append', []); + const newContent = createContent(el, { + content: '{{promo-discount}}', + manifestId: false, + targetManifestId: false, + action: 'append', + modifiers: [], + }); expect(newContent.innerHTML).to.equal('50'); }); it('replace action', () => { el.innerHTML = 'Hello World'; - const newContent = createContent(el, '{{promo-discount}}', false, false, 'replace', []); + const newContent = createContent(el, { + content: '{{promo-discount}}', + manifestId: false, + targetManifestId: false, + action: 'replace', + modifiers: [], + }); expect(newContent.innerHTML).to.equal('50'); }); }); diff --git a/test/features/personalization/personalization.test.js b/test/features/personalization/personalization.test.js index 33ae9f2c97..0f4322e7be 100644 --- a/test/features/personalization/personalization.test.js +++ b/test/features/personalization/personalization.test.js @@ -325,28 +325,6 @@ describe('Functional Test', () => { }); }); -describe('matchGlob function', () => { - it('should match page', async () => { - const result = matchGlob('/products/special-offers', '/products/special-offers'); - expect(result).to.be.true; - }); - - it('should match page with HTML extension', async () => { - const result = matchGlob('/products/special-offers', '/products/special-offers.html'); - expect(result).to.be.true; - }); - - it('should not match child page', async () => { - const result = matchGlob('/products/special-offers', '/products/special-offers/free-download'); - expect(result).to.be.false; - }); - - it('should match child page', async () => { - const result = matchGlob('/products/special-offers**', '/products/special-offers/free-download'); - expect(result).to.be.true; - }); -}); - describe('matchGlob function', () => { it('should match page', async () => { const result = matchGlob('/products/special-offers', '/products/special-offers'); @@ -372,7 +350,16 @@ describe('matchGlob function', () => { const parent = document.createElement('div'); const el = document.createElement('div'); parent.appendChild(el); - const wrapper = createContent(el, '/fragments/promos/path-to-promo/#modal-hash:delay=1'); + const wrapper = createContent( + el, + { + content: '/fragments/promos/path-to-promo/#modal-hash:delay=1', + manifestId: 'manifest', + targetManifestId: '', + action: 'insertAfter', + modifiers: [], + }, + ); expect(wrapper.tagName).to.equal('P'); expect(wrapper.classList.contains('hide-block')).to.be.true; });