Skip to content

Commit 156b73b

Browse files
Added test for interaction with domain reference objects
1 parent 6e26db3 commit 156b73b

File tree

3 files changed

+86
-36
lines changed

3 files changed

+86
-36
lines changed

test/image/mocks/domain_refs_editable.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
]
5757
},
5858
"xaxis4": {
59+
"type": "log",
5960
"anchor": "y4",
6061
"domain": [
6162
0.55,
@@ -81,6 +82,7 @@
8182
]
8283
},
8384
"yaxis3": {
85+
"type": "log",
8486
"anchor": "x3",
8587
"domain": [
8688
0.0,
@@ -116,14 +118,14 @@
116118
"xref": "x4 domain",
117119
"yref": "y4 domain",
118120
"x0": 0.4,
119-
"y0": 0.6,
120-
"x1": 0.5,
121+
"y0": 0.5,
122+
"x1": 0.6,
121123
"y1": 0.7,
122124
"line": { "color": "rgb(10, 20, 31)" }
123125
}],
124126
"annotations": [{
125127
"text": "A",
126-
"bgcolor": "rgb(100, 200, 232)",
128+
"bordercolor": "rgb(100, 200, 232)",
127129
"xref": "x3 domain",
128130
"yref": "y3 domain",
129131
"x": 0.4,
@@ -134,7 +136,7 @@
134136
"ay": 0.7
135137
},{
136138
"text": "B",
137-
"bgcolor": "rgb(200, 200, 232)",
139+
"bordercolor": "rgb(200, 200, 232)",
138140
"xref": "x4 domain",
139141
"yref": "y4 domain",
140142
"x": 0.3,

test/jasmine/assets/domain_ref/components.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,10 @@ function compareBBoxes(a, b) {
437437
true);
438438
}
439439

440-
function findAROByColor(color, id) {
440+
function findAROByColor(color, id, type) {
441441
id = (id === undefined) ? '' : id + ' ';
442-
var selector = id + 'path';
442+
type = (type === undefined) ? 'path' : type;
443+
var selector = id + type;
443444
var ret = d3.selectAll(selector).filter(function() {
444445
return this.style.stroke === color;
445446
}).node();

test/jasmine/tests/domain_ref_interact_test.js

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,57 @@ var getSVGElemScreenBBox = require(
1010
var testMock = require('../../image/mocks/domain_refs_editable.json');
1111
var delay = require('../assets/delay');
1212
var mouseEvent = require('../assets/mouse_event');
13+
var drag = require('../assets/drag');
1314

14-
// color of first rectangle
15-
var rectColor1 = "rgb(10, 20, 30)";
15+
// color of the rectangles
16+
var rectColor1 = 'rgb(10, 20, 30)';
17+
var rectColor2 = 'rgb(10, 20, 31)';
18+
var rectColor3 = 'rgb(100, 200, 232)';
19+
var rectColor4 = 'rgb(200, 200, 232)';
1620

1721
var DELAY_TIME = 0;
1822

19-
describe("Shapes referencing domain", function () {
23+
function testObjectMove(objectColor, moveX, moveY, type) {
24+
var bboxBefore = getSVGElemScreenBBox(
25+
domainRefComponents.findAROByColor(objectColor, undefined, type)
26+
);
27+
var pos = {
28+
mouseStartX: bboxBefore.x + bboxBefore.width * 0.5,
29+
mouseStartY: bboxBefore.y + bboxBefore.height * 0.5,
30+
};
31+
pos.mouseEndX = pos.mouseStartX + moveX;
32+
pos.mouseEndY = pos.mouseStartY + moveY;
33+
mouseEvent('mousemove', pos.mouseStartX, pos.mouseStartY);
34+
mouseEvent('mousedown', pos.mouseStartX, pos.mouseStartY);
35+
mouseEvent('mousemove', pos.mouseEndX, pos.mouseEndY);
36+
mouseEvent('mouseup', pos.mouseEndX, pos.mouseEndY);
37+
var bboxAfter = getSVGElemScreenBBox(
38+
domainRefComponents.findAROByColor(objectColor, undefined, type)
39+
);
40+
expect(bboxAfter.x).toBeCloseTo(bboxBefore.x + moveX, 2);
41+
expect(bboxAfter.y).toBeCloseTo(bboxBefore.y + moveY, 2);
42+
}
43+
44+
function testAnnotationMove(objectColor, moveX, moveY, type) {
45+
var bboxBefore = getSVGElemScreenBBox(
46+
domainRefComponents.findAROByColor(objectColor, undefined, type)
47+
);
48+
var opt = {
49+
pos0: [ bboxBefore.x + bboxBefore.width * 0.5,
50+
bboxBefore.y + bboxBefore.height * 0.5 ],
51+
};
52+
opt.dpos = [moveX, moveY];
53+
return (new Promise(function() { drag(opt); }))
54+
.then(function() {
55+
var bboxAfter = getSVGElemScreenBBox(
56+
domainRefComponents.findAROByColor(objectColor, undefined, type)
57+
);
58+
expect(bboxAfter.x).toBeCloseTo(bboxBefore.x + moveX, 2);
59+
expect(bboxAfter.y).toBeCloseTo(bboxBefore.y + moveY, 2);
60+
});
61+
}
62+
63+
describe('Shapes referencing domain', function() {
2064
var gd;
2165
beforeEach(function() {
2266
gd = createGraphDiv();
@@ -26,31 +70,34 @@ describe("Shapes referencing domain", function () {
2670
destroyGraphDiv(gd);
2771
gd = null;
2872
});
29-
it("should move to the proper position", function(done) {
30-
Plotly.newPlot(gd, Lib.extendDeep({}, testMock))
31-
.then(delay(DELAY_TIME))
32-
.then(function () {
33-
var rectPos1before = getSVGElemScreenBBox(
34-
domainRefComponents.findAROByColor(rectColor1)
35-
);
36-
var pos = {
37-
mouseStartX: rectPos1before.x + rectPos1before.width * 0.5,
38-
mouseStartY: rectPos1before.y + rectPos1before.height * 0.5,
39-
};
40-
pos.mouseEndX = pos.mouseStartX + 100;
41-
pos.mouseEndY = pos.mouseStartY + -300;
42-
mouseEvent('mousemove', pos.mouseStartX, pos.mouseStartY);
43-
mouseEvent('mousedown', pos.mouseStartX, pos.mouseStartY);
44-
mouseEvent('mousemove', pos.mouseEndX, pos.mouseEndY);
45-
mouseEvent('mouseup', pos.mouseEndX, pos.mouseEndY);
46-
var rectPos1after = getSVGElemScreenBBox(
47-
domainRefComponents.findAROByColor(rectColor1)
48-
);
49-
expect(rectPos1after.x).toBeCloseTo(rectPos1before.x + 100, 2);
50-
expect(rectPos1after.y).toBeCloseTo(rectPos1before.y - 300, 2);
51-
})
52-
.then(delay(DELAY_TIME))
53-
.catch(failTest)
54-
.then(done);
55-
});
73+
function testObjectMoveItFun(color, x, y, type) {
74+
return function(done) {
75+
Plotly.newPlot(gd, Lib.extendDeep({}, testMock))
76+
.then(delay(DELAY_TIME))
77+
.then(function() {
78+
testObjectMove(color, x, y, type);
79+
})
80+
.then(delay(DELAY_TIME))
81+
.catch(failTest)
82+
.then(done);
83+
};
84+
}
85+
function testAnnotationMoveItFun(color, x, y, type) {
86+
return function(done) {
87+
Plotly.newPlot(gd, Lib.extendDeep({}, testMock))
88+
.then(delay(DELAY_TIME))
89+
.then(testAnnotationMove(color, x, y, type))
90+
.then(delay(DELAY_TIME))
91+
.catch(failTest)
92+
.then(done);
93+
};
94+
}
95+
it('should move box on linear x axis and log y to the proper position',
96+
testObjectMoveItFun(rectColor1, 100, -300, 'path'));
97+
it('should move box on log x axis and linear y to the proper position',
98+
testObjectMoveItFun(rectColor2, -400, -200, 'path'));
99+
it('should move annotation box on linear x axis and log y to the proper position',
100+
testAnnotationMoveItFun(rectColor3, 50, -100, 'rect'));
101+
it('should move annotation box on log x axis and linear y to the proper position',
102+
testAnnotationMoveItFun(rectColor4, -75, -150, 'rect'));
56103
});

0 commit comments

Comments
 (0)