mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
fix test and coverage Angular2 Final release uploader component #749
This commit is contained in:
@@ -15,29 +15,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
import { PLATFORM_PIPES } from '@angular/core';
|
||||
import { beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
import {
|
||||
AlfrescoTranslationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoPipeTranslate
|
||||
} from 'ng2-alfresco-core';
|
||||
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import {
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService,
|
||||
CoreModule,
|
||||
AlfrescoTranslationService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
|
||||
declare var AlfrescoApi: any;
|
||||
|
||||
describe('AlfrescoUploadButton', () => {
|
||||
|
||||
let uploadButtonFixture;
|
||||
describe('Test ng2-alfresco-upload UploadButton', () => {
|
||||
|
||||
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||
let fakeEvent = {
|
||||
@@ -72,68 +63,73 @@ describe('AlfrescoUploadButton', () => {
|
||||
reject(fakeRejectRest);
|
||||
});
|
||||
|
||||
beforeEach( () => {
|
||||
window['componentHandler'] = null;
|
||||
});
|
||||
let component: any;
|
||||
let fixture: ComponentFixture<UploadButtonComponent>;
|
||||
let debug: DebugElement;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
HTTP_PROVIDERS,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
UploadService
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach( inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb
|
||||
.createAsync(UploadButtonComponent)
|
||||
.then(fixture => uploadButtonFixture = fixture);
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
],
|
||||
declarations: [UploadButtonComponent],
|
||||
providers: [
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
UploadService,
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
window['componentHandler'] = null;
|
||||
|
||||
fixture = TestBed.createComponent(UploadButtonComponent);
|
||||
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should render upload-single-file button as default', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.multipleFiles = false;
|
||||
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||
uploadButtonFixture.detectChanges();
|
||||
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', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.multipleFiles = true;
|
||||
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||
uploadButtonFixture.detectChanges();
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#upload-multiple-files')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should render an uploadFolder button if uploadFolder is true', () => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.uploadFolder = true;
|
||||
let compiled = uploadButtonFixture.debugElement.nativeElement;
|
||||
uploadButtonFixture.detectChanges();
|
||||
let compiled = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
uploadButtonFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.onFilesAdded(fakeEvent);
|
||||
expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
|
||||
});
|
||||
|
||||
it('should create a folder and emit an File uploaded event', (done) => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
component.currentFolderPath = '/fake-root-path';
|
||||
uploadButtonFixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(component._uploaderService, 'callApiCreateFolder').and.returnValue(fakeResolvePromise);
|
||||
|
||||
@@ -152,9 +148,6 @@ describe('AlfrescoUploadButton', () => {
|
||||
});
|
||||
|
||||
it('should emit an onError event when the folder already exist', (done) => {
|
||||
let component = uploadButtonFixture.componentInstance;
|
||||
uploadButtonFixture.detectChanges();
|
||||
|
||||
spyOn(component._uploaderService, 'callApiCreateFolder').and.returnValue(fakeRejectPromise);
|
||||
component.onError.subscribe(e => {
|
||||
expect(e.value).toEqual('FILE_UPLOAD.MESSAGES.FOLDER_ALREADY_EXIST');
|
||||
@@ -164,4 +157,4 @@ describe('AlfrescoUploadButton', () => {
|
||||
component.onDirectoryAdded(fakeEvent);
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
|
Reference in New Issue
Block a user