Make sure no one can show the chrome if the default setting is hidden. (#13250) (#13317)

* Make sure no one can show the chrome if the default setting is hidden.

add tests

Fixes https://github.com/elastic/kibana/issues/13040

* Improve variable and function names and fix tests
This commit is contained in:
Stacey Gammon 2017-08-03 13:10:24 -04:00 committed by GitHub
parent 7e0559f667
commit 7e5d2c4842
5 changed files with 46 additions and 5 deletions

View file

@ -11,14 +11,20 @@ export default function (chrome, internals) {
* determines if the Kibana chrome should be displayed
*/
let def = true;
internals.setVisibleDefault = (_def) => def = Boolean(_def);
let permanentlyHideChrome = false;
internals.permanentlyHideChrome = () => {
permanentlyHideChrome = true;
internals.visible = false;
};
/**
* @param {boolean} display - should the chrome be displayed
* @return {chrome}
*/
chrome.setVisible = function (display) {
if (permanentlyHideChrome) {
return chrome;
}
internals.visible = Boolean(display);
return chrome;
};
@ -27,7 +33,7 @@ export default function (chrome, internals) {
* @return {boolean} - display state of the chrome
*/
chrome.getVisible = function () {
if (_.isUndefined(internals.visible)) return def;
if (_.isUndefined(internals.visible)) return !permanentlyHideChrome;
return internals.visible;
};
}

View file

@ -1,6 +1,7 @@
<div class="content" chrome-context data-test-subj="kibanaChrome">
<global-nav
chrome="chrome"
data-test-subj="globalNav"
is-visible="chrome.getVisible()"
logo-brand="chrome.getBrand('logo')"
small-logo-brand="chrome.getBrand('smallLogo')"

View file

@ -37,7 +37,9 @@ export function kbnChromeProvider(chrome, internals) {
const getUnhashableStates = Private(getUnhashableStatesProvider);
// are we showing the embedded version of the chrome?
internals.setVisibleDefault(!$location.search().embed);
if (Boolean($location.search().embed)) {
internals.permanentlyHideChrome();
}
// listen for route changes, propogate to tabs
const onRouteChange = function () {

View file

@ -190,6 +190,36 @@ export default function ({ getService, getPageObjects }) {
});
});
describe('embed mode', () => {
it('hides the chrome', async () => {
let isChromeVisible = await PageObjects.common.isChromeVisible();
expect(isChromeVisible).to.be(true);
const currentUrl = await remote.getCurrentUrl();
const newUrl = currentUrl + '&embed=true';
// Embed parameter only works on a hard refresh.
const useTimeStamp = true;
await remote.get(newUrl.toString(), useTimeStamp);
await retry.try(async () => {
isChromeVisible = await PageObjects.common.isChromeVisible();
expect(isChromeVisible).to.be(false);
});
});
after(async function () {
console.log('showing chrome again');
const currentUrl = await remote.getCurrentUrl();
const newUrl = currentUrl.replace('&embed=true', '');
// First use the timestamp to cause a hard refresh so the new embed parameter works correctly.
let useTimeStamp = true;
await remote.get(newUrl.toString(), useTimeStamp);
// Then get rid of the timestamp so the rest of the tests work with state and app switching.
useTimeStamp = false;
await remote.get(newUrl.toString(), useTimeStamp);
});
});
describe('add new visualization link', () => {
it('adds a new visualization', async () => {
await PageObjects.dashboard.clickAddVisualization();

View file

@ -257,7 +257,9 @@ export function CommonPageProvider({ getService, getPageObjects }) {
}
async isChromeVisible() {
return await testSubjects.exists('kibanaChrome');
const globalNavShown = await testSubjects.exists('globalNav');
const topNavShown = await testSubjects.exists('top-nav');
return globalNavShown && topNavShown;
}
async waitForTopNavToBeVisible() {