Skip to content

Commit

Permalink
Merge pull request #69 from adobecom/MWPW-159126-gnav-footer-locale
Browse files Browse the repository at this point in the history
MWPW-159126: Load gnav/footer based on locale
  • Loading branch information
zagi25 authored Sep 26, 2024
2 parents 828819c + 8053072 commit 9f5d9d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
24 changes: 14 additions & 10 deletions edsdme/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,25 @@ 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`;
if (!gnavMeta) return;
const { prefix } = getLocale(locales);
let { content } = gnavMeta;
if (isMember()) {
content = getMetadataContent('gnav-loggedin-source') ?? `${prefix}/edsdme/partners-shared/loggedin-gnav`;
}
gnavMeta.content = content.startsWith('/edsdme') ? prefix + content : content;
}

export function updateFooter(locales) {
const { prefix } = getLocale(locales);
const footerMeta = getMetadata('footer-source');
if (!footerMeta || !isMember()) return;

const footerLoggedIn = getMetadataContent('footer-loggedin-source');
footerMeta.content = footerLoggedIn ?? `${prefix}/edsdme/partners-shared/loggedin-footer`;
if (!footerMeta) return;
const { prefix } = getLocale(locales);
let { content } = footerMeta;
if (isMember()) {
content = getMetadataContent('footer-loggedin-source') ?? `${prefix}/edsdme/partners-shared/loggedin-footer`;
}
footerMeta.content = content.startsWith('/edsdme') ? prefix + content : content;
}

export function getNodesByXPath(query, context = document) {
Expand Down
30 changes: 29 additions & 1 deletion test/scripts/utils.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ describe('Test utils.js', () => {
const protectedFooterPath = document.querySelector('meta[name="footer-loggedin-source"]')?.content;
expect(footerPathModified).toEqual(protectedFooterPath);
});
it('Public footer is fetched based on locale', async () => {
const cookieObject = { CPP: { status: 'NOT_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 footerPath = document.querySelector('meta[name="footer-source"]')?.content;
updateFooter(locales);
const footerPathModified = document.querySelector('meta[name="footer-source"]')?.content;
expect(footerPath).not.toEqual(footerPathModified);
expect(footerPathModified).toEqual('/de/edsdme/partners-shared/footer');
});
it('Protected footer is fetched based on locale if footer-loggeding-source metadata is not present', async () => {
const cookieObject = { CPP: { status: 'MEMBER' } };
document.cookie = `partner_data=${JSON.stringify(cookieObject)}`;
Expand Down Expand Up @@ -128,7 +142,21 @@ describe('Test utils.js', () => {
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 () => {
it('Public gnav is fetched based on locale', async () => {
const cookieObject = { CPP: { status: 'NOT_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;
updateNavigation(locales);
const gnavPathModified = document.querySelector('meta[name="gnav-source"]')?.content;
expect(gnavPath).not.toEqual(gnavPathModified);
expect(gnavPathModified).toEqual('/de/edsdme/partners-shared/public-gnav');
});
it('Protected gnav 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/';
Expand Down

0 comments on commit 9f5d9d9

Please sign in to comment.