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.
*/
import { Ng2ActivitiProcesslistComponent } from './src/components/ng2-activiti-processlist.component';
import { ActivitiProcessService } from './src/services/activiti-process-service.service';
import { ActivitiProcesslistComponent } from './src/components/activiti-processlist.component';
import { ActivitiProcessService } from './src/services/activiti-process.service';
// components
export * from './src/components/ng2-activiti-processlist.component';
export * from './src/components/activiti-processlist.component';
// services
export * from './src/services/activiti-process-service.service';
export * from './src/services/activiti-process.service';
export const ACTIVITI_PROCESSLIST_DIRECTIVES: [any] = [
Ng2ActivitiProcesslistComponent
ActivitiProcesslistComponent
];
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.
*/
import {
Component,
OnInit
} from '@angular/core';
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 {Component, OnInit } from '@angular/core';
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';
import { ProcessInstance } from '../models/process-instance';
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 ],
pipes: [ AlfrescoPipeTranslate ],
providers: [ CONTEXT_MENU_PROVIDERS ]
})
export class Ng2ActivitiProcesslistComponent implements OnInit {
export class ActivitiProcesslistComponent implements OnInit {
errorMessage: string;
processInstances: ProcessInstance[];
data: ObjectDataTableAdapter;
constructor (
private processService: ActivitiProcessService,
private translate: AlfrescoTranslationService
) {
constructor (private processService: ActivitiProcessService, private translate: AlfrescoTranslationService) {
if (translate !== null) {
translate.addTranslationFolder('node_modules/ng2-activiti-processlist/src');
}
@ -72,8 +58,7 @@ export class Ng2ActivitiProcesslistComponent implements OnInit {
this.processService.getProcesses()
.subscribe(
(processInstances) => {
// this.processInstances = processInstances;
this.data = new ObjectDataTableAdapter(
this.data = new ObjectDataTableAdapter(
processInstances,
[
{type: 'text', key: 'id', title: 'Id', sortable: true},
@ -89,5 +74,4 @@ export class Ng2ActivitiProcesslistComponent implements OnInit {
onItemClick(processInstance: ProcessInstance, event: any) {
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,
"max-line-length": [
true,
140
180
],
"member-ordering": [
true,

View File

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

View File

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