diff --git a/src/plugins/kibana/public/settings/__tests__/get_editor_type.js b/src/plugins/kibana/public/settings/__tests__/get_editor_type.js new file mode 100644 index 000000000000..968a3cf3f44b --- /dev/null +++ b/src/plugins/kibana/public/settings/__tests__/get_editor_type.js @@ -0,0 +1,27 @@ + +var getEditorType = require('plugins/kibana/settings/sections/advanced/lib/get_editor_type'); +var expect = require('expect.js'); + +describe('Settings', function () { + describe('Advanced', function () { + describe('getEditorType(conf)', function () { + context('when given type has a named editor', function () { + it('returns that named editor', function () { + expect(getEditorType({ type: 'json' })).to.equal('json'); + expect(getEditorType({ type: 'array' })).to.equal('array'); + expect(getEditorType({ type: 'boolean' })).to.equal('boolean'); + expect(getEditorType({ type: 'select' })).to.equal('select'); + }); + }); + + context('when given a type of number, string, null, or undefined', function () { + it('returns "normal"', function () { + expect(getEditorType({ type: 'number' })).to.equal('normal'); + expect(getEditorType({ type: 'string' })).to.equal('normal'); + expect(getEditorType({ type: 'null' })).to.equal('normal'); + expect(getEditorType({ type: 'undefined' })).to.equal('normal'); + }); + }); + }); + }); +}); diff --git a/src/plugins/kibana/public/settings/sections/advanced/index.js b/src/plugins/kibana/public/settings/sections/advanced/index.js index 4f3ec0f5a15e..9e604846e088 100644 --- a/src/plugins/kibana/public/settings/sections/advanced/index.js +++ b/src/plugins/kibana/public/settings/sections/advanced/index.js @@ -1,6 +1,7 @@ define(function (require) { var _ = require('lodash'); var getValType = require('plugins/kibana/settings/sections/advanced/lib/get_val_type'); + var getEditorType = require('plugins/kibana/settings/sections/advanced/lib/get_editor_type'); require('plugins/kibana/settings/sections/advanced/advanced_row'); @@ -21,13 +22,6 @@ define(function (require) { }; var IMMUTABLE_CONFIG_VALS = ['buildNum']; - var NAMED_EDITORS = ['json', 'array', 'boolean', 'select']; - var NORMAL_EDITOR = ['number', 'string', 'null', 'undefined']; - - function getEditorType(conf) { - if (_.contains(NAMED_EDITORS, conf.type)) return conf.type; - if (_.contains(NORMAL_EDITOR, conf.type)) return 'normal'; - } function isTypeComplex(conf) { return !(conf.json || conf.array || conf.bool || conf.normal); diff --git a/src/plugins/kibana/public/settings/sections/advanced/lib/get_editor_type.js b/src/plugins/kibana/public/settings/sections/advanced/lib/get_editor_type.js new file mode 100644 index 000000000000..54ec1e240bbf --- /dev/null +++ b/src/plugins/kibana/public/settings/sections/advanced/lib/get_editor_type.js @@ -0,0 +1,17 @@ +define(function (require) { + var _ = require('lodash'); + + var NAMED_EDITORS = ['json', 'array', 'boolean', 'select']; + var NORMAL_EDITOR = ['number', 'string', 'null', 'undefined']; + + /** + * @param {object} advanced setting configuration object + * @returns {string} the editor type to use when editing value + */ + function getEditorType(conf) { + if (_.contains(NAMED_EDITORS, conf.type)) return conf.type; + if (_.contains(NORMAL_EDITOR, conf.type)) return 'normal'; + } + + return getEditorType; +});