Skip to content

Commit 0503901

Browse files
committed
test: add relayout tests for annotations
1 parent 2b632e1 commit 0503901

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

test/jasmine/tests/annotations_test.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
require('@src/plotly');
2-
var Plots = require('@src/plots/plots');
31
var Annotations = require('@src/components/annotations');
2+
3+
var Plotly = require('@lib/index');
4+
var Plots = require('@src/plots/plots');
5+
var Lib = require('@src/lib');
46
var Dates = require('@src/lib/dates');
57

8+
var d3 = require('d3');
9+
var createGraphDiv = require('../assets/create_graph_div');
10+
var destroyGraphDiv = require('../assets/destroy_graph_div');
11+
612
describe('Test annotations', function() {
713
'use strict';
814

@@ -31,3 +37,46 @@ describe('Test annotations', function() {
3137
});
3238
});
3339
});
40+
41+
describe('annotations relayout', function() {
42+
'use strict';
43+
44+
var mock = require('@mocks/annotations.json');
45+
var len = mock.layout.annotations.length;
46+
var gd;
47+
48+
beforeEach(function(done) {
49+
gd = createGraphDiv();
50+
51+
var mockData = Lib.extendDeep([], mock.data),
52+
mockLayout = Lib.extendDeep({}, mock.layout);
53+
54+
Plotly.plot(gd, mockData, mockLayout).then(done);
55+
});
56+
57+
afterEach(destroyGraphDiv);
58+
59+
function countAnnotations() {
60+
return d3.selectAll('g.annotation').size();
61+
}
62+
63+
it('should be able to add /remove annotations', function(done) {
64+
expect(countAnnotations()).toEqual(len);
65+
66+
var ann = { text: '' };
67+
68+
Plotly.relayout(gd, 'annotations[' + len + ']', ann).then(function() {
69+
expect(countAnnotations()).toEqual(len + 1);
70+
71+
return Plotly.relayout(gd, 'annotations[' + 0 + ']', 'remove');
72+
}).then(function() {
73+
expect(countAnnotations()).toEqual(len);
74+
75+
return Plotly.relayout(gd, { annotations: [] });
76+
}).then(function() {
77+
expect(countAnnotations()).toEqual(0);
78+
79+
done();
80+
});
81+
});
82+
});

0 commit comments

Comments
 (0)