Skip to content

Commit

Permalink
Prevent showing an alert() with event object
Browse files Browse the repository at this point in the history
  • Loading branch information
psmyrek committed Jan 12, 2021
1 parent ac23816 commit 402e793
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ckeditor5-image/src/imageupload/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function getBlobFromCanvas( imageSrc ) {
canvas.toBlob( blob => blob ? resolve( blob ) : reject() );
} );

image.addEventListener( 'error', reject );
image.addEventListener( 'error', () => reject() );

image.src = imageSrc;
} );
Expand Down
31 changes: 30 additions & 1 deletion packages/ckeditor5-image/tests/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ describe( 'ImageUploadEditing', () => {
} );
} );

it( 'should not upload and remove image if canvas convertion failed', done => {
it( 'should not upload and remove image if canvas conversion failed', done => {
setModelData( model, '<paragraph>[]foo</paragraph>' );

const clipboardHtml = `<img src=${ base64Sample } />`;
Expand Down Expand Up @@ -1020,6 +1020,35 @@ describe( 'ImageUploadEditing', () => {
false
);
} );

it( 'should not show notification when image could not be loaded', done => {
const spy = sinon.spy();
const notification = editor.plugins.get( Notification );

notification.on( 'show:warning', evt => {
spy();
evt.stop();
}, { priority: 'high' } );

setModelData( model, '<paragraph>[]foo</paragraph>' );

const clipboardHtml = '<img src=data:image/png;base64,INVALID-DATA />';
const dataTransfer = mockDataTransfer( clipboardHtml );

const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );

adapterMocks[ 0 ].loader.file.then( () => {
expect.fail( 'Promise should be rejected.' );
} ).catch( () => {
setTimeout( () => {
sinon.assert.notCalled( spy );
done();
} );
} );
} );
} );

// Helper for validating clipboard and model data as a result of a paste operation. This function checks both clipboard
Expand Down

0 comments on commit 402e793

Please sign in to comment.