@@ -3,6 +3,7 @@ var Lib = require('@src/lib');
33
44var Box = require ( '@src/traces/box' ) ;
55
6+ var d3 = require ( 'd3' ) ;
67var createGraphDiv = require ( '../assets/create_graph_div' ) ;
78var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
89var failTest = require ( '../assets/fail_test' ) ;
@@ -348,3 +349,54 @@ describe('Box edge cases', function() {
348349 . then ( done ) ;
349350 } ) ;
350351} ) ;
352+
353+ describe ( 'Test box restyle:' , function ( ) {
354+ var gd ;
355+
356+ beforeEach ( function ( ) {
357+ gd = createGraphDiv ( ) ;
358+ } ) ;
359+
360+ afterEach ( destroyGraphDiv ) ;
361+
362+ it ( 'should be able to add/remove innner parts' , function ( done ) {
363+ var fig = Lib . extendDeep ( { } , require ( '@mocks/box_plot_jitter.json' ) ) ;
364+ // start with just 1 box
365+ delete fig . data [ 0 ] . boxpoints ;
366+
367+ function _assertOne ( msg , exp , trace3 , k , query ) {
368+ expect ( trace3 . selectAll ( query ) . size ( ) )
369+ . toBe ( exp [ k ] || 0 , k + ' - ' + msg ) ;
370+ }
371+
372+ function _assert ( msg , exp ) {
373+ var trace3 = d3 . select ( gd ) . select ( '.boxlayer > .trace' ) ;
374+ _assertOne ( msg , exp , trace3 , 'boxCnt' , 'path.box' ) ;
375+ _assertOne ( msg , exp , trace3 , 'meanlineCnt' , 'path.mean' ) ;
376+ _assertOne ( msg , exp , trace3 , 'ptsCnt' , 'path.point' ) ;
377+ }
378+
379+ Plotly . plot ( gd , fig )
380+ . then ( function ( ) {
381+ _assert ( 'base' , { boxCnt : 1 } ) ;
382+ } )
383+ . then ( function ( ) { return Plotly . restyle ( gd , 'boxmean' , true ) ; } )
384+ . then ( function ( ) {
385+ _assert ( 'with meanline' , { boxCnt : 1 , meanlineCnt : 1 } ) ;
386+ } )
387+ . then ( function ( ) { return Plotly . restyle ( gd , 'boxmean' , 'sd' ) ; } )
388+ . then ( function ( ) {
389+ _assert ( 'with mean+sd line' , { boxCnt : 1 , meanlineCnt : 1 } ) ;
390+ } )
391+ . then ( function ( ) { return Plotly . restyle ( gd , 'boxpoints' , 'all' ) ; } )
392+ . then ( function ( ) {
393+ _assert ( 'with mean+sd line + pts' , { boxCnt : 1 , meanlineCnt : 1 , ptsCnt : 9 } ) ;
394+ } )
395+ . then ( function ( ) { return Plotly . restyle ( gd , 'boxmean' , false ) ; } )
396+ . then ( function ( ) {
397+ _assert ( 'with pts' , { boxCnt : 1 , ptsCnt : 9 } ) ;
398+ } )
399+ . catch ( failTest )
400+ . then ( done ) ;
401+ } ) ;
402+ } ) ;
0 commit comments