Skip to content

Commit ae9cba8

Browse files
committed
clean up scattermapbox event data tests
1 parent 550d7f6 commit ae9cba8

File tree

1 file changed

+24
-56
lines changed

1 file changed

+24
-56
lines changed

test/jasmine/tests/scattermapbox_test.js

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -632,59 +632,32 @@ describe('@noCI scattermapbox hover', function() {
632632

633633
describe('@noCI Test plotly events on a scattermapbox plot:', function() {
634634
var mock = require('@mocks/mapbox_0.json');
635+
var pointPos = [440, 290];
636+
var nearPos = [460, 290];
637+
var blankPos = [10, 10];
638+
var mockCopy;
639+
var gd;
635640

636-
var mockCopy, gd;
637-
638-
var blankPos = [10, 10],
639-
pointPos,
640-
nearPos;
641-
642-
function getPointData(gd) {
643-
var cd = gd.calcdata,
644-
mapbox = gd._fullLayout.mapbox._subplot;
645-
646-
return {
647-
index: false,
648-
distance: 20,
649-
cd: cd[0],
650-
trace: cd[0][0].trace,
651-
xa: mapbox.xaxis,
652-
ya: mapbox.yaxis
653-
};
654-
}
655-
656-
beforeAll(function(done) {
641+
beforeAll(function() {
657642
Plotly.setPlotConfig({
658643
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
659644
});
660-
661-
gd = createGraphDiv();
662-
mockCopy = Lib.extendDeep({}, mock);
663-
664-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
665-
var bb = gd._fullLayout.mapbox._subplot.div.getBoundingClientRect(),
666-
xval = 10,
667-
yval = 10,
668-
point = ScatterMapbox.hoverPoints(getPointData(gd), xval, yval)[0];
669-
pointPos = [Math.floor(bb.left + (point.x0 + point.x1) / 2),
670-
Math.floor(bb.top + (point.y0 + point.y1) / 2)];
671-
nearPos = [pointPos[0] - 30, pointPos[1] - 30];
672-
}).then(destroyGraphDiv).then(done);
673645
});
674646

675-
beforeEach(function() {
647+
beforeEach(function(done) {
676648
gd = createGraphDiv();
677649
mockCopy = Lib.extendDeep({}, mock);
650+
mockCopy.layout.width = 800;
651+
mockCopy.layout.height = 500;
652+
Plotly.plot(gd, mockCopy).then(done);
678653
});
679654

680655
afterEach(destroyGraphDiv);
681656

682657
describe('click events', function() {
683658
var futureData;
684659

685-
beforeEach(function(done) {
686-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
687-
660+
beforeEach(function() {
688661
futureData = undefined;
689662
gd.on('plotly_click', function(data) {
690663
futureData = data;
@@ -720,16 +693,15 @@ describe('@noCI Test plotly events on a scattermapbox plot:', function() {
720693

721694
describe('modified click events', function() {
722695
var clickOpts = {
723-
altKey: true,
724-
ctrlKey: true,
725-
metaKey: true,
726-
shiftKey: true
727-
},
728-
futureData;
696+
altKey: true,
697+
ctrlKey: true,
698+
metaKey: true,
699+
shiftKey: true
700+
};
729701

730-
beforeEach(function(done) {
731-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
702+
var futureData;
732703

704+
beforeEach(function() {
733705
futureData = undefined;
734706
gd.on('plotly_click', function(data) {
735707
futureData = data;
@@ -774,9 +746,7 @@ describe('@noCI Test plotly events on a scattermapbox plot:', function() {
774746
describe('hover events', function() {
775747
var futureData;
776748

777-
beforeEach(function(done) {
778-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
779-
749+
beforeEach(function() {
780750
gd.on('plotly_hover', function(data) {
781751
futureData = data;
782752
});
@@ -786,8 +756,8 @@ describe('@noCI Test plotly events on a scattermapbox plot:', function() {
786756
mouseEvent('mousemove', blankPos[0], blankPos[1]);
787757
mouseEvent('mousemove', pointPos[0], pointPos[1]);
788758

789-
var pt = futureData.points[0],
790-
evt = futureData.event;
759+
var pt = futureData.points[0];
760+
var evt = futureData.event;
791761

792762
expect(Object.keys(pt)).toEqual([
793763
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', 'lon', 'lat'
@@ -808,18 +778,16 @@ describe('@noCI Test plotly events on a scattermapbox plot:', function() {
808778
describe('unhover events', function() {
809779
var futureData;
810780

811-
beforeEach(function(done) {
812-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
813-
781+
beforeEach(function() {
814782
gd.on('plotly_unhover', function(data) {
815783
futureData = data;
816784
});
817785
});
818786

819787
it('should contain the correct fields', function(done) {
820788
move(pointPos[0], pointPos[1], nearPos[0], nearPos[1], HOVERMINTIME + 10).then(function() {
821-
var pt = futureData.points[0],
822-
evt = futureData.event;
789+
var pt = futureData.points[0];
790+
var evt = futureData.event;
823791

824792
expect(Object.keys(pt)).toEqual([
825793
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex', 'lon', 'lat'

0 commit comments

Comments
 (0)