Merge pull request #16 from w33ble/fix/3959-tests

Data mutation tests
This commit is contained in:
Shelby Sturgis 2015-06-04 20:40:21 -04:00
commit 398a8053ee
2 changed files with 54 additions and 181 deletions

View file

@ -2,6 +2,11 @@ define(function (require) {
var angular = require('angular');
var _ = require('lodash');
var Data;
var dataSeries = require('vislib_fixtures/mock_data/date_histogram/_series');
var dataSeriesNeg = require('vislib_fixtures/mock_data/date_histogram/_series_neg');
var dataStacked = require('vislib_fixtures/mock_data/stacked/_stacked');
var seriesData = {
'label': '',
'series': [
@ -94,118 +99,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 +133,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 +146,6 @@ define(function (require) {
});
describe('Data.flatten', function () {
var DataFactory;
var serIn;
var rowIn;
var colIn;
@ -246,16 +154,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 +166,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 +182,20 @@ 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 visDataNeg;
var visDataStacked;
var minValue = 4;
var minValueNeg = -41;
var minValueStacked = 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, {});
visDataNeg = new Data(dataSeriesNeg, {});
visDataStacked = new Data(dataStacked, { type: 'histogram' });
});
// The first value in the time series is less than the min date in the
@ -317,12 +203,15 @@ define(function (require) {
// when calculating the Y max value since it falls outside of the range.
it('should return the Y domain min value', function () {
expect(visData.getYMin()).to.be(minValue);
expect(stackedVisData.getYMin()).to.be(stackedMinValue);
expect(visDataNeg.getYMin()).to.be(minValueNeg);
expect(visDataStacked.getYMin()).to.be(minValueStacked);
});
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(visDataStacked.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);
expect(_.min(stackedSeries.values, function (d) { return d.x; })).to.be.greaterThan(minValueStacked);
});
it('allows passing a value getter for manipulating the values considered', function () {
@ -333,32 +222,17 @@ 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 visDataNeg;
var visDataStacked;
var maxValue = 41;
var maxValueNeg = -4;
var maxValueStacked = 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, {});
visDataNeg = new Data(dataSeriesNeg, {});
visDataStacked = new Data(dataStacked, { type: 'histogram' });
});
// The first value in the time series is less than the min date in the
@ -366,12 +240,15 @@ define(function (require) {
// when calculating the Y max value since it falls outside of the range.
it('should return the Y domain min value', function () {
expect(visData.getYMax()).to.be(maxValue);
expect(stackedVisData.getYMax()).to.be(stackedMaxValue);
expect(visDataNeg.getYMax()).to.be(maxValueNeg);
expect(visDataStacked.getYMax()).to.be(maxValueStacked);
});
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(visDataStacked.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);
expect(_.min(stackedSeries, function (d) { return d.x; })).to.be.greaterThan(maxValueStacked);
});
it('allows passing a value getter for manipulating the values considered', function () {

View file

@ -36,9 +36,6 @@ define(function (require) {
'stacked'
];
var min;
var max;
angular.module('ColumnChartFactory', ['kibana']);
dataArray.forEach(function (data, i) {
@ -62,9 +59,6 @@ define(function (require) {
vis.on('brush', _.noop);
vis.render(data);
min = vis.handler.data.getYMin();
max = vis.handler.data.getYMax();
});
});
@ -212,6 +206,8 @@ define(function (require) {
it('should return yAxis extents equal to data extents', function () {
vis.handler.charts.forEach(function (chart) {
var yAxis = chart.handler.yAxis;
var min = vis.handler.data.getYMin();
var max = vis.handler.data.getYMax();
expect(yAxis.domain[0]).to.equal(min);
expect(yAxis.domain[1]).to.equal(max);