|
| 1 | +var d3 = require('d3'); |
| 2 | + |
| 3 | +var Plotly = require('@lib/index'); |
| 4 | +var Lib = require('@src/lib'); |
| 5 | + |
| 6 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 7 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 8 | + |
| 9 | + |
| 10 | +describe('Test shapes nodes', function() { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + var mock = require('@mocks/shapes.json'); |
| 14 | + var gd; |
| 15 | + |
| 16 | + beforeEach(function(done) { |
| 17 | + gd = createGraphDiv(); |
| 18 | + |
| 19 | + var mockData = Lib.extendDeep([], mock.data), |
| 20 | + mockLayout = Lib.extendDeep({}, mock.layout); |
| 21 | + |
| 22 | + Plotly.plot(gd, mockData, mockLayout).then(done); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(destroyGraphDiv); |
| 26 | + |
| 27 | + function countShapeLayers() { |
| 28 | + return d3.selectAll('.shapelayer').size(); |
| 29 | + } |
| 30 | + |
| 31 | + function countPaths() { |
| 32 | + return d3.selectAll('.shapelayer > path').size(); |
| 33 | + } |
| 34 | + |
| 35 | + it('has one *shapelayer* node', function() { |
| 36 | + expect(countShapeLayers()).toEqual(1); |
| 37 | + }); |
| 38 | + |
| 39 | + it('has as many *path* nodes as there are shapes', function() { |
| 40 | + expect(countPaths()).toEqual(mock.layout.shapes.length); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should be able to get relayout', function(done) { |
| 44 | + expect(countShapeLayers()).toEqual(1); |
| 45 | + expect(countPaths()).toEqual(mock.layout.shapes.length); |
| 46 | + |
| 47 | + Plotly.relayout(gd, {height: 200, width: 400}).then(function() { |
| 48 | + expect(countShapeLayers()).toEqual(1); |
| 49 | + expect(countPaths()).toEqual(mock.layout.shapes.length); |
| 50 | + done(); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments