adding additional vis unit tests (#14031)
This commit is contained in:
parent
7bcc7435e2
commit
9346b49769
59
src/ui/public/vis/__tests__/response_handlers/basic.js
Normal file
59
src/ui/public/vis/__tests__/response_handlers/basic.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import { BasicResponseHandlerProvider } from 'ui/vis/response_handlers/basic';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import fixtures from 'fixtures/fake_hierarchical_data';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
|
||||
const rowAgg = [
|
||||
{ id: 'agg_1', type: 'avg', schema: 'metric', params: { field: 'bytes' } },
|
||||
{ id: 'agg_2', type: 'terms', schema: 'split', params: { field: 'extension', rows: true } },
|
||||
{ id: 'agg_3', type: 'terms', schema: 'segment', params: { field: 'machine.os' } },
|
||||
{ id: 'agg_4', type: 'terms', schema: 'segment', params: { field: 'geo.src' } }
|
||||
];
|
||||
|
||||
|
||||
describe('Basic Response Handler', function () {
|
||||
let basicResponseHandler;
|
||||
let indexPattern;
|
||||
let Vis;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
basicResponseHandler = Private(BasicResponseHandlerProvider).handler;
|
||||
Vis = Private(VisProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
}));
|
||||
|
||||
it('calls hierarchical converter if isHierarchical is set to true', () => {
|
||||
const vis = new Vis(indexPattern, {
|
||||
type: 'pie',
|
||||
aggs: rowAgg
|
||||
});
|
||||
basicResponseHandler(vis, fixtures.threeTermBuckets).then(data => {
|
||||
expect(data).to.not.be.an('undefined');
|
||||
expect(data.rows[0].slices).to.not.be.an('undefined');
|
||||
expect(data.rows[0].series).to.be.an('undefined');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns empty object if conversion failed', () => {
|
||||
basicResponseHandler({}, {}).then(data => {
|
||||
expect(data).to.not.be.an('undefined');
|
||||
expect(data.rows).to.equal([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns converted data', () => {
|
||||
const vis = new Vis(indexPattern, {
|
||||
type: 'histogram',
|
||||
aggs: rowAgg.slice(0, 3)
|
||||
});
|
||||
basicResponseHandler(vis, fixtures.threeTermBuckets).then(data => {
|
||||
expect(data).to.not.be.an('undefined');
|
||||
expect(data.rows[0].slices).to.be.an('undefined');
|
||||
expect(data.rows[0].series).to.not.be.an('undefined');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
41
src/ui/public/vis/__tests__/vis_types/base_vis_type.js
Normal file
41
src/ui/public/vis/__tests__/vis_types/base_vis_type.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import { VisTypeProvider } from 'ui/vis/vis_types/base_vis_type';
|
||||
|
||||
describe('Base Vis Type', function () {
|
||||
let BaseVisType;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
BaseVisType = Private(VisTypeProvider);
|
||||
}));
|
||||
|
||||
describe('initialization', () => {
|
||||
it('should throw if mandatory properties are missing', () => {
|
||||
expect(() => {
|
||||
new BaseVisType({});
|
||||
}).to.throwError('vis_type must define its name');
|
||||
|
||||
expect(() => {
|
||||
new BaseVisType({ name: 'test' });
|
||||
}).to.throwError('vis_type must define its title');
|
||||
|
||||
expect(() => {
|
||||
new BaseVisType({ name: 'test', title: 'test' });
|
||||
}).to.throwError('vis_type must define its description');
|
||||
|
||||
expect(() => {
|
||||
new BaseVisType({ name: 'test', title: 'test', description: 'test' });
|
||||
}).to.throwError('vis_type must define its icon or image');
|
||||
|
||||
expect(() => {
|
||||
new BaseVisType({ name: 'test', title: 'test', description: 'test', icon: 'test' });
|
||||
}).to.throwError('vis_type must define visualization controller');
|
||||
|
||||
expect(() => {
|
||||
new BaseVisType({ name: 'test', title: 'test', description: 'test', icon: 'test', visualization: {} });
|
||||
}).to.not.throwError();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
57
src/ui/public/vis/__tests__/vis_types/react_vis_type.js
Normal file
57
src/ui/public/vis/__tests__/vis_types/react_vis_type.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import { ReactVisTypeProvider } from 'ui/vis/vis_types/react_vis_type';
|
||||
|
||||
describe('React Vis Type', function () {
|
||||
let ReactVisType;
|
||||
|
||||
const visConfig = {
|
||||
name: 'test',
|
||||
title: 'test',
|
||||
description: 'test',
|
||||
icon: 'test',
|
||||
visConfig: { component: 'test' },
|
||||
type: { visConfig: { component: 'test' } }
|
||||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
ReactVisType = Private(ReactVisTypeProvider);
|
||||
}));
|
||||
|
||||
describe('initialization', () => {
|
||||
it('should throw if component is not set', () => {
|
||||
expect(() => {
|
||||
new ReactVisType({});
|
||||
}).to.throwError();
|
||||
});
|
||||
|
||||
it('creates react controller', () => {
|
||||
const visType = new ReactVisType(visConfig);
|
||||
expect(visType.visualization).to.not.be.an('undefined');
|
||||
});
|
||||
});
|
||||
|
||||
describe('controller render method', () => {
|
||||
let vis;
|
||||
beforeEach(() => {
|
||||
const visType = new ReactVisType(visConfig);
|
||||
const Vis = visType.visualization;
|
||||
|
||||
vis = new Vis(window.document.body, {});
|
||||
});
|
||||
|
||||
it('rejects if data is not provided', () => {
|
||||
vis.render().then(() => {
|
||||
expect('promise was not rejected').to.equal(false);
|
||||
}).catch(() => {});
|
||||
});
|
||||
|
||||
it('renders the component', () => {
|
||||
expect(() => {
|
||||
vis.render({});
|
||||
}).to.not.throwError();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
90
src/ui/public/vis/__tests__/vis_types/vislib_vis_type.js
Normal file
90
src/ui/public/vis/__tests__/vis_types/vislib_vis_type.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import { VislibVisTypeProvider } from 'ui/vis/vis_types/vislib_vis_type';
|
||||
|
||||
describe('Vislib Vis Type', function () {
|
||||
let VislibVisType;
|
||||
|
||||
const visConfig = {
|
||||
name: 'test',
|
||||
title: 'test',
|
||||
description: 'test',
|
||||
icon: 'test',
|
||||
visConfig: { component: 'test' },
|
||||
type: { visConfig: { component: 'test' } }
|
||||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
VislibVisType = Private(VislibVisTypeProvider);
|
||||
}));
|
||||
|
||||
describe('initialization', () => {
|
||||
it('should set the basic response handler if not set', () => {
|
||||
const visType = new VislibVisType(visConfig);
|
||||
expect(visType.responseHandler).to.equal('basic');
|
||||
});
|
||||
|
||||
it('should not change response handler if its already set', () => {
|
||||
visConfig.responseHandler = 'none';
|
||||
const visType = new VislibVisType(visConfig);
|
||||
expect(visType.responseHandler).to.equal('none');
|
||||
});
|
||||
|
||||
it('creates vislib controller', () => {
|
||||
visConfig.responseHandler = 'none';
|
||||
const visType = new VislibVisType(visConfig);
|
||||
expect(visType.visualization).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('controller', function () {
|
||||
it('constructor sets vis and element properties', () => {
|
||||
visConfig.responseHandler = 'none';
|
||||
const visType = new VislibVisType(visConfig);
|
||||
const Vis = visType.visualization;
|
||||
const vis = new Vis(window.document.body, {});
|
||||
expect(vis.el).to.not.be.undefined;
|
||||
expect(vis.vis).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('render method', () => {
|
||||
let vis;
|
||||
beforeEach(() => {
|
||||
visConfig.responseHandler = 'none';
|
||||
const visType = new VislibVisType(visConfig);
|
||||
const Vis = visType.visualization;
|
||||
vis = new Vis(window.document.body, { params: {} });
|
||||
});
|
||||
|
||||
it('rejects if response is not provided', () => {
|
||||
vis.render().then(() => {
|
||||
expect('promise was not rejected').to.equal(false);
|
||||
}).catch(() => {});
|
||||
});
|
||||
|
||||
it('creates new vislib vis', () => {
|
||||
vis.render({});
|
||||
expect(vis.vis.vislibVis).to.not.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('destroy method', () => {
|
||||
let vis;
|
||||
beforeEach(() => {
|
||||
visConfig.responseHandler = 'none';
|
||||
const visType = new VislibVisType(visConfig);
|
||||
const Vis = visType.visualization;
|
||||
vis = new Vis(window.document.body, { params: {} });
|
||||
});
|
||||
|
||||
it('destroys vislib vis', () => {
|
||||
vis.render({}).then(() => {
|
||||
vis.destroy();
|
||||
expect(vis.vis.vislibVis).to.be.undefined;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
|
||||
describe('nestingIndicator directive', () => {
|
||||
let element;
|
||||
let $rootScope;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject((_$rootScope_, _$compile_) => {
|
||||
$rootScope = _$rootScope_;
|
||||
|
||||
$rootScope.list = ['test'];
|
||||
$rootScope.item = 'test';
|
||||
element = _$compile_('<nesting-indicator item="item" list="list">')($rootScope);
|
||||
}));
|
||||
|
||||
it('should update background color on list change', () => {
|
||||
$rootScope.list.push('test2');
|
||||
$rootScope.$digest();
|
||||
expect(element.find('span').length).to.equal(1);
|
||||
});
|
||||
|
||||
});
|
|
@ -43,6 +43,7 @@ export function VislibVisTypeProvider(Private) {
|
|||
this.vis.vislibVis.off('brush', this.vis.API.events.brush);
|
||||
this.vis.vislibVis.off('click', this.vis.API.events.filter);
|
||||
this.vis.vislibVis.destroy();
|
||||
delete this.vis.vislibVis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue