Skip to content

Commit 0c3fc59

Browse files
committed
Tests: add tests for when editable
1 parent 7269c33 commit 0c3fc59

File tree

1 file changed

+79
-7
lines changed

1 file changed

+79
-7
lines changed

test/jasmine/tests/config_test.js

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
var Plotly = require('@lib/index');
22
var createGraphDiv = require('../assets/create_graph_div');
33
var destroyGraphDiv = require('../assets/destroy_graph_div');
4+
var mouseEvent = require('../assets/mouse_event');
45

56
describe('config argument', function() {
67

7-
var gd;
8+
describe('showLink attribute', function() {
89

9-
beforeEach(function(done) {
10-
gd = createGraphDiv();
11-
done();
12-
});
10+
var gd;
1311

14-
afterEach(destroyGraphDiv);
12+
beforeEach(function(done) {
13+
gd = createGraphDiv();
14+
done();
15+
});
1516

16-
describe('showLink attribute', function() {
17+
afterEach(destroyGraphDiv);
1718

1819
it('should not display the edit link by default', function() {
1920
Plotly.plot(gd, [], {});
@@ -39,4 +40,75 @@ describe('config argument', function() {
3940
expect(bBox.height).toBeGreaterThan(0);
4041
});
4142
});
43+
44+
45+
describe('editable attribute', function() {
46+
47+
var gd;
48+
49+
beforeEach(function(done) {
50+
gd = createGraphDiv();
51+
52+
Plotly.plot(gd, [
53+
{ x: [1,2,3], y: [1,2,3] },
54+
{ x: [1,2,3], y: [3,2,1] }
55+
], {
56+
width: 600,
57+
height: 400
58+
}, { editable: true })
59+
.then(done);
60+
});
61+
62+
afterEach(destroyGraphDiv);
63+
64+
function checkIfEditable(elClass, text) {
65+
var label = document.getElementsByClassName(elClass)[0];
66+
67+
expect(label.textContent).toBe(text);
68+
69+
var labelBox = label.getBoundingClientRect(),
70+
labelX = labelBox.left + labelBox.width / 2,
71+
labelY = labelBox.top + labelBox.height / 2;
72+
73+
mouseEvent('click', labelX, labelY);
74+
75+
setTimeout(function() {
76+
var editBox = document.getElementsByClassName('plugin-editable editable')[0];
77+
expect(editBox).toBeDefined();
78+
expect(editBox.textContent).toBe(text);
79+
expect(editBox.getAttribute('contenteditable')).toBe('true');
80+
}, 10);
81+
}
82+
83+
it('should make titles editable', function() {
84+
checkIfEditable('gtitle', 'Click to enter Plot title');
85+
});
86+
87+
it('should make axes labels editable', function() {
88+
checkIfEditable('g-xtitle', 'Click to enter X axis title');
89+
checkIfEditable('g-ytitle', 'Click to enter Y axis title');
90+
});
91+
92+
it('should make legend labels editable', function() {
93+
checkIfEditable('legendtext', 'trace 0');
94+
});
95+
96+
it('should make legends draggable', function() {
97+
98+
var legend = document.getElementsByClassName('legend')[0],
99+
legendBox = legend.getBoundingClientRect(),
100+
legendX = legendBox.left + legendBox.width / 2,
101+
legendY = legendBox.top + legendBox.height / 2;
102+
103+
mouseEvent('mousedown', legendX, legendY);
104+
mouseEvent('mousemove', legendX - 20, legendY + 20);
105+
mouseEvent('mouseup', legendX - 20, legendY + 20);
106+
107+
var movedlegendBox = legend.getBoundingClientRect();
108+
109+
expect(movedlegendBox.left).not.toBe(legendBox.left);
110+
expect(movedlegendBox.top).not.toBe(legendBox.top);
111+
112+
});
113+
});
42114
});

0 commit comments

Comments
 (0)