Skip to content

Commit 62145e9

Browse files
committed
fix test to check responsive charts only have one resize handler
1 parent d82447a commit 62145e9

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

test/jasmine/tests/config_test.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,24 @@ describe('config argument', function() {
572572
.catch(failTest);
573573
}
574574

575+
it('should only have one resize handler when plotted more than once', function(done) {
576+
var cntWindowResize = 0;
577+
window.addEventListener('resize', function() {cntWindowResize++;});
578+
spyOn(Plotly.Plots, 'resize').and.callThrough();
579+
580+
Plotly.plot(gd, data, {}, {responsive: true})
581+
.then(function() {return Plotly.restyle(gd, 'y[0]', data[0].y[0] + 2);})
582+
.then(function() {viewport.set(newWidth, newHeight);})
583+
.then(delay(200))
584+
// .then(function() {viewport.set(newWidth, 2 * newHeight);}).then(delay(200))
585+
.then(function() {
586+
expect(cntWindowResize).toBe(1);
587+
expect(Plotly.Plots.resize.calls.count()).toBe(1);
588+
})
589+
.catch(failTest)
590+
.then(done);
591+
});
592+
575593
it('should resize when the viewport width/height changes', function(done) {
576594
Plotly.plot(gd, data, {}, {responsive: true})
577595
.then(testResponsive)
@@ -592,23 +610,6 @@ describe('config argument', function() {
592610
.then(done);
593611
});
594612

595-
it('should only have one resize handler when plotted more than once', function(done) {
596-
var cntWindowResize = 0;
597-
window.addEventListener('resize', function() {cntWindowResize++;});
598-
spyOn(Plotly.Plots, 'resize').and.callThrough();
599-
600-
Plotly.plot(gd, data, {}, {responsive: true})
601-
.then(function() {return Plotly.restyle(gd, 'y[0]', data[0].y[0] + 2);})
602-
.then(function() {viewport.set(newWidth, newHeight);})
603-
.then(delay(200))
604-
.then(function() {
605-
expect(cntWindowResize).toBe(1);
606-
expect(Plotly.Plots.resize.calls.count()).toBe(4);
607-
})
608-
.catch(failTest)
609-
.then(done);
610-
});
611-
612613
it('should become responsive if configured as such via Plotly.react', function(done) {
613614
Plotly.plot(gd, data, {}, {responsive: false})
614615
.then(function() {return Plotly.react(gd, data, {}, {responsive: true});})

0 commit comments

Comments
 (0)