Skip to content

Commit d8e09ee

Browse files
committed
Add test for handleTickDevaults
1 parent 34c6fef commit d8e09ee

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/jasmine/tests/axes_test.js

+76
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ var Color = require('@src/components/color');
77
var handleTickValueDefaults = require('@src/plots/cartesian/tick_value_defaults');
88
var Axes = PlotlyInternal.Axes;
99

10+
var createGraph = require('../assets/create_graph_div');
11+
var destroyGraph = require('../assets/destroy_graph_div');
12+
1013

1114
describe('Test axes', function() {
1215
'use strict';
@@ -252,6 +255,79 @@ describe('Test axes', function() {
252255
});
253256
});
254257

258+
describe('handleTickDefaults', function() {
259+
var data = [{ x: [1,2,3], y: [3,4,5] }],
260+
gd;
261+
262+
beforeEach(function() {
263+
gd = createGraph();
264+
});
265+
266+
afterEach(destroyGraph);
267+
268+
it('should set defaults on bad inputs', function() {
269+
var layout = {
270+
yaxis: {
271+
ticklen: 'invalid',
272+
tickwidth: 'invalid',
273+
tickcolor: 'invalid',
274+
showticklabels: 'invalid',
275+
tickfont: 'invalid',
276+
tickangle: 'invalid'
277+
}
278+
};
279+
280+
PlotlyInternal.plot(gd, data, layout);
281+
282+
var yaxis = gd._fullLayout.yaxis;
283+
expect(yaxis.ticklen).toBe(5);
284+
expect(yaxis.tickwidth).toBe(1);
285+
expect(yaxis.tickcolor).toBe('#444');
286+
expect(yaxis.ticks).toBe('outside');
287+
expect(yaxis.showticklabels).toBe(true);
288+
expect(yaxis.tickfont).toEqual({ family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444' });
289+
expect(yaxis.tickangle).toBe('auto');
290+
});
291+
292+
it('should use valid inputs', function() {
293+
var layout = {
294+
yaxis: {
295+
ticklen: 10,
296+
tickwidth: 5,
297+
tickcolor: '#F00',
298+
showticklabels: true,
299+
tickfont: { family: 'Garamond', size: 72, color: '#0FF' },
300+
tickangle: -20
301+
}
302+
};
303+
304+
PlotlyInternal.plot(gd, data, layout);
305+
306+
var yaxis = gd._fullLayout.yaxis;
307+
expect(yaxis.ticklen).toBe(10);
308+
expect(yaxis.tickwidth).toBe(5);
309+
expect(yaxis.tickcolor).toBe('#F00');
310+
expect(yaxis.ticks).toBe('outside');
311+
expect(yaxis.showticklabels).toBe(true);
312+
expect(yaxis.tickfont).toEqual({ family: 'Garamond', size: 72, color: '#0FF' });
313+
expect(yaxis.tickangle).toBe(-20);
314+
});
315+
316+
it('should conditionally coerce based on showticklabels', function() {
317+
var layout = {
318+
yaxis: {
319+
showticklabels: false,
320+
tickangle: -90
321+
}
322+
};
323+
324+
PlotlyInternal.plot(gd, data, layout);
325+
326+
var yaxis = gd._fullLayout.yaxis;
327+
expect(yaxis.tickangle).toBeUndefined();
328+
});
329+
});
330+
255331
describe('handleTickValueDefaults', function() {
256332
function mockSupplyDefaults(axIn, axOut, axType) {
257333
function coerce(attr, dflt) {

0 commit comments

Comments
 (0)