Skip to content

Commit 1a93bc1

Browse files
committed
adding unit test
1 parent c170865 commit 1a93bc1

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

src/ui/public/vis/__tests__/_vis.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ describe('Vis Class', function () {
4444
listeners: { click: _.noop }
4545
};
4646

47+
// Wrap the given vis type definition in a state, that can be passed to vis
48+
const state = (type) => ({
49+
type: {
50+
visConfig: { defaults: {} },
51+
...type,
52+
}
53+
});
54+
4755
beforeEach(ngMock.module('kibana'));
4856
beforeEach(ngMock.inject(function (Private) {
4957
Vis = Private(VisProvider);
@@ -111,14 +119,6 @@ describe('Vis Class', function () {
111119

112120
describe('inspector', () => {
113121

114-
// Wrap the given vis type definition in a state, that can be passed to vis
115-
const state = (type) => ({
116-
type: {
117-
visConfig: { defaults: {} },
118-
...type,
119-
}
120-
});
121-
122122
describe('hasInspector()', () => {
123123
it('should forward to inspectors hasInspector', () => {
124124
const vis = new Vis(indexPattern, state({
@@ -256,4 +256,40 @@ describe('Vis Class', function () {
256256

257257
});
258258

259+
describe('vis addFilter method', () => {
260+
let aggConfig;
261+
let data;
262+
263+
beforeEach(() => {
264+
aggConfig = {
265+
type: { name: 'terms' },
266+
params: {},
267+
createFilter: sinon.stub()
268+
};
269+
270+
data = {
271+
columns: [{
272+
title: 'test',
273+
aggConfig
274+
}],
275+
rows: [['US']]
276+
};
277+
});
278+
279+
280+
it('adds a simple filter', () => {
281+
const vis = new Vis(indexPattern, state({ requestHandler: 'none' }));
282+
vis.API.events.addFilter(data, 0, 0);
283+
expect(aggConfig.createFilter.callCount).to.be(1);
284+
expect(aggConfig.createFilter.getCall(0).args[0]).to.be('US');
285+
});
286+
287+
it('adds a filter if value is provided instead of row index', () => {
288+
const vis = new Vis(indexPattern, state({ requestHandler: 'none' }));
289+
vis.API.events.addFilter(data, 0, -1, 'UK');
290+
expect(aggConfig.createFilter.callCount).to.be(1);
291+
expect(aggConfig.createFilter.getCall(0).args[0]).to.be('UK');
292+
});
293+
});
294+
259295
});

0 commit comments

Comments
 (0)