@@ -6,6 +6,7 @@ var Scatter = require('@src/traces/scatter');
66var Bar = require ( '@src/traces/bar' ) ;
77var Legend = require ( '@src/components/legend' ) ;
88var pkg = require ( '../../../package.json' ) ;
9+ var subroutines = require ( '@src/plot_api/subroutines' ) ;
910
1011var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1112var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -879,4 +880,80 @@ describe('Test plot api', function() {
879880 expect ( gd . data [ 1 ] . contours ) . toBeUndefined ( ) ;
880881 } ) ;
881882 } ) ;
883+
884+ describe ( 'Plotly.update should' , function ( ) {
885+ var gd , calcdata ;
886+
887+ beforeAll ( function ( ) {
888+ Object . keys ( subroutines ) . forEach ( function ( k ) {
889+ spyOn ( subroutines , k ) . and . callThrough ( ) ;
890+ } ) ;
891+ } ) ;
892+
893+ beforeEach ( function ( done ) {
894+ gd = createGraphDiv ( ) ;
895+ Plotly . plot ( gd , [ { y : [ 2 , 1 , 2 ] } ] ) . then ( function ( ) {
896+ calcdata = gd . calcdata ;
897+ done ( ) ;
898+ } ) ;
899+ } ) ;
900+
901+ afterEach ( destroyGraphDiv ) ;
902+
903+ it ( 'call doTraceStyle on trace style updates' , function ( done ) {
904+ expect ( subroutines . doTraceStyle ) . not . toHaveBeenCalled ( ) ;
905+
906+ Plotly . update ( gd , { 'marker.color' : 'blue' } ) . then ( function ( ) {
907+ expect ( subroutines . doTraceStyle ) . toHaveBeenCalledTimes ( 1 ) ;
908+ expect ( calcdata ) . toBe ( gd . calcdata ) ;
909+ done ( ) ;
910+ } ) ;
911+ } ) ;
912+
913+ it ( 'clear calcdata on data updates' , function ( done ) {
914+ Plotly . update ( gd , { x : [ [ 3 , 1 , 3 ] ] } ) . then ( function ( ) {
915+ expect ( calcdata ) . not . toBe ( gd . calcdata ) ;
916+ done ( ) ;
917+ } ) ;
918+ } ) ;
919+
920+ it ( 'call doLegend on legend updates' , function ( done ) {
921+ expect ( subroutines . doLegend ) . not . toHaveBeenCalled ( ) ;
922+
923+ Plotly . update ( gd , { } , { 'showlegend' : true } ) . then ( function ( ) {
924+ expect ( subroutines . doLegend ) . toHaveBeenCalledTimes ( 1 ) ;
925+ expect ( calcdata ) . toBe ( gd . calcdata ) ;
926+ done ( ) ;
927+ } ) ;
928+ } ) ;
929+
930+ it ( 'call layoutReplot when adding update menu' , function ( done ) {
931+ expect ( subroutines . layoutReplot ) . not . toHaveBeenCalled ( ) ;
932+
933+ var layoutUpdate = {
934+ updatemenus : [ {
935+ buttons : [ {
936+ method : 'relayout' ,
937+ args : [ 'title' , 'Hello World' ]
938+ } ]
939+ } ]
940+ } ;
941+
942+ Plotly . update ( gd , { } , layoutUpdate ) . then ( function ( ) {
943+ expect ( subroutines . doLegend ) . toHaveBeenCalledTimes ( 1 ) ;
944+ expect ( calcdata ) . toBe ( gd . calcdata ) ;
945+ done ( ) ;
946+ } ) ;
947+ } ) ;
948+
949+ it ( 'call doModeBar when updating \'dragmode\'' , function ( done ) {
950+ expect ( subroutines . doModeBar ) . not . toHaveBeenCalled ( ) ;
951+
952+ Plotly . update ( gd , { } , { 'dragmode' : 'pan' } ) . then ( function ( ) {
953+ expect ( subroutines . doModeBar ) . toHaveBeenCalledTimes ( 1 ) ;
954+ expect ( calcdata ) . toBe ( gd . calcdata ) ;
955+ done ( ) ;
956+ } ) ;
957+ } ) ;
958+ } ) ;
882959} ) ;
0 commit comments