Skip to content

Commit

Permalink
updating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Aug 27, 2018
1 parent 45880bb commit 19a5fd0
Show file tree
Hide file tree
Showing 36 changed files with 323 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('point series editor', function () {
});

it('should update series when new agg is added', function () {
const aggConfig = new AggConfig($parentScope.vis, { type: 'avg', schema: 'metric', params: { field: 'bytes' } });
const aggConfig = new AggConfig($parentScope.vis.aggs, { type: 'avg', schema: 'metric', params: { field: 'bytes' } });
$parentScope.vis.aggs.push(aggConfig);
$parentScope.$digest();
expect($parentScope.editorState.params.seriesParams.length).to.be(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ function discoverController(
schema: 'segment',
params: {
field: $scope.opts.timefield,
interval: $state.interval
interval: $state.interval,
timeRange: timefilter.getTime(),
}
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@
*/

import expect from 'expect.js';
import ngMock from 'ng_mock';
import { PointSeriesAddToSiriProvider } from '../_add_to_siri';
import { addToSiri } from '../_add_to_siri';

describe('addToSiri', function () {
let addToSiri;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
addToSiri = Private(PointSeriesAddToSiriProvider);
}));

it('creates a new series the first time it sees an id', function () {
const series = new Map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,20 @@
*/

import expect from 'expect.js';
import ngMock from 'ng_mock';
import { VisProvider } from '../../../vis';
import { AggConfig } from '../../../vis/agg_config';
import { AggType } from '../../../agg_types/agg_type';
import { PointSeriesFakeXAxisProvider } from '../_fake_x_aspect';
import { makeFakeXAspect } from '../_fake_x_aspect';

describe('makeFakeXAspect', function () {

let makeFakeXAspect;
let Vis;
let indexPattern;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
indexPattern = Private(VisProvider);
makeFakeXAspect = Private(PointSeriesFakeXAxisProvider);
}));

it('creates an object that looks like an aspect', function () {
const vis = new Vis(indexPattern, { type: 'histogram' });
const aspect = makeFakeXAspect(vis);
const aspect = makeFakeXAspect();

expect(aspect)
.to.have.property('i', -1)
.and.have.property('agg')
.and.have.property('col');
.and.have.property('agg');

expect(aspect.agg)
.to.be.an(AggConfig)
.to.have.property('fieldFormatter')
.and.to.have.property('type');

expect(aspect.agg.type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ import moment from 'moment';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { VisProvider } from '../../../vis';
import { AggConfig } from '../../../vis/agg_config';
import { PointSeriesGetAspectsProvider } from '../_get_aspects';
import { getAspects } from '../_get_aspects';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('getAspects', function () {
let Vis;
let indexPattern;
let getAspects;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
getAspects = Private(PointSeriesGetAspectsProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

Expand Down Expand Up @@ -115,7 +112,7 @@ describe('getAspects', function () {
it('produces an aspect object for each of the aspect types found in the columns', function () {
init(1, 1, 1);

const aspects = getAspects(vis, table);
const aspects = getAspects(table);
validate(aspects.x, 0);
validate(aspects.series, 1);
validate(aspects.y, 2);
Expand All @@ -124,7 +121,7 @@ describe('getAspects', function () {
it('uses arrays only when there are more than one aspect of a specific type', function () {
init(0, 1, 2);

const aspects = getAspects(vis, table);
const aspects = getAspects(table);

validate(aspects.x, 0);
expect(aspects.series == null).to.be(true);
Expand All @@ -138,22 +135,21 @@ describe('getAspects', function () {
init(0, 2, 1);

expect(function () {
getAspects(vis, table);
getAspects(table);
}).to.throwError(TypeError);
});

it('creates a fake x aspect if the column does not exist', function () {
init(0, 0, 1);

const aspects = getAspects(vis, table);
const aspects = getAspects(table);

expect(aspects.x)
.to.be.an('object')
.and.have.property('i', -1)
.and.have.property('agg')
.and.have.property('col');

expect(aspects.x.agg).to.be.an(AggConfig);
expect(aspects.x.col)
.to.be.an('object')
.and.to.have.property('aggConfig', aspects.x.agg);
Expand Down
10 changes: 1 addition & 9 deletions src/ui/public/agg_response/point_series/__tests__/_get_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,13 @@

import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { PointSeriesGetPointProvider } from '../_get_point';
import { getPoint } from '../_get_point';

describe('getPoint', function () {

let getPoint;

const truthFormatted = { fieldFormatter: _.constant(_.constant(true)) };
const identFormatted = { fieldFormatter: _.constant(_.identity) };

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
getPoint = Private(PointSeriesGetPointProvider);
}));

describe('Without series aspect', function () {
let seriesAspect;
let xAspect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@

import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { PointSeriesGetSeriesProvider } from '../_get_series';
import { getSeries } from '../_get_series';

describe('getSeries', function () {
let getSeries;

const agg = { fieldFormatter: _.constant(_.identity) };

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
getSeries = Private(PointSeriesGetSeriesProvider);
}));

function wrapRows(row) {
return row.map(function (v) {
return { value: v };
Expand Down
18 changes: 3 additions & 15 deletions src/ui/public/agg_response/point_series/__tests__/_init_x_axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@

import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { PointSeriesInitXAxisProvider } from '../_init_x_axis';
import { initXAxis } from '../_init_x_axis';

describe('initXAxis', function () {

let initXAxis;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
initXAxis = Private(PointSeriesInitXAxisProvider);
}));

const baseChart = {
aspects: {
x: {
Expand Down Expand Up @@ -62,9 +54,7 @@ describe('initXAxis', function () {
chart.aspects.x.agg.params = {
field: field
};
chart.aspects.x.agg.vis = {
indexPattern: indexPattern
};
chart.aspects.x.agg._indexPattern = indexPattern;

initXAxis(chart);
expect(chart)
Expand All @@ -86,9 +76,7 @@ describe('initXAxis', function () {
chart.aspects.x.agg.params = {
field: field
};
chart.aspects.x.agg.vis = {
indexPattern: indexPattern
};
chart.aspects.x.agg._indexPattern = indexPattern;

initXAxis(chart);
expect(chart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@

import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { PointSeriesInitYAxisProvider } from '../_init_y_axis';
import { initYAxis } from '../_init_y_axis';

describe('initYAxis', function () {

let initYAxis;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
initYAxis = Private(PointSeriesInitYAxisProvider);
}));

function agg() {
return {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/agg_response/point_series/__tests__/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('pointSeriesChartDataFromTable', function () {
table.columns = [ { aggConfig: agg } ];
table.rows.push([ result ]);

const chartData = pointSeriesChartDataFromTable(vis, table);
const chartData = pointSeriesChartDataFromTable(table);

expect(chartData).to.be.an('object');
expect(chartData.series).to.be.an('array');
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('pointSeriesChartDataFromTable', function () {
table.rows.push([date, new AggConfigResult(y.agg, date, y.at(i))]);
});

const chartData = pointSeriesChartDataFromTable(vis, table);
const chartData = pointSeriesChartDataFromTable(table);

expect(chartData).to.be.an('object');
expect(chartData.series).to.be.an('array');
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('pointSeriesChartDataFromTable', function () {
table.rows.push([dateResult, avgResult, maxResult]);
});

const chartData = pointSeriesChartDataFromTable(vis, table);
const chartData = pointSeriesChartDataFromTable(table);
expect(chartData).to.be.an('object');
expect(chartData.series).to.be.an('array');
expect(chartData.series).to.have.length(2);
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('pointSeriesChartDataFromTable', function () {
table.rows.push([dateResult, termResult, avgResult, maxResult]);
});

const chartData = pointSeriesChartDataFromTable(vis, table);
const chartData = pointSeriesChartDataFromTable(table);
expect(chartData).to.be.an('object');
expect(chartData.series).to.be.an('array');
// one series for each extension, and then one for each metric inside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import moment from 'moment';
import _ from 'lodash';
import sinon from 'sinon';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { PointSeriesOrderedDateAxisProvider } from '../_ordered_date_axis';
import { orderedDateAxis } from '../_ordered_date_axis';

describe('orderedDateAxis', function () {

Expand All @@ -48,25 +47,18 @@ describe('orderedDateAxis', function () {
}
};

let orderedDateAxis;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
orderedDateAxis = Private(PointSeriesOrderedDateAxisProvider);
}));

describe('xAxisFormatter', function () {
it('sets the xAxisFormatter', function () {
const args = _.cloneDeep(baseArgs);
orderedDateAxis(args.vis, args.chart);
orderedDateAxis(args.chart);

expect(args.chart).to.have.property('xAxisFormatter');
expect(args.chart.xAxisFormatter).to.be.a('function');
});

it('formats values using moment, and returns strings', function () {
const args = _.cloneDeep(baseArgs);
orderedDateAxis(args.vis, args.chart);
orderedDateAxis(args.chart);

const val = '2014-08-06T12:34:01';
expect(args.chart.xAxisFormatter(val))
Expand All @@ -77,7 +69,7 @@ describe('orderedDateAxis', function () {
describe('ordered object', function () {
it('sets date: true', function () {
const args = _.cloneDeep(baseArgs);
orderedDateAxis(args.vis, args.chart);
orderedDateAxis(args.chart);

expect(args.chart)
.to.have.property('ordered');
Expand All @@ -89,21 +81,21 @@ describe('orderedDateAxis', function () {
it('relies on agg.buckets for the interval', function () {
const args = _.cloneDeep(baseArgs);
const spy = sinon.spy(args.chart.aspects.x.agg.buckets, 'getInterval');
orderedDateAxis(args.vis, args.chart);
orderedDateAxis(args.chart);
expect(spy).to.have.property('callCount', 1);
});

it('sets the min/max when the buckets are bounded', function () {
const args = _.cloneDeep(baseArgs);
orderedDateAxis(args.vis, args.chart);
orderedDateAxis(args.chart);
expect(moment.isMoment(args.chart.ordered.min)).to.be(true);
expect(moment.isMoment(args.chart.ordered.max)).to.be(true);
});

it('does not set the min/max when the buckets are unbounded', function () {
const args = _.cloneDeep(baseArgs);
args.chart.aspects.x.agg.buckets.getBounds = _.constant();
orderedDateAxis(args.vis, args.chart);
orderedDateAxis(args.chart);
expect(args.chart.ordered).to.not.have.property('min');
expect(args.chart.ordered).to.not.have.property('max');
});
Expand Down
21 changes: 11 additions & 10 deletions src/ui/public/agg_response/point_series/__tests__/point_series.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
* under the License.
*/

import './_main';
import './_add_to_siri';
import './_fake_x_aspect';
import './_get_aspects';
import './_get_point';
import './_get_series';
import './_init_x_axis';
import './_init_y_axis';
import './_ordered_date_axis';
import './_tooltip_formatter';

describe('Point Series Agg Response', function () {
require('./_main');
require('./_add_to_siri');
require('./_fake_x_aspect');
require('./_get_aspects');
require('./_get_point');
require('./_get_series');
require('./_init_x_axis');
require('./_init_y_axis');
require('./_ordered_date_axis');
require('./_tooltip_formatter');
});
Loading

0 comments on commit 19a5fd0

Please sign in to comment.