From 0d213b70b3a5421795c0f81f757c4abf1ebb4e8e Mon Sep 17 00:00:00 2001 From: Nicolas Riesco Date: Sat, 2 Apr 2016 13:05:18 +0100 Subject: [PATCH] Add shapes tests --- test/jasmine/tests/shapes_test.js | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/jasmine/tests/shapes_test.js diff --git a/test/jasmine/tests/shapes_test.js b/test/jasmine/tests/shapes_test.js new file mode 100644 index 00000000000..b9562a88e56 --- /dev/null +++ b/test/jasmine/tests/shapes_test.js @@ -0,0 +1,53 @@ +var d3 = require('d3'); + +var Plotly = require('@lib/index'); +var Lib = require('@src/lib'); + +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); + + +describe('Test shapes nodes', function() { + 'use strict'; + + var mock = require('@mocks/shapes.json'); + var gd; + + beforeEach(function(done) { + gd = createGraphDiv(); + + var mockData = Lib.extendDeep([], mock.data), + mockLayout = Lib.extendDeep({}, mock.layout); + + Plotly.plot(gd, mockData, mockLayout).then(done); + }); + + afterEach(destroyGraphDiv); + + function countShapeLayers() { + return d3.selectAll('.shapelayer').size(); + } + + function countPaths() { + return d3.selectAll('.shapelayer > path').size(); + } + + it('has one *shapelayer* node', function() { + expect(countShapeLayers()).toEqual(1); + }); + + it('has as many *path* nodes as there are shapes', function() { + expect(countPaths()).toEqual(mock.layout.shapes.length); + }); + + it('should be able to get relayout', function(done) { + expect(countShapeLayers()).toEqual(1); + expect(countPaths()).toEqual(mock.layout.shapes.length); + + Plotly.relayout(gd, {height: 200, width: 400}).then(function() { + expect(countShapeLayers()).toEqual(1); + expect(countPaths()).toEqual(mock.layout.shapes.length); + done(); + }); + }); +});