Skip to content

Commit 095ce0c

Browse files
committed
Set tick test to use fullLayout, not mock x
1 parent 41ae65d commit 095ce0c

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

test/jasmine/tests/axes_test.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8216,7 +8216,9 @@ describe('shift tests', function() {
82168216
});
82178217
});
82188218
});
8219-
describe('test tickmode calculator', function() {
8219+
fdescribe('test tickmode calculator', function() {
8220+
var gd;
8221+
82208222
beforeEach(function() {
82218223
gd = createGraphDiv();
82228224
});
@@ -8229,20 +8231,31 @@ describe('test tickmode calculator', function() {
82298231
// Number of ticks will be random
82308232
var n = Math.floor(Math.random() * 99) + 1;
82318233
tickVals = [];
8232-
for(let i = 0; i <= n; i++) tickVals.push(i);
8234+
for(let i = 0; i <= n; i++) {
8235+
tickVals.push(i);
8236+
}
82338237
standardConfig['tickvals'] = tickVals;
82348238
standardConfig['ticktext'] = tickVals;
82358239
return standardConfig;
82368240
}
82378241
var ticksOff = {tickmode:"array", ticks: '', tickvals:[], ticktext:[], ticklen: 0, showticklabels: false};
8238-
// the goal is target the arrayTicks() function, the subject of PR: https://github.com/plotly/plotly.js/pull/6829
8239-
// we test xMajor and xMinor in on/on on/off off/on and off/off
8240-
// since we can't unit test functions that are not exported, we shim functions we don't care about instead and
8241-
// test the nearest exported functions (calcTicks)
8242+
8243+
function _assert(expLength) {
8244+
var ax = gd._fullLayout.xaxis;
8245+
8246+
// all positions
8247+
var positions =
8248+
ax._vals
8249+
.filter(function(d) { return d; })
8250+
.map(function(d) { return d.x; });
8251+
8252+
expect(positions.length).toEqual(expLength);
8253+
}
8254+
82428255
describe('arrayTicks', function() {
82438256
for(let i = 0; i < 4; i++) {
82448257
(function(i) {
8245-
it('should return the specified correct number of major ticks and minor ticks', function() {
8258+
it('should return the specified correct number of major ticks and minor ticks', function(done) {
82468259
const BOTH = 0;
82478260
const MAJOR = 1;
82488261
const MINOR = 2;
@@ -8259,20 +8272,29 @@ describe('test tickmode calculator', function() {
82598272
} else if(i == NEITHER) {
82608273
// Do nothing, all ticks off
82618274
}
8262-
xaxis = {
8263-
r2l: Lib.cleanNumber,
8264-
d2l: Lib.cleanNumber,
8265-
_separators: ',',
8266-
range: [0, 1000],
8267-
...xMajorConfig,
8268-
minor: {
8269-
...xMinorConfig,
8270-
},
8271-
};
8272-
Axes.prepMinorTicks = function() { return }; // Not part of this test
8273-
Axes.prepTicks = function() { return }; // Not part of this test
8274-
ticksOut = Axes.calcTicks(xaxis);
8275-
expect(ticksOut.length).toEqual(xMajorConfig.tickvals.length + xMinorConfig.tickvals.length);
8275+
Plotly.newPlot(gd, {
8276+
data: [{
8277+
x: [0, 1],
8278+
y: [0, 1]
8279+
}],
8280+
layout: {
8281+
width: 400,
8282+
height: 400,
8283+
margin: {
8284+
t: 40,
8285+
b: 40,
8286+
l: 40,
8287+
r: 40
8288+
},
8289+
xaxis: {
8290+
range: [0, 1000],
8291+
...xMajorConfig,
8292+
minor: xMinorConfig,
8293+
},
8294+
}
8295+
}).then(function() {
8296+
_assert(xMajorConfig.tickvals.length + xMinorConfig.tickvals.length);
8297+
}).then(done, done.fail);
82768298
});
82778299
})(i);
82788300
}

0 commit comments

Comments
 (0)