Skip to content

Commit

Permalink
Merge pull request #37 from adobecom/MWPW-154134-global-navigation
Browse files Browse the repository at this point in the history
MWPW-154134: Swap navigation logic
  • Loading branch information
Ben-Zahler authored Aug 12, 2024
2 parents 65f0abb + 10d8243 commit 5d9d1fe
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
3 changes: 2 additions & 1 deletion edsdme/scripts/scripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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';
Expand Down Expand Up @@ -72,6 +72,7 @@ const miloLibs = setLibs(LIBS);
}());

function setUpPage() {
updateNavigation(CONFIG.locales);
updateFooter(CONFIG.locales);
}

Expand Down
9 changes: 9 additions & 0 deletions edsdme/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,15 @@ export async function preloadResources(locales, miloLibs) {
});
}

export function updateNavigation(locales) {
const { prefix } = getLocale(locales);
const gnavMeta = getMetadata('gnav-source');
if (!gnavMeta || !isMember()) return;

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');
Expand Down
56 changes: 55 additions & 1 deletion test/scripts/utils.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit 5d9d1fe

Please sign in to comment.