Skip to content

Commit 2ed5879

Browse files
committed
clean up maindrag pan test
1 parent 210da2e commit 2ed5879

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

test/jasmine/tests/cartesian_interact_test.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,49 +63,24 @@ describe('zoom box element', function() {
6363

6464
describe('main plot pan', function() {
6565

66-
var mock = require('@mocks/10.json');
6766
var gd, modeBar, relayoutCallback;
6867

69-
beforeEach(function(done) {
68+
beforeEach(function() {
7069
gd = createGraphDiv();
71-
72-
Plotly.plot(gd, mock.data, mock.layout).then(function() {
73-
74-
modeBar = gd._fullLayout._modeBar;
75-
relayoutCallback = jasmine.createSpy('relayoutCallback');
76-
77-
gd.on('plotly_relayout', relayoutCallback);
78-
})
79-
.catch(failTest)
80-
.then(done);
8170
});
8271

8372
afterEach(destroyGraphDiv);
8473

8574
it('should respond to pan interactions', function(done) {
86-
75+
var mock = require('@mocks/10.json');
8776
var precision = 5;
8877

89-
var buttonPan = selectButton(modeBar, 'pan2d');
90-
9178
var originalX = [-0.6225, 5.5];
9279
var originalY = [-1.6340975059013805, 7.166241526218911];
9380

9481
var newX = [-2.0255729166666665, 4.096927083333333];
9582
var newY = [-0.3769062155984817, 8.42343281652181];
9683

97-
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
98-
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
99-
100-
// Switch to pan mode
101-
expect(buttonPan.isActive()).toBe(false); // initially, zoom is active
102-
buttonPan.click();
103-
expect(buttonPan.isActive()).toBe(true); // switched on dragmode
104-
105-
// Switching mode must not change visible range
106-
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
107-
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
108-
10984
function _drag(x0, y0, x1, y1) {
11085
mouseEvent('mousedown', x0, y0);
11186
mouseEvent('mousemove', x1, y1);
@@ -143,9 +118,27 @@ describe('main plot pan', function() {
143118
_checkAxes(xr0, yr0);
144119
}
145120

146-
delay(MODEBAR_DELAY)()
147-
.then(function() {
121+
Plotly.plot(gd, mock.data, mock.layout).then(function() {
122+
modeBar = gd._fullLayout._modeBar;
123+
relayoutCallback = jasmine.createSpy('relayoutCallback');
124+
gd.on('plotly_relayout', relayoutCallback);
125+
126+
var buttonPan = selectButton(modeBar, 'pan2d');
127+
128+
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
129+
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
130+
131+
// Switch to pan mode
132+
expect(buttonPan.isActive()).toBe(false); // initially, zoom is active
133+
buttonPan.click();
134+
expect(buttonPan.isActive()).toBe(true); // switched on dragmode
148135

136+
// Switching mode must not change visible range
137+
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
138+
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
139+
})
140+
.then(delay(MODEBAR_DELAY))
141+
.then(function() {
149142
expect(relayoutCallback).toHaveBeenCalledTimes(1);
150143
relayoutCallback.calls.reset();
151144
_runDrag(originalX, newX, originalY, newY);

0 commit comments

Comments
 (0)