Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-155566] [MEP] Allow relevant actions in MEP to use text and HTML instead of just fragments #2683

Merged
merged 54 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ff11544
getSelectedElement - V2
Jul 31, 2024
68cb583
getSelectedElement - V2
Aug 1, 2024
fe4eb9b
getSelectedElement - V2
Aug 1, 2024
0e9373a
getSelectedElement - V2
Aug 1, 2024
2995b6a
getSelectedElement - V2
Aug 1, 2024
60ef8de
added test coverage for action
Aug 1, 2024
fa9534a
cleanup
Aug 2, 2024
711c61c
added comments
Aug 2, 2024
af2fd88
comments
Aug 2, 2024
48b5168
comments
Aug 2, 2024
8233d58
fixes erroring but still has failure
vgoodric Aug 3, 2024
6d148d2
rooEl fix
Aug 2, 2024
7a5d77b
fixed tests
Aug 4, 2024
a5800c5
added modifier
Aug 5, 2024
4d3ac3b
eslint
Aug 5, 2024
f43bf5b
lint
Aug 5, 2024
a5980f0
removed reduncant try catch
Aug 5, 2024
c66ee38
Add target analytics for update action
markpadbe Aug 6, 2024
7668b82
removed test-results and added to .gitignore
Aug 6, 2024
e3666bd
reverted a deletion of a prependtosection validation code
Aug 6, 2024
62465fb
removed comments
Aug 6, 2024
58f7fee
updated validation for appendtosdection
Aug 6, 2024
b61f5ee
removed comments and eslint escapes
Aug 7, 2024
20810a7
change modifier to an array that is not a separate column
vgoodric Aug 9, 2024
edf2f4f
add highight for update
vgoodric Aug 9, 2024
3eb103b
add timeout to merch-card highlight
vgoodric Aug 9, 2024
64d70d8
remove setTimeout and move preview.js call from loadPostLCP to loadDe…
vgoodric Aug 9, 2024
731a528
Merge branch 'stage' into MWPW-148284
vgoodric Aug 14, 2024
a3d476d
update unit test
vgoodric Aug 14, 2024
bc1d1ec
remove update to git ignore
vgoodric Aug 14, 2024
ebf718c
Merge branch 'stage' into MWPW-148284
vgoodric Aug 19, 2024
a689d1c
add temp console message for easy QA
vgoodric Aug 19, 2024
aa56554
MWPW-155566 [MEP] Changing from a new action to just expanding power …
vgoodric Aug 20, 2024
80fc416
Merge branch 'stage' into MWPW-148284
vgoodric Aug 20, 2024
80fe19c
remove console
vgoodric Aug 20, 2024
c94c9a8
rename checkSelectorType to getSelectorType
vgoodric Aug 22, 2024
6876b47
move parts of createContent into sub functions
vgoodric Aug 23, 2024
f205ce2
small big fix
vgoodric Aug 23, 2024
9ada6e2
update modifySelectorTerm function per suggestion
vgoodric Aug 23, 2024
c068205
update modifyNonFragmentSelector per suggestion
vgoodric Aug 23, 2024
30c4e43
update to getSelectedElement
vgoodric Aug 23, 2024
63b732d
change equal to not equal
vgoodric Aug 23, 2024
5266bc1
Merge branch 'stage' into MWPW-148284
vgoodric Aug 23, 2024
60637fd
fix end number update
vgoodric Aug 23, 2024
9f26e2f
codecov
vgoodric Aug 23, 2024
943c84e
no longer require fragments be in URL for fragments because of gnav
vgoodric Aug 24, 2024
ba9620a
call getModifiers in modifyNonFragmentSelector instead
vgoodric Aug 24, 2024
507aa76
require space before first flag
vgoodric Aug 24, 2024
ac24ad7
update unit tests to need space before flags
vgoodric Aug 24, 2024
3d67f6b
handle adding flags to fragment selectors
vgoodric Aug 27, 2024
0e0bd46
revert for demo
vgoodric Aug 27, 2024
bd0d11b
put back
vgoodric Aug 27, 2024
f005125
Merge branch 'stage' into MWPW-148284
vgoodric Aug 29, 2024
03e43f5
remove utils update so it does not conflict
vgoodric Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 170 additions & 130 deletions libs/features/personalization/personalization.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libs/features/personalization/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ function addHighlightData(manifests) {
selectedVariant?.updatemetadata?.forEach(({ selector }) => {
if (selector === 'gnav-source') updateManifestId('header, footer');
});

// eslint-disable-next-line max-len
document.querySelectorAll(`.section[class*="merch-cards"] .fragment[data-manifest-id="${manifestName}"] merch-card`)
.forEach((el) => (el.dataset.manifestId = manifestName));
Expand Down
36 changes: 35 additions & 1 deletion test/features/personalization/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ 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').getAttribute('href')).to.equal('/my-page.html');
expect(document.querySelector('#inserted-html')).to.be.null;
await init(mepSettings);
expect(getConfig().mep.commands[0].targetManifestId).to.equal(false);

Expand All @@ -98,6 +100,8 @@ 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').getAttribute('href')).to.equal('/my-page.html#modal');
expect(document.querySelector('#inserted-html')).to.not.be.null;
});
});

