@@ -539,6 +539,7 @@ describe('Test plot api', function() {
539
539
540
540
supplyAllDefaults ( gd ) ;
541
541
Plots . doCalcdata ( gd ) ;
542
+ gd . emit = function ( ) { } ;
542
543
return gd ;
543
544
}
544
545
@@ -699,6 +700,7 @@ describe('Test plot api', function() {
699
700
gd . calcdata = gd . _fullData . map ( function ( trace ) {
700
701
return [ { x : 1 , y : 1 , trace : trace } ] ;
701
702
} ) ;
703
+ gd . emit = function ( ) { } ;
702
704
}
703
705
704
706
it ( 'calls Scatter.arraysToCalcdata and Plots.style on scatter styling' , function ( ) {
@@ -2566,11 +2568,14 @@ describe('Test plot api', function() {
2566
2568
] ;
2567
2569
2568
2570
var gd ;
2569
- var plotCalls ;
2571
+ var afterPlotCnt ;
2570
2572
2571
2573
beforeEach ( function ( ) {
2572
2574
gd = createGraphDiv ( ) ;
2573
2575
2576
+ spyOn ( plotApi , 'plot' ) . and . callThrough ( ) ;
2577
+ spyOn ( Registry , 'call' ) . and . callThrough ( ) ;
2578
+
2574
2579
mockedMethods . forEach ( function ( m ) {
2575
2580
spyOn ( subroutines , m ) . and . callThrough ( ) ;
2576
2581
subroutines [ m ] . calls . reset ( ) ;
@@ -2584,13 +2589,14 @@ describe('Test plot api', function() {
2584
2589
afterEach ( destroyGraphDiv ) ;
2585
2590
2586
2591
function countPlots ( ) {
2587
- plotCalls = 0 ;
2588
-
2589
- gd . on ( 'plotly_afterplot' , function ( ) { plotCalls ++ ; } ) ;
2592
+ plotApi . plot . calls . reset ( ) ;
2590
2593
subroutines . layoutStyles . calls . reset ( ) ;
2591
2594
annotations . draw . calls . reset ( ) ;
2592
2595
annotations . drawOne . calls . reset ( ) ;
2593
2596
images . draw . calls . reset ( ) ;
2597
+
2598
+ afterPlotCnt = 0 ;
2599
+ gd . on ( 'plotly_afterplot' , function ( ) { afterPlotCnt ++ ; } ) ;
2594
2600
}
2595
2601
2596
2602
function countCalls ( counts ) {
@@ -2602,8 +2608,14 @@ describe('Test plot api', function() {
2602
2608
subroutines [ m ] . calls . reset ( ) ;
2603
2609
} ) ;
2604
2610
2605
- expect ( plotCalls ) . toBe ( counts . plot || 0 , 'calls to Plotly.plot' ) ;
2606
- plotCalls = 0 ;
2611
+ // calls to Plotly.plot via plot_api.js or Registry.call('plot')
2612
+ var plotCalls = plotApi . plot . calls . count ( ) +
2613
+ Registry . call . calls . all ( )
2614
+ . filter ( function ( d ) { return d . args [ 0 ] === 'plot' ; } )
2615
+ . length ;
2616
+ expect ( plotCalls ) . toBe ( counts . plot || 0 , 'Plotly.plot calls' ) ;
2617
+ plotApi . plot . calls . reset ( ) ;
2618
+ Registry . call . calls . reset ( ) ;
2607
2619
2608
2620
// only consider annotation and image draw calls if we *don't* do a full plot.
2609
2621
if ( ! counts . plot ) {
@@ -2614,6 +2626,9 @@ describe('Test plot api', function() {
2614
2626
annotations . draw . calls . reset ( ) ;
2615
2627
annotations . drawOne . calls . reset ( ) ;
2616
2628
images . draw . calls . reset ( ) ;
2629
+
2630
+ expect ( afterPlotCnt ) . toBe ( 1 , 'plotly_afterplot should be called only once per edit' ) ;
2631
+ afterPlotCnt = 0 ;
2617
2632
}
2618
2633
2619
2634
it ( 'can add / remove traces' , function ( done ) {
@@ -2654,14 +2669,14 @@ describe('Test plot api', function() {
2654
2669
. then ( function ( ) {
2655
2670
// didn't pick it up, as we modified in place!!!
2656
2671
expect ( d3 . selectAll ( '.point' ) . size ( ) ) . toBe ( 3 ) ;
2672
+ countCalls ( { plot : 0 } ) ;
2657
2673
2658
2674
data [ 0 ] . y = [ 1 , 2 , 3 , 4 , 5 ] ;
2659
2675
return Plotly . react ( gd , data , layout ) ;
2660
2676
} )
2661
2677
. then ( function ( ) {
2662
2678
// new object, we picked it up!
2663
2679
expect ( d3 . selectAll ( '.point' ) . size ( ) ) . toBe ( 5 ) ;
2664
-
2665
2680
countCalls ( { plot : 1 } ) ;
2666
2681
} )
2667
2682
. catch ( failTest )
@@ -2683,6 +2698,7 @@ describe('Test plot api', function() {
2683
2698
. then ( function ( ) {
2684
2699
// didn't pick it up, as we didn't modify datarevision
2685
2700
expect ( d3 . selectAll ( '.point' ) . size ( ) ) . toBe ( 3 ) ;
2701
+ countCalls ( { plot : 0 } ) ;
2686
2702
2687
2703
data [ 0 ] . y . push ( 5 ) ;
2688
2704
layout . datarevision = 'bananas' ;
@@ -2869,7 +2885,7 @@ describe('Test plot api', function() {
2869
2885
sizex : 1 ,
2870
2886
sizey : 1
2871
2887
} ] ;
2872
- Plotly . react ( gd , data , layout ) ;
2888
+ return Plotly . react ( gd , data , layout ) ;
2873
2889
} )
2874
2890
. then ( function ( ) {
2875
2891
countCalls ( { imageDraw : 1 } ) ;
@@ -2883,7 +2899,7 @@ describe('Test plot api', function() {
2883
2899
2884
2900
layout . images [ 0 ] . y = 0.8 ;
2885
2901
layout . images [ 0 ] . sizey = 0.4 ;
2886
- Plotly . react ( gd , data , layout ) ;
2902
+ return Plotly . react ( gd , data , layout ) ;
2887
2903
} )
2888
2904
. then ( function ( ) {
2889
2905
countCalls ( { imageDraw : 1 } ) ;
0 commit comments