Skip to content

Commit dddb6e1

Browse files
committed
lock test graphDiv to position 0,0 and other jasmine reliability tweaks
fixes #666
1 parent ffd56c7 commit dddb6e1

8 files changed

+90
-74
lines changed

test/jasmine/assets/create_graph_div.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ module.exports = function createGraphDiv() {
44
var gd = document.createElement('div');
55
gd.id = 'graph';
66
document.body.appendChild(gd);
7+
8+
// force the graph to be at position 0,0 no matter what
9+
gd.style.position = 'fixed';
10+
gd.style.left = 0;
11+
gd.style.top = 0;
12+
713
return gd;
814
};

test/jasmine/tests/click_test.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe('Test click interactions:', function() {
1414

1515
var mockCopy, gd;
1616

17-
var pointPos = [351, 223],
18-
blankPos = [70, 363];
17+
var pointPos = [344, 216],
18+
blankPos = [63, 356];
1919

2020
var autoRangeX = [-3.011967491973726, 2.1561305597186564],
2121
autoRangeY = [-0.9910086301469277, 1.389382716298284];
@@ -46,8 +46,8 @@ describe('Test click interactions:', function() {
4646

4747
setTimeout(function() {
4848
click(x, y);
49-
resolve();
50-
}, DBLCLICKDELAY / 2);
49+
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
50+
}, DBLCLICKDELAY / 4);
5151
});
5252
}
5353

