From b23c8791c7e416c7380fb25b3673488c7ccfda0f Mon Sep 17 00:00:00 2001 From: Bozo Jovicic <37440641+bozojovicic@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:05:25 +0100 Subject: [PATCH] MWPW-157864 [Catalog] Localise external modals (#3277) * 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 --- libs/blocks/merch/merch.js | 10 ++++++++- test/blocks/merch/merch.test.js | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index 73afd8b8eb..744e1825a9 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -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, @@ -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) }; } diff --git a/test/blocks/merch/merch.test.js b/test/blocks/merch/merch.test.js index 70ee9a03f5..0e2786d48c 100644 --- a/test/blocks/merch/merch.test.js +++ b/test/blocks/merch/merch.test.js @@ -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: '', + }, ], }; @@ -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);