-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chrome/nav] copy global state around when the url changes
- Loading branch information
Showing
7 changed files
with
100 additions
and
25 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...ublic/chrome/__tests__/_tab_fake_store.js → ..._tests__/fixtures/stub_browser_storage.js
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
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 |
---|---|---|
@@ -1,45 +1,73 @@ | ||
import expect from 'expect.js'; | ||
|
||
import initChromeNavApi from 'ui/chrome/api/nav'; | ||
import StubBrowserStorage from '../../__tests__/fixtures/stub_browser_storage'; | ||
|
||
const basePath = '/someBasePath'; | ||
|
||
function getChrome(customInternals = { basePath }) { | ||
function init(customInternals = { basePath }) { | ||
const chrome = {}; | ||
initChromeNavApi(chrome, { | ||
const internals = { | ||
nav: [], | ||
...customInternals, | ||
}); | ||
return chrome; | ||
}; | ||
initChromeNavApi(chrome, internals); | ||
return { chrome, internals }; | ||
} | ||
|
||
describe('chrome nav apis', function () { | ||
describe('#getBasePath()', function () { | ||
it('returns the basePath', function () { | ||
const chrome = getChrome(); | ||
const { chrome } = init(); | ||
expect(chrome.getBasePath()).to.be(basePath); | ||
}); | ||
}); | ||
|
||
describe('#addBasePath()', function () { | ||
it('returns undefined when nothing is passed', function () { | ||
const chrome = getChrome(); | ||
const { chrome } = init(); | ||
expect(chrome.addBasePath()).to.be(undefined); | ||
}); | ||
|
||
it('prepends the base path when the input is a path', function () { | ||
const chrome = getChrome(); | ||
const { chrome } = init(); | ||
expect(chrome.addBasePath('/other/path')).to.be(`${basePath}/other/path`); | ||
}); | ||
|
||
it('ignores non-path urls', function () { | ||
const chrome = getChrome(); | ||
const { chrome } = init(); | ||
expect(chrome.addBasePath('http://github.com/elastic/kibana')).to.be('http://github.com/elastic/kibana'); | ||
}); | ||
|
||
it('includes the query string', function () { | ||
const chrome = getChrome(); | ||
const { chrome } = init(); | ||
expect(chrome.addBasePath('/app/kibana?a=b')).to.be(`${basePath}/app/kibana?a=b`); | ||
}); | ||
}); | ||
|
||
describe('internals.trackPossibleSubUrl()', function () { | ||
it('injects the globalState of the current url to all links for the same app', function () { | ||
const appUrlStore = new StubBrowserStorage(); | ||
const nav = [ | ||
{ url: 'https://localhost:9200/app/kibana#discover' }, | ||
{ url: 'https://localhost:9200/app/kibana#visualize' }, | ||
{ url: 'https://localhost:9200/app/kibana#dashboard' }, | ||
].map(l => { | ||
l.lastSubUrl = l.url; | ||
return l; | ||
}); | ||
|
||
const { chrome, internals } = init({ appUrlStore, nav }); | ||
|
||
internals.trackPossibleSubUrl('https://localhost:9200/app/kibana#dashboard?_g=globalstate'); | ||
expect(internals.nav[0].lastSubUrl).to.be('https://localhost:9200/app/kibana#discover?_g=globalstate'); | ||
expect(internals.nav[0].active).to.be(false); | ||
|
||
expect(internals.nav[1].lastSubUrl).to.be('https://localhost:9200/app/kibana#visualize?_g=globalstate'); | ||
expect(internals.nav[1].active).to.be(false); | ||
|
||
expect(internals.nav[2].lastSubUrl).to.be('https://localhost:9200/app/kibana#dashboard?_g=globalstate'); | ||
expect(internals.nav[2].active).to.be(true); | ||
}); | ||
}); | ||
}); |
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