Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
vgoodric committed Jan 2, 2025
1 parent fa66ca1 commit 640b850
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libs/features/personalization/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export function parsePageAndUrl(config, windowLocation, prefix) {
'www.stage.adobe.com',
'milo.stage.adobe.com',
];
if (env?.name === 'prod' || !stageDomainsMap) {
if (env?.name === 'prod') {
return { page: pathname.replace(`/${prefix}/`, '/'), url: `${origin}${pathname}` };
}
if (!stageDomainsMap) {
const domain = allowedHosts.includes(origin.replace('https://', ''))
? origin.replace('stage.adobe.com', 'adobe.com') : origin;
return { page: pathname.replace(`/${prefix}/`, '/'), url: `${domain}${pathname}` };
Expand Down Expand Up @@ -355,7 +358,8 @@ function addHighlightData(manifests) {
}
export async function saveToMmm() {
const data = parseMepConfig();
if (data.page.url.includes('/drafts/')) return false;
const excludedStrings = ['/drafts/', '.stage.', '.page/', '.live/', '/fragments/'];
if (excludedStrings.some((str) => data.page.url.includes(str))) return false;
data.activities = data.activities.filter((activity) => {
const { url, source } = activity;
activity.source = source.filter((item) => item !== 'mep param');
Expand Down
7 changes: 7 additions & 0 deletions test/features/personalization/preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ describe('preview feature', () => {
expect(url).to.equal('https://www.adobe.com/fr/products/photoshop.html');
expect(page).to.equal('/products/photoshop.html');
});
it('parse url and page for no stage map', () => {
config.env.name = 'stage';
delete config.stageDomainsMap;
const { url, page } = parsePageAndUrl(config, new URL('https://www.stage.adobe.com/events/2024-10-31.html'), '');
expect(url).to.equal('https://www.adobe.com/events/2024-10-31.html');
expect(page).to.equal('/events/2024-10-31.html');
});
it('opens manifest', () => {
document.querySelector('a.mep-edit-manifest').click();
});
Expand Down

0 comments on commit 640b850

Please sign in to comment.