@@ -510,13 +510,34 @@ describe('legend anchor utils:', function() {
510
510
511
511
describe ( 'legend relayout update' , function ( ) {
512
512
'use strict' ;
513
+ var gd ;
514
+ var mock = require ( '@mocks/0.json' ) ;
513
515
516
+ beforeEach ( function ( ) {
517
+ gd = createGraphDiv ( ) ;
518
+ } ) ;
514
519
afterEach ( destroyGraphDiv ) ;
515
520
521
+ it ( 'should hide and show the legend' , function ( done ) {
522
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
523
+ Plotly . newPlot ( gd , mockCopy . data , mockCopy . layout )
524
+ . then ( function ( ) {
525
+ expect ( d3 . selectAll ( 'g.legend' ) . size ( ) ) . toBe ( 1 ) ;
526
+ return Plotly . relayout ( gd , { showlegend : false } ) ;
527
+ } )
528
+ . then ( function ( ) {
529
+ expect ( d3 . selectAll ( 'g.legend' ) . size ( ) ) . toBe ( 0 ) ;
530
+ return Plotly . relayout ( gd , { showlegend : true } ) ;
531
+ } )
532
+ . then ( function ( ) {
533
+ expect ( d3 . selectAll ( 'g.legend' ) . size ( ) ) . toBe ( 1 ) ;
534
+ } )
535
+ . catch ( fail )
536
+ . then ( done ) ;
537
+ } ) ;
538
+
516
539
it ( 'should update border styling' , function ( done ) {
517
- var mock = require ( '@mocks/0.json' ) ,
518
- mockCopy = Lib . extendDeep ( { } , mock ) ,
519
- gd = createGraphDiv ( ) ;
540
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
520
541
521
542
function assertLegendStyle ( bgColor , borderColor , borderWidth ) {
522
543
var node = d3 . select ( 'g.legend' ) . select ( 'rect' ) ;
@@ -547,9 +568,9 @@ describe('legend relayout update', function() {
547
568
return Plotly . relayout ( gd , 'paper_bgcolor' , 'blue' ) ;
548
569
} ) . then ( function ( ) {
549
570
assertLegendStyle ( 'rgb(0, 0, 255)' , 'rgb(255, 0, 0)' , 10 ) ;
550
-
551
- done ( ) ;
552
- } ) ;
571
+ } )
572
+ . catch ( fail )
573
+ . then ( done ) ;
553
574
} ) ;
554
575
} ) ;
555
576
0 commit comments