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

Commit

Permalink
Merge pull request #201 from ckeditor/t/200
Browse files Browse the repository at this point in the history
Fix: Image element will be cleared from upload progress classes if `uploadId` attribute changed to `null`. Closes #200.
  • Loading branch information
Piotr Jasiun authored Apr 4, 2018
2 parents 9f2dd28 + e736849 commit 5fadcf0
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 5fadcf0

Please sign in to comment.