diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 02d766b3be..8b1c1c52a0 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -129,8 +129,12 @@ export const createContent = (el, content, manifestId, targetManifestId, action, } if (el?.nodeName === 'A' && modifiers?.includes('href')) { if (action === 'replace') el.href = content; - else if (action === 'insertafter' || action === 'append') el.href = `${el.href}${content}`; - else if (action === 'insertbefore' || action === 'prepend') el.href = `${content}${el.href}`; + else if (action === 'insertafter' || action === 'append') { + el.setAttribute('href', `${el.getAttribute('href')}${content}`); + } else if (action === 'insertbefore' || action === 'prepend') { + el.setAttribute('href', `${content}${el.getAttribute('href')}`); + } + addManifestAndTargetId(el, manifestId, targetManifestId); return el; } if (checkSelectorType(content) !== 'fragment') { @@ -445,13 +449,13 @@ export function handleCommands(commands, rootEl = document, forceInline = false) if (action in COMMANDS) { COMMANDS[action]({ - el, target, manifestId, targetManifestId, modifiers, action, + el, target, manifestId, targetManifestId, action, modifiers, }); return; } el?.insertAdjacentElement( CREATE_CMDS[action], - createContent(el, target, manifestId, targetManifestId), + createContent(el, target, manifestId, targetManifestId, action, modifiers), ); }); } diff --git a/test/features/personalization/actions.test.js b/test/features/personalization/actions.test.js index 3ade489d31..6149bbd359 100644 --- a/test/features/personalization/actions.test.js +++ b/test/features/personalization/actions.test.js @@ -86,7 +86,7 @@ describe('insertAfter action', async () => { expect(document.querySelector('a[href="/fragments/insertafter"]')).to.be.null; expect(document.querySelector('a[href="/fragments/insertafterfragment"]')).to.be.null; - expect(document.querySelector('#insertafter').href).to.equal('/my-page.html'); + expect(document.querySelector('#insertafter').getAttribute('href')).to.equal('/my-page.html'); await init(mepSettings); expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); @@ -99,7 +99,7 @@ describe('insertAfter action', async () => { expect(fragment).to.not.be.null; expect(fragment.parentElement.previousElementSibling.querySelector('a[href="/fragments/insertaround"]')).to.exist; - expect(document.querySelector('#insertafter').href).to.equal('/my-page.html#modal'); + expect(document.querySelector('#insertafter').getAttribute('href')).to.equal('/my-page.html#modal'); }); }); @@ -111,7 +111,7 @@ describe('insertBefore action', async () => { setFetchResponse(manifestJson); expect(document.querySelector('a[href="/fragments/insertbefore"]')).to.be.null; - expect(document.querySelector('#insertbefore').href).to.equal('/my-page.html'); + expect(document.querySelector('#insertbefore').getAttribute('href')).to.equal('/my-page.html'); await init(mepSettings); expect(getConfig().mep.commands[0].targetManifestId).to.equal(false); @@ -124,7 +124,7 @@ describe('insertBefore action', async () => { expect(fragment).to.not.be.null; expect(fragment.parentElement.nextElementSibling.querySelector('a[href="/fragments/insertaround"]')).to.exist; - expect(document.querySelector('#insertbefore').href).to.equal('/de/my-page.html'); + expect(document.querySelector('#insertbefore').getAttribute('href')).to.equal('/de/my-page.html'); }); }); @@ -162,7 +162,7 @@ describe('appendToSection action', async () => { }); describe('replace action with html/text instead of fragment', () => { - it.only('should replace marquee content', async () => { + it('should replace marquee content', async () => { document.body.innerHTML = await readFile({ path: './mocks/personalization.html' }); let manifestJson = await readFile({ path: './mocks/actions/manifestUpdate.json' }); manifestJson = JSON.parse(manifestJson); diff --git a/test/features/personalization/mocks/actions/manifestInsertAfter.json b/test/features/personalization/mocks/actions/manifestInsertAfter.json index e8a95dd465..5fe1200b63 100644 --- a/test/features/personalization/mocks/actions/manifestInsertAfter.json +++ b/test/features/personalization/mocks/actions/manifestInsertAfter.json @@ -38,7 +38,7 @@ }, { "action": "insertAfter", - "selector": "#insertafter", + "selector": "#insertafter #_href", "page filter (optional)": "", "param-newoffer=123": "", "chrome": "#modal", diff --git a/test/features/personalization/mocks/actions/manifestInsertBefore.json b/test/features/personalization/mocks/actions/manifestInsertBefore.json index 8ba8260658..dd0e845941 100644 --- a/test/features/personalization/mocks/actions/manifestInsertBefore.json +++ b/test/features/personalization/mocks/actions/manifestInsertBefore.json @@ -27,7 +27,7 @@ }, { "action": "insertBefore", - "selector": "#insertbefore", + "selector": "#insertbefore #_href", "page filter (optional)": "", "param-newoffer=123": "", "chrome": "/de",