mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Improved 'upload' tests
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, expect, it, inject, beforeEachProviders } from '@angular/core/testing';
|
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||||
import { FileModel } from '../models/file.model';
|
import { FileModel } from '../models/file.model';
|
||||||
@@ -27,6 +27,9 @@ import { Observable } from 'rxjs/Observable';
|
|||||||
|
|
||||||
describe('FileUploadDialog', () => {
|
describe('FileUploadDialog', () => {
|
||||||
|
|
||||||
|
let componentFixture;
|
||||||
|
let uploadService;
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
return [
|
return [
|
||||||
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsService },
|
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsService },
|
||||||
@@ -35,144 +38,117 @@ describe('FileUploadDialog', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render completed upload 1 when an element is added to Observer',
|
beforeEach(
|
||||||
inject([TestComponentBuilder, UploadService],
|
inject(
|
||||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
[TestComponentBuilder, UploadService],
|
||||||
|
(tcb: TestComponentBuilder, service: UploadService) => {
|
||||||
return tcb
|
return tcb
|
||||||
.createAsync(FileUploadingDialogComponent)
|
.createAsync(FileUploadingDialogComponent)
|
||||||
.then((fixture) => {
|
.then(fixture => {
|
||||||
let fileFake = {
|
componentFixture = fixture;
|
||||||
id: 'fake-id',
|
uploadService = service;
|
||||||
name: 'fake-name'
|
});
|
||||||
};
|
|
||||||
let file = new FileModel(fileFake);
|
|
||||||
file.progress = {'percent': 50};
|
|
||||||
|
|
||||||
updService.totalCompleted$ = new Observable(observer => {
|
|
||||||
observer.next(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
component.filesUploadingList = [file];
|
|
||||||
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(compiled.querySelector('#total-upload-completed').innerText).toEqual('1');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it('should render dialog box with css class show when an element is added to Observer',
|
it('should render completed upload 1 when an element is added to Observer', () => {
|
||||||
inject([TestComponentBuilder, UploadService],
|
let fileFake = {
|
||||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
id: 'fake-id',
|
||||||
return tcb
|
name: 'fake-name'
|
||||||
.createAsync(FileUploadingDialogComponent)
|
};
|
||||||
.then((fixture) => {
|
let file = new FileModel(fileFake);
|
||||||
let fileFake = {
|
file.progress = {'percent': 50};
|
||||||
id: 'fake-id',
|
|
||||||
name: 'fake-name'
|
|
||||||
};
|
|
||||||
let file = new FileModel(fileFake);
|
|
||||||
file.progress = {'percent': 50};
|
|
||||||
|
|
||||||
updService.addToQueue([file]);
|
uploadService.totalCompleted$ = new Observable(observer => {
|
||||||
|
observer.next(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
let component = componentFixture.componentInstance;
|
||||||
|
componentFixture.detectChanges();
|
||||||
|
component.filesUploadingList = [file];
|
||||||
|
|
||||||
|
let compiled = componentFixture.debugElement.nativeElement;
|
||||||
|
|
||||||
|
componentFixture.detectChanges();
|
||||||
|
|
||||||
|
expect(compiled.querySelector('#total-upload-completed').innerText).toEqual('1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render dialog box with css class show when an element is added to Observer', () => {
|
||||||
|
let fileFake = {
|
||||||
|
id: 'fake-id',
|
||||||
|
name: 'fake-name'
|
||||||
|
};
|
||||||
|
let file = new FileModel(fileFake);
|
||||||
|
file.progress = {'percent': 50};
|
||||||
|
|
||||||
|
uploadService.addToQueue([file]);
|
||||||
|
|
||||||
|
|
||||||
let component = fixture.componentInstance;
|
let component = componentFixture.componentInstance;
|
||||||
fixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
component.filesUploadingList = [file];
|
component.filesUploadingList = [file];
|
||||||
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = componentFixture.debugElement.nativeElement;
|
||||||
|
|
||||||
fixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
|
||||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
it('should render dialog box with css class show when the toggleShowDialog is called',
|
it('should render dialog box with css class show when the toggleShowDialog is called', () => {
|
||||||
inject([TestComponentBuilder, UploadService],
|
let fileFake = {
|
||||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
id: 'fake-id',
|
||||||
return tcb
|
name: 'fake-name'
|
||||||
.createAsync(FileUploadingDialogComponent)
|
};
|
||||||
.then((fixture) => {
|
let file = new FileModel(fileFake);
|
||||||
let fileFake = {
|
|
||||||
id: 'fake-id',
|
|
||||||
name: 'fake-name'
|
|
||||||
};
|
|
||||||
let file = new FileModel(fileFake);
|
|
||||||
|
|
||||||
let component = fixture.componentInstance;
|
let component = componentFixture.componentInstance;
|
||||||
fixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
component.filesUploadingList = [file];
|
component.filesUploadingList = [file];
|
||||||
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = componentFixture.debugElement.nativeElement;
|
||||||
|
|
||||||
component.toggleShowDialog();
|
component.toggleShowDialog();
|
||||||
fixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
|
||||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog show');
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
it('should render dialog box with css class hide',
|
it('should render dialog box with css class hide', () => {
|
||||||
inject([TestComponentBuilder],
|
let fileFake = {
|
||||||
(tcb: TestComponentBuilder) => {
|
id: 'fake-id',
|
||||||
return tcb
|
name: 'fake-name'
|
||||||
.createAsync(FileUploadingDialogComponent)
|
};
|
||||||
.then((fixture) => {
|
let file = new FileModel(fileFake);
|
||||||
let fileFake = {
|
let component = componentFixture.componentInstance;
|
||||||
id: 'fake-id',
|
component.filesUploadingList = [file];
|
||||||
name: 'fake-name'
|
component.isDialogActive = true;
|
||||||
};
|
|
||||||
let file = new FileModel(fileFake);
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.filesUploadingList = [file];
|
|
||||||
component.isDialogActive = true;
|
|
||||||
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = componentFixture.debugElement.nativeElement;
|
||||||
|
|
||||||
component.toggleShowDialog();
|
component.toggleShowDialog();
|
||||||
fixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
|
||||||
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog');
|
expect(compiled.querySelector('.file-dialog').getAttribute('class')).toEqual('file-dialog');
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
it('should render minimize dialog as default',
|
it('should render minimize dialog as default', () => {
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
let fileFake = {
|
||||||
return tcb
|
id: 'fake-id',
|
||||||
.createAsync(FileUploadingDialogComponent)
|
name: 'fake-name'
|
||||||
.then((fixture) => {
|
};
|
||||||
let fileFake = {
|
let file = new FileModel(fileFake);
|
||||||
id: 'fake-id',
|
let component = componentFixture.componentInstance;
|
||||||
name: 'fake-name'
|
component.filesUploadingList = [file];
|
||||||
};
|
component.isDialogActive = true;
|
||||||
let file = new FileModel(fileFake);
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.filesUploadingList = [file];
|
|
||||||
component.isDialogActive = true;
|
|
||||||
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = componentFixture.debugElement.nativeElement;
|
||||||
|
|
||||||
component.toggleDialogMinimize();
|
component.toggleDialogMinimize();
|
||||||
fixture.detectChanges();
|
componentFixture.detectChanges();
|
||||||
|
|
||||||
expect(compiled.querySelector('.minimize-button').getAttribute('class')).toEqual('minimize-button active');
|
expect(compiled.querySelector('.minimize-button').getAttribute('class')).toEqual('minimize-button active');
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, expect, it, inject, beforeEachProviders } from '@angular/core/testing';
|
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { UploadButtonComponent } from './upload-button.component';
|
import { UploadButtonComponent } from './upload-button.component';
|
||||||
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
@@ -29,6 +29,8 @@ declare var AlfrescoApi: any;
|
|||||||
|
|
||||||
describe('AlfrescoUploadButton', () => {
|
describe('AlfrescoUploadButton', () => {
|
||||||
|
|
||||||
|
let uploadButtonFixture;
|
||||||
|
|
||||||
beforeEach( () => {
|
beforeEach( () => {
|
||||||
window['AlfrescoApi'] = AlfrescoApiMock;
|
window['AlfrescoApi'] = AlfrescoApiMock;
|
||||||
window['componentHandler'] = null;
|
window['componentHandler'] = null;
|
||||||
@@ -42,114 +44,92 @@ describe('AlfrescoUploadButton', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render upload-single-file button as default',
|
beforeEach( inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.multipleFiles = false;
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(compiled.querySelector('#upload-single-file')).toBeDefined();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should render upload-multiple-file button if multipleFiles is true',
|
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.multipleFiles = true;
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(compiled.querySelector('#upload-multiple-files')).toBeDefined();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should render an uploadFolder button if uploadFolder is true',
|
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.uploadFolder = true;
|
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call uploadFile with the default folder', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
||||||
return tcb
|
return tcb
|
||||||
.createAsync(UploadButtonComponent)
|
.createAsync(UploadButtonComponent)
|
||||||
.then((fixture) => {
|
.then(fixture => uploadButtonFixture = fixture);
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
|
||||||
component.onSuccess = null;
|
|
||||||
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
|
||||||
|
|
||||||
let fakeEvent = {
|
|
||||||
currentTarget: {
|
|
||||||
files: [file]
|
|
||||||
},
|
|
||||||
target: {value: 'fake-value'}
|
|
||||||
};
|
|
||||||
|
|
||||||
component.onFilesAdded(fakeEvent);
|
|
||||||
expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should create a folder and call upload file', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
it('should render upload-single-file button as default', () => {
|
||||||
return tcb
|
let component = uploadButtonFixture.componentInstance;
|
||||||
.createAsync(UploadButtonComponent)
|
component.multipleFiles = false;
|
||||||
.then((fixture) => {
|
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||||
let component = fixture.componentInstance;
|
uploadButtonFixture.detectChanges();
|
||||||
|
expect(compiled.querySelector('#upload-single-file')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
it('should render upload-multiple-file button if multipleFiles is true', () => {
|
||||||
let doneFn = jasmine.createSpy('success');
|
let component = uploadButtonFixture.componentInstance;
|
||||||
|
component.multipleFiles = true;
|
||||||
|
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||||
|
uploadButtonFixture.detectChanges();
|
||||||
|
expect(compiled.querySelector('#upload-multiple-files')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
fixture.detectChanges();
|
it('should render an uploadFolder button if uploadFolder is true', () => {
|
||||||
|
let component = uploadButtonFixture.componentInstance;
|
||||||
|
component.uploadFolder = true;
|
||||||
|
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||||
|
uploadButtonFixture.detectChanges();
|
||||||
|
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
it('should call uploadFile with the default folder', () => {
|
||||||
|
let component = uploadButtonFixture.componentInstance;
|
||||||
|
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||||
|
component.onSuccess = null;
|
||||||
|
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||||
|
|
||||||
let fakeEvent = {
|
uploadButtonFixture.detectChanges();
|
||||||
currentTarget: {
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||||
files: [file]
|
|
||||||
},
|
|
||||||
target: {value: 'fake-value'}
|
|
||||||
};
|
|
||||||
component.onDirectoryAdded(fakeEvent);
|
|
||||||
expect(doneFn).not.toHaveBeenCalledWith(fakeEvent);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throws an exception when the folder already exist', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
let fakeEvent = {
|
||||||
return tcb
|
currentTarget: {
|
||||||
.createAsync(UploadButtonComponent)
|
files: [file]
|
||||||
.then((fixture) => {
|
},
|
||||||
let component = fixture.componentInstance;
|
target: {value: 'fake-value'}
|
||||||
|
};
|
||||||
|
|
||||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
component.onFilesAdded(fakeEvent);
|
||||||
|
expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
|
||||||
|
});
|
||||||
|
|
||||||
fixture.detectChanges();
|
it('should create a folder and call upload file', () => {
|
||||||
|
let component = uploadButtonFixture.componentInstance;
|
||||||
|
|
||||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'folder-duplicate-fake/fake-name-1.json'};
|
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||||
|
let doneFn = jasmine.createSpy('success');
|
||||||
|
|
||||||
let fakeEvent = {
|
uploadButtonFixture.detectChanges();
|
||||||
currentTarget: {
|
|
||||||
files: [file]
|
|
||||||
},
|
|
||||||
target: {value: 'fake-value'}
|
|
||||||
};
|
|
||||||
component.onDirectoryAdded(fakeEvent);
|
|
||||||
expect(component.uploadFiles).not.toHaveBeenCalledWith(fakeEvent);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||||
|
|
||||||
|
let fakeEvent = {
|
||||||
|
currentTarget: {
|
||||||
|
files: [file]
|
||||||
|
},
|
||||||
|
target: {value: 'fake-value'}
|
||||||
|
};
|
||||||
|
component.onDirectoryAdded(fakeEvent);
|
||||||
|
expect(doneFn).not.toHaveBeenCalledWith(fakeEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throws an exception when the folder already exist', () => {
|
||||||
|
let component = uploadButtonFixture.componentInstance;
|
||||||
|
|
||||||
|
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||||
|
|
||||||
|
uploadButtonFixture.detectChanges();
|
||||||
|
|
||||||
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'folder-duplicate-fake/fake-name-1.json'};
|
||||||
|
|
||||||
|
let fakeEvent = {
|
||||||
|
currentTarget: {
|
||||||
|
files: [file]
|
||||||
|
},
|
||||||
|
target: {value: 'fake-value'}
|
||||||
|
};
|
||||||
|
component.onDirectoryAdded(fakeEvent);
|
||||||
|
expect(component.uploadFiles).not.toHaveBeenCalledWith(fakeEvent);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user