diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts index a917986792..60ab914d82 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.test.ts @@ -343,35 +343,22 @@ describe('WorkPackageResource service', () => { .returns($q.when()); }); - describe('when the work package is new', () => { - beforeEach(() => { - workPackage.isNew = true; - workPackage.uploadPendingAttachments(); - }); + beforeEach(() => { + workPackage.isNew = false; + workPackage.uploadPendingAttachments(); + }); - it('should not be called', () => { - expect(uploadAttachmentsStub.called).to.be.false; - }); + it('should call the uploadAttachments method with the pendingAttachments', () => { + expect(uploadAttachmentsStub.calledWith([{},{}])).to.be.true; }); - describe('when the work package is not new', () => { + describe('when the upload succeeds', () => { beforeEach(() => { - workPackage.isNew = false; - workPackage.uploadPendingAttachments(); - }); - - it('should call the uploadAttachments method with the pendingAttachments', () => { - expect(uploadAttachmentsStub.calledWith(workPackage.pendingAttachments)).to.be.true; + $rootScope.$apply(); }); - describe('when the upload succeeds', () => { - beforeEach(() => { - $rootScope.$apply(); - }); - - it('should reset the pending attachments', () => { - expect(workPackage.pendingAttachments).to.have.length(0); - }); + it('should reset the pending attachments', () => { + expect(workPackage.pendingAttachments).to.have.length(0); }); }); }); diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts index 34d1c0c804..4602db9139 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts @@ -227,10 +227,13 @@ export class WorkPackageResource extends HalResource { * Do nothing, if the work package is being created. */ public uploadPendingAttachments() { - if (!this.isNew) { - this.uploadAttachments(this.pendingAttachments) - .then(() => this.pendingAttachments = []); - } + if (!this.pendingAttachments.length) { + return; + } + + const attachments = this.pendingAttachments; + this.pendingAttachments = []; + return this.uploadAttachments(attachments); } /** diff --git a/frontend/app/components/routing/wp-show/wp.show.html b/frontend/app/components/routing/wp-show/wp.show.html index 968cb6bf2f..96fd3abf7f 100644 --- a/frontend/app/components/routing/wp-show/wp.show.html +++ b/frontend/app/components/routing/wp-show/wp.show.html @@ -21,9 +21,6 @@ -