Skip to content

Commit 8b41fd6

Browse files
committed
test layout image identity
1 parent e18ffd6 commit 8b41fd6

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

test/jasmine/tests/layout_images_test.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ describe('Layout images', function() {
441441
var data = [{ x: [1, 2, 3], y: [1, 2, 3] }];
442442
var layout = { width: 500, height: 400 };
443443

444+
var imgEls;
445+
444446
function makeImage(source, x, y) {
445447
return {
446448
source: source,
@@ -451,8 +453,21 @@ describe('Layout images', function() {
451453
};
452454
}
453455

454-
function assertImages(cnt) {
456+
function getImageEls() {
457+
return Array.from(gd.querySelectorAll('image'));
458+
}
459+
460+
function assertImages(cnt, expectedEls, msg) {
455461
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+
}
456471
}
457472

458473
Plotly.newPlot(gd, data, layout).then(function() {
@@ -463,42 +478,45 @@ describe('Layout images', function() {
463478
})
464479
.then(function() {
465480
assertImages(1);
481+
imgEls = getImageEls();
466482

467483
return Plotly.relayout(gd, 'images[1]', makeImage(pythonLogo, 0.9, 0.9));
468484
})
469485
.then(function() {
470-
assertImages(2);
486+
assertImages(2, [imgEls[0], null], 'add second image');
487+
imgEls = getImageEls();
471488

472489
// insert an image not at the end of the array
473490
return Plotly.relayout(gd, 'images[0]', makeImage(pythonLogo, 0.2, 0.5));
474491
})
475492
.then(function() {
476-
assertImages(3);
493+
assertImages(3, [null, imgEls[0], imgEls[1]], 'add third at the start');
477494
expect(gd.layout.images.length).toEqual(3);
495+
imgEls = getImageEls();
478496

479497
return Plotly.relayout(gd, 'images[1].visible', false);
480498
})
481499
.then(function() {
482-
assertImages(2);
483-
expect(gd.layout.images.length).toEqual(3);
500+
assertImages(2, [imgEls[0], imgEls[2]], 'hide second');
484501

485502
return Plotly.relayout(gd, 'images[1].visible', true);
486503
})
487504
.then(function() {
488-
assertImages(3);
505+
assertImages(3, [imgEls[0], null, imgEls[2]], 'reshow second');
489506
expect(gd.layout.images.length).toEqual(3);
507+
imgEls = getImageEls();
490508

491509
// delete not from the end of the array
492510
return Plotly.relayout(gd, 'images[0]', null);
493511
})
494512
.then(function() {
495-
assertImages(2);
513+
assertImages(2, [imgEls[1], imgEls[2]], 'delete first');
496514
expect(gd.layout.images.length).toEqual(2);
497515

498516
return Plotly.relayout(gd, 'images[1]', null);
499517
})
500518
.then(function() {
501-
assertImages(1);
519+
assertImages(1, [imgEls[1]], 'delete last');
502520
expect(gd.layout.images.length).toEqual(1);
503521

504522
return Plotly.relayout(gd, 'images[0]', null);

0 commit comments

Comments
 (0)