Skip to content

Commit 19300f9

Browse files
committed
improve layout transition test assertions
1 parent c708190 commit 19300f9

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

test/jasmine/tests/animate_test.js

+36-5
Original file line numberDiff line numberDiff line change
@@ -840,19 +840,41 @@ describe('animating scatter traces', function() {
840840
});
841841

842842
it('should animate axis ranges using the less number of steps', function(done) {
843+
// sanity-check that scatter points and bars are still there
844+
function _assertNodeCnt() {
845+
var gd3 = d3.select(gd);
846+
expect(gd3.select('.scatterlayer').selectAll('.point').size())
847+
.toBe(3, '# of pts on graph');
848+
expect(gd3.select('.barlayer').selectAll('.point').size())
849+
.toBe(3, '# of bars on graph');
850+
}
851+
852+
// assert what Cartesian.transitionAxes does
853+
function getSubplotTranslate() {
854+
var sp = d3.select(gd).select('.subplot.xy > .plot');
855+
return sp.attr('transform')
856+
.split('translate(')[1].split(')')[0]
857+
.split(',')
858+
.map(Number);
859+
}
860+
843861
Plotly.plot(gd, [{
844862
y: [1, 2, 1]
845863
}, {
846864
type: 'bar',
847865
y: [2, 1, 2]
848866
}])
849867
.then(function() {
868+
var t = getSubplotTranslate();
869+
expect(t[0]).toBe(80, 'subplot translate[0]');
870+
expect(t[1]).toBe(100, 'subplot translate[1]');
871+
850872
spyOn(gd._fullData[0]._module.basePlotModule, 'transitionAxes').and.callThrough();
851873
spyOn(gd._fullData[0]._module, 'plot').and.callThrough();
852874
spyOn(gd._fullData[1]._module, 'plot').and.callThrough();
853875
spyOn(Registry, 'call').and.callThrough();
854876

855-
return Plotly.animate('graph', {
877+
var promise = Plotly.animate('graph', {
856878
layout: {
857879
xaxis: {range: [0.45, 0.55]},
858880
yaxis: {range: [0.45, 0.55]}
@@ -861,12 +883,21 @@ describe('animating scatter traces', function() {
861883
transition: {duration: 500},
862884
frame: {redraw: false}
863885
});
886+
887+
setTimeout(function() {
888+
_assertNodeCnt();
889+
var t = getSubplotTranslate();
890+
expect(t[0]).toBeLessThan(80, 'subplot translate[0]');
891+
expect(t[1]).toBeLessThan(100, 'subplot translate[1]');
892+
}, 100);
893+
894+
return promise;
864895
})
865896
.then(function() {
866-
// sanity-check that scatter points and bars are still there
867-
var gd3 = d3.select(gd);
868-
expect(gd3.select('.scatterlayer').selectAll('.point').size()).toBe(3, '# of pts on graph');
869-
expect(gd3.select('.barlayer').selectAll('.point').size()).toBe(3, '# of bars on graph');
897+
_assertNodeCnt();
898+
var t = getSubplotTranslate();
899+
expect(t[0]).toBe(80, 'subplot translate[0]');
900+
expect(t[1]).toBe(100, 'subplot translate[1]');
870901

871902
// the only redraw should occur during Cartesian.transitionAxes,
872903
// where Registry.call('relayout') is called leading to a _module.plot call

0 commit comments

Comments
 (0)