@@ -968,7 +968,9 @@ describe('finance charts *special* handlers:', function() {
968
968
969
969
afterEach ( destroyGraphDiv ) ;
970
970
971
- it ( '`editable: true` handles should work' , function ( done ) {
971
+ it ( '`editable: true` handlers should work' , function ( done ) {
972
+
973
+ var gd = createGraphDiv ( ) ;
972
974
973
975
function editText ( itemNumber , newText ) {
974
976
var textNode = d3 . selectAll ( 'text.legendtext' )
@@ -981,11 +983,17 @@ describe('finance charts *special* handlers:', function() {
981
983
editNode . textContent = newText ;
982
984
editNode . dispatchEvent ( new window . FocusEvent ( 'focus' ) ) ;
983
985
editNode . dispatchEvent ( new window . FocusEvent ( 'blur' ) ) ;
986
+ }
984
987
985
- editNode . remove ( ) ;
988
+ // makeEditable in svg_text_utils clears the edit <div> in
989
+ // a 0-second transition, so push the resolve call at the back
990
+ // of the rendering queue to make sure the edit <div> is properly
991
+ // cleared after each mocked text edits.
992
+ function delayedResolve ( resolve ) {
993
+ setTimeout ( function ( ) { return resolve ( gd ) ; } , 0 ) ;
986
994
}
987
995
988
- Plotly . plot ( createGraphDiv ( ) , [
996
+ Plotly . plot ( gd , [
989
997
Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ,
990
998
Lib . extendDeep ( { } , mock0 , { type : 'candlestick' } )
991
999
] , { } , {
@@ -996,7 +1004,7 @@ describe('finance charts *special* handlers:', function() {
996
1004
gd . once ( 'plotly_restyle' , function ( eventData ) {
997
1005
expect ( eventData [ 0 ] [ 'increasing.name' ] ) . toEqual ( '0' ) ;
998
1006
expect ( eventData [ 1 ] ) . toEqual ( [ 0 ] ) ;
999
- resolve ( gd ) ;
1007
+ delayedResolve ( resolve ) ;
1000
1008
} ) ;
1001
1009
1002
1010
editText ( 0 , '0' ) ;
@@ -1007,7 +1015,7 @@ describe('finance charts *special* handlers:', function() {
1007
1015
gd . once ( 'plotly_restyle' , function ( eventData ) {
1008
1016
expect ( eventData [ 0 ] [ 'decreasing.name' ] ) . toEqual ( '1' ) ;
1009
1017
expect ( eventData [ 1 ] ) . toEqual ( [ 0 ] ) ;
1010
- resolve ( gd ) ;
1018
+ delayedResolve ( resolve ) ;
1011
1019
} ) ;
1012
1020
1013
1021
editText ( 1 , '1' ) ;
@@ -1018,7 +1026,7 @@ describe('finance charts *special* handlers:', function() {
1018
1026
gd . once ( 'plotly_restyle' , function ( eventData ) {
1019
1027
expect ( eventData [ 0 ] [ 'decreasing.name' ] ) . toEqual ( '2' ) ;
1020
1028
expect ( eventData [ 1 ] ) . toEqual ( [ 1 ] ) ;
1021
- resolve ( gd ) ;
1029
+ delayedResolve ( resolve ) ;
1022
1030
} ) ;
1023
1031
1024
1032
editText ( 3 , '2' ) ;
@@ -1029,7 +1037,7 @@ describe('finance charts *special* handlers:', function() {
1029
1037
gd . once ( 'plotly_restyle' , function ( eventData ) {
1030
1038
expect ( eventData [ 0 ] [ 'increasing.name' ] ) . toEqual ( '3' ) ;
1031
1039
expect ( eventData [ 1 ] ) . toEqual ( [ 1 ] ) ;
1032
- resolve ( gd ) ;
1040
+ delayedResolve ( resolve ) ;
1033
1041
} ) ;
1034
1042
1035
1043
editText ( 2 , '3' ) ;
0 commit comments