@@ -441,6 +441,8 @@ describe('Layout images', function() {
441
441
var data = [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] ;
442
442
var layout = { width : 500 , height : 400 } ;
443
443
444
+ var imgEls ;
445
+
444
446
function makeImage ( source , x , y ) {
445
447
return {
446
448
source : source ,
@@ -451,8 +453,21 @@ describe('Layout images', function() {
451
453
} ;
452
454
}
453
455
454
- function assertImages ( cnt ) {
456
+ function getImageEls ( ) {
457
+ return Array . from ( gd . querySelectorAll ( 'image' ) ) ;
458
+ }
459
+
460
+ function assertImages ( cnt , expectedEls , msg ) {
455
461
expect ( d3SelectAll ( 'image' ) . size ( ) ) . toEqual ( cnt ) ;
462
+
463
+ if ( expectedEls ) {
464
+ var foundImageEls = getImageEls ( ) ;
465
+ expectedEls . forEach ( function ( expi , i ) {
466
+ if ( expi ) {
467
+ expect ( foundImageEls [ i ] ) . toBe ( expi , msg + ': ' + i ) ;
468
+ }
469
+ } ) ;
470
+ }
456
471
}
457
472
458
473
Plotly . newPlot ( gd , data , layout ) . then ( function ( ) {
@@ -463,42 +478,45 @@ describe('Layout images', function() {
463
478
} )
464
479
. then ( function ( ) {
465
480
assertImages ( 1 ) ;
481
+ imgEls = getImageEls ( ) ;
466
482
467
483
return Plotly . relayout ( gd , 'images[1]' , makeImage ( pythonLogo , 0.9 , 0.9 ) ) ;
468
484
} )
469
485
. then ( function ( ) {
470
- assertImages ( 2 ) ;
486
+ assertImages ( 2 , [ imgEls [ 0 ] , null ] , 'add second image' ) ;
487
+ imgEls = getImageEls ( ) ;
471
488
472
489
// insert an image not at the end of the array
473
490
return Plotly . relayout ( gd , 'images[0]' , makeImage ( pythonLogo , 0.2 , 0.5 ) ) ;
474
491
} )
475
492
. then ( function ( ) {
476
- assertImages ( 3 ) ;
493
+ assertImages ( 3 , [ null , imgEls [ 0 ] , imgEls [ 1 ] ] , 'add third at the start' ) ;
477
494
expect ( gd . layout . images . length ) . toEqual ( 3 ) ;
495
+ imgEls = getImageEls ( ) ;
478
496
479
497
return Plotly . relayout ( gd , 'images[1].visible' , false ) ;
480
498
} )
481
499
. then ( function ( ) {
482
- assertImages ( 2 ) ;
483
- expect ( gd . layout . images . length ) . toEqual ( 3 ) ;
500
+ assertImages ( 2 , [ imgEls [ 0 ] , imgEls [ 2 ] ] , 'hide second' ) ;
484
501
485
502
return Plotly . relayout ( gd , 'images[1].visible' , true ) ;
486
503
} )
487
504
. then ( function ( ) {
488
- assertImages ( 3 ) ;
505
+ assertImages ( 3 , [ imgEls [ 0 ] , null , imgEls [ 2 ] ] , 'reshow second' ) ;
489
506
expect ( gd . layout . images . length ) . toEqual ( 3 ) ;
507
+ imgEls = getImageEls ( ) ;
490
508
491
509
// delete not from the end of the array
492
510
return Plotly . relayout ( gd , 'images[0]' , null ) ;
493
511
} )
494
512
. then ( function ( ) {
495
- assertImages ( 2 ) ;
513
+ assertImages ( 2 , [ imgEls [ 1 ] , imgEls [ 2 ] ] , 'delete first' ) ;
496
514
expect ( gd . layout . images . length ) . toEqual ( 2 ) ;
497
515
498
516
return Plotly . relayout ( gd , 'images[1]' , null ) ;
499
517
} )
500
518
. then ( function ( ) {
501
- assertImages ( 1 ) ;
519
+ assertImages ( 1 , [ imgEls [ 1 ] ] , 'delete last' ) ;
502
520
expect ( gd . layout . images . length ) . toEqual ( 1 ) ;
503
521
504
522
return Plotly . relayout ( gd , 'images[0]' , null ) ;
0 commit comments