refactorin process list and test viewer

This commit is contained in:
Eugenio Romano 2016-08-19 09:59:27 +01:00
parent e2b3259e14
commit 876f2736e7
13 changed files with 339 additions and 563 deletions

View File

@ -15,17 +15,17 @@
* limitations under the License. * limitations under the License.
*/ */
import { Ng2ActivitiProcesslistComponent } from './src/components/ng2-activiti-processlist.component'; import { ActivitiProcesslistComponent } from './src/components/activiti-processlist.component';
import { ActivitiProcessService } from './src/services/activiti-process-service.service'; import { ActivitiProcessService } from './src/services/activiti-process.service';
// components // components
export * from './src/components/ng2-activiti-processlist.component'; export * from './src/components/activiti-processlist.component';
// services // services
export * from './src/services/activiti-process-service.service'; export * from './src/services/activiti-process.service';
export const ACTIVITI_PROCESSLIST_DIRECTIVES: [any] = [ export const ACTIVITI_PROCESSLIST_DIRECTIVES: [any] = [
Ng2ActivitiProcesslistComponent ActivitiProcesslistComponent
]; ];
export const ACTIVITI_PROCESSLIST_PROVIDERS: [any] = [ export const ACTIVITI_PROCESSLIST_PROVIDERS: [any] = [

View File

@ -1,49 +0,0 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Observable } from 'rxjs/Observable';
import {
ProcessList,
SingleProcessList
} from './activiti-process.model.mock';
import { ActivitiProcessService } from './../services/activiti-process-service.service';
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
export class ActivitiProcessServiceMock extends ActivitiProcessService {
getProcessesResult: ProcessList = new SingleProcessList('Example process 1');
getProcessesReject: boolean = false;
getProcessesRejectError: string = 'Error';
constructor(
settings?: AlfrescoSettingsService
) {
super(settings, null);
}
getProcesses() {
if (this.getProcessesReject) {
return Observable.throw(this.getProcessesRejectError);
}
return Observable.create(observer => {
observer.next(this.getProcessesResult);
observer.complete();
}).map((json) => {
return json.data;
});
}
}

View File

@ -0,0 +1,65 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, expect, it, inject, beforeEachProviders, beforeEach} from '@angular/core/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoAuthenticationService} from 'ng2-alfresco-core';
import {ActivitiProcesslistComponent} from '../../src/components/activiti-processlist.component';
import {TranslationMock} from './../assets/translation.service.mock';
import {ActivitiProcessService} from '../services/activiti-process.service';
describe('ActivitiProcesslistComponent', () => {
let processlistComponentFixture, element, component;
beforeEachProviders(() => {
return [
ActivitiProcessService,
AlfrescoSettingsService,
AlfrescoAuthenticationService,
{provide: AlfrescoTranslationService, useClass: TranslationMock}
];
});
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ActivitiProcesslistComponent)
.then(fixture => {
processlistComponentFixture = fixture;
element = processlistComponentFixture.nativeElement;
component = processlistComponentFixture.componentInstance;
});
}));
it('should have a valid title', () => {
expect(element.querySelector('h1')).toBeDefined();
expect(element.getElementsByTagName('h1')[0].innerHTML).toEqual('My Activiti Processes');
});
it('should contain a list of processes', () => {
let componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered'
]);
window['componentHandler'] = componentHandler;
component.ngOnInit();
processlistComponentFixture.detectChanges();
expect(element.querySelector('table')).toBeDefined();
expect(element.querySelectorAll('table tbody tr').length).toEqual(1);
});
});

View File

