@@ -525,21 +525,21 @@ describe('attaching component bindings', function() {
525525 destroyGraphDiv ( gd ) ;
526526 } ) ;
527527
528- it ( 'attaches bindings when events are added ' , function ( done ) {
528+ it ( 'attaches and updates bindings for sliders ' , function ( done ) {
529529 expect ( gd . _internalEv . _events . plotly_animatingframe ) . toBeUndefined ( ) ;
530530
531531 Plotly . relayout ( gd , {
532532 sliders : [ {
533533 // This one gets bindings:
534534 steps : [
535535 { 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' ] } ,
537537 ]
538538 } , {
539539 // This one does *not*:
540540 steps : [
541541 { 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' ] } ,
543543 ]
544544 } ]
545545 } ) . then ( function ( ) {
@@ -577,4 +577,57 @@ describe('attaching component bindings', function() {
577577 expect ( gd . _internalEv . _events . plotly_animatingframe ) . toBeUndefined ( ) ;
578578 } ) . catch ( fail ) . then ( done ) ;
579579 } ) ;
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+ } ) ;
580633} ) ;
0 commit comments