@@ -526,38 +526,36 @@ describe('Test colorbar:', function() {
526
526
} ) ;
527
527
528
528
it ( 'creates the same colorbars attributes in newPlot and react' , function ( done ) {
529
- var z = [ [ 1 , 10 ] , [ 100 , 1000 ] ] ;
530
-
531
- var expectedAttrs = [ ] ;
532
- var actualAttrs = [ ] ;
533
-
534
- Plotly . newPlot ( gd , [ { type : 'contour' , z : z } ] )
535
- . then ( function ( ) {
529
+ function getCBFillAttributes ( ) {
530
+ var attrs = [ ] ;
536
531
var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
537
532
colorbars . selectAll ( '.cbfill' ) . each ( function ( ) {
538
533
var attrsForElem = { } ;
539
534
for ( var i = 0 ; i < this . attributes . length ; i ++ ) {
540
535
var attr = this . attributes . item ( i ) ;
541
536
attrsForElem [ attr . name ] = attr . value ;
542
537
}
543
- expectedAttrs . push ( attrsForElem ) ;
538
+ attrs . push ( attrsForElem ) ;
544
539
} ) ;
540
+ return attrs ;
541
+ }
542
+
543
+ var z = [ [ 1 , 10 ] , [ 100 , 1000 ] ] ;
544
+
545
+ var expectedAttrs ;
546
+ var actualAttrs ;
547
+
548
+ Plotly . newPlot ( gd , [ { type : 'contour' , z : z } ] )
549
+ . then ( function ( ) {
550
+ expectedAttrs = getCBFillAttributes ( ) ;
545
551
546
552
return Plotly . newPlot ( gd , [ { type : 'heatmap' , z : z } ] )
547
553
. then ( function ( ) {
548
554
return Plotly . react ( gd , [ { type : 'contour' , z : z } ] ) ;
549
555
} ) ;
550
556
} )
551
557
. then ( function ( ) {
552
- var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
553
- colorbars . selectAll ( '.cbfill' ) . each ( function ( ) {
554
- var attrsForElem = { } ;
555
- for ( var i = 0 ; i < this . attributes . length ; i ++ ) {
556
- var attr = this . attributes . item ( i ) ;
557
- attrsForElem [ attr . name ] = attr . value ;
558
- }
559
- actualAttrs . push ( attrsForElem ) ;
560
- } ) ;
558
+ actualAttrs = getCBFillAttributes ( ) ;
561
559
expect ( actualAttrs ) . toEqual ( expectedAttrs ) ;
562
560
} )
563
561
. catch ( failTest )
0 commit comments