Skip to content

Commit 00a7054

Browse files
committed
Add tests to cover staticPlot for legend and range slider
These Jasmine tests should help ensure that neither the legend nor range slider can be interacted with if `staticPlot` is set. Fixes #5177
1 parent 4c1cacb commit 00a7054

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

Diff for: test/jasmine/tests/legend_test.js

+41
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,47 @@ describe('legend interaction', function() {
12891289
});
12901290
});
12911291

1292+
describe('staticPlot', function() {
1293+
var gd;
1294+
1295+
beforeEach(function() {
1296+
gd = createGraphDiv();
1297+
});
1298+
1299+
afterEach(destroyGraphDiv);
1300+
1301+
function toggleTrace() {
1302+
var toggle = d3.select('.legendtoggle').node();
1303+
expect(toggle).not.toEqual(null);
1304+
1305+
toggle.dispatchEvent(new MouseEvent('mousedown'));
1306+
toggle.dispatchEvent(new MouseEvent('mouseup'));
1307+
1308+
// Delay needs to be long enough for Plotly to react
1309+
return delay(300)();
1310+
}
1311+
1312+
function assertToggled(toggled) {
1313+
return function() {
1314+
var container = d3.select('g.traces').node();
1315+
expect(container).not.toEqual(null);
1316+
expect(container.style.opacity).toBe(toggled ? '0.5' : '1');
1317+
};
1318+
}
1319+
1320+
it('should prevent toggling if set', function(done) {
1321+
var data = [{ x: [0, 1], y: [0, 1], type: 'scatter' }];
1322+
var layout = { showlegend: true };
1323+
var config = { staticPlot: true };
1324+
1325+
Plotly.newPlot(gd, data, layout, config)
1326+
.then(toggleTrace)
1327+
.then(assertToggled(false))
1328+
.catch(failTest)
1329+
.then(done);
1330+
});
1331+
});
1332+
12921333
describe('visible toggle', function() {
12931334
var gd;
12941335

Diff for: test/jasmine/tests/range_slider_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,40 @@ describe('Visible rangesliders', function() {
201201
.then(done);
202202
});
203203

204+
fit('should not react to any interactions when staticPlot is set', function(done) {
205+
var mockCopy = Lib.extendDeep({}, mock);
206+
var moveDelta = 50;
207+
Plotly.newPlot(gd, mockCopy.data, mockCopy.layout, { staticPlot: true })
208+
.then(function() {
209+
// Try move minimum handle
210+
var minHandle = d3.select('.' + constants.grabberMinClassName).node();
211+
expect(minHandle).not.toEqual(null);
212+
var minHandleRect = minHandle.getBoundingClientRect();
213+
var x = minHandleRect.x + minHandleRect.width / 2;
214+
var y = minHandleRect.y + minHandleRect.height / 2;
215+
return slide(x, y, x + moveDelta, y);
216+
})
217+
.then(function() {
218+
// Try move maximum handle
219+
var maxHandle = d3.select('.' + constants.grabberMaxClassName).node();
220+
expect(maxHandle).not.toEqual(null);
221+
var maxHandleRect = maxHandle.getBoundingClientRect();
222+
var x = maxHandleRect.x + maxHandleRect.width / 2;
223+
var y = maxHandleRect.y + maxHandleRect.height / 2;
224+
return slide(x, y, x - moveDelta, y);
225+
})
226+
.then(function() {
227+
// Slidebox should not exist
228+
var slidebox = d3.select('.' + constants.slideBoxClassName).node();
229+
expect(slidebox).toEqual(null);
230+
})
231+
.then(function() {
232+
expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49]);
233+
})
234+
.catch(failTest)
235+
.then(done);
236+
});
237+
204238
it('should update correctly when moving slider on an axis with rangebreaks', function(done) {
205239
var start = 250;
206240
var end = 300;

0 commit comments

Comments
 (0)