@@ -525,21 +525,21 @@ describe('attaching component bindings', function() {
525
525
destroyGraphDiv ( gd ) ;
526
526
} ) ;
527
527
528
- it ( 'attaches bindings when events are added ' , function ( done ) {
528
+ it ( 'attaches and updates bindings for sliders ' , function ( done ) {
529
529
expect ( gd . _internalEv . _events . plotly_animatingframe ) . toBeUndefined ( ) ;
530
530
531
531
Plotly . relayout ( gd , {
532
532
sliders : [ {
533
533
// This one gets bindings:
534
534
steps : [
535
535
{ label : 'first' , method : 'restyle' , args : [ 'marker.color' , 'red' ] } ,
536
- { label : 'first ' , method : 'restyle' , args : [ 'marker.color' , 'blue' ] } ,
536
+ { label : 'second ' , method : 'restyle' , args : [ 'marker.color' , 'blue' ] } ,
537
537
]
538
538
} , {
539
539
// This one does *not*:
540
540
steps : [
541
541
{ label : 'first' , method : 'restyle' , args : [ 'line.color' , 'red' ] } ,
542
- { label : 'first ' , method : 'restyle' , args : [ 'marker.color' , 'blue' ] } ,
542
+ { label : 'second ' , method : 'restyle' , args : [ 'marker.color' , 'blue' ] } ,
543
543
]
544
544
} ]
545
545
} ) . then ( function ( ) {
@@ -577,4 +577,57 @@ describe('attaching component bindings', function() {
577
577
expect ( gd . _internalEv . _events . plotly_animatingframe ) . toBeUndefined ( ) ;
578
578
} ) . catch ( fail ) . then ( done ) ;
579
579
} ) ;
580
+
581
+ it ( 'attaches and updates bindings for updatemenus' , function ( done ) {
582
+ expect ( gd . _internalEv . _events . plotly_animatingframe ) . toBeUndefined ( ) ;
583
+
584
+ Plotly . relayout ( gd , {
585
+ updatemenus : [ {
586
+ // This one gets bindings:
587
+ buttons : [
588
+ { label : 'first' , method : 'restyle' , args : [ 'marker.color' , 'red' ] } ,
589
+ { label : 'second' , method : 'restyle' , args : [ 'marker.color' , 'blue' ] } ,
590
+ ]
591
+ } , {
592
+ // This one does *not*:
593
+ buttons : [
594
+ { label : 'first' , method : 'restyle' , args : [ 'line.color' , 'red' ] } ,
595
+ { label : 'second' , method : 'restyle' , args : [ 'marker.color' , 'blue' ] } ,
596
+ ]
597
+ } ]
598
+ } ) . then ( function ( ) {
599
+ // Check that it has attached a listener:
600
+ expect ( typeof gd . _internalEv . _events . plotly_animatingframe ) . toBe ( 'function' ) ;
601
+
602
+ // Confirm the first position is selected:
603
+ expect ( gd . layout . updatemenus [ 0 ] . active ) . toBe ( 0 ) ;
604
+
605
+ // Modify the plot
606
+ return Plotly . restyle ( gd , { 'marker.color' : 'blue' } ) ;
607
+ } ) . then ( function ( ) {
608
+ // Confirm that this has changed the slider position:
609
+ expect ( gd . layout . updatemenus [ 0 ] . active ) . toBe ( 1 ) ;
610
+
611
+ // Swap the values of the components:
612
+ return Plotly . relayout ( gd , {
613
+ 'updatemenus[0].buttons[0].args[1]' : 'green' ,
614
+ 'updatemenus[0].buttons[1].args[1]' : 'red'
615
+ } ) ;
616
+ } ) . then ( function ( ) {
617
+ return Plotly . restyle ( gd , { 'marker.color' : 'green' } ) ;
618
+ } ) . then ( function ( ) {
619
+ // Confirm that the lookup table has been updated:
620
+ expect ( gd . layout . updatemenus [ 0 ] . active ) . toBe ( 0 ) ;
621
+
622
+ // Check that it still has one attached listener:
623
+ expect ( typeof gd . _internalEv . _events . plotly_animatingframe ) . toBe ( 'function' ) ;
624
+
625
+ // Change this to a non-simple binding:
626
+ return Plotly . relayout ( gd , { 'updatemenus[0].buttons[0].args[0]' : 'line.color' } ) ;
627
+ } ) . then ( function ( ) {
628
+ // Bindings are no longer simple, so check to ensure they have
629
+ // been removed
630
+ expect ( gd . _internalEv . _events . plotly_animatingframe ) . toBeUndefined ( ) ;
631
+ } ) . catch ( fail ) . then ( done ) ;
632
+ } ) ;
580
633
} ) ;
0 commit comments