[uiExports] test injectDefaultVars()

This commit is contained in:
spalger 2016-03-17 18:38:31 -07:00
parent cdcc795af8
commit f267ab1059
7 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,18 @@
import Bluebird from 'bluebird';
export default kibana => new kibana.Plugin({
config(Joi) {
return Joi.object().keys({
enabled: Joi.boolean().default(true),
delay: Joi.number().required(),
shared: Joi.string(),
}).default();
},
uiExports: {
async injectDefaultVars(server, options) {
await Bluebird.delay(options.delay);
return { shared: options.shared };
}
}
});

View file

@ -0,0 +1,4 @@
{
"name": "plugin_async_foo",
"version": "0.0.0"
}

View file

@ -0,0 +1,14 @@
export default kibana => new kibana.Plugin({
config(Joi) {
return Joi.object().keys({
enabled: Joi.boolean().default(true),
shared: Joi.string()
}).default();
},
uiExports: {
injectDefaultVars(server, options) {
return { shared: options.shared };
}
}
});

View file

@ -0,0 +1,4 @@
{
"name": "plugin_bar",
"version": "0.0.0"
}

View file

@ -0,0 +1,14 @@
export default kibana => new kibana.Plugin({
config(Joi) {
return Joi.object().keys({
enabled: Joi.boolean().default(true),
shared: Joi.string()
}).default();
},
uiExports: {
injectDefaultVars(server, options) {
return { shared: options.shared };
}
}
});

View file

@ -0,0 +1,4 @@
{
"name": "plugin_foo",
"version": "0.0.0"
}

View file

@ -1,6 +1,8 @@
import expect from 'expect.js';
import { resolve } from 'path';
import UiExports from '../ui_exports';
import * as kbnTestServer from '../../../test/utils/kbn_server';
describe('UiExports', function () {
describe('#find()', function () {
@ -23,4 +25,83 @@ describe('UiExports', function () {
expect(uiExports.find(['foo', 'bar'])).to.eql(['a', 'b', 'c']);
});
});
//
describe('#defaultInjectedVars', function () {
context('two plugins, two sync', function () {
this.slow(10000);
this.timeout(60000);
let kbnServer;
before(async function () {
kbnServer = kbnTestServer.createServer({
plugins: {
paths: [
resolve(__dirname, 'fixtures/plugin_bar'),
resolve(__dirname, 'fixtures/plugin_foo')
]
},
plugin_foo: {
shared: 'foo'
},
plugin_bar: {
shared: 'bar'
}
});
await kbnServer.ready();
});
after(async function () {
await kbnServer.close();
});
it('merges the two plugins in the order they are loaded', function () {
expect(kbnServer.uiExports.defaultInjectedVars).to.eql({
shared: 'foo'
});
});
});
context('two plugins, one async', function () {
this.slow(10000);
this.timeout(60000);
let kbnServer;
before(async function () {
kbnServer = kbnTestServer.createServer({
plugins: {
scanDirs: [],
paths: [
resolve(__dirname, 'fixtures/plugin_async_foo'),
resolve(__dirname, 'fixtures/plugin_foo')
]
},
plugin_async_foo: {
delay: 500,
shared: 'foo'
},
plugin_bar: {
shared: 'bar'
}
});
await kbnServer.ready();
});
after(async function () {
await kbnServer.close();
});
it('merges the two plugins in the order they are loaded', function () {
// even though plugin_async_foo loads 500ms later, it is still "first" to merge
expect(kbnServer.uiExports.defaultInjectedVars).to.eql({
shared: 'foo'
});
});
});
});
});