Merge pull request #4081 from w33ble/fix/d3-axis-errors
Fix d3 y-axis errors in tests
This commit is contained in:
commit
d2a7138fb5
|
@ -59,10 +59,10 @@ define(function (require) {
|
|||
var self = this;
|
||||
var xAxis = this.handler.xAxis;
|
||||
var xScale = xAxis.xScale;
|
||||
var yScale = xAxis.yScale;
|
||||
var ordered = xAxis.ordered;
|
||||
var missingMinMax = !ordered || _.isUndefined(ordered.min) || _.isUndefined(ordered.max);
|
||||
|
||||
if (!ordered || ordered.endzones === false) return;
|
||||
if (missingMinMax || ordered.endzones === false) return;
|
||||
|
||||
var attr = this.handler._attr;
|
||||
var height = attr.height;
|
||||
|
|
|
@ -10,183 +10,182 @@ define(function (require) {
|
|||
var histogramColumns = require('vislib_fixtures/mock_data/histogram/_columns');
|
||||
var rangeRows = require('vislib_fixtures/mock_data/range/_rows');
|
||||
var termSeries = require('vislib_fixtures/mock_data/terms/_series');
|
||||
var dateHistogramArray = [
|
||||
seriesPos,
|
||||
seriesPosNeg,
|
||||
seriesNeg,
|
||||
histogramColumns,
|
||||
rangeRows,
|
||||
termSeries,
|
||||
];
|
||||
var names = [
|
||||
'series pos',
|
||||
'series pos neg',
|
||||
'series neg',
|
||||
'histogram columns',
|
||||
'range rows',
|
||||
'term series',
|
||||
|
||||
var dataTypes = [
|
||||
['series pos', seriesPos],
|
||||
['series pos neg', seriesPosNeg],
|
||||
['series neg', seriesNeg],
|
||||
['histogram columns', histogramColumns],
|
||||
['range rows', rangeRows],
|
||||
['term series', termSeries],
|
||||
];
|
||||
|
||||
angular.module('LineChartFactory', ['kibana']);
|
||||
|
||||
dateHistogramArray.forEach(function (data, i) {
|
||||
describe('VisLib Line Chart Test Suite for ' + names[i] + ' Data', function () {
|
||||
var vis;
|
||||
var visLibParams = {
|
||||
type: 'line',
|
||||
addLegend: true,
|
||||
addTooltip: true,
|
||||
drawLinesBetweenPoints: true
|
||||
};
|
||||
describe('VisLib Line Chart', function () {
|
||||
dataTypes.forEach(function (type, i) {
|
||||
var name = type[0];
|
||||
var data = type[1];
|
||||
|
||||
beforeEach(function () {
|
||||
module('LineChartFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (Private) {
|
||||
vis = Private(require('vislib_fixtures/_vis_fixture'))(visLibParams);
|
||||
require('css!components/vislib/styles/main');
|
||||
|
||||
vis.on('brush', _.noop);
|
||||
|
||||
vis.render(data);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
$(vis.el).remove();
|
||||
vis = null;
|
||||
});
|
||||
|
||||
describe('addCircleEvents method', function () {
|
||||
var circle;
|
||||
var brush;
|
||||
var d3selectedCircle;
|
||||
var onBrush;
|
||||
var onClick;
|
||||
var onMouseOver;
|
||||
describe(name + ' Data', function () {
|
||||
var vis;
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
circle = $(chart.chartEl).find('.circle')[0];
|
||||
brush = $(chart.chartEl).find('.brush');
|
||||
d3selectedCircle = d3.select(circle)[0][0];
|
||||
module('LineChartFactory');
|
||||
});
|
||||
|
||||
// d3 instance of click and hover
|
||||
onBrush = (!!brush);
|
||||
onClick = (!!d3selectedCircle.__onclick);
|
||||
onMouseOver = (!!d3selectedCircle.__onmouseover);
|
||||
beforeEach(function () {
|
||||
var visLibParams = {
|
||||
type: 'line',
|
||||
addLegend: true,
|
||||
addTooltip: true,
|
||||
drawLinesBetweenPoints: true
|
||||
};
|
||||
|
||||
inject(function (Private) {
|
||||
vis = Private(require('vislib_fixtures/_vis_fixture'))(visLibParams);
|
||||
require('css!components/vislib/styles/main');
|
||||
|
||||
vis.on('brush', _.noop);
|
||||
|
||||
vis.render(data);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
$(vis.el).remove();
|
||||
vis = null;
|
||||
});
|
||||
|
||||
describe('addCircleEvents method', function () {
|
||||
var circle;
|
||||
var brush;
|
||||
var d3selectedCircle;
|
||||
var onBrush;
|
||||
var onClick;
|
||||
var onMouseOver;
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
circle = $(chart.chartEl).find('.circle')[0];
|
||||
brush = $(chart.chartEl).find('.brush');
|
||||
d3selectedCircle = d3.select(circle)[0][0];
|
||||
|
||||
// d3 instance of click and hover
|
||||
onBrush = (!!brush);
|
||||
onClick = (!!d3selectedCircle.__onclick);
|
||||
onMouseOver = (!!d3selectedCircle.__onmouseover);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// D3 brushing requires that a g element is appended that
|
||||
// listens for mousedown events. This g element includes
|
||||
// listeners, however, I was not able to test for the listener
|
||||
// function being present. I will need to update this test
|
||||
// in the future.
|
||||
it('should attach a brush g element', function () {
|
||||
vis.handler.charts.forEach(function () {
|
||||
expect(onBrush).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should attach a click event', function () {
|
||||
vis.handler.charts.forEach(function () {
|
||||
expect(onClick).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should attach a hover event', function () {
|
||||
vis.handler.charts.forEach(function () {
|
||||
expect(onMouseOver).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// D3 brushing requires that a g element is appended that
|
||||
// listens for mousedown events. This g element includes
|
||||
// listeners, however, I was not able to test for the listener
|
||||
// function being present. I will need to update this test
|
||||
// in the future.
|
||||
it('should attach a brush g element', function () {
|
||||
vis.handler.charts.forEach(function () {
|
||||
expect(onBrush).to.be(true);
|
||||
describe('addCircles method', function () {
|
||||
it('should append circles', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect($(chart.chartEl).find('circle').length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should attach a click event', function () {
|
||||
vis.handler.charts.forEach(function () {
|
||||
expect(onClick).to.be(true);
|
||||
describe('addLines method', function () {
|
||||
it('should append a paths', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect($(chart.chartEl).find('path').length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should attach a hover event', function () {
|
||||
vis.handler.charts.forEach(function () {
|
||||
expect(onMouseOver).to.be(true);
|
||||
// Cannot seem to get these tests to work on the box
|
||||
// They however pass in the browsers
|
||||
//describe('addClipPath method', function () {
|
||||
// it('should append a clipPath', function () {
|
||||
// vis.handler.charts.forEach(function (chart) {
|
||||
// expect($(chart.chartEl).find('clipPath').length).to.be(1);
|
||||
// });
|
||||
// });
|
||||
//});
|
||||
|
||||
describe('draw method', function () {
|
||||
it('should return a function', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect(chart.draw()).to.be.a(Function);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('addCircles method', function () {
|
||||
it('should append circles', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect($(chart.chartEl).find('circle').length).to.be.greaterThan(0);
|
||||
it('should return a yMin and yMax', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
|
||||
expect(yAxis.domain[0]).to.not.be(undefined);
|
||||
expect(yAxis.domain[1]).to.not.be(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('addLines method', function () {
|
||||
it('should append a paths', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect($(chart.chartEl).find('path').length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should render a zero axis line', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
|
||||
// Cannot seem to get these tests to work on the box
|
||||
// They however pass in the browsers
|
||||
//describe('addClipPath method', function () {
|
||||
// it('should append a clipPath', function () {
|
||||
// vis.handler.charts.forEach(function (chart) {
|
||||
// expect($(chart.chartEl).find('clipPath').length).to.be(1);
|
||||
// });
|
||||
// });
|
||||
//});
|
||||
|
||||
describe('draw method', function () {
|
||||
it('should return a function', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect(chart.draw()).to.be.a(Function);
|
||||
if (yAxis.yMin < 0 && yAxis.yMax > 0) {
|
||||
expect($(chart.chartEl).find('line.zero-line').length).to.be(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a yMin and yMax', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
describe('containerTooSmall error', function () {
|
||||
beforeEach(function () {
|
||||
$(vis.el).height(0);
|
||||
$(vis.el).width(0);
|
||||
});
|
||||
|
||||
expect(yAxis.domain[0]).to.not.be(undefined);
|
||||
expect(yAxis.domain[1]).to.not.be(undefined);
|
||||
it('should throw an error', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect(function () {
|
||||
chart.render();
|
||||
}).to.throwError();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should render a zero axis line', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
|
||||
if (yAxis.yMin < 0 && yAxis.yMax > 0) {
|
||||
expect($(chart.chartEl).find('line.zero-line').length).to.be(1);
|
||||
}
|
||||
describe('defaultYExtents is true', function () {
|
||||
beforeEach(function () {
|
||||
vis._attr.defaultYExtents = true;
|
||||
vis.render(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('containerTooSmall error', function () {
|
||||
beforeEach(function () {
|
||||
$(vis.el).height(0);
|
||||
$(vis.el).width(0);
|
||||
});
|
||||
it('should return yAxis extents equal to data extents', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
var yVals = [vis.handler.data.getYMin(), vis.handler.data.getYMax()];
|
||||
|
||||
it('should throw an error', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
expect(function () {
|
||||
chart.render();
|
||||
}).to.throwError();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('defaultYExtents is true', function () {
|
||||
beforeEach(function () {
|
||||
vis._attr.defaultYExtents = true;
|
||||
vis.render(data);
|
||||
});
|
||||
|
||||
it('should return yAxis extents equal to data extents', function () {
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
var yAxis = chart.handler.yAxis;
|
||||
var yVals = [vis.handler.data.getYMin(), vis.handler.data.getYMax()];
|
||||
|
||||
expect(yAxis.domain[0]).to.equal(yVals[0]);
|
||||
expect(yAxis.domain[1]).to.equal(yVals[1]);
|
||||
expect(yAxis.domain[0]).to.equal(yVals[0]);
|
||||
expect(yAxis.domain[1]).to.equal(yVals[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue