Skip to content

Commit

Permalink
Make sure no one can show the chrome if the default setting is hidden. (
Browse files Browse the repository at this point in the history
elastic#13250)

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

add tests

Fixes elastic#13040

* Improve variable and function names and fix tests
  • Loading branch information
stacey-gammon committed Aug 3, 2017
1 parent bb1e1e8 commit 9d6a184
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/ui/public/chrome/api/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
}
1 change: 1 addition & 0 deletions src/ui/public/chrome/directives/kbn_chrome.html
Original file line number Diff line number Diff line change
@@ -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')"
Expand Down
4 changes: 3 additions & 1 deletion src/ui/public/chrome/directives/kbn_chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
30 changes: 30 additions & 0 deletions test/functional/apps/dashboard/_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion test/functional/page_objects/common_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9d6a184

Please sign in to comment.