@@ -37,6 +37,44 @@ describe('Test frame api', function() {
3737 } ) ;
3838
3939 describe ( '#addFrames' , function ( ) {
40+
41+ it ( 'issues a warning if a number-named frame would overwrite a frame' , function ( done ) {
42+ var warnings = [ ] ;
43+ spyOn ( Lib , 'warn' ) . and . callFake ( function ( msg ) {
44+ warnings . push ( msg ) ;
45+ } ) ;
46+
47+ // Test with both multiframe additions and repeated `addFrames` calls - both should count toward the warn limit
48+ Plotly . addFrames ( gd , [
49+ { name : 8 , data : [ { x : [ 8 , 7 , 6 ] } ] } ,
50+ { name : 8888 , data : [ { x : [ 8 , 7 , 6 ] } ] } ,
51+ { name : 8 , data : [ { x : [ 8 , 7 , 6 ] } ] } ,
52+ { name : '8' , data : [ { x : [ 8 , 7 , 6 ] } ] }
53+ ] )
54+ . then ( function ( ) {
55+ // so far, two warnings
56+ expect ( Lib . warn . calls . count ( ) ) . toEqual ( 2 ) ;
57+ expect ( warnings [ 0 ] ) . toMatch ( / ^ a d d F r a m e s .* o v e r w r i t i n g / ) ;
58+ return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ;
59+ } )
60+ . then ( function ( ) { return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ; } )
61+ . then ( function ( ) { return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ; } )
62+ . then ( function ( ) {
63+ // so far, 5 + 1 warnings
64+ expect ( Lib . warn . calls . count ( ) ) . toEqual ( 5 + 1 ) ;
65+ expect ( warnings [ 5 ] ) . toMatch ( / ^ a d d F r a m e s .* s u p p r e s s e d / ) ;
66+ return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ;
67+ } )
68+ . then ( function ( ) { return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ; } )
69+ . then ( function ( ) { return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ; } )
70+ . then ( function ( ) { return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ; } )
71+ . then ( function ( ) { return Plotly . addFrames ( gd , [ { name : 8 , data : [ { x : [ 3 , 2 , 1 ] } ] } ] ) ; } )
72+ . then ( function ( ) {
73+ // Five (`var numericNameWarningCountLimit = 5`) warnings and one warning saying that there won't be more warnings
74+ expect ( Lib . warn . calls . count ( ) ) . toEqual ( 5 + 1 ) ;
75+ } ) . catch ( fail ) . then ( done ) ;
76+ } ) ;
77+
4078 it ( 'treats an undefined list as a noop' , function ( done ) {
4179 Plotly . addFrames ( gd , undefined ) . then ( function ( ) {
4280 expect ( Object . keys ( h ) ) . toEqual ( [ ] ) ;
@@ -102,20 +140,6 @@ describe('Test frame api', function() {
102140 } ) . catch ( fail ) . then ( done ) ;
103141 } ) ;
104142
105- it ( 'issues a warning if a number-named frame would overwrite a frame' , function ( done ) {
106- var warnings = [ ] ;
107- spyOn ( Lib , 'warn' ) . and . callFake ( function ( msg ) {
108- warnings . push ( msg ) ;
109- } ) ;
110-
111- Plotly . addFrames ( gd , [ { name : 2 } ] ) . then ( function ( ) {
112- return Plotly . addFrames ( gd , [ { name : 2 , layout : { foo : 'bar' } } ] ) ;
113- } ) . then ( function ( ) {
114- expect ( warnings . length ) . toEqual ( 1 ) ;
115- expect ( warnings [ 0 ] ) . toMatch ( / o v e r w r i t i n g / ) ;
116- } ) . catch ( fail ) . then ( done ) ;
117- } ) ;
118-
119143 it ( 'avoids name collisions' , function ( done ) {
120144 Plotly . addFrames ( gd , [ { name : 'frame 0' } , { name : 'frame 2' } ] ) . then ( function ( ) {
121145 expect ( f ) . toEqual ( [ { name : 'frame 0' } , { name : 'frame 2' } ] ) ;
0 commit comments