Skip to content

Commit 531aea8

Browse files
committed
flatten tickformatstops tests
1 parent 86777f7 commit 531aea8

File tree

1 file changed

+71
-86
lines changed

1 file changed

+71
-86
lines changed

test/jasmine/tests/tickformatstops_test.js

Lines changed: 71 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var d3 = require('d3');
66
var createGraphDiv = require('../assets/create_graph_div');
77
var destroyGraphDiv = require('../assets/destroy_graph_div');
88
var selectButton = require('../assets/modebar_button');
9+
var fail = require('../assets/fail_test');
910

1011
var mock = require('@mocks/tickformatstops.json');
1112

@@ -22,6 +23,8 @@ function getFormatter(format) {
2223
}
2324

2425
describe('Test Axes.getTickformat', function() {
26+
'use strict';
27+
2528
it('get proper tickformatstop for linear axis', function() {
2629
var lineartickformatstops = [
2730
{
@@ -197,6 +200,7 @@ describe('Test Axes.getTickformat', function() {
197200
});
198201

199202
describe('Test tickformatstops:', function() {
203+
'use strict';
200204

201205
var mockCopy, gd;
202206

@@ -207,101 +211,82 @@ describe('Test tickformatstops:', function() {
207211

208212
afterEach(destroyGraphDiv);
209213

210-
describe('Zooming-in until milliseconds zoom level', function() {
211-
it('Zoom in', function(done) {
212-
var promise = Plotly.plot(gd, mockCopy.data, mockCopy.layout);
213-
214-
var testCount = 0;
215-
216-
var zoomIn = function() {
217-
promise = promise.then(function() {
218-
getZoomInButton(gd).click();
219-
var xLabels = Axes.calcTicks(gd._fullLayout.xaxis);
220-
var formatter = getFormatter(Axes.getTickFormat(gd._fullLayout.xaxis));
221-
var expectedLabels = xLabels.map(function(d) {return formatter(new Date(d.x));});
222-
var actualLabels = xLabels.map(function(d) {return d.text;});
223-
expect(expectedLabels).toEqual(actualLabels);
224-
testCount++;
225-
226-
if(gd._fullLayout.xaxis.dtick > 1) {
227-
zoomIn();
228-
} else {
229-
// make sure we tested as many levels as we thought we would
230-
expect(testCount).toBe(32);
231-
done();
232-
}
233-
});
234-
};
235-
zoomIn();
236-
});
214+
it('handles zooming-in until milliseconds zoom level', function(done) {
215+
var promise = Plotly.plot(gd, mockCopy.data, mockCopy.layout);
216+
217+
var testCount = 0;
218+
219+
var zoomIn = function() {
220+
promise = promise.then(function() {
221+
getZoomInButton(gd).click();
222+
var xLabels = Axes.calcTicks(gd._fullLayout.xaxis);
223+
var formatter = getFormatter(Axes.getTickFormat(gd._fullLayout.xaxis));
224+
var expectedLabels = xLabels.map(function(d) {return formatter(new Date(d.x));});
225+
var actualLabels = xLabels.map(function(d) {return d.text;});
226+
expect(expectedLabels).toEqual(actualLabels);
227+
testCount++;
228+
229+
if(gd._fullLayout.xaxis.dtick > 1) {
230+
zoomIn();
231+
} else {
232+
// make sure we tested as many levels as we thought we would
233+
expect(testCount).toBe(32);
234+
done();
235+
}
236+
});
237+
};
238+
zoomIn();
237239
});
238240

239-
describe('Zooming-out until years zoom level', function() {
240-
it('Zoom out', function(done) {
241-
var promise = Plotly.plot(gd, mockCopy.data, mockCopy.layout);
242-
243-
var testCount = 0;
244-
245-
var zoomOut = function() {
246-
promise = promise.then(function() {
247-
getZoomOutButton(gd).click();
248-
var xLabels = Axes.calcTicks(gd._fullLayout.xaxis);
249-
var formatter = getFormatter(Axes.getTickFormat(gd._fullLayout.xaxis));
250-
var expectedLabels = xLabels.map(function(d) {return formatter(new Date(d.x));});
251-
var actualLabels = xLabels.map(function(d) {return d.text;});
252-
expect(expectedLabels).toEqual(actualLabels);
253-
testCount++;
254-
255-
if(typeof gd._fullLayout.xaxis.dtick === 'number' ||
256-
typeof gd._fullLayout.xaxis.dtick === 'string' && parseInt(gd._fullLayout.xaxis.dtick.replace(/\D/g, '')) < 48) {
257-
zoomOut();
258-
} else {
259-
// make sure we tested as many levels as we thought we would
260-
expect(testCount).toBe(5);
261-
done();
262-
}
263-
});
264-
};
265-
zoomOut();
266-
});
241+
it('handles zooming-out until years zoom level', function(done) {
242+
var promise = Plotly.plot(gd, mockCopy.data, mockCopy.layout);
243+
244+
var testCount = 0;
245+
246+
var zoomOut = function() {
247+
promise = promise.then(function() {
248+
getZoomOutButton(gd).click();
249+
var xLabels = Axes.calcTicks(gd._fullLayout.xaxis);
250+
var formatter = getFormatter(Axes.getTickFormat(gd._fullLayout.xaxis));
251+
var expectedLabels = xLabels.map(function(d) {return formatter(new Date(d.x));});
252+
var actualLabels = xLabels.map(function(d) {return d.text;});
253+
expect(expectedLabels).toEqual(actualLabels);
254+
testCount++;
255+
256+
if(typeof gd._fullLayout.xaxis.dtick === 'number' ||
257+
typeof gd._fullLayout.xaxis.dtick === 'string' && parseInt(gd._fullLayout.xaxis.dtick.replace(/\D/g, '')) < 48) {
258+
zoomOut();
259+
} else {
260+
// make sure we tested as many levels as we thought we would
261+
expect(testCount).toBe(5);
262+
done();
263+
}
264+
});
265+
};
266+
zoomOut();
267267
});
268268

269-
describe('Check tickformatstops for hover', function() {
270-
'use strict';
271-
269+
it('responds to hover', function(done) {
272270
var evt = { xpx: 270, ypx: 10 };
273271

274-
afterEach(destroyGraphDiv);
272+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
273+
Fx.hover(gd, evt, 'xy');
275274

276-
beforeEach(function() {
277-
gd = createGraphDiv();
278-
mockCopy = Lib.extendDeep({}, mock);
279-
});
275+
var hoverTrace = gd._hoverdata[0];
276+
var formatter = getFormatter(Axes.getTickFormat(gd._fullLayout.xaxis));
280277

281-
describe('hover info', function() {
278+
expect(hoverTrace.curveNumber).toEqual(0);
279+
expect(hoverTrace.pointNumber).toEqual(3);
280+
expect(hoverTrace.x).toEqual('2005-04-01');
281+
expect(hoverTrace.y).toEqual(0);
282282

283-
it('responds to hover', function(done) {
284-
var mockCopy = Lib.extendDeep({}, mock);
285-
286-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
287-
Fx.hover(gd, evt, 'xy');
288-
289-
var hoverTrace = gd._hoverdata[0];
290-
var formatter = getFormatter(Axes.getTickFormat(gd._fullLayout.xaxis));
291-
292-
expect(hoverTrace.curveNumber).toEqual(0);
293-
expect(hoverTrace.pointNumber).toEqual(3);
294-
expect(hoverTrace.x).toEqual('2005-04-01');
295-
expect(hoverTrace.y).toEqual(0);
296-
297-
expect(d3.selectAll('g.axistext').size()).toEqual(1);
298-
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
299-
expect(d3.selectAll('g.axistext').select('text').html()).toEqual(formatter(new Date(hoverTrace.x)));
300-
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('0');
301-
done();
302-
});
303-
});
304-
});
283+
expect(d3.selectAll('g.axistext').size()).toEqual(1);
284+
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
285+
expect(d3.selectAll('g.axistext').select('text').html()).toEqual(formatter(new Date(hoverTrace.x)));
286+
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('0');
287+
})
288+
.catch(fail)
289+
.then(done);
305290
});
306291

307292
});

0 commit comments

Comments
 (0)