Skip to content

Commit 7f3392f

Browse files
committed
Tests: add tests for when editable
1 parent 7269c33 commit 7f3392f

File tree

1 file changed

+81
-7
lines changed

1 file changed

+81
-7
lines changed

test/jasmine/tests/config_test.js

Lines changed: 81 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,77 @@ 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+
console.log('checking editable', elClass);
66+
var label = document.getElementsByClassName(elClass)[0];
67+
68+
expect(label.textContent).toBe(text);
69+
70+
var labelBox = label.getBoundingClientRect(),
71+
labelX = labelBox.left + labelBox.width / 2,
72+
labelY = labelBox.top + labelBox.height / 2;
73+
74+
mouseEvent('click', labelX, labelY);
75+
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+
}
81+
82+
it('should make titles editable', function() {
83+
checkIfEditable('gtitle', 'Click to enter Plot title');
84+
});
85+
86+
it('should make x axes labels editable', function() {
87+
checkIfEditable('g-xtitle', 'Click to enter X axis title');
88+
});
89+
90+
it('should make y axes labels editable', function() {
91+
checkIfEditable('g-ytitle', 'Click to enter Y axis title');
92+
});
93+
94+
it('should make legend labels editable', function() {
95+
checkIfEditable('legendtext', 'trace 0');
96+
});
97+
98+
it('should make legends draggable', function() {
99+
100+
var legend = document.getElementsByClassName('legend')[0],
101+
legendBox = legend.getBoundingClientRect(),
102+
legendX = legendBox.left + legendBox.width / 2,
103+
legendY = legendBox.top + legendBox.height / 2;
104+
105+
mouseEvent('mousedown', legendX, legendY);
106+
mouseEvent('mousemove', legendX - 20, legendY + 20);
107+
mouseEvent('mouseup', legendX - 20, legendY + 20);
108+
109+
var movedlegendBox = legend.getBoundingClientRect();
110+
111+
expect(movedlegendBox.left).not.toBe(legendBox.left);
112+
expect(movedlegendBox.top).not.toBe(legendBox.top);
113+
114+
});
115+
});
42116
});

0 commit comments

Comments
 (0)