diff --git a/libs/blocks/global-navigation/global-navigation.css b/libs/blocks/global-navigation/global-navigation.css index 1ea91085fb..b4dea14d46 100644 --- a/libs/blocks/global-navigation/global-navigation.css +++ b/libs/blocks/global-navigation/global-navigation.css @@ -402,7 +402,6 @@ header.global-navigation { .feds-utilities .unav-comp-app-switcher-popover, /* App Switcher */ .feds-utilities .spectrum-Dialog-content, /* Notifications */ -.feds-utilities .unav-comp-external-profile, /* Profile */ .feds-utilities .unav-comp-help-popover, /* Help */ .feds-utilities .unc-overlay-container { /* Tooltips */ transform: translate3d(0,0,0); /* Fix Safari issues w/ position: sticky */ diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index bba4fc4894..3fa04bb623 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -80,17 +80,32 @@ export const CONFIG = { name: 'profile', attributes: { isSignUpRequired: false, + messageEventListener: (event) => { + const { name, payload, executeDefaultAction } = event.detail; + if (name !== 'System') return; + switch (payload.subType) { + case 'AppInitiated': + window.adobeProfile?.getUserProfile() + .then((data) => { setUserProfile(data); }) + .catch(() => { setUserProfile({}); }); + break; + case 'SignOut': + executeDefaultAction(); + break; + case 'ProfileSwitch': + executeDefaultAction().then((profile) => { + if (profile) window.location.reload(); + }); + break; + default: + break; + } + }, componentLoaderConfig: { config: { enableLocalSection: true, + enableProfileSwitcher: true, miniAppContext: { - onMessage: (name, payload) => { - if (name === 'System' && payload.subType === 'AppInitiated') { - window.adobeProfile?.getUserProfile() - .then((data) => { setUserProfile(data); }) - .catch(() => { setUserProfile({}); }); - } - }, logger: { trace: () => {}, debug: () => {}, @@ -131,6 +146,7 @@ export const CONFIG = { callbacks: getConfig().jarvis?.callbacks, }, }, + cart: { name: 'cart' }, }, }, }; @@ -646,7 +662,7 @@ class Gnav { return 'linux'; }; - const unavVersion = new URLSearchParams(window.location.search).get('unavVersion') || '1.3'; + const unavVersion = new URLSearchParams(window.location.search).get('unavVersion') || '1.4'; await Promise.all([ loadScript(`https://${environment}.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js`), loadStyles(`https://${environment}.adobeccstatic.com/unav/${unavVersion}/UniversalNav.css`, true), @@ -746,6 +762,7 @@ class Gnav { }, children: getChildren(), isSectionDividerRequired: getConfig()?.unav?.showSectionDivider, + showTrayExperience: (!isDesktop.matches), }); // Exposing UNAV config for consumers @@ -753,7 +770,7 @@ class Gnav { await window.UniversalNav(CONFIG.universalNav.universalNavConfig); this.decorateAppPrompt({ getAnchorState: () => window.UniversalNav.getComponent?.('app-switcher') }); isDesktop.addEventListener('change', () => { - window.UniversalNav.reload(CONFIG.universalNav.universalNavConfig); + window.UniversalNav.reload(getConfiguration()); }); }; diff --git a/libs/utils/utils.js b/libs/utils/utils.js index e4260bba3b..c48c252d21 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -1021,7 +1021,7 @@ export async function loadIms() { return; } const [unavMeta, ahomeMeta] = [getMetadata('universal-nav')?.trim(), getMetadata('adobe-home-redirect')]; - const defaultScope = `AdobeID,openid,gnav${unavMeta && unavMeta !== 'off' ? ',pps.read,firefly_api,additional_info.roles,read_organizations' : ''}`; + const defaultScope = `AdobeID,openid,gnav${unavMeta && unavMeta !== 'off' ? ',pps.read,firefly_api,additional_info.roles,read_organizations,account_cluster.read' : ''}`; const timeout = setTimeout(() => reject(new Error('IMS timeout')), imsTimeout || 5000); window.adobeid = { client_id: imsClientId, diff --git a/test/blocks/global-navigation/global-navigation.test.js b/test/blocks/global-navigation/global-navigation.test.js index 04f517ac7c..f7352f2d5b 100644 --- a/test/blocks/global-navigation/global-navigation.test.js +++ b/test/blocks/global-navigation/global-navigation.test.js @@ -398,6 +398,7 @@ describe('global navigation', () => { }); window.UniversalNav = sinon.spy(() => Promise.resolve()); window.UniversalNav.reload = sinon.spy(() => Promise.resolve()); + window.adobeProfile = { getUserProfile: sinon.spy(() => Promise.resolve({})) }; // eslint-disable-next-line no-underscore-dangle window._satellite = { track: sinon.spy() }; window.alloy = () => new Promise((resolve) => { @@ -432,6 +433,27 @@ describe('global navigation', () => { expect(window.UniversalNav.reload.getCall(0)).to.exist; }); + it('should handle message events correctly', async () => { + // eslint-disable-next-line max-len + const mockEvent = (name, payload) => ({ detail: { name, payload, executeDefaultAction: sinon.spy(() => Promise.resolve(null)) } }); + await createFullGlobalNavigation({ unavContent: 'on' }); + const messageEventListener = window.UniversalNav.getCall(0).args[0].children + .map((c) => c.attributes.messageEventListener) + .find((listener) => listener); + + const appInitiatedEvent = mockEvent('System', { subType: 'AppInitiated' }); + messageEventListener(appInitiatedEvent); + expect(window.adobeProfile.getUserProfile.called).to.be.true; + + const signOutEvent = mockEvent('System', { subType: 'SignOut' }); + messageEventListener(signOutEvent); + expect(signOutEvent.detail.executeDefaultAction.called).to.be.true; + + const profileSwitch = mockEvent('System', { subType: 'ProfileSwitch' }); + messageEventListener(profileSwitch); + expect(profileSwitch.detail.executeDefaultAction.called).to.be.true; + }); + it('should send the correct analytics events', async () => { await createFullGlobalNavigation({ unavContent: 'on' }); const analyticsFn = window.UniversalNav.getCall(0) @@ -486,6 +508,14 @@ describe('global navigation', () => { expect(getUniversalNavLocale({ prefix: data.prefix })).to.equal(data.expectedLocale); } }); + + it('should pass enableProfileSwitcher to the profile component configuration', async () => { + await createFullGlobalNavigation({ unavContent: 'on' }); + const profileConfig = window.UniversalNav.getCall(0).args[0].children + .find((c) => c.name === 'profile').attributes.componentLoaderConfig.config; + + expect(profileConfig.enableProfileSwitcher).to.be.true; + }); }); describe('small desktop', () => { diff --git a/test/blocks/global-navigation/test-utilities.js b/test/blocks/global-navigation/test-utilities.js index a32b195f48..0cd594ed52 100644 --- a/test/blocks/global-navigation/test-utilities.js +++ b/test/blocks/global-navigation/test-utilities.js @@ -80,7 +80,7 @@ export const analyticsTestData = { 'unc|click|markUnread': 'Mark Notification as unread', }; -export const unavVersion = '1.3'; +export const unavVersion = '1.4'; export const addMetaDataV2 = (value) => { const metaTag = document.createElement('meta');