[vislib/yAxis] added tests for the tickLabel method

This commit is contained in:
Spencer Alger 2015-05-01 15:50:27 -07:00
parent 0a7596149c
commit ff3e5bc399

View file

@ -6,6 +6,7 @@ define(function (require) {
var YAxis;
var Data;
var el;
var buildYAxis;
var yAxis;
var yAxisDiv;
@ -70,14 +71,18 @@ define(function (require) {
defaultYMin: true
});
yAxis = new YAxis({
el: node,
yMin: dataObj.getYMin(),
yMax: dataObj.getYMax(),
_attr: {
margin: { top: 0, right: 0, bottom: 0, left: 0 }
}
});
buildYAxis = function (params) {
return new YAxis(_.merge({}, params, {
el: node,
yMin: dataObj.getYMin(),
yMax: dataObj.getYMax(),
_attr: {
margin: { top: 0, right: 0, bottom: 0, left: 0 }
}
}));
};
yAxis = buildYAxis();
}
describe('Vislib yAxis Class Test Suite', function () {
@ -346,5 +351,34 @@ define(function (require) {
expect(yAxis.tickScale(20)).to.be(0);
});
});
describe('#tickFormat()', function () {
var formatter = function () {};
it('returns a basic number formatter by default', function () {
var yAxis = buildYAxis();
expect(yAxis.tickFormat()).to.not.be(formatter);
expect(yAxis.tickFormat()(1)).to.be('1');
});
it('returns the yAxisFormatter when passed', function () {
var yAxis = buildYAxis({
yAxisFormatter: formatter
});
expect(yAxis.tickFormat()).to.be(formatter);
});
it('returns a percentage formatter when the vis is in percentage mode', function () {
var yAxis = buildYAxis({
yAxisFormatter: formatter,
_attr: {
mode: 'percentage'
}
});
expect(yAxis.tickFormat()).to.not.be(formatter);
expect(yAxis.tickFormat()(1)).to.be('100%');
});
});
});
});