Skip to content

Commit

Permalink
[vislib/yAxis] added tests for the tickLabel method
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Alger committed May 1, 2015
1 parent 0a75961 commit ff3e5bc
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions test/unit/specs/vislib/lib/y_axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(function (require) {
var YAxis;
var Data;
var el;
var buildYAxis;
var yAxis;
var yAxisDiv;

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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%');
});
});
});
});

0 comments on commit ff3e5bc

Please sign in to comment.