Skip to content

Commit

Permalink
Add tests for yaxis(), fix 1st yaxis losing settings. Closes elastic#97
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed May 10, 2016
1 parent 4ddf80d commit 1336024
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timelion",
"version": "5.0.0-0.1.307",
"version": "5.0.0-0.1.308",
"dependencies": {
"body-parser": "^1.12.0",
"boom": "^2.8.0",
Expand Down
1 change: 0 additions & 1 deletion public/directives/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ app.directive('chart', function ($compile, $rootScope, timefilter, $timeout, Pri
'<span class="ngLegendValueNumber"></span></span>';
}
},
yaxes: [ {}, { position: 'right' } ],
colors: ['#01A4A4', '#C66', '#D0D102', '#616161', '#00A1CB', '#32742C', '#F18D05', '#113F8C', '#61AE24', '#D70060']
};

Expand Down
70 changes: 70 additions & 0 deletions series_functions/__test__/yaxis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const filename = require('path').basename(__filename);
const fn = require(`../${filename}`);
const Promise = require('bluebird');

const _ = require('lodash');
const expect = require('chai').expect;
const invoke = require('./helpers/invoke_series_fn.js');

describe(filename, () => {

let seriesList;
beforeEach(() => {
seriesList = require('./fixtures/seriesList.js')();
});

it('creates the yaxes array', () => {
expect(seriesList._global).to.equal(undefined);
return invoke(fn, [seriesList, 2]).then((r) => {
expect(r.output.list[0]._global.yaxes).to.be.an('array');
});
});

it('puts odd numbers of the left, even on the right, by default', () => {
return Promise.all([
invoke(fn, [seriesList, 1]).then((r) => {
expect(r.output.list[0]._global.yaxes[0].position).to.equal('left');
}),
invoke(fn, [seriesList, 2]).then((r) => {
expect(r.output.list[0]._global.yaxes[1].position).to.equal('right');
}),
invoke(fn, [seriesList, 3]).then((r) => {
expect(r.output.list[0]._global.yaxes[2].position).to.equal('left');
}),
]);
});

it('it lets you override default positions', () => {
return Promise.all([
invoke(fn, [seriesList, 1, null, null, 'right']).then((r) => {
expect(r.output.list[0]._global.yaxes[0].position).to.equal('right');
}),
invoke(fn, [seriesList, 2, null, null, 'right']).then((r) => {
expect(r.output.list[0]._global.yaxes[1].position).to.equal('right');
}),
]);
});

it('sets the minimum (default: 0)', () => {
return Promise.all([
invoke(fn, [seriesList, 1, null]).then((r) => {
expect(r.output.list[0]._global.yaxes[0].min).to.equal(0);
}),
invoke(fn, [seriesList, 2, 10]).then((r) => {
expect(r.output.list[0]._global.yaxes[1].min).to.equal(10);
}),
]);
});

it('sets the max (default: no max)', () => {
return Promise.all([
invoke(fn, [seriesList, 1, null]).then((r) => {
expect(r.output.list[0]._global.yaxes[0].max).to.equal(undefined);
}),
invoke(fn, [seriesList, 2, null, 10]).then((r) => {
expect(r.output.list[0]._global.yaxes[1].max).to.equal(10);
}),
]);
});

});
2 changes: 1 addition & 1 deletion series_functions/yaxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = new Chainable('yaxis', {

var yaxes = eachSeries._global.yaxes = eachSeries._global.yaxes || [];
var myAxis = yaxes[yaxis - 1] = yaxes[yaxis - 1] || {};
myAxis.position = position;
myAxis.position = position || (yaxis % 2 ? 'left' : 'right');
myAxis.min = min == null ? 0 : min;
myAxis.max = max;

Expand Down

0 comments on commit 1336024

Please sign in to comment.