@@ -601,6 +601,50 @@ describe('update menus interactions', function() {
601601 . then ( done ) ;
602602 } ) ;
603603
604+ it ( 'should apply update on button click (toggle via args2 case)' , function ( done ) {
605+ var menuOpts = {
606+ type : 'buttons' ,
607+ buttons : [ {
608+ label : 'toggle' ,
609+ method : 'restyle' ,
610+ args : [ 'line.color' , 'blue' ] ,
611+ args2 : [ 'line.color' , 'red' ]
612+ } ]
613+ } ;
614+
615+ var btn ;
616+
617+ function assertLineColor ( msg , lineColor ) {
618+ expect ( gd . data [ 2 ] . line . color ) . toBe ( lineColor , 'gd.data line.color| ' + msg ) ;
619+ expect ( gd . _fullData [ 2 ] . line . color ) . toBe ( lineColor , 'gd._fullData line.color| ' + msg ) ;
620+ }
621+
622+ Plotly . relayout ( gd , 'updatemenus' , null )
623+ . then ( function ( ) { return Plotly . relayout ( gd , 'updatemenus[0]' , menuOpts ) ; } )
624+ . then ( function ( ) {
625+ btn = selectButton ( 0 , { type : 'buttons' } ) ;
626+ assertItemColor ( btn , activeColor ) ;
627+ assertLineColor ( 'base' , 'blue' ) ;
628+ return click ( btn ) ;
629+ } )
630+ . then ( function ( ) {
631+ assertItemColor ( btn , bgColor ) ;
632+ assertLineColor ( 'base' , 'red' ) ;
633+ return click ( btn ) ;
634+ } )
635+ . then ( function ( ) {
636+ assertItemColor ( btn , activeColor ) ;
637+ assertLineColor ( 'base' , 'blue' ) ;
638+ return click ( btn ) ;
639+ } )
640+ . then ( function ( ) {
641+ assertItemColor ( btn , bgColor ) ;
642+ assertLineColor ( 'base' , 'red' ) ;
643+ } )
644+ . catch ( failTest )
645+ . then ( done ) ;
646+ } ) ;
647+
604648 it ( 'should update correctly on failed binding comparisons' , function ( done ) {
605649 // See https://github.com/plotly/plotly.js/issues/1169
606650 // for more info.
@@ -871,8 +915,10 @@ describe('update menus interactions', function() {
871915 return header ;
872916 }
873917
874- function selectButton ( buttonIndex ) {
875- var buttons = d3 . selectAll ( '.' + constants . dropdownButtonClassName ) ;
918+ function selectButton ( buttonIndex , opts ) {
919+ opts = opts || { } ;
920+ var k = opts . type === 'buttons' ? 'buttonClassName' : 'dropdownButtonClassName' ;
921+ var buttons = d3 . selectAll ( '.' + constants [ k ] ) ;
876922 var button = d3 . select ( buttons [ 0 ] [ buttonIndex ] ) ;
877923 return button ;
878924 }
0 commit comments