@@ -2,6 +2,7 @@ var Lib = require('@src/lib');
22var setCursor = require ( '@src/lib/setcursor' ) ;
33
44var d3 = require ( 'd3' ) ;
5+ var Plotly = require ( '@lib' ) ;
56var PlotlyInternal = require ( '@src/plotly' ) ;
67var createGraphDiv = require ( '../assets/create_graph_div' ) ;
78var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -1042,3 +1043,73 @@ describe('Test lib.js:', function() {
10421043 } ) ;
10431044 } ) ;
10441045} ) ;
1046+
1047+ describe ( 'Queue' , function ( ) {
1048+ 'use strict' ;
1049+
1050+ var gd ;
1051+
1052+ beforeEach ( function ( ) {
1053+ gd = createGraphDiv ( ) ;
1054+ } ) ;
1055+
1056+ afterEach ( function ( ) {
1057+ destroyGraphDiv ( ) ;
1058+ Plotly . setPlotConfig ( { queueLength : 0 } ) ;
1059+ } ) ;
1060+
1061+ it ( 'should not fill in undoQueue by default' , function ( done ) {
1062+ Plotly . plot ( gd , [ {
1063+ y : [ 2 , 1 , 2 ]
1064+ } ] ) . then ( function ( ) {
1065+ expect ( gd . undoQueue ) . toBeUndefined ( ) ;
1066+
1067+ return Plotly . restyle ( gd , 'marker.color' , 'red' ) ;
1068+ } ) . then ( function ( ) {
1069+ expect ( gd . undoQueue . index ) . toEqual ( 0 ) ;
1070+ expect ( gd . undoQueue . queue ) . toEqual ( [ ] ) ;
1071+
1072+ return Plotly . relayout ( gd , 'title' , 'A title' ) ;
1073+ } ) . then ( function ( ) {
1074+ expect ( gd . undoQueue . index ) . toEqual ( 0 ) ;
1075+ expect ( gd . undoQueue . queue ) . toEqual ( [ ] ) ;
1076+
1077+ done ( ) ;
1078+ } ) ;
1079+ } ) ;
1080+
1081+ it ( 'should fill in undoQueue up to value found in *queueLength* config' , function ( done ) {
1082+ Plotly . setPlotConfig ( { queueLength : 2 } ) ;
1083+
1084+ Plotly . plot ( gd , [ {
1085+ y : [ 2 , 1 , 2 ]
1086+ } ] ) . then ( function ( ) {
1087+ expect ( gd . undoQueue ) . toBeUndefined ( ) ;
1088+
1089+ return Plotly . restyle ( gd , 'marker.color' , 'red' ) ;
1090+ } ) . then ( function ( ) {
1091+ expect ( gd . undoQueue . index ) . toEqual ( 1 ) ;
1092+ expect ( gd . undoQueue . queue [ 0 ] . undo . args [ 0 ] [ 1 ] [ 'marker.color' ] ) . toEqual ( [ undefined ] ) ;
1093+ expect ( gd . undoQueue . queue [ 0 ] . redo . args [ 0 ] [ 1 ] [ 'marker.color' ] ) . toEqual ( 'red' ) ;
1094+
1095+ return Plotly . relayout ( gd , 'title' , 'A title' ) ;
1096+ } ) . then ( function ( ) {
1097+ expect ( gd . undoQueue . index ) . toEqual ( 2 ) ;
1098+ expect ( gd . undoQueue . queue [ 1 ] . undo . args [ 0 ] [ 1 ] . title ) . toEqual ( undefined ) ;
1099+ expect ( gd . undoQueue . queue [ 1 ] . redo . args [ 0 ] [ 1 ] . title ) . toEqual ( 'A title' ) ;
1100+
1101+ return Plotly . restyle ( gd , 'mode' , 'markers' ) ;
1102+ } ) . then ( function ( ) {
1103+ expect ( gd . undoQueue . index ) . toEqual ( 2 ) ;
1104+ expect ( gd . undoQueue . queue [ 2 ] ) . toBeUndefined ( ) ;
1105+
1106+ expect ( gd . undoQueue . queue [ 1 ] . undo . args [ 0 ] [ 1 ] . mode ) . toEqual ( [ undefined ] ) ;
1107+ expect ( gd . undoQueue . queue [ 1 ] . redo . args [ 0 ] [ 1 ] . mode ) . toEqual ( 'markers' ) ;
1108+
1109+ expect ( gd . undoQueue . queue [ 0 ] . undo . args [ 0 ] [ 1 ] . title ) . toEqual ( undefined ) ;
1110+ expect ( gd . undoQueue . queue [ 0 ] . redo . args [ 0 ] [ 1 ] . title ) . toEqual ( 'A title' ) ;
1111+
1112+ done ( ) ;
1113+ } ) ;
1114+ } ) ;
1115+ } ) ;
0 commit comments