@@ -9,6 +9,7 @@ var Registry = require('@src/registry');
99var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1010var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1111var selectButton = require ( '../assets/modebar_button' ) ;
12+ var failTest = require ( '../assets/fail_test' ) ;
1213
1314
1415describe ( 'ModeBar' , function ( ) {
@@ -293,20 +294,12 @@ describe('ModeBar', function() {
293294
294295 describe ( 'modeBar.destroy' , function ( ) {
295296 it ( 'removes the mode bar entirely' , function ( ) {
296- var modeBarParent = modeBar . element . parentNode ,
297- gd = getMockGraphInfo ( ) ,
298- styleSelector = 'style[id*="modebar-' + gd . _fullLayout . _uid + '"]' ;
299-
300-
301- var style = document . querySelector ( styleSelector ) ;
302- expect ( style ) . toBeTruthy ( ) ;
297+ var modeBarParent = modeBar . element . parentNode ;
303298
304299 modeBar . destroy ( ) ;
305300
306301 expect ( modeBarParent . querySelector ( '.modebar' ) ) . toBeNull ( ) ;
307302
308- style = document . querySelector ( styleSelector ) ;
309- expect ( style ) . toBeNull ( ) ;
310303 } ) ;
311304 } ) ;
312305
@@ -1245,4 +1238,104 @@ describe('ModeBar', function() {
12451238 } ) ;
12461239 } ) ;
12471240 } ) ;
1241+
1242+ describe ( 'modebar styling' , function ( ) {
1243+ var gd ,
1244+ colors = [ 'rgba(128, 128, 128, 0.7)' , 'rgba(255, 0, 128, 0.2)' ] ,
1245+ targetBtn = 'pan2d' , button , style ;
1246+
1247+ beforeEach ( function ( ) {
1248+ gd = createGraphDiv ( ) ;
1249+ } ) ;
1250+
1251+ afterEach ( function ( ) {
1252+ Plotly . purge ( gd ) ;
1253+ destroyGraphDiv ( ) ;
1254+ } ) ;
1255+
1256+ function checkButtonColor ( button , color ) {
1257+ var paths = button . node . querySelector ( 'path' ) ;
1258+ var style = window . getComputedStyle ( paths ) ;
1259+ expect ( style . fill ) . toBe ( color ) ;
1260+ }
1261+
1262+ it ( 'create an associated style element and destroy it on purge' , function ( done ) {
1263+ var styleSelector , style ;
1264+ Plotly . plot ( gd , [ ] , { } )
1265+ . then ( function ( ) {
1266+ styleSelector = 'style[id*="modebar-' + gd . _fullLayout . _uid + '"]' ;
1267+
1268+ style = document . querySelector ( styleSelector ) ;
1269+ expect ( style ) . toBeTruthy ( ) ;
1270+ } )
1271+ . then ( function ( ) {
1272+ Plotly . purge ( gd ) ;
1273+ style = document . querySelector ( styleSelector ) ;
1274+ expect ( style ) . toBeNull ( ) ;
1275+ } )
1276+ . then ( done ) ;
1277+ } ) ;
1278+
1279+ it ( 'changes icon colors' , function ( done ) {
1280+ Plotly . plot ( gd , [ ] , { modebar : { color : colors [ 0 ] } } )
1281+ . then ( function ( ) {
1282+ button = selectButton ( gd . _fullLayout . _modeBar , targetBtn ) ;
1283+ checkButtonColor ( button , colors [ 0 ] ) ;
1284+ } )
1285+ . then ( function ( ) { Plotly . relayout ( gd , 'modebar.color' , colors [ 1 ] ) ; } )
1286+ . then ( function ( ) {
1287+ checkButtonColor ( button , colors [ 1 ] ) ;
1288+ } )
1289+ . catch ( failTest )
1290+ . then ( done ) ;
1291+ } ) ;
1292+
1293+ it ( 'changes active icon colors' , function ( done ) {
1294+ Plotly . plot ( gd , [ ] , { modebar : { activecolor : colors [ 0 ] } } )
1295+ . then ( function ( ) {
1296+ button = selectButton ( gd . _fullLayout . _modeBar , targetBtn ) ;
1297+ button . click ( ) ;
1298+ checkButtonColor ( button , colors [ 0 ] ) ;
1299+ } )
1300+ . then ( function ( ) { Plotly . relayout ( gd , 'modebar.activecolor' , colors [ 1 ] ) ; } )
1301+ . then ( function ( ) {
1302+ checkButtonColor ( button , colors [ 1 ] ) ;
1303+ } )
1304+ . catch ( failTest )
1305+ . then ( done ) ;
1306+ } ) ;
1307+
1308+ it ( 'changes background color' , function ( done ) {
1309+ Plotly . plot ( gd , [ ] , { modebar : { bgcolor : colors [ 0 ] } } )
1310+ . then ( function ( ) {
1311+ style = window . getComputedStyle ( gd . _fullLayout . _modeBar . element ) ;
1312+ expect ( style . backgroundColor ) . toBe ( colors [ 0 ] ) ;
1313+ } )
1314+ . then ( function ( ) { Plotly . relayout ( gd , 'modebar.bgcolor' , colors [ 1 ] ) ; } )
1315+ . then ( function ( ) {
1316+ style = window . getComputedStyle ( gd . _fullLayout . _modeBar . element ) ;
1317+ expect ( style . backgroundColor ) . toBe ( colors [ 1 ] ) ;
1318+ } )
1319+ . catch ( failTest )
1320+ . then ( done ) ;
1321+ } ) ;
1322+
1323+ it ( 'changes orientation' , function ( done ) {
1324+ var modeBarEl , size ;
1325+
1326+ Plotly . plot ( gd , [ ] , { modebar : { orientation : 'v' } } )
1327+ . then ( function ( ) {
1328+ modeBarEl = gd . _fullLayout . _modeBar . element ;
1329+ size = modeBarEl . getBoundingClientRect ( ) ;
1330+ expect ( size . width < size . height ) . toBeTruthy ( ) ;
1331+ } )
1332+ . then ( function ( ) { Plotly . relayout ( gd , 'modebar.orientation' , 'h' ) ; } )
1333+ . catch ( failTest )
1334+ . then ( function ( ) {
1335+ size = modeBarEl . getBoundingClientRect ( ) ;
1336+ expect ( size . width > size . height ) . toBeTruthy ( ) ;
1337+ } )
1338+ . then ( done ) ;
1339+ } ) ;
1340+ } ) ;
12481341} ) ;
0 commit comments