#1181 Show toast message once (#1189)

* #1181 Show toast once

* #1181 fix unit test

* #1181 Fix unit test compilation problem
This commit is contained in:
Maurizio Vitale
2016-12-01 16:28:16 +00:00
committed by Eugenio Romano
parent 294f7c0ec1
commit 3a288c6b1b
4 changed files with 32 additions and 21 deletions

View File

@@ -75,6 +75,11 @@ describe('Test ng2-alfresco-upload FileUploadDialog', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should render completed upload 1 when an element is added to Observer', () => { it('should render completed upload 1 when an element is added to Observer', () => {
component._uploaderService.updateFileCounterStream(1); component._uploaderService.updateFileCounterStream(1);
fixture.detectChanges(); fixture.detectChanges();

View File

@@ -95,6 +95,11 @@ describe('Test ng2-alfresco-upload UploadButton', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should render upload-single-file button as default', () => { it('should render upload-single-file button as default', () => {
component.multipleFiles = false; component.multipleFiles = false;
let compiled = fixture.debugElement.nativeElement; let compiled = fixture.debugElement.nativeElement;

View File

@@ -61,6 +61,11 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should show an folder non supported error in console when the file type is empty', () => { it('should show an folder non supported error in console when the file type is empty', () => {
component.showUdoNotificationBar = false; component.showUdoNotificationBar = false;
spyOn(console, 'error'); spyOn(console, 'error');
@@ -113,16 +118,12 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => {
expect(component._showUndoNotificationBar).toHaveBeenCalled(); 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.currentFolderPath = '/root-fake-/sites-fake/document-library-fake';
component.onSuccess = null; component.onSuccess = null;
fixture.detectChanges(); fixture.detectChanges();
spyOn(component._uploaderService, 'uploadFilesInTheQueue'); spyOn(component._uploaderService, 'uploadFilesInTheQueue');
spyOn(component, '_showUndoNotificationBar').and.callFake( () => {
expect(component._showUndoNotificationBar).toHaveBeenCalled();
done();
});
let itemEntity = { let itemEntity = {
fullPath: '/folder-fake/file-fake.png', 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._uploaderService, 'callApiCreateFolder').and.returnValue(fakePromise);
spyOn(component, 'onFilesEntityDropped').and.callFake( () => { spyOn(component, 'onFilesEntityDropped').and.callFake( () => {
expect(component.onFilesEntityDropped).toHaveBeenCalledWith(itemEntity); expect(component.onFilesEntityDropped).toHaveBeenCalledWith(itemEntity);
});
spyOn(component, '_showUndoNotificationBar').and.callFake( () => {
expect(component._showUndoNotificationBar).toHaveBeenCalled();
done(); done();
}); });

View File

@@ -111,16 +111,11 @@ export class UploadDragAreaComponent {
* @param item - FileEntity * @param item - FileEntity
*/ */
onFilesEntityDropped(item: any): void { onFilesEntityDropped(item: any): void {
let self = this; item.file( (file: any) => {
item.file(function (file: any) { this._uploaderService.addToQueue([file]);
self._uploaderService.addToQueue([file]);
let path = item.fullPath.replace(item.name, ''); let path = item.fullPath.replace(item.name, '');
let filePath = self.currentFolderPath + path; let filePath = this.currentFolderPath + path;
self._uploaderService.uploadFilesInTheQueue(filePath, self.onSuccess); this._uploaderService.uploadFilesInTheQueue(filePath, this.onSuccess);
let latestFilesAdded = self._uploaderService.getQueue();
if (self.showUdoNotificationBar) {
self._showUndoNotificationBar(latestFilesAdded);
}
}); });
} }
@@ -136,14 +131,17 @@ export class UploadDragAreaComponent {
this._uploaderService.createFolder(relativePath, folder.name) this._uploaderService.createFolder(relativePath, folder.name)
.subscribe( .subscribe(
message => { message => {
let self = this;
this.onSuccess.emit({ this.onSuccess.emit({
value: 'Created folder' value: 'Created folder'
}); });
let dirReader = folder.createReader(); let dirReader = folder.createReader();
dirReader.readEntries(function (entries: any) { dirReader.readEntries((entries: any) => {
for (let i = 0; i < entries.length; i++) { 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 { private _traverseFileTree(item: any): void {
if (item.isFile) { if (item.isFile) {
let self = this; this.onFilesEntityDropped(item);
self.onFilesEntityDropped(item);
} else { } else {
if (item.isDirectory) { if (item.isDirectory) {
let self = this; this.onFolderEntityDropped(item);
self.onFolderEntityDropped(item);
} }
} }
} }