Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vgoodric committed Aug 20, 2024
1 parent 89eca86 commit 6633997
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
12 changes: 8 additions & 4 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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),
);
});
}
Expand Down
10 changes: 5 additions & 5 deletions test/features/personalization/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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');
});
});

Expand All @@ -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);

Expand All @@ -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');
});
});

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"action": "insertAfter",
"selector": "#insertafter",
"selector": "#insertafter #_href",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "#modal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"action": "insertBefore",
"selector": "#insertbefore",
"selector": "#insertbefore #_href",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "/de",
Expand Down

0 comments on commit 6633997

Please sign in to comment.