diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts index 5f24a41908..6de21d82c6 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts @@ -75,6 +75,11 @@ describe('Test ng2-alfresco-upload FileUploadDialog', () => { fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + TestBed.resetTestingModule(); + }); + it('should render completed upload 1 when an element is added to Observer', () => { component._uploaderService.updateFileCounterStream(1); fixture.detectChanges(); diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index 598c632cde..1bbda0d357 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -95,6 +95,11 @@ describe('Test ng2-alfresco-upload UploadButton', () => { fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + TestBed.resetTestingModule(); + }); + it('should render upload-single-file button as default', () => { component.multipleFiles = false; let compiled = fixture.debugElement.nativeElement; diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts index a53bb3f9aa..6d724a9b1e 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts @@ -61,6 +61,11 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => { fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + TestBed.resetTestingModule(); + }); + it('should show an folder non supported error in console when the file type is empty', () => { component.showUdoNotificationBar = false; spyOn(console, 'error'); @@ -113,16 +118,12 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => { expect(component._showUndoNotificationBar).toHaveBeenCalled(); }); - it('should upload a file when dropped', done => { + it('should upload a file when dropped', () => { component.currentFolderPath = '/root-fake-/sites-fake/document-library-fake'; component.onSuccess = null; fixture.detectChanges(); spyOn(component._uploaderService, 'uploadFilesInTheQueue'); - spyOn(component, '_showUndoNotificationBar').and.callFake( () => { - expect(component._showUndoNotificationBar).toHaveBeenCalled(); - done(); - }); let itemEntity = { fullPath: '/folder-fake/file-fake.png', @@ -203,6 +204,10 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => { spyOn(component._uploaderService, 'callApiCreateFolder').and.returnValue(fakePromise); spyOn(component, 'onFilesEntityDropped').and.callFake( () => { expect(component.onFilesEntityDropped).toHaveBeenCalledWith(itemEntity); + }); + + spyOn(component, '_showUndoNotificationBar').and.callFake( () => { + expect(component._showUndoNotificationBar).toHaveBeenCalled(); done(); }); diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts index a632e40460..52f596ceed 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts @@ -111,16 +111,11 @@ export class UploadDragAreaComponent { * @param item - FileEntity */ onFilesEntityDropped(item: any): void { - let self = this; - item.file(function (file: any) { - self._uploaderService.addToQueue([file]); + item.file( (file: any) => { + this._uploaderService.addToQueue([file]); let path = item.fullPath.replace(item.name, ''); - let filePath = self.currentFolderPath + path; - self._uploaderService.uploadFilesInTheQueue(filePath, self.onSuccess); - let latestFilesAdded = self._uploaderService.getQueue(); - if (self.showUdoNotificationBar) { - self._showUndoNotificationBar(latestFilesAdded); - } + let filePath = this.currentFolderPath + path; + this._uploaderService.uploadFilesInTheQueue(filePath, this.onSuccess); }); } @@ -136,14 +131,17 @@ export class UploadDragAreaComponent { this._uploaderService.createFolder(relativePath, folder.name) .subscribe( message => { - let self = this; this.onSuccess.emit({ value: 'Created folder' }); let dirReader = folder.createReader(); - dirReader.readEntries(function (entries: any) { + dirReader.readEntries((entries: any) => { for (let i = 0; i < entries.length; i++) { - self._traverseFileTree(entries[i]); + this._traverseFileTree(entries[i]); + } + if (this.showUdoNotificationBar) { + let latestFilesAdded = this._uploaderService.getQueue(); + this._showUndoNotificationBar(latestFilesAdded); } }); }, @@ -168,12 +166,10 @@ export class UploadDragAreaComponent { */ private _traverseFileTree(item: any): void { if (item.isFile) { - let self = this; - self.onFilesEntityDropped(item); + this.onFilesEntityDropped(item); } else { if (item.isDirectory) { - let self = this; - self.onFolderEntityDropped(item); + this.onFolderEntityDropped(item); } } }