@ -15,21 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { import {Component, OnInit } from '@angular/core';
Component, import { AlfrescoPipeTranslate, AlfrescoTranslationService, CONTEXT_MENU_DIRECTIVES, CONTEXT_MENU_PROVIDERS } from 'ng2-alfresco-core';
OnInit import { ALFRESCO_DATATABLE_DIRECTIVES, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
} from '@angular/core'; import { ActivitiProcessService } from '../services/activiti-process.service';
import {
AlfrescoPipeTranslate,
AlfrescoTranslationService,
CONTEXT_MENU_DIRECTIVES,
CONTEXT_MENU_PROVIDERS
} from 'ng2-alfresco-core';
import {
ALFRESCO_DATATABLE_DIRECTIVES,
ObjectDataTableAdapter
} from 'ng2-alfresco-datatable';
import { ActivitiProcessService } from '../services/activiti-process-service.service';
import { ProcessInstance } from '../models/process-instance'; import { ProcessInstance } from '../models/process-instance';
declare let __moduleName: string; declare let __moduleName: string;
@ -44,21 +33,18 @@ declare let __moduleName: string;
} }
` `
], ],
templateUrl: './ng2-activiti-processlist.component.html', templateUrl: './activiti-processlist.component.html',
directives: [ ALFRESCO_DATATABLE_DIRECTIVES, CONTEXT_MENU_DIRECTIVES ], directives: [ ALFRESCO_DATATABLE_DIRECTIVES, CONTEXT_MENU_DIRECTIVES ],
pipes: [ AlfrescoPipeTranslate ], pipes: [ AlfrescoPipeTranslate ],
providers: [ CONTEXT_MENU_PROVIDERS ] providers: [ CONTEXT_MENU_PROVIDERS ]
}) })
export class Ng2ActivitiProcesslistComponent implements OnInit { export class ActivitiProcesslistComponent implements OnInit {
errorMessage: string; errorMessage: string;
processInstances: ProcessInstance[]; processInstances: ProcessInstance[];
data: ObjectDataTableAdapter; data: ObjectDataTableAdapter;
constructor ( constructor (private processService: ActivitiProcessService, private translate: AlfrescoTranslationService) {
private processService: ActivitiProcessService,
private translate: AlfrescoTranslationService
) {
if (translate !== null) { if (translate !== null) {
translate.addTranslationFolder('node_modules/ng2-activiti-processlist/src'); translate.addTranslationFolder('node_modules/ng2-activiti-processlist/src');
} }
@ -72,8 +58,7 @@ export class Ng2ActivitiProcesslistComponent implements OnInit {
this.processService.getProcesses() this.processService.getProcesses()
.subscribe( .subscribe(
(processInstances) => { (processInstances) => {
// this.processInstances = processInstances; this.data = new ObjectDataTableAdapter(
this.data = new ObjectDataTableAdapter(
processInstances, processInstances,
[ [
{type: 'text', key: 'id', title: 'Id', sortable: true}, {type: 'text', key: 'id', title: 'Id', sortable: true},
@ -89,5 +74,4 @@ export class Ng2ActivitiProcesslistComponent implements OnInit {
onItemClick(processInstance: ProcessInstance, event: any) { onItemClick(processInstance: ProcessInstance, event: any) {
console.log(processInstance, event); console.log(processInstance, event);
} }
} }

View File

@ -1,67 +0,0 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { HTTP_PROVIDERS } from '@angular/http';
import {describe, expect, it, inject, beforeEachProviders} from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing';
import {
AlfrescoSettingsService,
AlfrescoTranslationService
} from 'ng2-alfresco-core';
import { Ng2ActivitiProcesslistComponent } from '../../src/components/ng2-activiti-processlist.component';
import { ActivitiProcessServiceMock } from '../assets/activiti-process-service.mock';
import { TranslationMock } from './../assets/translation.service.mock';
import { ActivitiProcessService } from '../services/activiti-process-service.service';
describe('ActivitiProcesslistComponent', () => {
beforeEachProviders(() => {
return [
{ provide: AlfrescoSettingsService },
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
{ provide: ActivitiProcessService, useClass: ActivitiProcessServiceMock },
HTTP_PROVIDERS
];
});
it('should have a valid title', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(Ng2ActivitiProcesslistComponent)
.then((fixture) => {
let element = fixture.nativeElement;
expect(element.querySelector('h1')).toBeDefined();
expect(element.getElementsByTagName('h1')[0].innerHTML).toEqual('My Activiti Processes');
});
}));
it('should contain a list of processes', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
let componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered'
]);
window['componentHandler'] = componentHandler;
return tcb
.createAsync(Ng2ActivitiProcesslistComponent)
.then((fixture) => {
let element = fixture.nativeElement, component = fixture.componentInstance;
component.ngOnInit();
fixture.detectChanges();
expect(element.querySelector('table')).toBeDefined();
expect(element.querySelectorAll('table tbody tr').length).toEqual(1);
});
}));
});

View File

@ -1,74 +0,0 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
it,
describe,
expect,
beforeEachProviders,
inject
} from '@angular/core/testing';
import {
Response,
ResponseOptions,
HTTP_PROVIDERS,
XHRBackend
} from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
import { ActivitiProcessService } from './activiti-process-service.service';
import { ProcessInstance } from '../models/process-instance';
describe('ActivitiProcessService', () => {
beforeEachProviders(() => {
return [
HTTP_PROVIDERS,
{ provide: XHRBackend, useClass: MockBackend },
ActivitiProcessService,
AlfrescoSettingsService
];
});
it('should be there', inject([ActivitiProcessService], (processService: ActivitiProcessService) => {
expect(typeof processService.getProcesses).toBe('function');
}));
it('should get process instances',
inject([ActivitiProcessService, XHRBackend], (processService: ActivitiProcessService, mockBackend: MockBackend) => {
mockBackend.connections.subscribe(
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({
body: {
data: [{
id: 'myprocess:1',
name: 'my process'
}]
}
})));
});
processService.getProcesses().subscribe((instances: ProcessInstance[]) => {
expect(instances.length).toBe(1);
expect(instances[0].id).toBe('myprocess:1');
expect(instances[0].name).toBe('my process');
});
}));
});

View File

@ -1,58 +0,0 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
import { ProcessInstance } from '../models/process-instance';
import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class ActivitiProcessService {
constructor(private settingsService: AlfrescoSettingsService, private http: Http) {
}
getProcesses(): Observable<ProcessInstance[]> {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
// headers.append('Authorization', 'Basic ' + btoa('admin@app.activiti.com:admin'));
return this.http.post(
this.settingsService.bpmHost + '/activiti-app/api/enterprise/process-instances/query',
'{"page":0,"sort":"created-desc","state":"all"}',
new RequestOptions({
headers: headers
}))
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
return body.data || { };
}
private handleError(error: any) {
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}

View File

@ -0,0 +1,48 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { it, describe, expect, beforeEachProviders, beforeEach, inject } from '@angular/core/testing';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { ActivitiProcessService } from './activiti-process.service';
import { ProcessInstance } from '../models/process-instance';
describe('ActivitiProcessService', () => {
let processService;
beforeEachProviders(() => {
return [
ActivitiProcessService,
AlfrescoSettingsService,
AlfrescoAuthenticationService
];
});
beforeEach(inject([ActivitiProcessService], (service: ActivitiProcessService) => {
processService = service;
}));
// it('should get process instances', (done) => {
//
// processService.getProcesses().subscribe((instances: ProcessInstance[]) => {
// expect(instances.length).toBe(1);
// expect(instances[0].id).toBe('myprocess:1');
// expect(instances[0].name).toBe('my process');
// done();
// });
// });
});

View File

@ -0,0 +1,47 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {AlfrescoAuthenticationService} from 'ng2-alfresco-core';
import {ProcessInstance} from '../models/process-instance';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class ActivitiProcessService {
constructor(public authService: AlfrescoAuthenticationService) {
}
getProcesses(): Observable<ProcessInstance[]> {
let request = {'page': 0, 'sort': 'created-desc', 'state': 'all'};
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.processApi.getProcessInstances(request))
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: any) {
return res.data || {};
}
private handleError(error: any) {
console.error(error);
return Observable.throw(error || 'Server error');
}
}

View File

@ -24,7 +24,7 @@
"label-undefined": true, "label-undefined": true,
"max-line-length": [ "max-line-length": [
true, true,
140 180
], ],
"member-ordering": [ "member-ordering": [
true, true,

View File

@ -29,7 +29,6 @@ describe('PdfViewer', () => {
let pdfComponentFixture, element, component; let pdfComponentFixture, element, component;
beforeEachProviders(() => { beforeEachProviders(() => {
return [ return [
AlfrescoSettingsService, AlfrescoSettingsService,

View File

@ -15,335 +15,216 @@
* limitations under the License. * limitations under the License.
*/ */
import { describe, expect, it, inject, beforeEachProviders } from '@angular/core/testing'; import {describe, expect, it, inject, beforeEachProviders, beforeEach} from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing'; import {TestComponentBuilder} from '@angular/compiler/testing';
import { ViewerComponent } from './viewer.component'; import {ViewerComponent} from './viewer.component';
import { EventMock } from './assets/event.mock'; import {EventMock} from './assets/event.mock';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; import {AlfrescoAuthenticationService, AlfrescoSettingsService} from 'ng2-alfresco-core';
describe('ViewerComponent', () => { describe('ViewerComponent', () => {
beforeEachProviders(() => { let viewerComponentFixture, element, component;
return [
AlfrescoSettingsService,
AlfrescoAuthenticationService
];
});
describe('View', () => { beforeEachProviders(() => {
it('shadow overlay should be present if is overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { return [
return tcb AlfrescoSettingsService,
.createAsync(ViewerComponent) AlfrescoAuthenticationService
.then((fixture) => { ];
let element = fixture.nativeElement; });
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = true;
fixture.detectChanges(); beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ViewerComponent)
.then(fixture => {
viewerComponentFixture = fixture;
element = viewerComponentFixture.nativeElement;
component = viewerComponentFixture.componentInstance;
expect(element.querySelector('#viewer-shadow-transparent')).not.toBeNull(); component.urlFile = 'fake-url-file';
}); component.overlayMode = true;
}));
it('header should be present if is overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { viewerComponentFixture.detectChanges();
return tcb });
.createAsync(ViewerComponent) }));
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = true;
fixture.detectChanges(); describe('View', () => {
it('shadow overlay should be present if is overlay mode', () => {
expect(element.querySelector('#viewer-shadow-transparent')).not.toBeNull();
});
expect(element.querySelector('header')).not.toBeNull(); it('header should be present if is overlay mode', () => {
}); expect(element.querySelector('header')).not.toBeNull();
})); });
it('header should be NOT be present if is not overlay mode', () => {
component.overlayMode = false;
it('header should be NOT be present if is not overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { viewerComponentFixture.detectChanges();
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = false;
fixture.detectChanges(); expect(element.querySelector('header')).toBeNull();
});
expect(element.querySelector('header')).toBeNull(); it('Name File should be present if is overlay mode ', () => {
}); component.urlFile = 'http://localhost:9876/fake-url-file.pdf';
})); component.overlayMode = true;
it('Name File should be present if is overlay mode ', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { component.ngOnChanges().then(() => {
return tcb viewerComponentFixture.detectChanges();
.createAsync(ViewerComponent) expect(element.querySelector('#viewer-name-file').innerHTML).toEqual('fake-url-file.pdf');
.then((fixture) => { });
let element = fixture.nativeElement; });
let component = fixture.componentInstance;
component.urlFile = 'http://localhost:9876/fake-url-file.pdf';
component.overlayMode = true;
component.ngOnChanges().then(() => { it('Close button should be present if overlay mode', () => {
fixture.detectChanges(); component.urlFile = 'fake-url-file';
expect(element.querySelector('#viewer-name-file').innerHTML).toEqual('fake-url-file.pdf'); component.overlayMode = true;
});
});
}));
/* tslint:disable:max-line-length */ viewerComponentFixture.detectChanges();
it('should pick up filename from the fileName property when specified', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'http://localhost:9876/fake-url-file.pdf';
component.fileName = 'My Example.pdf';
component.ngOnChanges().then(() => { expect(element.querySelector('#viewer-close-button')).not.toBeNull();
fixture.detectChanges(); });
expect(element.querySelector('#viewer-name-file').innerHTML).toEqual('My Example.pdf');
});
});
}));
it('Close button should be present if overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { it('Close button should be not present if is not overlay mode', () => {
return tcb component.urlFile = 'fake-url-file';
.createAsync(ViewerComponent) component.overlayMode = false;
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = true;
fixture.detectChanges(); viewerComponentFixture.detectChanges();
expect(element.querySelector('#viewer-close-button')).not.toBeNull(); expect(element.querySelector('#viewer-close-button')).toBeNull();
}); });
}));
it('Close button should be not present if is not overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { it('Click on close button should hide the viewer', () => {
return tcb component.urlFile = 'fake-url-file';
.createAsync(ViewerComponent) component.overlayMode = true;
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = false;
fixture.detectChanges(); viewerComponentFixture.detectChanges();
element.querySelector('#viewer-close-button').click();
viewerComponentFixture.detectChanges();
expect(element.querySelector('#viewer-main-container')).toBeNull();
expect(element.querySelector('#viewer-close-button')).toBeNull(); });
});
}));
it('Esc button should not hide the viewerls if is not overlay mode', () => {
component.overlayMode = false;
it('Click on close button should hide the viewer', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { component.urlFile = 'fake-url-file';
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = true;
fixture.detectChanges(); viewerComponentFixture.detectChanges();
element.querySelector('#viewer-close-button').click(); EventMock.keyDown(27);
fixture.detectChanges(); viewerComponentFixture.detectChanges();
expect(element.querySelector('#viewer-main-container')).toBeNull(); expect(element.querySelector('#viewer-main-container')).not.toBeNull();
}); });
}));
it('Esc button should not hide the viewerls if is not overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { it('Esc button should hide the viewer', () => {
return tcb component.urlFile = 'fake-url-file';
.createAsync(ViewerComponent) component.overlayMode = true;
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.overlayMode = false;
component.urlFile = 'fake-url-file'; viewerComponentFixture.detectChanges();
EventMock.keyDown(27);
viewerComponentFixture.detectChanges();
expect(element.querySelector('#viewer-main-container')).toBeNull();
});
fixture.detectChanges(); });
EventMock.keyDown(27);
fixture.detectChanges();
expect(element.querySelector('#viewer-main-container')).not.toBeNull();
});
}));
it('Esc button should hide the viewer', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { describe('Attribute', () => {
return tcb it('Url File should be mandatory', () => {
.createAsync(ViewerComponent) component.showViewer = true;
.then((fixture) => { component.urlFile = undefined;
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
component.overlayMode = true;
fixture.detectChanges(); expect(() => {
EventMock.keyDown(27); component.ngOnChanges();
fixture.detectChanges(); }).toThrow();
expect(element.querySelector('#viewer-main-container')).toBeNull(); });
});
}));
});
describe('Attribute', () => { it('showViewer default value should be true', () => {
it('Url File should be mandatory', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { expect(component.showViewer).toBe(true);
return tcb });
.createAsync(ViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
component.showViewer = true;
expect(() => { it('if showViewer value is false the viewer should be hide', () => {
component.ngOnChanges(); component.urlFile = 'fake-url-file';
}).toThrow(); component.showViewer = false;
});
}));
it('showViewer default value should be true', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { viewerComponentFixture.detectChanges();
return tcb expect(element.querySelector('#viewer-main-container')).toBeNull();
.createAsync(ViewerComponent) });
.then((fixture) => { });
let component = fixture.componentInstance;
expect(component.showViewer).toBe(true); describe('Extension Type Test', () => {
}); it('if extension file is a pdf the pdf viewer should be loaded', (done) => {
})); component.urlFile = 'fake-url-file.pdf';
it('if showViewer value is false the viewer should be hide', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { component.ngOnChanges().then(() => {
return tcb viewerComponentFixture.detectChanges();
.createAsync(ViewerComponent) expect(element.querySelector('pdf-viewer')).not.toBeNull();
.then((fixture) => { done();
let component = fixture.componentInstance; });
let element = fixture.nativeElement; });
component.urlFile = 'fake-url-file';
component.showViewer = false;
fixture.detectChanges(); it('if extension file is a image the img viewer should be loaded', (done) => {
expect(element.querySelector('#viewer-main-container')).toBeNull(); component.urlFile = 'fake-url-file.png';
});
}));
});
/* tslint:disable:max-line-length */ component.ngOnChanges().then(() => {
describe('Extension Type Test', () => { viewerComponentFixture.detectChanges();
it('if extension file is a pdf the pdf viewer should be loaded', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { expect(element.querySelector('#viewer-image')).not.toBeNull();
return tcb done();
.createAsync(ViewerComponent) });
.then((fixture) => { });
let component = fixture.componentInstance;
let element = fixture.nativeElement;
component.urlFile = 'fake-url-file.pdf';
component.ngOnChanges().then(() => { it('if extension file is a not supported the not supported div should be loaded', (done) => {
fixture.detectChanges(); component.urlFile = 'fake-url-file.unsupported';
expect(element.querySelector('pdf-viewer')).not.toBeNull();
});
});
}));
/* tslint:disable:max-line-length */ component.ngOnChanges().then(() => {
it('if extension file is a image the img viewer should be loaded', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { viewerComponentFixture.detectChanges();
return tcb expect(element.querySelector('not-supported-format')).not.toBeNull();
.createAsync(ViewerComponent) done();
.then((fixture) => { });
let component = fixture.componentInstance; });
let element = fixture.nativeElement; });
component.urlFile = 'fake-url-file.png';
component.ngOnChanges().then(() => { describe('MimeType handling', () => {
fixture.detectChanges(); it('should display a PDF file identified by mimetype when the filename has no extension', (done) => {
expect(element.querySelector('#viewer-image')).not.toBeNull(); component.urlFile = 'content';
}); component.mimeType = 'application/pdf';
});
}));
/* tslint:disable:max-line-length */ component.ngOnChanges().then(() => {
it('if extension file is a not supported the not supported div should be loaded', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { viewerComponentFixture.detectChanges();
return tcb expect(element.querySelector('pdf-viewer')).not.toBeNull();
.createAsync(ViewerComponent) done();
.then((fixture) => { });
let component = fixture.componentInstance;
let element = fixture.nativeElement;
component.urlFile = 'fake-url-file.unsupported';
component.ngOnChanges().then(() => { });
fixture.detectChanges();
expect(element.querySelector('not-supported-format')).not.toBeNull();
});
});
}));
});
/* tslint:disable:max-line-length */ it('should display a PDF file identified by mimetype when the file extension is wrong', (done) => {
describe('MimeType handling', () => { component.urlFile = 'content.bin';
it('should display a PDF file identified by mimetype when the filename has no extension', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { component.mimeType = 'application/pdf';
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
let element = fixture.nativeElement;
component.urlFile = 'content';
component.mimeType = 'application/pdf';
component.ngOnChanges().then(() => { component.ngOnChanges().then(() => {
fixture.detectChanges(); viewerComponentFixture.detectChanges();
expect(element.querySelector('pdf-viewer')).not.toBeNull(); expect(element.querySelector('pdf-viewer')).not.toBeNull();
}); done();
}); });
})); });
it('should display a PDF file identified by mimetype when the file extension is wrong', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { it('should display an image file identified by mimetype when the filename has no extension', (done) => {
return tcb component.urlFile = 'content';
.createAsync(ViewerComponent) component.mimeType = 'image/png';
.then((fixture) => {
let component = fixture.componentInstance;
let element = fixture.nativeElement;
component.urlFile = 'content.bin';
component.mimeType = 'application/pdf';
component.ngOnChanges().then(() => { component.ngOnChanges().then(() => {
fixture.detectChanges(); viewerComponentFixture.detectChanges();
expect(element.querySelector('pdf-viewer')).not.toBeNull(); expect(element.querySelector('#viewer-image')).not.toBeNull();
}); done();
}); });
})); });
it('should display an image file identified by mimetype when the filename has no extension', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { it('should display a image file identified by mimetype when the file extension is wrong', (done) => {
return tcb component.urlFile = 'content.bin';
.createAsync(ViewerComponent) component.mimeType = 'image/png';
.then((fixture) => {
let component = fixture.componentInstance;
let element = fixture.nativeElement;
component.urlFile = 'content';
component.mimeType = 'image/png';
component.ngOnChanges().then(() => { component.ngOnChanges().then(() => {
fixture.detectChanges(); viewerComponentFixture.detectChanges();
expect(element.querySelector('#viewer-image')).not.toBeNull(); expect(element.querySelector('#viewer-image')).not.toBeNull();
}); done();
}); });
})); });
});
it('should display a image file identified by mimetype when the file extension is wrong', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { });
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
let element = fixture.nativeElement;
component.urlFile = 'content.bin';
component.mimeType = 'image/png';
component.ngOnChanges().then(() => {
fixture.detectChanges();
expect(element.querySelector('#viewer-image')).not.toBeNull();
});
});
}));
});
});