Expand All @@ -109,6 +113,7 @@ describe('insertBefore action', async () => {
setFetchResponse(manifestJson);

expect(document.querySelector('a[href="/fragments/insertbefore"]')).to.be.null;
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 @@ -121,11 +126,12 @@ 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').getAttribute('href')).to.equal('/de/my-page.html');
});
});

describe('prependToSection action', async () => {
it('appendToSection should add fragment to beginning of section', async () => {
it('prependToSection should add fragment to beginning of section', async () => {
let manifestJson = await readFile({ path: './mocks/actions/manifestPrependToSection.json' });

manifestJson = JSON.parse(manifestJson);
Expand Down Expand Up @@ -157,6 +163,34 @@ describe('appendToSection action', async () => {
});
});

describe('replace action with html/text instead of fragment', () => {
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);
setFetchResponse(manifestJson);

const primaryCTA = document.querySelector('.marquee p strong a');
const secondaryCTA = document.querySelector('.marquee p a');
const header = document.querySelector('.marquee h2');
const actionArea = document.querySelector('main div:nth-child(5) .marquee p:has(em a, strong a)');

expect(header.innerText).to.not.equal('updated text');
expect(primaryCTA.innerText).to.not.equal('updated text');
expect(primaryCTA.href).to.not.equal('updated text');
expect(secondaryCTA.innerText).to.not.equal('updated text');
expect(actionArea.innerHTML).to.not.equal('<p>updated text</p>');

await init(mepSettings);

expect(header.innerText).to.equal('updated text');
expect(primaryCTA.innerText).to.equal('updated text');
expect(primaryCTA.href).to.equal('https://test.com/updated_href');
expect(secondaryCTA.innerText).to.equal('updated text');
expect(actionArea.innerHTML).to.equal('<p>updated text</p>');
});
});

describe('remove action', () => {
before(async () => {
let manifestJson = await readFile({ path: './mocks/actions/manifestRemove.json' });
Expand Down
24 changes: 24 additions & 0 deletions test/features/personalization/actionsTargetManifestId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ describe('appendToSection action', async () => {
});
});

describe('replace action with html/text instead of fragment', () => {
it('should replace marquee content', async () => {
document.body.innerHTML = await readFile({ path: './mocks/personalization.html' });
let manifestJson = await readFile({ path: './mocks/actions/manifestTargetUpdate.json' });
manifestJson = JSON.parse(manifestJson);
setFetchResponse(manifestJson);

const primaryCTA = document.querySelector('.marquee p strong a');
const secondaryCTA = document.querySelector('.marquee p a');
const header = document.querySelector('.marquee h2');
const actionArea = document.querySelector('main div:nth-child(5) .marquee p:has(em a, strong a)');

expect(header.dataset.adobeTargetTestid).not.to.exist;
expect(primaryCTA.dataset.adobeTargetTestid).not.to.exist;
expect(secondaryCTA.dataset.adobeTargetTestid).not.to.exist;
expect(actionArea.dataset.adobeTargetTestid).not.to.exist;
await init(mepSettings);
expect(header.dataset.adobeTargetTestid).to.equal('manifest');
expect(primaryCTA.dataset.adobeTargetTestid).to.equal('manifest');
expect(secondaryCTA.dataset.adobeTargetTestid).to.equal('manifest');
expect(actionArea.dataset.adobeTargetTestid).to.equal('manifest');
});
});

describe('useBlockCode action', async () => {
it('useBlockCode should override a current block with the custom block code provided', async () => {
let manifestJson = await readFile({ path: './mocks/actions/manifestUseBlockCode.json' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "insertAfter",
"selector": "#insertafter",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "<div id=\"inserted-html\">Hello World</div>",
"target-var1": "/test/features/personalization/mocks/fragments/insertafter",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "insertAfter",
"selector": "#insertafter #_href",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "#modal",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
}
],
":type": "sheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "insertBefore",
"selector": "#insertbefore #_href",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "/de",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
}
],
":type": "sheet"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"total": 5,
"offset": 0,
"limit": 5,
"data": [
{
"action": "replace",
"selector": ".marquee h2",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "",
"target-var1": "updated text",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "marquee primary-cta",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "",
"target-var1": "updated text",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": ".marquee primary-cta",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "",
"'modifier": "href",
"target-var1": "https://test.com/updated_href",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "marquee secondary-cta",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "",
"target-var1": "updated text",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "section5 marquee action-area",
"'modifier": "html",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "",
"target-var1": "<p>updated text</p>",
"firefox": "",
"android": "",
"ios": ""
}
],
":type": "sheet"
}
74 changes: 74 additions & 0 deletions test/features/personalization/mocks/actions/manifestUpdate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"total": 5,
"offset": 0,
"limit": 5,
"data": [
{
"action": "replace",
"selector": ".marquee h2",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "updated text",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "marquee primary-cta",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "updated text",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": ".marquee primary-cta #_href",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "https://test.com/updated_href",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "marquee secondary-cta",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "updated text",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "section5 marquee action-area",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "<p>updated text</p>",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
},
{
"action": "replace",
"selector": "section5...%$@#",
"page filter (optional)": "",
"param-newoffer=123": "",
"chrome": "<p>updated text</p>",
"target-var1": "",
"firefox": "",
"android": "",
"ios": ""
}
],
":type": "sheet"
}
11 changes: 2 additions & 9 deletions test/features/personalization/mocks/manifestSectionBlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
"data": [
{
"action": "removeContent",
"selector": "section2 block2",
"selector": ".custom-block1",
"page filter (optional)": "",
"param-newoffer=123": "",
"all": "on"
},
{
"action": "removeContent",
"selector": "custom-block2",
"page filter (optional)": "",
"param-newoffer=123": "",
"all": "on"
},
{
"action": "removeContent",
"selector": "section5 custom-block",
"selector": "section2 .custom-block",
"page filter (optional)": "",
"param-newoffer=123": "",
"all": "on"
Expand Down
14 changes: 12 additions & 2 deletions test/features/personalization/mocks/personalization.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
<div data-valign="middle">
<h2 id="milo-experimentation-platform">Milo Experimentation Platform</h2>
<p>Leverage the Milo Experimentation Platform (MEP) for all your personalization needs on Milo!</p>
<p><strong><a href="https://wiki.corp.adobe.com/display/marketingtech/Milo+Experiment+Manifests">Review
Docs</a></strong></p>
<p>
<strong>
<a href="https://wiki.corp.adobe.com/display/marketingtech/Milo+Experiment+Manifests">Review Docs</a>
</strong>
<em>
<a href="https://test.com/secondary-cta-url">Secondary CTA</a>
</em>
</p>
</div>
<div data-valign="middle">
<picture>
Expand Down Expand Up @@ -168,6 +174,10 @@ <h2 id="second-marquee-title">The second marquee</h2>
<div class="custom-block custom-block-4">
<div>
<div>Custom block 4</div>
<div><a id="insertbefore" href="/my-page.html">Hello</a></div>
<div><a id="insertafter" href="/my-page.html">Hello</a></div>
<div><a id="prepend" href="/my-page.html">Hello</a></div>
<div><a id="append" href="/my-page.html">Hello</a></div>
</div>
</div>
</div>
Expand Down
Loading
Loading