Skip to content

Commit

Permalink
MWPW-158462 [MEP] any-marquee-section simplified selector (#2884)
Browse files Browse the repository at this point in the history
* MWPW-158462 [MEP] any-marquee-section simplified selector

* unit test update

* MWPW-158475 [MEP] classes that end in a number are modified when they should not be (#2886)

* unit test update

* MWPW-158475 [MEP] classes that end in a number are modified when they should not be

* unit test repair

* unit test repair

* MWPW-157686 [MEP] Cannot spoof an experience that exists in manifest but not in Target (#2887)

* working so far

* lint update

* update something merging stage did not
  • Loading branch information
vgoodric committed Sep 17, 2024
1 parent d51b989 commit 8da3683
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
40 changes: 19 additions & 21 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */

import {
createTag, getConfig, loadLink, loadScript, localizeLink, updateConfig,
} from '../../utils/utils.js';
import { createTag, getConfig, loadLink, loadScript, localizeLink } from '../../utils/utils.js';
import { getEntitlementMap } from './entitlements.js';

/* c8 ignore start */
Expand Down Expand Up @@ -359,6 +357,7 @@ function modifySelectorTerm(termParam) {
'primary-cta': 'strong a',
'secondary-cta': 'em a',
'action-area': '*:has(> em a, > strong a)',
'any-marquee-section': 'main > div:has([class*="marquee"])',
'any-marquee': '[class*="marquee"]',
'any-header': ':is(h1, h2, h3, h4, h5, h6)',
};
Expand All @@ -372,7 +371,7 @@ function modifySelectorTerm(termParam) {
const startText = startTextMatch ? startTextMatch[0].toLowerCase() : '';
const startTextPart1 = startText.split(/\.|:/)[0];
const endNumberMatch = term.match(/[0-9]*$/);
const endNumber = endNumberMatch ? endNumberMatch[0] : '';
const endNumber = endNumberMatch && startText.match(/^[a-zA-Z]/) ? endNumberMatch[0] : '';
if (!startText || htmlEls.includes(startText)) return term;
if (otherSelectors.includes(startText)) {
term = term.replace(startText, '> div');
Expand Down Expand Up @@ -791,28 +790,13 @@ export async function getManifestConfig(info, variantOverride = false) {
}

manifestConfig.manifestPath = normalizePath(manifestPath);
const selectedVariantName = await getPersonalizationVariant(
manifestConfig.selectedVariantName = await getPersonalizationVariant(
manifestConfig.manifestPath,
manifestConfig.variantNames,
variantLabel,
);

if (selectedVariantName && manifestConfig.variantNames.includes(selectedVariantName)) {
manifestConfig.run = true;
manifestConfig.selectedVariantName = selectedVariantName;
manifestConfig.selectedVariant = manifestConfig.variants[selectedVariantName];
} else {
/* c8 ignore next 2 */
manifestConfig.selectedVariantName = 'default';
manifestConfig.selectedVariant = 'default';
}
const placeholders = manifestPlaceholders || data?.placeholders?.data;
if (placeholders) {
updateConfig(
parsePlaceholders(placeholders, getConfig(), manifestConfig.selectedVariantName),
);
}

manifestConfig.placeholderData = manifestPlaceholders || data?.placeholders?.data;
manifestConfig.name = name;
manifestConfig.manifest = manifestPath;
manifestConfig.manifestUrl = manifestUrl;
Expand Down Expand Up @@ -900,6 +884,20 @@ export function cleanAndSortManifestList(manifests) {
} else {
manifestObj[manifest.manifestPath] = manifest;
}

const manifestConfig = manifestObj[manifest.manifestPath];
const { selectedVariantName, variantNames, placeholderData } = manifestConfig;
if (selectedVariantName && variantNames.includes(selectedVariantName)) {
manifestConfig.run = true;
manifestConfig.selectedVariantName = selectedVariantName;
manifestConfig.selectedVariant = manifestConfig.variants[selectedVariantName];
} else {
/* c8 ignore next 2 */
manifestConfig.selectedVariantName = 'default';
manifestConfig.selectedVariant = 'default';
}

parsePlaceholders(placeholderData, getConfig(), manifestConfig.selectedVariantName);
} catch (e) {
console.warn(e);
window.lana?.log(`MEP Error parsing manifests: ${e.toString()}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data": [
{
"action": "removeContent",
"selector": ".custom-block1",
"selector": ".custom-block-1",
"page filter (optional)": "",
"param-newoffer=123": "",
"all": "on"
Expand Down
10 changes: 9 additions & 1 deletion test/features/personalization/modifyNonFragmentSelector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const values = [
},
{
b: 'section1 .random-block2',
a: 'main > div:nth-child(1) .random-block:nth-child(2 of .random-block)',
a: 'main > div:nth-child(1) .random-block2',
},
{
b: 'main > section30',
Expand All @@ -143,6 +143,14 @@ const values = [
b: 'any-marquee ul li:nth-child(2)',
a: '[class*="marquee"] ul li:nth-child(2)',
},
{
b: 'any-marquee-section',
a: 'main > div:has([class*="marquee"])',
},
{
b: '.aside03',
a: '.aside03',
},
];
describe('test different values', () => {
values.forEach((value) => {
Expand Down

0 comments on commit 8da3683

Please sign in to comment.