Add tests for range calc

pull/765/head
Andrew Watkins 2017-01-12 13:44:53 -08:00
parent c2850bb670
commit 996c1d077b
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,43 @@
import getRange from 'shared/parsing/getRangeForDygraph';
describe('getRangeForDygraphSpec', () => {
it('gets the range for one timeSeries', () => {
const timeSeries = [[new Date(1000), 1], [new Date(2000), 2], [new Date(3000), 3]];
const actual = getRange(timeSeries);
const expected = [1, 3];
expect(actual).to.deep.equal(expected);
});
it('does not get range when a range is provided', () => {
const timeSeries = [[new Date(1000), 1], [new Date(2000), 2], [new Date(3000), 3]];
const providedRange = [0, 4];
const actual = getRange(timeSeries, providedRange);
expect(actual).to.deep.equal(providedRange);
});
it('gets the range for multiple timeSeries', () => {
const timeSeries = [
[new Date(1000), null, 1],
[new Date(1000), 100, 1],
[new Date(2000), null, 2],
[new Date(3000), 200, 3],
];
const actual = getRange(timeSeries);
const expected = [1, 200];
expect(actual).to.deep.equal(expected);
});
it('returns a null array of two elements when min and max are equal', () => {
const timeSeries = [[new Date(1000), 1], [new Date(2000), 1], [new Date(3000), 1]];
const actual = getRange(timeSeries);
const expected = [null, null];
expect(actual).to.deep.equal(expected);
});
});

View File

@ -26,7 +26,7 @@ export default function getRange(timeSeries, override, value = null, rangeValue
[null, pad(rangeValue, "top")],
];
const range = points.reduce(([min, max], series) => {
const range = points.reduce(([min, max] = [], series) => {
for (let i = 1; i < series.length; i++) {
const val = series[i];