From cc0d2997ada67ac337cbdf2608e5b7a022e40750 Mon Sep 17 00:00:00 2001 From: Ratko Zagorac Date: Fri, 9 Aug 2024 15:07:19 +0200 Subject: [PATCH 1/3] MWPW-154134: Swap navigation logic --- edsdme/scripts/scripts.js | 7 ++++++- edsdme/scripts/utils.js | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/edsdme/scripts/scripts.js b/edsdme/scripts/scripts.js index 0a3b037..93da938 100644 --- a/edsdme/scripts/scripts.js +++ b/edsdme/scripts/scripts.js @@ -1,4 +1,4 @@ -import { setLibs, redirectLoggedinPartner, updateIMSConfig, preloadResources, getRenewBanner } from './utils.js'; +import { setLibs, redirectLoggedinPartner, updateIMSConfig, preloadResources, getRenewBanner, updateNavigation } from './utils.js'; // Add project-wide style path here. const STYLES = '/edsdme/styles/styles.css'; @@ -71,7 +71,12 @@ const miloLibs = setLibs(LIBS); }); }()); +function setUpPage() { + updateNavigation(); +} + (async function loadPage() { + setUpPage(); redirectLoggedinPartner(); updateIMSConfig(); await preloadResources(CONFIG.locales, miloLibs); diff --git a/edsdme/scripts/utils.js b/edsdme/scripts/utils.js index ccac877..c37de08 100644 --- a/edsdme/scripts/utils.js +++ b/edsdme/scripts/utils.js @@ -352,3 +352,11 @@ export async function preloadResources(locales, miloLibs) { preload(caasUrl); }); } + +export function updateNavigation() { + const gnavMeta = document.querySelector('meta[name="gnav-source"]'); + if (!gnavMeta || !isMember()) return; + + const gnavLoggedIn = document.querySelector('meta[name="gnav-loggedin-source"]'); + gnavMeta.content = gnavLoggedIn?.content ?? `${localePrefix}/edsdme/partners-shared/loggedin-gnav`; +} From 7560d2763c2846d17411e72930a029c89dfce52e Mon Sep 17 00:00:00 2001 From: Ratko Zagorac Date: Mon, 12 Aug 2024 09:49:16 +0200 Subject: [PATCH 2/3] MWPW-154134: Fixed prefix bug and use existing functions --- edsdme/scripts/scripts.js | 2 +- edsdme/scripts/utils.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/edsdme/scripts/scripts.js b/edsdme/scripts/scripts.js index 93da938..ca1d45f 100644 --- a/edsdme/scripts/scripts.js +++ b/edsdme/scripts/scripts.js @@ -72,7 +72,7 @@ const miloLibs = setLibs(LIBS); }()); function setUpPage() { - updateNavigation(); + updateNavigation(CONFIG.locales); } (async function loadPage() { diff --git a/edsdme/scripts/utils.js b/edsdme/scripts/utils.js index c37de08..f4e576f 100644 --- a/edsdme/scripts/utils.js +++ b/edsdme/scripts/utils.js @@ -119,6 +119,10 @@ export function getMetadataContent(name) { return document.querySelector(`meta[name="${name}"]`)?.content; } +export function getMetadata(name) { + return document.querySelector(`meta[name="${name}"]`); +} + export function redirectLoggedinPartner() { if (!isMember()) return; const target = getMetadataContent('adobe-target-after-login'); @@ -353,10 +357,11 @@ export async function preloadResources(locales, miloLibs) { }); } -export function updateNavigation() { - const gnavMeta = document.querySelector('meta[name="gnav-source"]'); +export function updateNavigation(locales) { + const { prefix } = getLocale(locales); + const gnavMeta = getMetadata('gnav-source'); if (!gnavMeta || !isMember()) return; - const gnavLoggedIn = document.querySelector('meta[name="gnav-loggedin-source"]'); - gnavMeta.content = gnavLoggedIn?.content ?? `${localePrefix}/edsdme/partners-shared/loggedin-gnav`; + const gnavLoggedIn = getMetadataContent('gnav-loggedin-source'); + gnavMeta.content = gnavLoggedIn ?? `${prefix}/edsdme/partners-shared/loggedin-gnav`; } From 10d8243b16ed5bf280f7aaa3ff1156317ba93714 Mon Sep 17 00:00:00 2001 From: Ratko Zagorac Date: Mon, 12 Aug 2024 14:26:13 +0200 Subject: [PATCH 3/3] MWPW-154134: Resolved conflicts and added unit tests for gnav swap logic --- edsdme/scripts/scripts.js | 3 +- edsdme/scripts/utils.js | 2 ++ test/scripts/utils.jest.js | 56 +++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/edsdme/scripts/scripts.js b/edsdme/scripts/scripts.js index 8ec31d3..48014f8 100644 --- a/edsdme/scripts/scripts.js +++ b/edsdme/scripts/scripts.js @@ -1,5 +1,4 @@ -import { setLibs, redirectLoggedinPartner, updateIMSConfig, preloadResources, getRenewBanner, updateNavigation } from './utils.js'; -import { setLibs, redirectLoggedinPartner, updateIMSConfig, preloadResources, getRenewBanner, updateFooter } from './utils.js'; +import { setLibs, redirectLoggedinPartner, updateIMSConfig, preloadResources, getRenewBanner, updateNavigation, updateFooter } from './utils.js'; // Add project-wide style path here. const STYLES = '/edsdme/styles/styles.css'; diff --git a/edsdme/scripts/utils.js b/edsdme/scripts/utils.js index 7846424..875c67b 100644 --- a/edsdme/scripts/utils.js +++ b/edsdme/scripts/utils.js @@ -364,6 +364,8 @@ export function updateNavigation(locales) { const gnavLoggedIn = getMetadataContent('gnav-loggedin-source'); gnavMeta.content = gnavLoggedIn ?? `${prefix}/edsdme/partners-shared/loggedin-gnav`; +} + export function updateFooter(locales) { const { prefix } = getLocale(locales); const footerMeta = getMetadata('footer-source'); diff --git a/test/scripts/utils.jest.js b/test/scripts/utils.jest.js index ddd2b73..043064a 100644 --- a/test/scripts/utils.jest.js +++ b/test/scripts/utils.jest.js @@ -3,7 +3,7 @@ */ import path from 'path'; import fs from 'fs'; -import { updateFooter } from '../../edsdme/scripts/utils.js'; +import { updateFooter, updateNavigation } from '../../edsdme/scripts/utils.js'; describe('Test utils.js', () => { beforeEach(() => { window = Object.create(window); @@ -75,6 +75,60 @@ describe('Test utils.js', () => { expect(footerPath).not.toEqual(footerPathModified); expect(footerPathModified).toEqual('/de/edsdme/partners-shared/loggedin-footer'); }); + it('Public navigation is shown for non member', async () => { + const cookieObject = { + SPP: { + status: 'MEMBER', + } + }; + document.cookie = `partner_data=${JSON.stringify(cookieObject)}`; + const locales = { + '': { ietf: 'en-US', tk: 'hah7vzn.css' }, + de: { ietf: 'de-DE', tk: 'hah7vzn.css' }, + }; + const gnavPath = document.querySelector('meta[name="gnav-source"]')?.content + updateNavigation(locales); + const gnavPathModified = document.querySelector('meta[name="gnav-source"]')?.content + expect(gnavPath).toEqual(gnavPathModified); + }); + it('Protected navigation is shown for members', async () => { + const cookieObject = { + CPP: { + status: 'MEMBER', + } + }; + document.cookie = `partner_data=${JSON.stringify(cookieObject)}`; + const locales = { + '': { ietf: 'en-US', tk: 'hah7vzn.css' }, + de: { ietf: 'de-DE', tk: 'hah7vzn.css' }, + }; + const gnavPath = document.querySelector('meta[name="gnav-source"]')?.content; + updateNavigation(locales); + const gnavPathModified = document.querySelector('meta[name="gnav-source"]')?.content; + expect(gnavPath).not.toEqual(gnavPathModified); + const protectedGnavPath = document.querySelector('meta[name="gnav-loggedin-source"]')?.content; + expect(gnavPathModified).toEqual(protectedGnavPath); + }); + it('Protected footer is fetched based on locale if gnav-loggeding-source metadata is not present', async () => { + const cookieObject = { + CPP: { + status: 'MEMBER', + } + }; + document.cookie = `partner_data=${JSON.stringify(cookieObject)}`; + window.location.pathname = '/de/channelpartners/'; + const locales = { + '': { ietf: 'en-US', tk: 'hah7vzn.css' }, + de: { ietf: 'de-DE', tk: 'hah7vzn.css' }, + }; + const gnavPath = document.querySelector('meta[name="gnav-source"]')?.content; + const protectedGnav = document.querySelector('meta[name="gnav-loggedin-source"]'); + protectedGnav.remove(); + updateNavigation(locales); + const gnavPathModified = document.querySelector('meta[name="gnav-source"]')?.content; + expect(gnavPath).not.toEqual(gnavPathModified); + expect(gnavPathModified).toEqual('/de/edsdme/partners-shared/loggedin-gnav'); + }); }); });