Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/jasmine/tests/layout_images_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var mouseEvent = require('../assets/mouse_event');
var jsLogo = 'https://images.plot.ly/language-icons/api-home/js-logo.png';
var pythonLogo = 'https://images.plot.ly/language-icons/api-home/python-logo.png';

// Single red pixel png generated with http://png-pixel.com/
var dataUriImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfF' +
'cSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==';

describe('Layout images', function() {
describe('supplyLayoutDefaults', function() {
var layoutIn,
Expand Down Expand Up @@ -290,6 +294,31 @@ describe('Layout images', function() {

afterEach(destroyGraphDiv);

it('should only create canvas if url image', function(done) {
var originalCreateElement = document.createElement;
var newCanvasElement;
spyOn(document, 'createElement').and.callFake(function(elementType) {
var element = originalCreateElement.call(document, elementType);
if(elementType === 'canvas') {
newCanvasElement = element;
spyOn(newCanvasElement, 'toDataURL');
}
return element;
});

Plotly.relayout(gd, 'images[0].source', dataUriImage).then(function() {
setTimeout(function() {
expect(newCanvasElement).toBeUndefined();
Plotly.relayout(gd, 'images[0].source', pythonLogo).then(function() {
expect(newCanvasElement).eventually.toBeDefined();
expect(newCanvasElement.toDataURL).toHaveBeenCalledTimes(1);
});

done();
}, 500);
});
});

it('should update the image if changed', function(done) {
var img = Plotly.d3.select('image');
var url = img.attr('xlink:href');
Expand Down