11var Plotly = require ( '@lib/index' ) ;
2+ var Lib = require ( '@src/lib' ) ;
3+
24var createGraph = require ( '../assets/create_graph_div' ) ;
35var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
46var getBBox = require ( '../assets/get_bbox' ) ;
@@ -26,10 +28,15 @@ describe('The legend', function() {
2628
2729
2830 describe ( 'when plotted with many traces' , function ( ) {
29- beforeEach ( function ( ) {
31+ beforeEach ( function ( done ) {
3032 gd = createGraph ( ) ;
31- Plotly . plot ( gd , mock . data , mock . layout ) ;
32- legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
33+
34+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
35+
36+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
37+ legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
38+ done ( ) ;
39+ } ) ;
3340 } ) ;
3441
3542 afterEach ( destroyGraph ) ;
@@ -96,7 +103,7 @@ describe('The legend', function() {
96103 it ( 'should resize when relayout\'ed with new height' , function ( done ) {
97104 var origLegendHeight = getBBox ( legend ) . height ;
98105
99- Plotly . relayout ( gd , { 'height' : gd . _fullLayout . height / 2 } ) . then ( function ( ) {
106+ Plotly . relayout ( gd , 'height' , gd . _fullLayout . height / 2 ) . then ( function ( ) {
100107 var legendHeight = getBBox ( legend ) . height ;
101108
102109 //legend still exists and not duplicated
@@ -114,7 +121,7 @@ describe('The legend', function() {
114121
115122
116123 describe ( 'when plotted with few traces' , function ( ) {
117- var gd , legend ;
124+ var gd ;
118125
119126 beforeEach ( function ( ) {
120127 gd = createGraph ( ) ;
@@ -147,14 +154,15 @@ describe('The legend', function() {
147154 } ) ;
148155
149156 it ( 'should resize when traces added' , function ( done ) {
150- legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
151- var origLegendHeight = getBBox ( legend ) . height ;
157+ var origLegend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
158+ var origLegendHeight = getBBox ( origLegend ) . height ;
152159
153- Plotly . addTrace ( gd , { x : [ 1 , 2 , 3 ] , y : [ 4 , 3 , 2 ] , name : 'Test2' } ) . then ( function ( ) {
160+ Plotly . addTraces ( gd , { x : [ 1 , 2 , 3 ] , y : [ 4 , 3 , 2 ] , name : 'Test2' } ) . then ( function ( ) {
154161 var legend = document . getElementsByClassName ( 'legend' ) [ 0 ] ;
155162 var legendHeight = getBBox ( legend ) . height ;
163+
156164 // clippath resized to show new trace
157- expect ( + legendHeight ) . toBeCloseTo ( + origLegendHeight + 18 , 0 ) ;
165+ expect ( + legendHeight ) . toBeCloseTo ( + origLegendHeight + 19 , 0 ) ;
158166
159167 done ( ) ;
160168 } ) ;
0 commit comments