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

Restored a part of code and added a test for it #108

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions src/filerepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ class FileLoader {
return this.file
.then( file => this._reader.read( file ) )
.then( data => {
// Edge case: reader was aborted after file was read - double check for proper status.
// It can happen when image was deleted during its upload.
if ( this.status !== 'reading' ) {
throw this.status;
}

this.status = 'idle';

return data;
Expand Down
24 changes: 24 additions & 0 deletions tests/filerepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,30 @@ describe( 'FileRepository', () => {

return promise;
} );

it( 'should abort upload if image is removed during the upload process', () => {
const file = createNativeFileMock();
const loader = fileRepository.createLoader( file );

sinon.stub( loader._reader, 'read' ).callsFake( () => {
expect( loader.status ).to.equal( 'reading' );

// Reader is being aborted after file was read.
// It can happen if an element (and its file that is being uploaded) will be removed during the upload process.
loader.status = 'aborted';
} );

return loader.read()
.then(
() => {
throw new Error( 'Supposed to be rejected.' );
},
status => {
expect( status ).to.equal( 'aborted' );
expect( loader.status ).to.equal( 'aborted' );
}
);
} );
} );

describe( 'upload()', () => {
Expand Down