@@ -9,6 +9,7 @@ var Legend = require('@src/components/legend');
99var Axes = require ( '@src/plots/cartesian/axes' ) ;
1010var pkg = require ( '../../../package.json' ) ;
1111var subroutines = require ( '@src/plot_api/subroutines' ) ;
12+ var manageArrays = require ( '@src/plot_api/manage_arrays' ) ;
1213var helpers = require ( '@src/plot_api/helpers' ) ;
1314var editTypes = require ( '@src/plot_api/edit_types' ) ;
1415
@@ -2649,16 +2650,29 @@ describe('Test plot api', function() {
26492650 it ( 'should only have one modebar-container' , function ( done ) {
26502651 var data = [ { y : [ 1 , 2 ] } ] ;
26512652
2652- Plotly . plot ( gd , data ) . then ( function ( ) {
2653- var modebars = document . getElementsByClassName ( 'modebar-container' ) ;
2654- expect ( modebars . length ) . toBe ( 1 ) ;
2653+ function _assert ( msg ) {
2654+ return function ( ) {
2655+ var modebars = document . getElementsByClassName ( 'modebar-container' ) ;
2656+ expect ( modebars . length ) . toBe ( 1 , msg + ' # of modebar container' ) ;
2657+ var groups = document . getElementsByClassName ( 'modebar-group' ) ;
2658+ expect ( groups . length ) . toBe ( 5 , msg + ' # of modebar button groups' ) ;
2659+ } ;
2660+ }
26552661
2656- return Plotly . newPlot ( gd , data ) ;
2657- } )
2658- . then ( function ( ) {
2659- var modebars = document . getElementsByClassName ( 'modebar-container' ) ;
2660- expect ( modebars . length ) . toBe ( 1 ) ;
2662+ Plotly . plot ( gd , data )
2663+ . then ( _assert ( 'base' ) )
2664+ . then ( function ( ) { return Plotly . newPlot ( gd , data ) ; } )
2665+ . then ( _assert ( 'after newPlot()' ) )
2666+ . then ( function ( ) {
2667+ // funky combinations of update flags found in
2668+ // https://github.com/plotly/plotly.js/issues/3824
2669+ return Plotly . update ( gd , {
2670+ visible : false
2671+ } , {
2672+ annotations : [ { text : 'a' } ]
2673+ } ) ;
26612674 } )
2675+ . then ( _assert ( 'after update()' ) )
26622676 . catch ( failTest )
26632677 . then ( done ) ;
26642678 } ) ;
@@ -2674,6 +2688,10 @@ describe('Test plot api', function() {
26742688 } ) ;
26752689
26762690 beforeEach ( function ( done ) {
2691+ Object . keys ( subroutines ) . forEach ( function ( k ) {
2692+ subroutines [ k ] . calls . reset ( ) ;
2693+ } ) ;
2694+
26772695 gd = createGraphDiv ( ) ;
26782696 Plotly . plot ( gd , [ { y : [ 2 , 1 , 2 ] } ] ) . then ( function ( ) {
26792697 data = gd . data ;
@@ -2687,8 +2705,6 @@ describe('Test plot api', function() {
26872705 afterEach ( destroyGraphDiv ) ;
26882706
26892707 it ( 'call doTraceStyle on trace style updates' , function ( done ) {
2690- expect ( subroutines . doTraceStyle ) . not . toHaveBeenCalled ( ) ;
2691-
26922708 Plotly . update ( gd , { 'marker.color' : 'blue' } ) . then ( function ( ) {
26932709 expect ( subroutines . doTraceStyle ) . toHaveBeenCalledTimes ( 1 ) ;
26942710 expect ( calcdata ) . toBe ( gd . calcdata ) ;
@@ -2720,16 +2736,14 @@ describe('Test plot api', function() {
27202736 expect ( data ) . toBe ( gd . data ) ;
27212737 expect ( layout ) . toBe ( gd . layout ) ;
27222738 expect ( calcdata ) . not . toBe ( gd . calcdata ) ;
2723-
27242739 expect ( gd . data . length ) . toEqual ( 1 ) ;
2740+ expect ( subroutines . layoutReplot ) . toHaveBeenCalledTimes ( 1 ) ;
27252741 } )
27262742 . catch ( failTest )
27272743 . then ( done ) ;
27282744 } ) ;
27292745
27302746 it ( 'call doLegend on legend updates' , function ( done ) {
2731- expect ( subroutines . doLegend ) . not . toHaveBeenCalled ( ) ;
2732-
27332747 Plotly . update ( gd , { } , { 'showlegend' : true } ) . then ( function ( ) {
27342748 expect ( subroutines . doLegend ) . toHaveBeenCalledTimes ( 1 ) ;
27352749 expect ( calcdata ) . toBe ( gd . calcdata ) ;
@@ -2738,8 +2752,8 @@ describe('Test plot api', function() {
27382752 . then ( done ) ;
27392753 } ) ;
27402754
2741- it ( 'call layoutReplot when adding update menu' , function ( done ) {
2742- expect ( subroutines . layoutReplot ) . not . toHaveBeenCalled ( ) ;
2755+ it ( 'call array manager when adding update menu' , function ( done ) {
2756+ spyOn ( manageArrays , 'applyContainerArrayChanges' ) . and . callThrough ( ) ;
27432757
27442758 var layoutUpdate = {
27452759 updatemenus : [ {
@@ -2751,16 +2765,15 @@ describe('Test plot api', function() {
27512765 } ;
27522766
27532767 Plotly . update ( gd , { } , layoutUpdate ) . then ( function ( ) {
2754- expect ( subroutines . doLegend ) . toHaveBeenCalledTimes ( 1 ) ;
2768+ expect ( manageArrays . applyContainerArrayChanges ) . toHaveBeenCalledTimes ( 1 ) ;
2769+ expect ( subroutines . layoutReplot ) . toHaveBeenCalledTimes ( 0 ) ;
27552770 expect ( calcdata ) . toBe ( gd . calcdata ) ;
27562771 } )
27572772 . catch ( failTest )
27582773 . then ( done ) ;
27592774 } ) ;
27602775
27612776 it ( 'call doModeBar when updating \'dragmode\'' , function ( done ) {
2762- expect ( subroutines . doModeBar ) . not . toHaveBeenCalled ( ) ;
2763-
27642777 Plotly . update ( gd , { } , { 'dragmode' : 'pan' } ) . then ( function ( ) {
27652778 expect ( subroutines . doModeBar ) . toHaveBeenCalledTimes ( 1 ) ;
27662779 expect ( calcdata ) . toBe ( gd . calcdata ) ;
0 commit comments