Skip to content

Commit 7f9bc9c

Browse files
committed
test: check main drag update on relayout
1 parent f0110ee commit 7f9bc9c

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

test/jasmine/tests/fx_test.js

+68-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
var Fx = require('@src/plots/cartesian/graph_interact');
1+
var Plotly = require('@lib/index');
22
var Plots = require('@src/plots/plots');
33

4+
var Fx = require('@src/plots/cartesian/graph_interact');
5+
6+
var d3 = require('d3');
7+
var createGraphDiv = require('../assets/create_graph_div');
8+
var destroyGraphDiv = require('../assets/destroy_graph_div');
49

510

611
describe('Fx defaults', function() {
@@ -65,4 +70,66 @@ describe('Fx defaults', function() {
6570
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
6671
});
6772
});
73+
74+
describe('relayout', function() {
75+
'use strict';
76+
77+
var gd;
78+
79+
beforeEach(function() {
80+
gd = createGraphDiv();
81+
});
82+
83+
afterEach(destroyGraphDiv);
84+
85+
it('should update main drag with correct', function(done) {
86+
87+
function assertMainDrag(cursor, isActive) {
88+
expect(d3.selectAll('rect.nsewdrag').size()).toEqual(1, 'number of nodes');
89+
var mainDrag = d3.select('rect.nsewdrag'),
90+
node = mainDrag.node();
91+
92+
expect(mainDrag.classed('cursor-' + cursor)).toBe(true, 'cursor ' + cursor);
93+
expect(mainDrag.style('pointer-events')).toEqual('all', 'pointer event');
94+
expect(!!node.onmousedown).toBe(isActive, 'mousedown handler');
95+
}
96+
97+
Plotly.plot(gd, [{
98+
y: [2, 1, 2]
99+
}]).then(function() {
100+
assertMainDrag('crosshair', true);
101+
102+
return Plotly.relayout(gd, 'dragmode', 'pan');
103+
}).then(function() {
104+
assertMainDrag('move', true);
105+
106+
return Plotly.relayout(gd, 'dragmode', 'drag');
107+
}).then(function() {
108+
assertMainDrag('crosshair', true);
109+
110+
return Plotly.relayout(gd, 'xaxis.fixedrange', true);
111+
}).then(function() {
112+
assertMainDrag('ns-resize', true);
113+
114+
return Plotly.relayout(gd, 'yaxis.fixedrange', true);
115+
}).then(function() {
116+
assertMainDrag('pointer', false);
117+
118+
return Plotly.relayout(gd, 'dragmode', 'drag');
119+
}).then(function() {
120+
assertMainDrag('pointer', false);
121+
122+
return Plotly.relayout(gd, 'dragmode', 'lasso');
123+
}).then(function() {
124+
assertMainDrag('pointer', true);
125+
126+
return Plotly.relayout(gd, 'dragmode', 'select');
127+
}).then(function() {
128+
assertMainDrag('pointer', true);
129+
130+
return Plotly.relayout(gd, 'xaxis.fixedrange', false);
131+
}).then(function() {
132+
assertMainDrag('ew-resize', true);
133+
}).then(done);
134+
});
68135
});

0 commit comments

Comments
 (0)