@@ -7,7 +7,7 @@ var manageModebar = require('@src/components/modebar/manage');
77describe ( 'Modebar' , function ( ) {
88 'use strict' ;
99
10- function noop ( ) { } ;
10+ function noop ( ) { }
1111
1212 function getMockContainerTree ( ) {
1313 var root = document . createElement ( 'div' ) ;
@@ -45,6 +45,10 @@ describe('Modebar', function() {
4545 return d3 . select ( modebar . element ) . selectAll ( 'a.plotlyjsicon' ) [ 0 ] . length ;
4646 }
4747
48+ function checkBtnAttr ( modebar , index , attr ) {
49+ var buttons = d3 . select ( modebar . element ) . selectAll ( 'a.modebar-btn' ) ;
50+ return d3 . select ( buttons [ 0 ] [ index ] ) . attr ( attr ) ;
51+ }
4852
4953 var buttons = [ [ {
5054 name : 'button 1' ,
@@ -88,6 +92,32 @@ describe('Modebar', function() {
8892 } ) . toThrowError ( ) ;
8993 } ) ;
9094
95+ it ( 'defaults title to name when missing' , function ( ) {
96+ var modebar = createModebar ( getMockGraphInfo ( ) , [ [
97+ { name : 'the title too' , click : noop }
98+ ] ] ) ;
99+
100+ expect ( checkBtnAttr ( modebar , 0 , 'data-title' ) ) . toEqual ( 'the title too' ) ;
101+ } ) ;
102+
103+ it ( 'hides title to when title is set to null or \'\' or false' , function ( ) {
104+ var modebar ;
105+
106+ modebar = createModebar ( getMockGraphInfo ( ) , [ [
107+ { name : 'button' , title : null , click : noop }
108+ ] ] ) ;
109+ expect ( checkBtnAttr ( modebar , 0 , 'data-title' ) ) . toBe ( null ) ;
110+
111+ modebar = createModebar ( getMockGraphInfo ( ) , [ [
112+ { name : 'button' , title : '' , click : noop }
113+ ] ] ) ;
114+ expect ( checkBtnAttr ( modebar , 0 , 'data-title' ) ) . toBe ( null ) ;
115+
116+ modebar = createModebar ( getMockGraphInfo ( ) , [ [
117+ { name : 'button' , title : false , click : noop }
118+ ] ] ) ;
119+ expect ( checkBtnAttr ( modebar , 0 , 'data-title' ) ) . toBe ( null ) ;
120+ } ) ;
91121 } ) ;
92122
93123 describe ( 'modebar.removeAllButtons' , function ( ) {
0 commit comments