adding tests

This commit is contained in:
Shelby Sturgis 2015-04-17 15:34:58 -04:00
parent 887e5dbda6
commit 35e0f86e3a
3 changed files with 70 additions and 6 deletions

View file

@ -24,7 +24,8 @@ define(function (require) {
}
PieChart.Super.apply(this, arguments);
this._validatePieData();
var charts = this.handler.data.getVisData();
this._validatePieData(charts);
this._attr = _.defaults(handler._attr || {}, {
isDonut: handler._attr.isDonut || false
@ -35,15 +36,12 @@ define(function (require) {
* Checks whether pie slices have all zero values.
* If so, an error is thrown.
*/
PieChart.prototype._validatePieData = function () {
var charts = this.handler.data.getVisData();
PieChart.prototype._validatePieData = function (charts) {
var isAllZeros = charts.every(function (chart) {
return chart.slices.children.length === 0;
});
if (isAllZeros) {
throw new errors.PieContainsAllZeros();
}
if (isAllZeros) { throw new errors.PieContainsAllZeros(); }
};
/**

View file

@ -205,6 +205,37 @@ define(function (require) {
});
describe('_removeZeroSlices', function () {
var pieData = {
slices: {
children: [
{size: 30},
{size: 20},
{size: 0}
]
}
};
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);
});
});
it('should remove zero values', function () {
var slices = data.data.slices;
expect(slices.children.length).to.be(2);
});
});
describe('Data.flatten', function () {
var DataFactory;
var serIn;

View file

@ -118,6 +118,41 @@ define(function (require) {
expect($(chart1.el).find('.y-axis-chart-title').length).to.be(1);
expect($(chart2.el).find('.x-axis-chart-title').length).to.be(1);
});
describe('_validatePieData method', function () {
var allZeros = [
{ slices: { children: [] } },
{ slices: { children: [] } },
{ slices: { children: [] } }
];
var someZeros = [
{ slices: { children: [{}] } },
{ slices: { children: [{}] } },
{ slices: { children: [] } }
];
var noZeros = [
{ slices: { children: [{}] } },
{ slices: { children: [{}] } },
{ slices: { children: [{}] } }
];
it('should throw an error when all charts contain zeros', function () {
expect(function () {
chart1.ChartClass.prototype._validatePieData(allZeros);
}).to.throwError();
});
it('should not throw an error when only some or no charts contain zeros', function () {
expect(function () {
chart1.ChartClass.prototype._validatePieData(someZeros);
}).to.not.throwError();
expect(function () {
chart1.ChartClass.prototype._validatePieData(noZeros);
}).to.not.throwError();
});
});
});
aggArray.forEach(function (dataAgg, i) {