Skip to content

Commit

Permalink
MWPW-166076 Update a.com Business plans page CTAs to point to CME-1 M…
Browse files Browse the repository at this point in the history
…7 Business plans page
  • Loading branch information
Bozo Jovicic committed Feb 21, 2025
1 parent e88890a commit e5282a3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 48 deletions.
Empty file.
31 changes: 31 additions & 0 deletions libs/blocks/m7business/m7business.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getConfig } from '../../utils/utils.js';

async function getImsCountry() {
if (window.adobeIMS?.isSignedInUser()) {
const profile = await window.adobeIMS.getProfile();
return profile.countryCode;
}

return null;
}

export async function generateM7Link() {
const { locale } = getConfig();
const { getMiloLocaleSettings } = await import('../merch/merch.js');
const pageCountry = getMiloLocaleSettings(locale).country;
const imsCountry = await getImsCountry();
const country = imsCountry || pageCountry;

const m7link = new URL('https://commerce.adobe.com/store/segmentation');
m7link.searchParams.append('cli', 'adobe_com');
m7link.searchParams.append('co', country);
m7link.searchParams.append('pa', 'ccsn_direct_individual');
m7link.searchParams.append('cs', 't');
m7link.searchParams.append('af', 'uc_segmentation_hide_tabs');
return m7link.toString();
}

export default async function init(el) {
const m7Link = await generateM7Link();
el.href = m7Link;
}
34 changes: 2 additions & 32 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const MILO_BLOCKS = [
'instagram',
'locui',
'locui-create',
'm7business',
'marketo',
'marquee',
'marquee-anchors',
Expand Down Expand Up @@ -111,6 +112,7 @@ const AUTO_BLOCKS = [
{ video: '.mp4' },
{ merch: '/tools/ost?' },
{ 'mas-autoblock': 'mas.adobe.com/studio' },
{ m7business: '/creativecloud/business-plans.html' },
];
const DO_NOT_INLINE = [
'accordion',
Expand Down Expand Up @@ -151,7 +153,6 @@ const PREVIEW = 'target-preview';
const PAGE_URL = new URL(window.location.href);
export const SLD = PAGE_URL.hostname.includes('.aem.') ? 'aem' : 'hlx';

const BUSINESS_PLANS_PATH = '/creativecloud/business-plans.html';
const PROMO_PARAM = 'promo';
let isMartechLoaded = false;

Expand Down Expand Up @@ -690,31 +691,6 @@ export function convertStageLinks({ anchors, config, hostname, href }) {
});
}

async function getImsCountry() {
if (window.adobeIMS?.isSignedInUser()) {
const profile = await window.adobeIMS.getProfile();
return profile.countryCode;
}

return null;
}

export async function generateM7Link() {
const { locale } = getConfig();
const { getMiloLocaleSettings } = await import('../blocks/merch/merch.js');
const pageCountry = getMiloLocaleSettings(locale).country;
const imsCountry = await getImsCountry();
const country = imsCountry || pageCountry;

const m7link = new URL('https://commerce.adobe.com/store/segmentation');
m7link.searchParams.append('cli', 'adobe_com');
m7link.searchParams.append('co', country);
m7link.searchParams.append('pa', 'ccsn_direct_individual');
m7link.searchParams.append('cs', 't');
m7link.searchParams.append('af', 'uc_segmentation_hide_tabs');
return m7link.toString();
}

export function decorateLinks(el) {
const config = getConfig();
decorateImageLinks(el);
Expand Down Expand Up @@ -764,12 +740,6 @@ export function decorateLinks(el) {
})();
}

if (a.href.includes(BUSINESS_PLANS_PATH)) {
generateM7Link().then((m7Link) => {
a.href = m7Link;
});
}

// Append aria-label
const pipeRegex = /\s?\|([^|]*)$/;
if (pipeRegex.test(a.textContent) && !/\.[a-z]+/i.test(a.textContent)) {
Expand Down
20 changes: 20 additions & 0 deletions test/blocks/m7business/m7business.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from '@esm-bundle/chai';
import init, { generateM7Link } from '../../../libs/blocks/m7business/m7business.js';

describe('m7business autoblock', () => {
it('Converts business plans link to M7 link', async () => {
const a = document.createElement('a');
a.setAttribute('href', 'https://www.adobe.com/creativecloud/business-plans.html');
await init(a);
expect(a.href).to.equal('https://commerce.adobe.com/store/segmentation?cli=adobe_com&co=US&pa=ccsn_direct_individual&cs=t&af=uc_segmentation_hide_tabs');
});

it('Converts business plans link to M7 link for signed in user', async () => {
const buIms = window.adobeIMS;
const profile = { countryCode: 'CH' };
window.adobeIMS = { getProfile: () => profile, isSignedInUser: () => true };
const m7Link = await generateM7Link();
expect(m7Link).to.equal('https://commerce.adobe.com/store/segmentation?cli=adobe_com&co=CH&pa=ccsn_direct_individual&cs=t&af=uc_segmentation_hide_tabs');
window.adobeIMS = buIms;
});
});
16 changes: 0 additions & 16 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,22 +433,6 @@ describe('Utils', () => {
expect(httpLink.dataset.httpLink).to.equal('true');
});

it('Converts business plans link to M7 link', () => {
const container = document.querySelector('main div');
utils.decorateLinks(container);
const m7Link = container.querySelector('.business-plans');
expect(m7Link.href).to.equal('https://commerce.adobe.com/store/segmentation?cli=adobe_com&co=US&pa=ccsn_direct_individual&cs=t&af=uc_segmentation_hide_tabs');
});

it('Converts business plans link to M7 link for IMS user', async () => {
const buIms = window.adobeIMS;
const profile = { countryCode: 'CH' };
window.adobeIMS = { getProfile: () => profile, isSignedInUser: () => true };
const m7Link = await utils.generateM7Link();
expect(m7Link).to.equal('https://commerce.adobe.com/store/segmentation?cli=adobe_com&co=CH&pa=ccsn_direct_individual&cs=t&af=uc_segmentation_hide_tabs');
window.adobeIMS = buIms;
});

it('Sets up milo.deferredPromise', async () => {
const { resolveDeferred } = utils.getConfig();
expect(window.milo.deferredPromise).to.exist;
Expand Down

0 comments on commit e5282a3

Please sign in to comment.