forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding additional vis unit tests (elastic#14031)
- Loading branch information
1 parent
22d606f
commit b6d7e30
Showing
6 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/ui/public/vis/editors/default/__tests__/nesting_indicator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters