Skip to content

Commit e0761e5

Browse files
committed
merge gl_plot_interact_basic_test.js into gl3d_plot_interact_test.js
1 parent 9aa0357 commit e0761e5

File tree

2 files changed

+71
-81
lines changed

2 files changed

+71
-81
lines changed

test/jasmine/tests/gl3d_plot_interact_test.js

+71
Original file line numberDiff line numberDiff line change
@@ -1562,3 +1562,74 @@ describe('Test removal of gl contexts', function() {
15621562
.then(done);
15631563
});
15641564
});
1565+
1566+
describe('Test gl3d drag events', function() {
1567+
var gd;
1568+
1569+
beforeEach(function() {
1570+
gd = createGraphDiv();
1571+
});
1572+
1573+
afterEach(function() {
1574+
Plotly.purge(gd);
1575+
destroyGraphDiv();
1576+
});
1577+
1578+
// Expected shape of projection-related data
1579+
var cameraStructure = {
1580+
projection: {type: jasmine.any(String)},
1581+
up: {x: jasmine.any(Number), y: jasmine.any(Number), z: jasmine.any(Number)},
1582+
center: {x: jasmine.any(Number), y: jasmine.any(Number), z: jasmine.any(Number)},
1583+
eye: {x: jasmine.any(Number), y: jasmine.any(Number), z: jasmine.any(Number)}
1584+
};
1585+
1586+
function makePlot(gd, mock) {
1587+
return Plotly.plot(gd, mock.data, mock.layout);
1588+
}
1589+
1590+
function addEventCallback(graphDiv) {
1591+
var relayoutCallback = jasmine.createSpy('relayoutCallback');
1592+
graphDiv.on('plotly_relayout', relayoutCallback);
1593+
return {graphDiv: graphDiv, relayoutCallback: relayoutCallback};
1594+
}
1595+
1596+
function verifyInteractionEffects(tuple) {
1597+
// One 'drag': simulating fairly thoroughly as the mouseup event is also needed here
1598+
mouseEvent('mousemove', 400, 200);
1599+
mouseEvent('mousedown', 400, 200);
1600+
mouseEvent('mousemove', 320, 320, {buttons: 1});
1601+
mouseEvent('mouseup', 320, 320);
1602+
1603+
// Check event emission count
1604+
expect(tuple.relayoutCallback).toHaveBeenCalledTimes(1);
1605+
1606+
// Check structure of event callback value contents
1607+
expect(tuple.relayoutCallback).toHaveBeenCalledWith(jasmine.objectContaining({'scene.camera': cameraStructure}));
1608+
1609+
// Check camera contents on the DIV layout
1610+
var divCamera = tuple.graphDiv.layout.scene.camera;
1611+
1612+
expect(divCamera).toEqual(cameraStructure);
1613+
1614+
return tuple.graphDiv;
1615+
}
1616+
1617+
function testEvents(plot) {
1618+
return plot.then(function(graphDiv) {
1619+
var tuple = addEventCallback(graphDiv);
1620+
verifyInteractionEffects(tuple);
1621+
});
1622+
}
1623+
1624+
it('@gl should respond to drag interactions with mock of unset camera', function(done) {
1625+
testEvents(makePlot(gd, require('@mocks/gl3d_scatter3d-connectgaps.json')))
1626+
.catch(failTest)
1627+
.then(done);
1628+
});
1629+
1630+
it('@gl should respond to drag interactions with mock of partially set camera', function(done) {
1631+
testEvents(makePlot(gd, require('@mocks/gl3d_errorbars_zx.json')))
1632+
.catch(failTest)
1633+
.then(done);
1634+
});
1635+
});

test/jasmine/tests/gl_plot_interact_basic_test.js

-81
This file was deleted.

0 commit comments

Comments
 (0)