|
1 |
| -require('@src/plotly'); |
2 |
| -var Plots = require('@src/plots/plots'); |
3 | 1 | 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'); |
4 | 6 | var Dates = require('@src/lib/dates');
|
5 | 7 |
|
| 8 | +var d3 = require('d3'); |
| 9 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 10 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 11 | + |
6 | 12 | describe('Test annotations', function() {
|
7 | 13 | 'use strict';
|
8 | 14 |
|
@@ -31,3 +37,46 @@ describe('Test annotations', function() {
|
31 | 37 | });
|
32 | 38 | });
|
33 | 39 | });
|
| 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