Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-157965: Upgrade Universal Nav to Version 1.3 #2867

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class Gnav {
return 'linux';
};

const unavVersion = new URLSearchParams(window.location.search).get('unavVersion') || '1.1';
const unavVersion = new URLSearchParams(window.location.search).get('unavVersion') || '1.3';
await Promise.all([
loadScript(`https://${environment}.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js`),
loadStyles(`https://${environment}.adobeccstatic.com/unav/${unavVersion}/UniversalNav.css`),
Expand Down Expand Up @@ -608,9 +608,6 @@ class Gnav {
locale,
imsClientId: window.adobeid?.client_id,
theme: isDarkMode() ? 'dark' : 'light',
onReady: () => {
this.decorateAppPrompt({ getAnchorState: () => window.UniversalNav.getComponent?.('app-switcher') });
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is onReady callback removed in new version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in PR description - Unav suggested to not rely on onReady

Copy link
Contributor

@sharmrj sharmrj Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this is true for 1.2 as well? (should someone want to use that version)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think it affects 1.2 as the window.UNav() promise came up with 1.3

analyticsContext: {
consumer: {
name: 'adobecom',
Expand All @@ -627,8 +624,8 @@ class Gnav {

// Exposing UNAV config for consumers
CONFIG.universalNav.universalNavConfig = getConfiguration();
window.UniversalNav(CONFIG.universalNav.universalNavConfig);

await window.UniversalNav(CONFIG.universalNav.universalNavConfig);
this.decorateAppPrompt({ getAnchorState: () => window.UniversalNav.getComponent?.('app-switcher') });
isDesktop.addEventListener('change', () => {
window.UniversalNav.reload(CONFIG.universalNav.universalNavConfig);
});
Expand Down
11 changes: 6 additions & 5 deletions test/blocks/global-navigation/global-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
viewports,
unavLocalesTestData,
analyticsTestData,
unavVersion,
} from './test-utilities.js';
import { setConfig, getLocale } from '../../../libs/utils/utils.js';
import initGnav, { getUniversalNavLocale, osMap } from '../../../libs/blocks/global-navigation/global-navigation.js';
Expand All @@ -27,7 +28,7 @@ describe('global navigation', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down Expand Up @@ -366,8 +367,8 @@ describe('global navigation', () => {
toFake: ['setTimeout'],
shouldAdvanceTime: true,
});
window.UniversalNav = sinon.spy();
window.UniversalNav.reload = sinon.spy();
window.UniversalNav = sinon.spy(() => Promise.resolve());
window.UniversalNav.reload = sinon.spy(() => Promise.resolve());
// eslint-disable-next-line no-underscore-dangle
window._satellite = { track: sinon.spy() };
window.alloy = () => new Promise((resolve) => {
Expand Down Expand Up @@ -578,7 +579,7 @@ describe('global navigation', () => {
document.head.innerHTML = `<meta name="app-prompt" content="off" />
<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any" />
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
const gnav = await createFullGlobalNavigation({});
gnav.decorateAppPrompt();
Expand All @@ -592,7 +593,7 @@ describe('global navigation', () => {
<meta name="app-prompt-path" content="https://dismiss-pep--milo--adobecom.hlx.page/drafts/raghavs/pep-prompt-content"/>
<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any" />
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
const gnav = await createFullGlobalNavigation({});
window.adobeIMS = { isSignedInUser: () => true };
Expand Down
3 changes: 2 additions & 1 deletion test/blocks/global-navigation/gnav-brand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createFullGlobalNavigation,
selectors,
isElementVisible,
unavVersion,
} from './test-utilities.js';
import logoOnlyNav from './mocks/global-navigation-only-logo.plain.js';
import brandOnlyNav from './mocks/global-navigation-only-brand.plain.js';
Expand All @@ -15,7 +16,7 @@ describe('brand', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
3 changes: 2 additions & 1 deletion test/blocks/global-navigation/gnav-cross-cloud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {
createFullGlobalNavigation,
selectors,
isElementVisible,
unavVersion,
} from './test-utilities.js';
import globalNavigationCrossCloud from './mocks/global-navigation-cross-cloud.plain.js';

describe('Cross Cloud Menu', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
3 changes: 2 additions & 1 deletion test/blocks/global-navigation/gnav-main-nav-popup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createFullGlobalNavigation,
selectors,
isElementVisible,
unavVersion,
} from './test-utilities.js';
import { toFragment } from '../../../libs/blocks/global-navigation/utilities/utilities.js';
import globalNavigationMock from './mocks/global-navigation.plain.js';
Expand All @@ -14,7 +15,7 @@ describe('main nav popups', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
3 changes: 2 additions & 1 deletion test/blocks/global-navigation/gnav-main-nav.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
selectors,
isElementVisible,
viewports,
unavVersion,
} from './test-utilities.js';
import { isDesktop, setActiveLink, toFragment } from '../../../libs/blocks/global-navigation/utilities/utilities.js';
import globalNavigationActiveMock from './mocks/global-navigation-active.plain.js';
Expand All @@ -15,7 +16,7 @@ describe('main nav', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
3 changes: 2 additions & 1 deletion test/blocks/global-navigation/gnav-profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
createFullGlobalNavigation,
selectors,
isElementVisible,
unavVersion,
} from './test-utilities.js';
import globalNavigationMock from './mocks/global-navigation.plain.js';

describe('profile', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
4 changes: 2 additions & 2 deletions test/blocks/global-navigation/gnav-promo.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable no-restricted-syntax */
import { expect } from '@esm-bundle/chai';
import { createFullGlobalNavigation } from './test-utilities.js';
import { createFullGlobalNavigation, unavVersion } from './test-utilities.js';
import { toFragment } from '../../../libs/blocks/global-navigation/utilities/utilities.js';

describe('Promo', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
3 changes: 2 additions & 1 deletion test/blocks/global-navigation/gnav-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
selectors,
isElementVisible,
mockRes,
unavVersion,
} from './test-utilities.js';

const ogFetch = window.fetch;
Expand All @@ -19,7 +20,7 @@ describe('search', () => {
before(() => {
document.head.innerHTML = `<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script src="https://auth.services.adobe.com/imslib/imslib.min.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/1.1/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
<script src="https://stage.adobeccstatic.com/unav/${unavVersion}/UniversalNav.js" type="javascript/blocked" data-loaded="true"></script>
`;
});

Expand Down
2 changes: 2 additions & 0 deletions test/blocks/global-navigation/test-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const analyticsTestData = {
'unc|click|markUnread': 'Mark Notification as unread',
};

export const unavVersion = '1.3';

export const unavLocalesTestData = Object.entries(LANGMAP).reduce((acc, curr) => {
const result = [];
const [locale, prefixes] = curr;
Expand Down
Loading