Skip to content

Commit

Permalink
MWPW-157864 [Catalog] Localise external modals (adobecom#3277)
Browse files Browse the repository at this point in the history
* MWPW-157864 [Catalog] Localise external modals

* MWPW-157864 [Catalog] Localise external modals

* MWPW-157864 [Catalog] Localise external modals

* Trigger Build

---------

Co-authored-by: Bozo Jovicic <bozo@hitthecode.com>
  • Loading branch information
2 people authored and nishantka committed Dec 13, 2024
1 parent 7d61e4e commit b23c879
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libs/blocks/merch/merch.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ export function setCtaHash(el, checkoutLinkConfig, offerType) {
return hash;
}

const isProdModal = (url) => {
try {
return (new URL(url)).hostname.endsWith('.adobe.com');
} catch (e) {
return false;
}
};

export async function getModalAction(offers, options, el) {
const [{
offerType,
Expand All @@ -529,7 +537,7 @@ export async function getModalAction(offers, options, el) {
const hash = setCtaHash(el, checkoutLinkConfig, offerType);
let url = checkoutLinkConfig[columnName];
if (!url) return undefined;
url = isInternalModal(url)
url = isInternalModal(url) || isProdModal(url)
? localizeLink(checkoutLinkConfig[columnName]) : checkoutLinkConfig[columnName];
return { url, handler: (e) => openModal(e, url, offerType, hash, options.extraOptions) };
}
Expand Down
36 changes: 36 additions & 0 deletions test/blocks/merch/merch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ const CHECKOUT_LINK_CONFIGS = {
PRODUCT_FAMILY: 'testProductCode',
DOWNLOAD_TEXT: 'productCode',
},
{
PRODUCT_FAMILY: 'AUDITION',
DOWNLOAD_TEXT: 'Download',
DOWNLOAD_URL: 'https://creativecloud.adobe.com/apps/download/audition',
FREE_TRIAL_PATH: 'https://www.adobe.com/mini-plans/audition.html?mid=ft&web=1',
BUY_NOW_PATH: 'www.adobe.com/will/not/be/localized.html',
LOCALE: '',
},
],
};

Expand Down Expand Up @@ -707,6 +715,34 @@ describe('Merch Block', () => {
expect(action).to.be.undefined;
});

it('getModalAction: localize buy now path if it comes from us/en production', async () => {
setConfig({
...config,
pathname: '/fr/test.html',
locales: { fr: { ietf: 'fr-FR' } },
prodDomains: PROD_DOMAINS,
placeholders: { download: 'Télécharger' },
});
fetchCheckoutLinkConfigs.promise = undefined;
setCheckoutLinkConfigs(CHECKOUT_LINK_CONFIGS);
const action = await getModalAction([{ productArrangement: { productFamily: 'ILLUSTRATOR' } }], { modal: true });
expect(action.url).to.equal('https://www.adobe.com/fr/plans-fragments/modals/individual/modals-content-rich/illustrator/master.modal.html');
});

it('getModalAction: skip modal url localization if url is invalid', async () => {
setConfig({
...config,
pathname: '/fr/test.html',
locales: { fr: { ietf: 'fr-FR' } },
prodDomains: PROD_DOMAINS,
placeholders: { download: 'Télécharger' },
});
fetchCheckoutLinkConfigs.promise = undefined;
setCheckoutLinkConfigs(CHECKOUT_LINK_CONFIGS);
const action = await getModalAction([{ productArrangement: { productFamily: 'AUDITION' } }], { modal: true });
expect(action.url).to.equal('www.adobe.com/will/not/be/localized.html');
});

it('getModalAction: returns undefined if checkout-link config is not found', async () => {
fetchCheckoutLinkConfigs.promise = undefined;
setCheckoutLinkConfigs(CHECKOUT_LINK_CONFIGS);
Expand Down

0 comments on commit b23c879

Please sign in to comment.