Skip to content

Commit

Permalink
MWPW-167066 [MEP] Add capabilty for merch-card-collection block to ru…
Browse files Browse the repository at this point in the history
…n MEP commands (#3623)

* first commit

* add unit test
  • Loading branch information
ivanvatadobe authored Feb 7, 2025
1 parent 8d0f0d6 commit 94faeaa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
10 changes: 9 additions & 1 deletion libs/blocks/merch-card-collection/merch-card-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ const fail = (el, err = '') => {

/** Parse and prepare cards */
async function getCardsRoot(config, html) {
const cards = `<div>${html}</div>`;
let cards = `<div>${html}</div>`;
const { mep, placeholders } = config;
if (mep?.commands?.length) {
const mepRoot = createTag('div', {}, cards);
const { handleCommands, replacePlaceholders } = await import('../../features/personalization/personalization.js');
handleCommands(mep?.commands, mepRoot, false, true);
if (placeholders) mepRoot.innerHTML = replacePlaceholders(mepRoot.innerHTML, placeholders);
cards = mepRoot.innerHTML;
}
const fragment = document.createRange().createContextualFragment(
await replaceText(cards, config),
);
Expand Down
33 changes: 32 additions & 1 deletion test/blocks/merch-card-collection/merch-card-collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('Merch Cards', async () => {
expect(merchCards.outerHTML).to.equal(merchCards.nextElementSibling.outerHTML);
});

it('should override cards when asked to', async () => {
it('MEP: should override cards when asked to', async () => {
const el = document.getElementById('multipleFilters');
setConfig({
...conf,
Expand Down Expand Up @@ -207,6 +207,37 @@ describe('Merch Cards', async () => {
expect(merchCards.dataset.overrides).to.equal('promo1.json:/override-photoshop,promo2.json:/override-express');
});

it('MEP: should modify cards when asked to', async () => {
const el = document.getElementById('multipleFilters');
setConfig({
...conf,
mep: {
preview: true,
commands: [
{
action: 'remove',
selector: 'merch-card h3 #_include-fragments #_all',
pageFilter: '',
content: 'true',
selectorType: 'other',
manifestId: 'merchcardupdates.json',
targetManifestId: false,
modifiers: [
'include-fragments',
'all',
],
},
],
},
});
cards = [...document.querySelectorAll('#cards .merch-card')]
.map((merchCardEl) => ({ cardContent: merchCardEl.outerHTML })); // mock cards
const merchCards = await init(el);
expect(merchCards.filter).to.equal('all');
await delay(500);
expect(merchCards.querySelectorAll('h3[data-removed-manifest-id]').length).to.equal(4);
});

it('should localize the query-index url', async () => {
setConfig({
...conf,
Expand Down

0 comments on commit 94faeaa

Please sign in to comment.