Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6abb696

Browse files
committed
Tests: added test for dragging annotations
1 parent 5aa2d9a commit 6abb696

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

test/jasmine/tests/config_test.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ describe('config argument', function() {
5454
{ x: [1,2,3], y: [3,2,1] }
5555
], {
5656
width: 600,
57-
height: 400
57+
height: 400,
58+
annotations: [
59+
{ text: 'testing', x: 1, y: 1, showarrow: true }
60+
]
5861
}, { editable: true })
5962
.then(done);
6063
});
@@ -78,6 +81,24 @@ describe('config argument', function() {
7881
expect(editBox.getAttribute('contenteditable')).toBe('true');
7982
}
8083

84+
function checkIfDraggable(elClass) {
85+
var el = document.getElementsByClassName(elClass)[0];
86+
87+
var elBox = el.getBoundingClientRect(),
88+
elX = elBox.left + elBox.width / 2,
89+
elY = elBox.top + elBox.height / 2;
90+
91+
mouseEvent('mousedown', elX, elY);
92+
mouseEvent('mousemove', elX - 20, elY + 20);
93+
94+
var movedBox = el.getBoundingClientRect();
95+
96+
expect(movedBox.left).toBe(elBox.left - 20);
97+
expect(movedBox.top).toBe(elBox.top + 20);
98+
99+
mouseEvent('mouseup', elX - 20, elY + 20);
100+
}
101+
81102
it('should make titles editable', function() {
82103
checkIfEditable('gtitle', 'Click to enter Plot title');
83104
});
@@ -94,22 +115,21 @@ describe('config argument', function() {
94115
checkIfEditable('legendtext', 'trace 0');
95116
});
96117

97-
it('should make legends draggable', function() {
98-
99-
var legend = document.getElementsByClassName('legend')[0],
100-
legendBox = legend.getBoundingClientRect(),
101-
legendX = legendBox.left + legendBox.width / 2,
102-
legendY = legendBox.top + legendBox.height / 2;
103-
104-
mouseEvent('mousedown', legendX, legendY);
105-
mouseEvent('mousemove', legendX - 20, legendY + 20);
106-
mouseEvent('mouseup', legendX - 20, legendY + 20);
118+
it('should make annotation labels editable', function() {
119+
checkIfEditable('annotation-text-g', 'testing');
120+
});
107121

108-
var movedlegendBox = legend.getBoundingClientRect();
122+
it('should make annotation labels draggable', function() {
123+
checkIfDraggable('annotation-text-g');
124+
});
109125

110-
expect(movedlegendBox.left).not.toBe(legendBox.left);
111-
expect(movedlegendBox.top).not.toBe(legendBox.top);
126+
it('should make annotation arrows draggable', function() {
127+
checkIfDraggable('annotation-arrow-g');
128+
});
112129

130+
it('should make legends draggable', function() {
131+
checkIfDraggable('legend');
113132
});
133+
114134
});
115135
});

0 commit comments

Comments
 (0)