@@ -530,8 +530,8 @@ describe('Test click interactions:', function() {
530530

531531
return drag(100, 100, 200, 200, DBLCLICKDELAY / 2);
532532
}).then(function() {
533-
expect(gd.layout.xaxis.range).toBeCloseToArray([-2.70624901567643, -1.9783478816352495]);
534-
expect(gd.layout.yaxis.range).toBeCloseToArray([0.5007032802920716, 1.2941670624404753]);
533+
expect(gd.layout.xaxis.range).toBeCloseToArray([-2.6480169249531356,-1.920115790911955]);
534+
expect(gd.layout.yaxis.range).toBeCloseToArray([0.4372261777201992,1.2306899598686027]);
535535

536536
done();
537537
});
@@ -697,14 +697,14 @@ describe('Test click interactions:', function() {
697697
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
698698
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
699699

700-
drag(100, 100, 400, 300).then(function() {
701-
expect(gd.layout.xaxis.range).toBeCloseToArray([-2.70624901, -0.52254561]);
702-
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.29276050, 1.294167062]);
700+
drag(93, 93, 393, 293).then(function() {
701+
expect(gd.layout.xaxis.range).toBeCloseToArray([-2.69897000,-0.515266602]);
702+
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.30069513,1.2862324246]);
703703

704-
return drag(100, 100, 400, 300);
704+
return drag(93, 93, 393, 293);
705705
}).then(function() {
706-
expect(gd.layout.xaxis.range).toBeCloseToArray([-2.57707219, -1.65438061]);
707-
expect(gd.layout.yaxis.range).toBeCloseToArray([0.172738250, 1.230689959]);
706+
expect(gd.layout.xaxis.range).toBeCloseToArray([-2.56671754,-1.644025966]);
707+
expect(gd.layout.yaxis.range).toBeCloseToArray([0.159513853,1.2174655634]);
708708

709709
done();
710710
});
@@ -721,8 +721,8 @@ describe('Test click interactions:', function() {
721721

722722
var plot = gd._fullLayout._plots.xy.plot;
723723

724-
mouseEvent('mousemove', 400, 250);
725-
mouseEvent('scroll', 400, 250, { deltaX: 0, deltaY: -1000 });
724+
mouseEvent('mousemove', 393, 243);
725+
mouseEvent('scroll', 393, 243, { deltaX: 0, deltaY: -1000 });
726726

727727
var transform = plot.attr('transform');
728728

@@ -735,7 +735,7 @@ describe('Test click interactions:', function() {
735735
var translate = Lib.getTranslate(mockEl),
736736
scale = Lib.getScale(mockEl);
737737

738-
expect([translate.x, translate.y]).toBeCloseToArray([62.841, 99.483]);
738+
expect([translate.x, translate.y]).toBeCloseToArray([61.070, 97.712]);
739739
expect([scale.x, scale.y]).toBeCloseToArray([1.221, 1.221]);
740740
});
741741
});
@@ -751,11 +751,11 @@ describe('Test click interactions:', function() {
751751
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
752752
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
753753

754-
drag(100, 100, 400, 300).then(function() {
754+
drag(93, 93, 393, 293).then(function() {
755755
expect(gd.layout.xaxis.range).toBeCloseToArray([-5.19567089, -0.02757284]);
756756
expect(gd.layout.yaxis.range).toBeCloseToArray([0.595918934, 2.976310280]);
757757

758-
return drag(100, 100, 400, 300);
758+
return drag(93, 93, 393, 293);
759759
}).then(function() {
760760
expect(gd.layout.xaxis.range).toBeCloseToArray([-7.37937429, -2.21127624]);
761761
expect(gd.layout.yaxis.range).toBeCloseToArray([2.182846498, 4.563237844]);

test/jasmine/tests/hover_label_test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ describe('hover info', function() {
406406

407407
it('should display the correct format when ticklabels true', function() {
408408
Plotly.plot(this.gd, data, layout);
409-
mouseEvent('mousemove', 310, 220);
409+
mouseEvent('mousemove', 303, 213);
410410

411411
var hovers = d3.selectAll('g.hovertext');
412412

@@ -417,7 +417,7 @@ describe('hover info', function() {
417417
it('should display the correct format when ticklabels false', function() {
418418
layout.yaxis.showticklabels = false;
419419
Plotly.plot(this.gd, data, layout);
420-
mouseEvent('mousemove', 310, 220);
420+
mouseEvent('mousemove', 303, 213);
421421

422422
var hovers = d3.selectAll('g.hovertext');
423423

@@ -445,27 +445,27 @@ describe('hover info', function() {
445445
});
446446

447447
it('should show text labels', function() {
448-
mouseEvent('mousemove', 115, 310);
448+
mouseEvent('mousemove', 108, 303);
449449
var hovers = d3.selectAll('g.hovertext');
450450
expect(hovers.size()).toEqual(1);
451451
expect(hovers.select('text')[0][0].textContent).toEqual('test');
452452
});
453453

454454
it('should show number labels', function() {
455-
mouseEvent('mousemove', 370, 180);
455+
mouseEvent('mousemove', 363, 173);
456456
var hovers = d3.selectAll('g.hovertext');
457457
expect(hovers.size()).toEqual(1);
458458
expect(hovers.select('text')[0][0].textContent).toEqual('42');
459459
});
460460

461461
it('should not show null text labels', function() {
462-
mouseEvent('mousemove', 236, 246);
462+
mouseEvent('mousemove', 229, 239);
463463
var hovers = d3.selectAll('g.hovertext');
464464
expect(hovers.size()).toEqual(0);
465465
});
466466

467467
it('should not show undefined text labels', function() {
468-
mouseEvent('mousemove', 500, 115);
468+
mouseEvent('mousemove', 493, 108);
469469
var hovers = d3.selectAll('g.hovertext');
470470
expect(hovers.size()).toEqual(0);
471471
});
@@ -586,7 +586,7 @@ describe('hover info on overlaid subplots', function() {
586586
var mock = require('@mocks/autorange-tozero-rangemode.json');
587587

588588
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() {
589-
mouseEvent('mousemove', 775, 352);
589+
mouseEvent('mousemove', 768, 345);
590590

591591
var axisText = d3.selectAll('g.axistext'),
592592
hoverText = d3.selectAll('g.hovertext');
@@ -630,8 +630,8 @@ describe('hover after resizing', function() {
630630
layout = { width: 600, height: 500 },
631631
gd = createGraphDiv();
632632

633-
var pos0 = [311, 409],
634-
pos1 = [407, 128];
633+
var pos0 = [305, 403],
634+
pos1 = [401, 122];
635635

636636
Plotly.plot(gd, data, layout).then(function() {
637637
return assertLabelCount(pos0, 1, 'before resize, showing pt label');
@@ -683,11 +683,11 @@ describe('hover on fill', function() {
683683
mock.data.forEach(function(trace) { trace.hoveron = 'fills'; });
684684

685685
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() {
686-
return assertLabelsCorrect([250, 150], [252.575, 133.8], 'trace 2');
686+
return assertLabelsCorrect([242, 142], [249.175, 133.8], 'trace 2');
687687
}).then(function() {
688-
return assertLabelsCorrect([250, 300], [234.125, 210], 'trace 1');
688+
return assertLabelsCorrect([242, 292], [231.125, 210], 'trace 1');
689689
}).then(function() {
690-
return assertLabelsCorrect([155, 260], [160.325, 248.1], 'trace 0');
690+
return assertLabelsCorrect([147, 252], [158.925, 248.1], 'trace 0');
691691
}).then(done);
692692
});
693693

@@ -696,11 +696,11 @@ describe('hover on fill', function() {
696696
mock.data.forEach(function(trace) { trace.hoveron = 'fills'; });
697697

698698
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() {
699-
return assertLabelsCorrect([245, 171], [249.7, 166], 'trace 2');
699+
return assertLabelsCorrect([237, 163], [247.7, 166], 'trace 2');
700700
}).then(function() {
701-
return assertLabelsCorrect([245, 226], [268.75, 265], 'trace 1');
701+
return assertLabelsCorrect([237, 218], [266.75, 265], 'trace 1');
702702
}).then(function() {
703-
return assertLabelsCorrect([245, 259], [249.7, 254], 'trace 0');
703+
return assertLabelsCorrect([237, 251], [247.7, 254], 'trace 0');
704704
}).then(done);
705705
});
706-
});
706+
});

test/jasmine/tests/hover_pie_test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ describe('pie hovering', function() {
5454
unhoverData = data;
5555
});
5656

57-
mouseEvent('mouseover', width / 2, height / 2);
58-
mouseEvent('mouseout', width / 2, height / 2);
57+
mouseEvent('mouseover', width / 2 - 7, height / 2 - 7);
58+
mouseEvent('mouseout', width / 2 - 7, height / 2 - 7);
5959

6060
expect(hoverData.points.length).toEqual(1);
6161
expect(unhoverData.points.length).toEqual(1);
@@ -82,9 +82,9 @@ describe('pie hovering', function() {
8282
hoverData.push(data);
8383
});
8484

85-
mouseEvent('mouseover', 180, 140);
85+
mouseEvent('mouseover', 173, 133);
8686
setTimeout(function() {
87-
mouseEvent('mouseover', 240, 200);
87+
mouseEvent('mouseover', 233, 193);
8888
expect(count).toEqual(2);
8989
expect(hoverData[0]).not.toEqual(hoverData[1]);
9090
done();
@@ -100,11 +100,11 @@ describe('pie hovering', function() {
100100
unhoverData.push(data);
101101
});
102102

103-
mouseEvent('mouseover', 180, 140);
104-
mouseEvent('mouseout', 180, 140);
103+
mouseEvent('mouseover', 173, 133);
104+
mouseEvent('mouseout', 173, 133);
105105
setTimeout(function() {
106-
mouseEvent('mouseover', 240, 200);
107-
mouseEvent('mouseout', 240, 200);
106+
mouseEvent('mouseover', 233, 193);
107+
mouseEvent('mouseout', 233, 193);
108108
expect(count).toEqual(2);
109109
expect(unhoverData[0]).not.toEqual(unhoverData[1]);
110110
done();
@@ -130,7 +130,7 @@ describe('pie hovering', function() {
130130

131131
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
132132

133-
mouseEvent('mouseover', 230, 150);
133+
mouseEvent('mouseover', 223, 143);
134134

135135
var labels = Plotly.d3.selectAll('.hovertext .nums .line');
136136

@@ -152,7 +152,7 @@ describe('pie hovering', function() {
152152

153153
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
154154

155-
mouseEvent('mouseover', 230, 150);
155+
mouseEvent('mouseover', 223, 143);
156156

157157
var labels = Plotly.d3.selectAll('.hovertext .nums .line');
158158

test/jasmine/tests/modebar_test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ describe('ModeBar', function() {
660660
yaxis2: {
661661
anchor: 'x2',
662662
range: [0, 4]
663-
}
663+
},
664+
width: 600,
665+
height: 500
664666
};
665667

666668
gd = createGraphDiv();
@@ -696,7 +698,7 @@ describe('ModeBar', function() {
696698

697699
buttonZoomIn.click();
698700
buttonAutoScale.click();
699-
assertRange(gd._fullLayout.xaxis.range, [-0.1375913, 2.137591]);
701+
assertRange(gd._fullLayout.xaxis.range, [-0.1584327, 2.1584327]);
700702
assertRange(gd._fullLayout.yaxis.range, [0.92675159, 2.073248]);
701703
assertRange(gd._fullLayout.xaxis2.range, [-0.5, 2.5]);
702704
assertRange(gd._fullLayout.yaxis2.range, [0, 2.105263]);

0 commit comments

Comments
 (0)