mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +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,12 +38,21 @@ 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 => {
|
||||||
|
componentFixture = fixture;
|
||||||
|
uploadService = service;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
it('should render completed upload 1 when an element is added to Observer', () => {
|
||||||
let fileFake = {
|
let fileFake = {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
name: 'fake-name'
|
name: 'fake-name'
|
||||||
@@ -48,31 +60,22 @@ describe('FileUploadDialog', () => {
|
|||||||
let file = new FileModel(fileFake);
|
let file = new FileModel(fileFake);
|
||||||
file.progress = {'percent': 50};
|
file.progress = {'percent': 50};
|
||||||
|
|
||||||
updService.totalCompleted$ = new Observable(observer => {
|
uploadService.totalCompleted$ = new Observable(observer => {
|
||||||
observer.next(1);
|
observer.next(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
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('#total-upload-completed').innerText).toEqual('1');
|
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 dialog box with css class show when an element is added to Observer', () => {
|
||||||
inject([TestComponentBuilder, UploadService],
|
|
||||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(FileUploadingDialogComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let fileFake = {
|
let fileFake = {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
name: 'fake-name'
|
name: 'fake-name'
|
||||||
@@ -80,99 +83,72 @@ describe('FileUploadDialog', () => {
|
|||||||
let file = new FileModel(fileFake);
|
let file = new FileModel(fileFake);
|
||||||
file.progress = {'percent': 50};
|
file.progress = {'percent': 50};
|
||||||
|
|
||||||
updService.addToQueue([file]);
|
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],
|
|
||||||
(tcb: TestComponentBuilder, updService: UploadService) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(FileUploadingDialogComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let fileFake = {
|
let fileFake = {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
name: 'fake-name'
|
name: 'fake-name'
|
||||||
};
|
};
|
||||||
let file = new FileModel(fileFake);
|
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],
|
|
||||||
(tcb: TestComponentBuilder) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(FileUploadingDialogComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let fileFake = {
|
let fileFake = {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
name: 'fake-name'
|
name: 'fake-name'
|
||||||
};
|
};
|
||||||
let file = new FileModel(fileFake);
|
let file = new FileModel(fileFake);
|
||||||
let component = fixture.componentInstance;
|
let component = componentFixture.componentInstance;
|
||||||
component.filesUploadingList = [file];
|
component.filesUploadingList = [file];
|
||||||
component.isDialogActive = true;
|
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) => {
|
|
||||||
return tcb
|
|
||||||
.createAsync(FileUploadingDialogComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let fileFake = {
|
let fileFake = {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
name: 'fake-name'
|
name: 'fake-name'
|
||||||
};
|
};
|
||||||
let file = new FileModel(fileFake);
|
let file = new FileModel(fileFake);
|
||||||
let component = fixture.componentInstance;
|
let component = componentFixture.componentInstance;
|
||||||
component.filesUploadingList = [file];
|
component.filesUploadingList = [file];
|
||||||
component.isDialogActive = true;
|
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,55 +44,43 @@ describe('AlfrescoUploadButton', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render upload-single-file button as default',
|
beforeEach( inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
||||||
return tcb
|
return tcb
|
||||||
.createAsync(UploadButtonComponent)
|
.createAsync(UploadButtonComponent)
|
||||||
.then((fixture) => {
|
.then(fixture => uploadButtonFixture = fixture);
|
||||||
let component = fixture.componentInstance;
|
}));
|
||||||
|
|
||||||
|
it('should render upload-single-file button as default', () => {
|
||||||
|
let component = uploadButtonFixture.componentInstance;
|
||||||
component.multipleFiles = false;
|
component.multipleFiles = false;
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||||
fixture.detectChanges();
|
uploadButtonFixture.detectChanges();
|
||||||
expect(compiled.querySelector('#upload-single-file')).toBeDefined();
|
expect(compiled.querySelector('#upload-single-file')).toBeDefined();
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should render upload-multiple-file button if multipleFiles is true',
|
it('should render upload-multiple-file button if multipleFiles is true', () => {
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
let component = uploadButtonFixture.componentInstance;
|
||||||
return tcb
|
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.multipleFiles = true;
|
component.multipleFiles = true;
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||||
fixture.detectChanges();
|
uploadButtonFixture.detectChanges();
|
||||||
expect(compiled.querySelector('#upload-multiple-files')).toBeDefined();
|
expect(compiled.querySelector('#upload-multiple-files')).toBeDefined();
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should render an uploadFolder button if uploadFolder is true',
|
it('should render an uploadFolder button if uploadFolder is true', () => {
|
||||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
let component = uploadButtonFixture.componentInstance;
|
||||||
return tcb
|
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.uploadFolder = true;
|
component.uploadFolder = true;
|
||||||
let compiled = fixture.debugElement.nativeElement;
|
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||||
fixture.detectChanges();
|
uploadButtonFixture.detectChanges();
|
||||||
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call uploadFile with the default folder', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
it('should call uploadFile with the default folder', () => {
|
||||||
return tcb
|
let component = uploadButtonFixture.componentInstance;
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||||
component.onSuccess = null;
|
component.onSuccess = null;
|
||||||
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
|
||||||
|
|
||||||
fixture.detectChanges();
|
uploadButtonFixture.detectChanges();
|
||||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||||
|
|
||||||
let fakeEvent = {
|
let fakeEvent = {
|
||||||
@@ -103,18 +93,14 @@ describe('AlfrescoUploadButton', () => {
|
|||||||
component.onFilesAdded(fakeEvent);
|
component.onFilesAdded(fakeEvent);
|
||||||
expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
|
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 create a folder and call upload file', () => {
|
||||||
return tcb
|
let component = uploadButtonFixture.componentInstance;
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
|
|
||||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||||
let doneFn = jasmine.createSpy('success');
|
let doneFn = jasmine.createSpy('success');
|
||||||
|
|
||||||
fixture.detectChanges();
|
uploadButtonFixture.detectChanges();
|
||||||
|
|
||||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||||
|
|
||||||
@@ -127,17 +113,13 @@ describe('AlfrescoUploadButton', () => {
|
|||||||
component.onDirectoryAdded(fakeEvent);
|
component.onDirectoryAdded(fakeEvent);
|
||||||
expect(doneFn).not.toHaveBeenCalledWith(fakeEvent);
|
expect(doneFn).not.toHaveBeenCalledWith(fakeEvent);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throws an exception when the folder already exist', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
it('should throws an exception when the folder already exist', () => {
|
||||||
return tcb
|
let component = uploadButtonFixture.componentInstance;
|
||||||
.createAsync(UploadButtonComponent)
|
|
||||||
.then((fixture) => {
|
|
||||||
let component = fixture.componentInstance;
|
|
||||||
|
|
||||||
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
component.uploadFiles = jasmine.createSpy('uploadFiles');
|
||||||
|
|
||||||
fixture.detectChanges();
|
uploadButtonFixture.detectChanges();
|
||||||
|
|
||||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'folder-duplicate-fake/fake-name-1.json'};
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'folder-duplicate-fake/fake-name-1.json'};
|
||||||
|
|
||||||
@@ -150,6 +132,4 @@ describe('AlfrescoUploadButton', () => {
|
|||||||
component.onDirectoryAdded(fakeEvent);
|
component.onDirectoryAdded(fakeEvent);
|
||||||
expect(component.uploadFiles).not.toHaveBeenCalledWith(fakeEvent);
|
expect(component.uploadFiles).not.toHaveBeenCalledWith(fakeEvent);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user