Add tests for start process component

Refs #730
This commit is contained in:
Will Abson 2016-11-03 22:46:02 +00:00
parent aeb44e56c5
commit daec68b423
5 changed files with 150 additions and 18 deletions

View File

@ -54,6 +54,7 @@ var map = {
'ng2-translate': 'npm:ng2-translate',
'alfresco-js-api': 'npm:alfresco-js-api/dist',
'ng2-activiti-form': 'npm:ng2-activiti-form/dist',
'ng2-activiti-tasklist': 'npm:ng2-activiti-tasklist/dist',
'ng2-alfresco-core': 'npm:ng2-alfresco-core/dist',
'ng2-alfresco-datatable': 'npm:ng2-alfresco-datatable/dist'
@ -65,6 +66,7 @@ var packages = {
'ng2-translate': { defaultExtension: 'js' },
'alfresco-js-api': { main: './alfresco-js-api.js', defaultExtension: 'js'},
'ng2-activiti-form': { main: './index.js', defaultExtension: 'js'},
'ng2-activiti-tasklist': { main: './index.js', defaultExtension: 'js'},
'ng2-alfresco-core': { main: './index.js', defaultExtension: 'js'},
'ng2-alfresco-datatable': { main: './index.js', defaultExtension: 'js'}

View File

@ -46,7 +46,7 @@ module.exports = function (config) {
{ pattern: 'node_modules/ng2-alfresco-core/dist/**/*.*', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.*', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-activiti-tasklist/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-activiti-form/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-activiti-form/dist/**/*.*', included: false, served: true, watched: false },
// paths to support debugging with source maps in dev tools
{pattern: 'src/**/*.ts', included: false, watched: false},

View File

@ -16,22 +16,13 @@
*/
import { Observable } from 'rxjs/Rx';
import { EventEmitter } from '@angular/core';
export interface LangChangeEvent {
lang: string;
translations: any;
}
export class TranslationMock {
public onLangChange: EventEmitter<LangChangeEvent> = new EventEmitter<LangChangeEvent>();
public get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
return Observable.of(key);
}
addTranslationFolder() {
}
}

View File

@ -0,0 +1,143 @@
/*!
* @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 { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { ActivitiFormModule } from 'ng2-activiti-form';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { FormService } from 'ng2-activiti-form';
import { TranslationMock } from './../assets/translation.service.mock';
import { ActivitiStartProcessButton } from './activiti-start-process.component';
import { ActivitiProcessService } from '../services/activiti-process.service';
describe('ActivitiStartProcessButton', () => {
let componentHandler: any;
let component: ActivitiStartProcessButton;
let fixture: ComponentFixture<ActivitiStartProcessButton>;
let processService: ActivitiProcessService;
let formService: FormService;
let getDefinitionsSpy: jasmine.Spy;
let startProcessSpy: jasmine.Spy;
let de: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ CoreModule, ActivitiFormModule ],
declarations: [
ActivitiStartProcessButton
],
providers: [
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
ActivitiProcessService,
FormService
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivitiStartProcessButton);
component = fixture.componentInstance;
processService = fixture.debugElement.injector.get(ActivitiProcessService);
formService = fixture.debugElement.injector.get(FormService);
getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(Observable.of([{
id: 'my:process1',
name: 'My Process 1'
}, {
id: 'my:process2',
name: 'My Process 2'
}]));
startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(Observable.of({
id: '32323',
name: 'Process'
}));
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered',
'upgradeElement'
]);
window['componentHandler'] = componentHandler;
});
it('should display the correct number of processes in the select list', () => {
fixture.detectChanges();
de = fixture.debugElement.query(By.css('select'));
expect(de.children.length).toBe(2);
});
it('should display the correct process def details', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
de = fixture.debugElement.query(By.css('select option'));
let optionEl: HTMLOptionElement = de.nativeElement;
expect(optionEl.value).toBe('my:process1');
expect(optionEl.textContent.trim()).toBe('My Process 1');
done();
});
});
it('should call service to start process if required fields provided', (done) => {
component.name = 'My new process';
component.processDefinitionId = 'my:process1';
component.showDialog();
fixture.detectChanges();
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).toHaveBeenCalled();
done();
});
});
it('should avoid calling service to start process if required fields NOT provided', (done) => {
component.showDialog();
fixture.detectChanges();
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).not.toHaveBeenCalled();
done();
});
});
it('should call service to start process with the correct parameters', (done) => {
component.name = 'My new process';
component.processDefinitionId = 'my:process1';
component.showDialog();
fixture.detectChanges();
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined);
done();
});
});
it('should indicate start form is missing when process does not have a start form', (done) => {
component.name = 'My new process';
component.processDefinitionId = 'my:process1';
component.showDialog();
fixture.detectChanges();
component.startProcess();
fixture.whenStable().then(() => {
expect(component.isStartFormMissingOrValid()).toBe(true);
done();
});
});
});

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { Component, Input, OnInit, ViewChild, DebugElement } from '@angular/core';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { ActivitiStartForm } from 'ng2-activiti-form';
import { ActivitiProcessService } from './../services/activiti-process.service';
@ -34,7 +34,7 @@ export class ActivitiStartProcessButton implements OnInit {
appId: string;
@ViewChild('dialog')
dialog: any;
dialog: DebugElement;
@ViewChild('startForm')
startForm: ActivitiStartForm;
@ -68,9 +68,7 @@ export class ActivitiStartProcessButton implements OnInit {
}
public showDialog() {
if (this.dialog) {
this.dialog.nativeElement.showModal();
}
this.dialog.nativeElement.showModal();
}
public startProcess() {
@ -90,9 +88,7 @@ export class ActivitiStartProcessButton implements OnInit {
}
public cancel() {
if (this.dialog) {
this.dialog.nativeElement.close();
}
this.dialog.nativeElement.close();
}
private getSelectedProcess(): any {