@@ -9,6 +9,7 @@ var Legend = require('@src/components/legend');
9
9
var Axes = require ( '@src/plots/cartesian/axes' ) ;
10
10
var pkg = require ( '../../../package.json' ) ;
11
11
var subroutines = require ( '@src/plot_api/subroutines' ) ;
12
+ var manageArrays = require ( '@src/plot_api/manage_arrays' ) ;
12
13
var helpers = require ( '@src/plot_api/helpers' ) ;
13
14
var editTypes = require ( '@src/plot_api/edit_types' ) ;
14
15
@@ -2649,16 +2650,29 @@ describe('Test plot api', function() {
2649
2650
it ( 'should only have one modebar-container' , function ( done ) {
2650
2651
var data = [ { y : [ 1 , 2 ] } ] ;
2651
2652
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
+ }
2655
2661
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
+ } ) ;
2661
2674
} )
2675
+ . then ( _assert ( 'after update()' ) )
2662
2676
. catch ( failTest )
2663
2677
. then ( done ) ;
2664
2678
} ) ;
@@ -2674,6 +2688,10 @@ describe('Test plot api', function() {
2674
2688
} ) ;
2675
2689
2676
2690
beforeEach ( function ( done ) {
2691
+ Object . keys ( subroutines ) . forEach ( function ( k ) {
2692
+ subroutines [ k ] . calls . reset ( ) ;
2693
+ } ) ;
2694
+
2677
2695
gd = createGraphDiv ( ) ;
2678
2696
Plotly . plot ( gd , [ { y : [ 2 , 1 , 2 ] } ] ) . then ( function ( ) {
2679
2697
data = gd . data ;
@@ -2687,8 +2705,6 @@ describe('Test plot api', function() {
2687
2705
afterEach ( destroyGraphDiv ) ;
2688
2706
2689
2707
it ( 'call doTraceStyle on trace style updates' , function ( done ) {
2690
- expect ( subroutines . doTraceStyle ) . not . toHaveBeenCalled ( ) ;
2691
-
2692
2708
Plotly . update ( gd , { 'marker.color' : 'blue' } ) . then ( function ( ) {
2693
2709
expect ( subroutines . doTraceStyle ) . toHaveBeenCalledTimes ( 1 ) ;
2694
2710
expect ( calcdata ) . toBe ( gd . calcdata ) ;
@@ -2720,16 +2736,14 @@ describe('Test plot api', function() {
2720
2736
expect ( data ) . toBe ( gd . data ) ;
2721
2737
expect ( layout ) . toBe ( gd . layout ) ;
2722
2738
expect ( calcdata ) . not . toBe ( gd . calcdata ) ;
2723
-
2724
2739
expect ( gd . data . length ) . toEqual ( 1 ) ;
2740
+ expect ( subroutines . layoutReplot ) . toHaveBeenCalledTimes ( 1 ) ;
2725
2741
} )
2726
2742
. catch ( failTest )
2727
2743
. then ( done ) ;
2728
2744
} ) ;
2729
2745
2730
2746
it ( 'call doLegend on legend updates' , function ( done ) {
2731
- expect ( subroutines . doLegend ) . not . toHaveBeenCalled ( ) ;
2732
-
2733
2747
Plotly . update ( gd , { } , { 'showlegend' : true } ) . then ( function ( ) {
2734
2748
expect ( subroutines . doLegend ) . toHaveBeenCalledTimes ( 1 ) ;
2735
2749
expect ( calcdata ) . toBe ( gd . calcdata ) ;
@@ -2738,8 +2752,8 @@ describe('Test plot api', function() {
2738
2752
. then ( done ) ;
2739
2753
} ) ;
2740
2754
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 ( ) ;
2743
2757
2744
2758
var layoutUpdate = {
2745
2759
updatemenus : [ {
@@ -2751,16 +2765,15 @@ describe('Test plot api', function() {
2751
2765
} ;
2752
2766
2753
2767
Plotly . update ( gd , { } , layoutUpdate ) . then ( function ( ) {
2754
- expect ( subroutines . doLegend ) . toHaveBeenCalledTimes ( 1 ) ;
2768
+ expect ( manageArrays . applyContainerArrayChanges ) . toHaveBeenCalledTimes ( 1 ) ;
2769
+ expect ( subroutines . layoutReplot ) . toHaveBeenCalledTimes ( 0 ) ;
2755
2770
expect ( calcdata ) . toBe ( gd . calcdata ) ;
2756
2771
} )
2757
2772
. catch ( failTest )
2758
2773
. then ( done ) ;
2759
2774
} ) ;
2760
2775
2761
2776
it ( 'call doModeBar when updating \'dragmode\'' , function ( done ) {
2762
- expect ( subroutines . doModeBar ) . not . toHaveBeenCalled ( ) ;
2763
-
2764
2777
Plotly . update ( gd , { } , { 'dragmode' : 'pan' } ) . then ( function ( ) {
2765
2778
expect ( subroutines . doModeBar ) . toHaveBeenCalledTimes ( 1 ) ;
2766
2779
expect ( calcdata ) . toBe ( gd . calcdata ) ;
0 commit comments