Commit 230f018c by ilgizar

Added validation of input parameters.

parent bd3d17ab
...@@ -6,6 +6,10 @@ import _ from 'lodash'; ...@@ -6,6 +6,10 @@ import _ from 'lodash';
* @param align Y level * @param align Y level
*/ */
export function alignYLevel(yaxis, alignLevel) { export function alignYLevel(yaxis, alignLevel) {
if (isNaN(alignLevel) || !checkCorrectAxis(yaxis)) {
return;
}
var [yLeft, yRight] = yaxis; var [yLeft, yRight] = yaxis;
moveLevelToZero(yLeft, yRight, alignLevel); moveLevelToZero(yLeft, yRight, alignLevel);
...@@ -92,6 +96,14 @@ function restoreLevelFromZero(yLeft, yRight, alignLevel) { ...@@ -92,6 +96,14 @@ function restoreLevelFromZero(yLeft, yRight, alignLevel) {
} }
} }
function checkCorrectAxis(axis) {
return axis.length === 2 && checkCorrectAxes(axis[0]) && checkCorrectAxes(axis[1]);
}
function checkCorrectAxes(axes) {
return 'min' in axes && 'max' in axes;
}
function checkOneSide(yLeft, yRight) { function checkOneSide(yLeft, yRight) {
// on the one hand with respect to zero // on the one hand with respect to zero
return (yLeft.min >= 0 && yRight.min >= 0) || (yLeft.max <= 0 && yRight.max <= 0); return (yLeft.min >= 0 && yRight.min >= 0) || (yLeft.max <= 0 && yRight.max <= 0);
......
...@@ -197,4 +197,15 @@ describe('Graph Y axes aligner', function() { ...@@ -197,4 +197,15 @@ describe('Graph Y axes aligner', function() {
expect(yaxes).toMatchObject(expected); expect(yaxes).toMatchObject(expected);
}); });
}); });
describe('on level not number value', () => {
it('Should ignore without errors', () => {
alignY = 'q';
yaxes = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
expected = [{ min: 5, max: 10 }, { min: 2, max: 4 }];
alignYLevel(yaxes, alignY);
expect(yaxes).toMatchObject(expected);
});
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment