mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
This commit is contained in:
parent
df790a42c1
commit
7173053102
5 changed files with 19 additions and 1 deletions
|
@ -64,6 +64,7 @@
|
|||
ng-keyup="maybeCancel($event, conf)"
|
||||
elastic-textarea
|
||||
validate-json
|
||||
data-test-subj="unsavedValueJsonTextArea"
|
||||
></textarea>
|
||||
|
||||
<p
|
||||
|
|
|
@ -44,6 +44,12 @@ uiModules.get('apps/management')
|
|||
};
|
||||
|
||||
$scope.save = function (conf) {
|
||||
// an empty JSON is valid as per the validateJson directive.
|
||||
// set the value to empty JSON in this case so that its parsing upon retrieving the setting does not fail.
|
||||
if (conf.type === 'json' && conf.unsavedValue === '') {
|
||||
conf.unsavedValue = '{}';
|
||||
}
|
||||
|
||||
loading(conf, function () {
|
||||
if (conf.unsavedValue === conf.defVal) {
|
||||
return config.remove(conf.name);
|
||||
|
|
|
@ -78,6 +78,10 @@ describe('validate-json directive', function () {
|
|||
checkValid(input.invalid, 'ng-invalid');
|
||||
});
|
||||
|
||||
it('should be invalid if a number', function () {
|
||||
checkValid('0', 'ng-invalid');
|
||||
});
|
||||
|
||||
it('should update validity on changes', function () {
|
||||
checkValid(input.valid, 'ng-valid');
|
||||
checkValid(input.invalid, 'ng-invalid');
|
||||
|
|
|
@ -21,7 +21,7 @@ module.directive('validateJson', function () {
|
|||
|
||||
// We actually need a proper object in all JSON inputs
|
||||
newValue = (newValue || '').trim();
|
||||
if (newValue[0] === '{' || '[') {
|
||||
if (newValue[0] === '{' || newValue[0] === '[') {
|
||||
try {
|
||||
JSON.parse(newValue);
|
||||
setValid();
|
||||
|
|
|
@ -28,6 +28,13 @@ export default function ({ getService, getPageObjects }) {
|
|||
expect(advancedSetting).to.be('America/Phoenix');
|
||||
});
|
||||
|
||||
it('should coerce an empty setting of type JSON into an empty object', async function () {
|
||||
await PageObjects.settings.clickKibanaSettings();
|
||||
await PageObjects.settings.setAdvancedSettingsInput('query:queryString:options', '', 'unsavedValueJsonTextArea');
|
||||
const advancedSetting = await PageObjects.settings.getAdvancedSettings('query:queryString:options');
|
||||
expect(advancedSetting).to.be.eql('{}');
|
||||
});
|
||||
|
||||
describe('state:storeInSessionStorage', () => {
|
||||
it ('defaults to false', async () => {
|
||||
await PageObjects.settings.clickKibanaSettings();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue