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.
Merge branch 'stage' of https://github.com/adobecom/milo into dismiss…
…-pep
- Loading branch information
Showing
9 changed files
with
109 additions
and
3 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
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"> |