Move getEditorType to its own module
A unit test is also included since the function is now importable.
This commit is contained in:
parent
2378e6282d
commit
3932bd00d5
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
});
|
Loading…
Reference in a new issue