Skip to content

Commit

Permalink
add jasmine tests to guard against negative sizes during calc step
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Jul 23, 2019
1 parent e584f80 commit 39b9840
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@ describe('Bar.calc', function() {
assertPointField(cd, 'x', [[1, NaN, NaN, 15]]);
assertPointField(cd, 'y', [[1, 2, 10, 30]]);
});

it('should guard against negative marker.line.width values', function() {
var gd = mockBarPlot([{
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
}
},
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
});
});

describe('Bar.crossTraceCalc (formerly known as setPositions)', function() {
Expand Down
28 changes: 28 additions & 0 deletions test/jasmine/tests/funnel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,34 @@ describe('Funnel.calc', function() {
assertPointField(cd, 'y', [[1, NaN, NaN, 15]]);
assertPointField(cd, 'x', [[0.5, 1, 5, 15]]);
});

it('should guard against negative marker.line.width values', function() {
var gd = mockFunnelPlot([{
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
}
},
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
});

it('should guard against negative marker.line.width values', function() {
var gd = mockFunnelPlot([{
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
}
},
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
});
});

describe('Funnel.crossTraceCalc', function() {
Expand Down
52 changes: 52 additions & 0 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var Scatter = require('@src/traces/scatter');
var makeBubbleSizeFn = require('@src/traces/scatter/make_bubble_size_func');
var linePoints = require('@src/traces/scatter/line_points');
var Lib = require('@src/lib');
var Plots = require('@src/plots/plots');

var Plotly = require('@lib/index');
var createGraphDiv = require('../assets/create_graph_div');
Expand All @@ -18,6 +19,8 @@ var assertMultiNodeOrder = customAssertions.assertMultiNodeOrder;
var checkEventData = require('../assets/check_event_data');
var constants = require('@src/traces/scatter/constants');

var supplyAllDefaults = require('../assets/supply_defaults');

var getOpacity = function(node) { return Number(node.style.opacity); };
var getFillOpacity = function(node) { return Number(node.style['fill-opacity']); };
var getColor = function(node) { return node.style.fill; };
Expand Down Expand Up @@ -273,6 +276,55 @@ describe('Test scatter', function() {
});
});

describe('calc', function() {
function assertPointField(calcData, prop, expectation) {
var values = [];

calcData.forEach(function(calcTrace) {
var vals = calcTrace.map(function(pt) {
return Lib.nestedProperty(pt, prop).get();
});

values.push(vals);
});

expect(values).toBeCloseTo2DArray(expectation, undefined, '(field ' + prop + ')');
}

it('should guard against negative size values', function() {
var gd = {
data: [{
type: 'scatter',
mode: 'markers+text',
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
},
opacity: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}],
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
},
textfont: {
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
},
text: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}],
layout: {},
calcdata: [],
_context: {locale: 'en', locales: {}}
};

supplyAllDefaults(gd);
Plots.doCalcdata(gd);

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'mo', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'ms', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'ts', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
});
});

describe('isBubble', function() {
it('should return true when marker.size is an Array', function() {
var trace = {
Expand Down

0 comments on commit 39b9840

Please sign in to comment.