Skip to content

Commit

Permalink
Fix a type error from the default to named conversion (#12021) (#12036)
Browse files Browse the repository at this point in the history
* Fix a type error from the default to named conversion

add tests that would have caught it.

* address code review comments
  • Loading branch information
stacey-gammon committed May 26, 2017
1 parent d6501e8 commit b994f60
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
ng-model="conf.unsavedValue"
type="checkbox"
class="kuiCheckBox"
data-test-subj="advancedSetting-{{conf.name}}-checkbox"
>

<select
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/state_management/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Notifier } from 'ui/notify/notifier';

import {
createStateHash,
hashedItemStoreSingleton,
HashedItemStoreSingleton,
isStateHash,
} from './state_storage';

Expand All @@ -26,7 +26,7 @@ export function StateProvider(Private, $rootScope, $location, config, kbnUrl) {
function State(
urlParam,
defaults,
hashedItemStore = hashedItemStoreSingleton,
hashedItemStore = HashedItemStoreSingleton,
notifier = new Notifier()
) {
State.Super.call(this);
Expand Down
104 changes: 67 additions & 37 deletions test/functional/apps/management/_kibana_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@ import expect from 'expect.js';

export default function ({ getService, getPageObjects }) {
const kibanaServer = getService('kibanaServer');
const log = getService('log');
const screenshots = getService('screenshots');
const PageObjects = getPageObjects(['settings', 'common']);
const remote = getService('remote');
const PageObjects = getPageObjects(['settings', 'common', 'dashboard', 'header']);

describe('creating and deleting default index', function describeIndexTests() {
before(function () {
before(async function () {
// delete .kibana index and then wait for Kibana to re-create it
return kibanaServer.uiSettings.replace({})
.then(function () {
return PageObjects.settings.navigateTo();
})
.then(function () {
return PageObjects.settings.clickKibanaIndices();
})
.then(function () {
return PageObjects.settings.createIndexPattern();
})
.then(function () {
return PageObjects.settings.navigateTo();
});
await kibanaServer.uiSettings.replace({});
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaIndices();
await PageObjects.settings.createIndexPattern();
await PageObjects.settings.navigateTo();
});

after(async function afterAll() {
Expand All @@ -30,29 +21,68 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.settings.removeIndexPattern();
});

it('should allow setting advanced settings', function () {
return PageObjects.settings.clickKibanaSettings()
.then(function TestCallSetAdvancedSettingsForTimezone() {
screenshots.take('Settings-advanced-tab');
log.debug('calling setAdvancedSetting');
return PageObjects.settings.setAdvancedSettings('dateFormat:tz', 'America/Phoenix');
})
.then(function GetAdvancedSetting() {
screenshots.take('Settings-set-timezone');
return PageObjects.settings.getAdvancedSettings('dateFormat:tz');
})
.then(function (advancedSetting) {
expect(advancedSetting).to.be('America/Phoenix');
});
it('should allow setting advanced settings', async function () {
await PageObjects.settings.clickKibanaSettings();
await PageObjects.settings.setAdvancedSettings('dateFormat:tz', 'America/Phoenix');
const advancedSetting = await PageObjects.settings.getAdvancedSettings('dateFormat:tz');
expect(advancedSetting).to.be('America/Phoenix');
});

after(function () {
return PageObjects.settings.clickKibanaSettings()
.then(function TestCallSetAdvancedSettingsForTimezone() {
screenshots.take('Settings-advanced-tab');
log.debug('calling setAdvancedSetting');
return PageObjects.settings.setAdvancedSettings('dateFormat:tz', 'UTC');
describe('state:storeInSessionStorage', () => {
it ('defaults to false', async () => {
await PageObjects.settings.clickKibanaSettings();
const storeInSessionStorage = await PageObjects.settings.getAdvancedSettings('state:storeInSessionStorage');
expect(storeInSessionStorage).to.be('false');
});

it('when false, dashboard state is unhashed', async function () {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.header.setAbsoluteRange('2015-09-19 06:31:44.000', '2015-09-23 18:31:44.000');
const currentUrl = await remote.getCurrentUrl();
const urlPieces = currentUrl.match(/(.*)?_g=(.*)&_a=(.*)/);
const globalState = urlPieces[2];
const appState = urlPieces[3];

// We don't have to be exact, just need to ensure it's greater than when the hashed variation is being used,
// which is less than 20 characters.
expect(globalState.length).to.be.greaterThan(20);
expect(appState.length).to.be.greaterThan(20);
});

it('setting to true change is preserved', async function () {
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSettings();
await PageObjects.settings.toggleAdvancedSettingCheckbox('state:storeInSessionStorage');
const storeInSessionStorage = await PageObjects.settings.getAdvancedSettings('state:storeInSessionStorage');
expect(storeInSessionStorage).to.be('true');
});

it('when true, dashboard state is hashed', async function () {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.header.setAbsoluteRange('2015-09-19 06:31:44.000', '2015-09-23 18:31:44.000');
const currentUrl = await remote.getCurrentUrl();
const urlPieces = currentUrl.match(/(.*)?_g=(.*)&_a=(.*)/);
const globalState = urlPieces[2];
const appState = urlPieces[3];

// We don't have to be exact, just need to ensure it's less than the unhashed version, which will be
// greater than 20 characters with the default state plus a time.
expect(globalState.length).to.be.lessThan(20);
expect(appState.length).to.be.lessThan(20);
});

after('navigate to settings page and turn state:storeInSessionStorage back to false', async () => {
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSettings();
await PageObjects.settings.toggleAdvancedSettingCheckbox('state:storeInSessionStorage');
});
});

after(async function () {
await PageObjects.settings.clickKibanaSettings();
await PageObjects.settings.setAdvancedSettings('dateFormat:tz', 'UTC');
});
});
}
10 changes: 10 additions & 0 deletions test/functional/page_objects/settings_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export function SettingsPageProvider({ getService, getPageObjects }) {
await PageObjects.header.waitUntilLoadingHasFinished();
}

async toggleAdvancedSettingCheckbox(propertyName) {
await testSubjects.click(`advancedSetting-${propertyName}-editButton`);
await PageObjects.header.waitUntilLoadingHasFinished();
const checkbox = await testSubjects.find(`advancedSetting-${propertyName}-checkbox`);
await checkbox.click();
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.click(`advancedSetting-${propertyName}-saveButton`);
await PageObjects.header.waitUntilLoadingHasFinished();
}

async navigateTo() {
await PageObjects.common.navigateToApp('settings');
}
Expand Down

0 comments on commit b994f60

Please sign in to comment.