Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Fix: Image element should be cleared from progress if uploadId chan…
Browse files Browse the repository at this point in the history
…ged to `null`.
  • Loading branch information
scofalik committed Apr 4, 2018
1 parent 9f2dd28 commit e736849
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/imageupload/imageuploadprogress.js
Expand Up @@ -60,12 +60,12 @@ export default class ImageUploadProgress extends Plugin {
const modelImage = data.item;
const uploadId = modelImage.getAttribute( 'uploadId' );

if ( !conversionApi.consumable.consume( data.item, evt.name ) || !uploadId ) {
if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
return;
}

const fileRepository = editor.plugins.get( FileRepository );
const status = data.attributeNewValue;
const status = uploadId ? data.attributeNewValue : null;
const placeholder = this.placeholder;
const viewFigure = editor.editing.mapper.toViewElement( modelImage );
const viewWriter = conversionApi.writer;
Expand Down
22 changes: 22 additions & 0 deletions tests/imageupload/imageuploadprogress.js
Expand Up @@ -137,6 +137,28 @@ describe( 'ImageUploadProgress', () => {
);
} );

it( 'should "clear" image when uploadId changes to null', () => {
setModelData( model, '<image></image>' );
const image = document.getRoot().getChild( 0 );

// Set attributes directly on image to simulate instant "uploading" status.
model.change( writer => {
writer.setAttribute( 'uploadStatus', 'uploading', image );
writer.setAttribute( 'uploadId', '12345', image );
} );

model.change( writer => {
writer.setAttribute( 'uploadStatus', null, image );
writer.setAttribute( 'uploadId', null, image );
} );

expect( getViewData( view ) ).to.equal(
'[<figure class="ck ck-widget image" contenteditable="false">' +
`<img src="data:image/svg+xml;utf8,${ imagePlaceholder }"></img>` +
'</figure>]'
);
} );

it( 'should update progressbar width on progress', done => {
setModelData( model, '<paragraph>[]foo</paragraph>' );
editor.execute( 'imageUpload', { file: createNativeFileMock() } );
Expand Down

0 comments on commit e736849

Please sign in to comment.