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

Commit

Permalink
Merge c792768 into 2f61c00
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Jan 4, 2019
2 parents 2f61c00 + c792768 commit e812ec8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/cloudservicesuploadadapter.js
Expand Up @@ -64,14 +64,16 @@ class Adapter {
}

upload() {
this.fileUploader = this.uploadGateway.upload( this.loader.file );
return this.loader.file.then( file => {
this.fileUploader = this.uploadGateway.upload( file );

this.fileUploader.on( 'progress', ( evt, data ) => {
this.loader.uploadTotal = data.total;
this.loader.uploaded = data.uploaded;
} );
this.fileUploader.on( 'progress', ( evt, data ) => {
this.loader.uploadTotal = data.total;
this.loader.uploaded = data.uploaded;
} );

return this.fileUploader.send();
return this.fileUploader.send();
} );
}

abort() {
Expand Down
37 changes: 29 additions & 8 deletions tests/cloudservicesuploadadapter.js
Expand Up @@ -107,32 +107,53 @@ describe( 'CloudServicesUploadAdapter', () => {
} )
.catch( err => done( err ) );

// Wait for the promise from the mock.getUploader()
// Wait for the promise from the mock.getUploader().
setTimeout( () => {
upload._uploadGateway.resolveLastUpload();
} );
} );

it( 'should update the progress', () => {
it( 'should update the progress', done => {
const loader = fileRepository.createLoader( createNativeFileMock() );
loader.upload();

upload._uploadGateway.lastFileUploader.fire( 'progress', { uploaded: 50, total: 100 } );
// Wait for the `loader.file` promise.
setTimeout( () => {
upload._uploadGateway.lastFileUploader.fire( 'progress', { uploaded: 50, total: 100 } );

expect( loader.uploaded ).to.equal( 50 );
expect( loader.uploadTotal ).to.equal( 100 );

// expect( loader.uploaded ).to.equal( 50 );
expect( loader.uploadTotal ).to.equal( 100 );
done();
} );
} );
} );

describe( 'abort()', () => {
it( 'should call abort on the CSS uploader', () => {
it( 'should not call abort on the non-existing CSS uploader (`loader.file` not resolved)', () => {
const loader = fileRepository.createLoader( createNativeFileMock() );

expect( () => {
loader.upload();
loader.abort();
} ).to.not.throw();

expect( upload._uploadGateway.lastFileUploader ).to.be.undefined;
} );

it( 'should call abort on the CSS uploader (`loader.file` resolved)', done => {
const loader = fileRepository.createLoader( createNativeFileMock() );

loader.upload();

loader.abort();
// Wait for the `loader.file` promise.
setTimeout( () => {
loader.abort();

expect( upload._uploadGateway.lastFileUploader.aborted ).to.be.true;
expect( upload._uploadGateway.lastFileUploader.aborted ).to.be.true;

done();
} );
} );
} );
} );
Expand Down

0 comments on commit e812ec8

Please sign in to comment.