generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-145574 - Dynamic Nav Gnav Implementation (#2180)
* Modifies dynamic nav to work inside the gnav, simplifies logic and code, adds additional tests * Only load if key is present * Linting issues * Condensing logic re: code review * Moving code out of init into function per code review
- Loading branch information
1 parent
6c70a8a
commit e74e21e
Showing
7 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getMetadata } from '../utils/utils.js'; | ||
|
||
export default function dynamicNav(url, key) { | ||
const metadataContent = getMetadata('dynamic-nav'); | ||
|
||
if (metadataContent === 'entry') { | ||
window.sessionStorage.setItem('gnavSource', url); | ||
window.sessionStorage.setItem('dynamicNavKey', key); | ||
return url; | ||
} | ||
|
||
if (metadataContent !== 'on' || key !== window.sessionStorage.getItem('dynamicNavKey')) return url; | ||
|
||
return window.sessionStorage.getItem('gnavSource') || url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import { setConfig } from '../../../libs/utils/utils.js'; | ||
import dynamicNav from '../../../libs/features/dynamic-navigation.js'; | ||
|
||
describe('Dynamic nav', () => { | ||
beforeEach(() => { | ||
const conf = { dynamicNavKey: 'bacom' }; | ||
setConfig(conf); | ||
window.sessionStorage.setItem('gnavSource', 'some-source-string'); | ||
}); | ||
|
||
it('Saves the gnavSource and dynamicNavKey to session storage', async () => { | ||
document.head.innerHTML = await readFile({ path: './mocks/entry.html' }); | ||
window.sessionStorage.removeItem('gnavSource'); | ||
dynamicNav('gnav/aem-sites', 'bacom'); | ||
expect(window.sessionStorage.getItem('gnavSource')).to.equal('gnav/aem-sites'); | ||
expect(window.sessionStorage.getItem('dynamicNavKey')).to.equal('bacom'); | ||
}); | ||
|
||
it('Returns the provided url when the dynamic nav metadata is not present', async () => { | ||
document.head.innerHTML = await readFile({ path: './mocks/off.html' }); | ||
const url = dynamicNav('gnav/aem-sites', 'nocom'); | ||
expect(window.sessionStorage.getItem('gnavSource')).to.equal('some-source-string'); | ||
expect(url).to.equal('gnav/aem-sites'); | ||
}); | ||
|
||
it('Returns the provided url with when the wrong dynamicNavKey is passed', async () => { | ||
document.head.innerHTML = await readFile({ path: './mocks/on.html' }); | ||
const url = dynamicNav('gnav/aem-sites', 'nocom'); | ||
expect(window.sessionStorage.getItem('gnavSource')).to.equal('some-source-string'); | ||
expect(url).to.equal('gnav/aem-sites'); | ||
}); | ||
|
||
it('Returns the sessionStorage url if the item exists, the keys match, and dynamic nav is on', async () => { | ||
document.head.innerHTML = await readFile({ path: './mocks/on.html' }); | ||
const url = dynamicNav('gnav/aem-sites', 'bacom'); | ||
expect(window.sessionStorage.getItem('gnavSource')).to.equal('some-source-string'); | ||
expect(url).to.equal('some-source-string'); | ||
}); | ||
|
||
it('Returns the pprovided url if it does not find an item in sessionStorage and dynamic nav is on', async () => { | ||
document.head.innerHTML = await readFile({ path: './mocks/on.html' }); | ||
window.sessionStorage.removeItem('gnavSource'); | ||
const url = dynamicNav('gnav/aem-sites', 'bacom'); | ||
expect(url).to.equal('gnav/aem-sites'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<meta name="dynamic-nav" content="entry"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<meta name="stub" content="stub"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<meta name="dynamic-nav" content="on"> |