mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
refactor data class test suite
remove unused data sets only one beforeEach for to inject the Data class don't inject d3 (not used) shuffle a little bit of code
This commit is contained in:
parent
db33d63dbe
commit
c8dfb38378
1 changed files with 37 additions and 169 deletions
|
@ -2,6 +2,10 @@ define(function (require) {
|
|||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
|
||||
var Data;
|
||||
var dataSeries = require('vislib_fixtures/mock_data/date_histogram/_series');
|
||||
var stackedDataSeries = require('vislib_fixtures/mock_data/stacked/_stacked');
|
||||
|
||||
var seriesData = {
|
||||
'label': '',
|
||||
'series': [
|
||||
|
@ -94,118 +98,31 @@ define(function (require) {
|
|||
]
|
||||
};
|
||||
|
||||
var seriesData2 = {
|
||||
'label': '',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
},
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var rowsData2 = {
|
||||
'rows': [
|
||||
{
|
||||
'label': 'a',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
},
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'b',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
},
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var colsData2 = {
|
||||
'columns': [
|
||||
{
|
||||
'label': 'a',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
},
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'b',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
},
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var flattenedData = [
|
||||
[{x: 0, y: 0}, {x: 1, y: 2}, {x: 2, y: 4}, {x: 3, y: 6}, {x: 4, y: 8}],
|
||||
[{x: 0, y: 0}, {x: 1, y: 2}, {x: 2, y: 4}, {x: 3, y: 6}, {x: 4, y: 8}],
|
||||
[{x: 0, y: 0}, {x: 1, y: 2}, {x: 2, y: 4}, {x: 3, y: 6}, {x: 4, y: 8}]
|
||||
];
|
||||
|
||||
angular.module('DataFactory', ['kibana']);
|
||||
|
||||
describe('Vislib Data Class Test Suite', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
module('DataFactory');
|
||||
|
||||
inject(function (Private) {
|
||||
Data = Private(require('components/vislib/lib/data'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Data Class (main)', function () {
|
||||
var DataFactory;
|
||||
var rowIn;
|
||||
|
||||
beforeEach(function () {
|
||||
module('DataFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
DataFactory = Private(require('components/vislib/lib/data'));
|
||||
});
|
||||
rowIn = new DataFactory(rowsData, {});
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(_.isFunction(DataFactory)).to.be(true);
|
||||
expect(_.isFunction(Data)).to.be(true);
|
||||
});
|
||||
|
||||
it('should return an object', function () {
|
||||
var rowIn = new Data(rowsData, {});
|
||||
expect(_.isObject(rowIn)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('_removeZeroSlices', function () {
|
||||
var data;
|
||||
var pieData = {
|
||||
slices: {
|
||||
children: [
|
||||
|
@ -215,19 +132,10 @@ define(function (require) {
|
|||
]
|
||||
}
|
||||
};
|
||||
var DataFactory;
|
||||
var data;
|
||||
|
||||
beforeEach(function () {
|
||||
module('DataFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (Private) {
|
||||
DataFactory = Private(require('components/vislib/lib/data'));
|
||||
data = new DataFactory(pieData, {});
|
||||
data._removeZeroSlices(pieData.slices);
|
||||
});
|
||||
data = new Data(pieData, {});
|
||||
data._removeZeroSlices(pieData.slices);
|
||||
});
|
||||
|
||||
it('should remove zero values', function () {
|
||||
|
@ -237,7 +145,6 @@ define(function (require) {
|
|||
});
|
||||
|
||||
describe('Data.flatten', function () {
|
||||
var DataFactory;
|
||||
var serIn;
|
||||
var rowIn;
|
||||
var colIn;
|
||||
|
@ -246,16 +153,9 @@ define(function (require) {
|
|||
var colOut;
|
||||
|
||||
beforeEach(function () {
|
||||
module('DataFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
DataFactory = Private(require('components/vislib/lib/data'));
|
||||
});
|
||||
serIn = new DataFactory(seriesData, {});
|
||||
rowIn = new DataFactory(rowsData, {});
|
||||
colIn = new DataFactory(colsData, {});
|
||||
serIn = new Data(seriesData, {});
|
||||
rowIn = new Data(rowsData, {});
|
||||
colIn = new Data(colsData, {});
|
||||
serOut = serIn.flatten();
|
||||
rowOut = rowIn.flatten();
|
||||
colOut = colIn.flatten();
|
||||
|
@ -265,9 +165,13 @@ define(function (require) {
|
|||
expect(serOut.every(_.isObject)).to.be(true);
|
||||
});
|
||||
|
||||
it('should return all points from every series', testLength(seriesData));
|
||||
it('should return all points from every series', testLength(rowsData));
|
||||
it('should return all points from every series', testLength(colsData));
|
||||
|
||||
function testLength(inputData) {
|
||||
return function () {
|
||||
var data = new DataFactory(inputData, {});
|
||||
var data = new Data(inputData, {});
|
||||
var len = _.reduce(data.chartData(), function (sum, chart) {
|
||||
return sum + chart.series.reduce(function (sum, series) {
|
||||
return sum + series.values.length;
|
||||
|
@ -277,39 +181,17 @@ define(function (require) {
|
|||
expect(data.flatten()).to.have.length(len);
|
||||
};
|
||||
}
|
||||
|
||||
it('should return all points from every series', testLength(seriesData));
|
||||
it('should return all points from every series', testLength(rowsData));
|
||||
it('should return all points from every series', testLength(colsData));
|
||||
});
|
||||
|
||||
describe('getYMin method', function () {
|
||||
var Data;
|
||||
var dataSeries;
|
||||
var stackedDataSeries;
|
||||
var visData;
|
||||
var stackedVisData;
|
||||
var series;
|
||||
var stackedSeries;
|
||||
var minValue;
|
||||
var stackedMinValue;
|
||||
var minValue = 4;
|
||||
var stackedMinValue = 15;
|
||||
|
||||
beforeEach(function () {
|
||||
module('DataFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
Data = Private(require('components/vislib/lib/data'));
|
||||
dataSeries = require('vislib_fixtures/mock_data/date_histogram/_series');
|
||||
stackedDataSeries = require('vislib_fixtures/mock_data/stacked/_stacked');
|
||||
visData = new Data(dataSeries, {});
|
||||
stackedVisData = new Data(stackedDataSeries, { type: 'histogram' });
|
||||
series = _.pluck(visData.chartData(), 'series');
|
||||
stackedSeries = _.pluck(stackedVisData.chartData(), 'series');
|
||||
minValue = 4;
|
||||
stackedMinValue = 15;
|
||||
});
|
||||
visData = new Data(dataSeries, {});
|
||||
stackedVisData = new Data(stackedDataSeries, { type: 'histogram' });
|
||||
});
|
||||
|
||||
// The first value in the time series is less than the min date in the
|
||||
|
@ -321,6 +203,8 @@ define(function (require) {
|
|||
});
|
||||
|
||||
it('should have a minimum date value that is greater than the max value within the date range', function () {
|
||||
var series = _.pluck(visData.chartData(), 'series');
|
||||
var stackedSeries = _.pluck(stackedVisData.chartData(), 'series');
|
||||
expect(_.min(series.values, function (d) { return d.x; })).to.be.greaterThan(minValue);
|
||||
expect(_.min(stackedSeries.values, function (d) { return d.x; })).to.be.greaterThan(stackedMinValue);
|
||||
});
|
||||
|
@ -333,32 +217,14 @@ define(function (require) {
|
|||
});
|
||||
|
||||
describe('getYMax method', function () {
|
||||
var Data;
|
||||
var dataSeries;
|
||||
var stackedDataSeries;
|
||||
var visData;
|
||||
var stackedVisData;
|
||||
var series;
|
||||
var stackedSeries;
|
||||
var maxValue;
|
||||
var stackedMaxValue;
|
||||
var maxValue = 41;
|
||||
var stackedMaxValue = 115;
|
||||
|
||||
beforeEach(function () {
|
||||
module('DataFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
Data = Private(require('components/vislib/lib/data'));
|
||||
dataSeries = require('vislib_fixtures/mock_data/date_histogram/_series');
|
||||
stackedDataSeries = require('vislib_fixtures/mock_data/stacked/_stacked');
|
||||
visData = new Data(dataSeries, {});
|
||||
stackedVisData = new Data(stackedDataSeries, { type: 'histogram' });
|
||||
series = _.pluck(visData.chartData(), 'series');
|
||||
stackedSeries = _.pluck(stackedVisData.chartData(), 'series');
|
||||
maxValue = 41;
|
||||
stackedMaxValue = 115;
|
||||
});
|
||||
visData = new Data(dataSeries, {});
|
||||
stackedVisData = new Data(stackedDataSeries, { type: 'histogram' });
|
||||
});
|
||||
|
||||
// The first value in the time series is less than the min date in the
|
||||
|
@ -370,6 +236,8 @@ define(function (require) {
|
|||
});
|
||||
|
||||
it('should have a minimum date value that is greater than the max value within the date range', function () {
|
||||
var series = _.pluck(visData.chartData(), 'series');
|
||||
var stackedSeries = _.pluck(stackedVisData.chartData(), 'series');
|
||||
expect(_.min(series, function (d) { return d.x; })).to.be.greaterThan(maxValue);
|
||||
expect(_.min(stackedSeries, function (d) { return d.x; })).to.be.greaterThan(stackedMaxValue);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue