#1107 Process list refactoring

This commit is contained in:
mauriziovitale84
2016-11-18 11:47:20 +00:00
committed by Mario Romano
parent 3f826bf47a
commit 2bcb8e9b04
6 changed files with 322 additions and 125 deletions

View File

@@ -15,40 +15,51 @@
* limitations under the License.
*/
import { DebugElement, SimpleChange } from '@angular/core';
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { Observable } from 'rxjs/Rx';
import { ActivitiProcessInstanceListComponent } from './activiti-processlist.component';
import { TranslationMock } from './../assets/translation.service.mock';
import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
import { FilterRepresentationModel } from 'ng2-activiti-tasklist';
import { ActivitiProcessService } from '../services/activiti-process.service';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { ActivitiProcessInstanceListComponent } from './activiti-processlist.component';
import { Observable } from 'rxjs/Rx';
import { ObjectDataRow, DataRowEvent, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
import { TranslationMock } from './../assets/translation.service.mock';
import { ActivitiProcessService } from '../services/activiti-process.service';
describe('ActivitiProcessInstanceListComponent', () => {
let fakeGlobalProcesses = [
{
id: 1, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name',
processDefinitionId: 'fakeprocess:5:7507',
processDefinitionKey: 'fakeprocess',
processDefinitionName: 'Fake Process Name',
description: null, category: null,
started: '2017-11-09T12:37:25.184+0000',
startedBy: {
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
}
},
{
id: 2, name: '', description: null, category: null,
started: '2015-11-09T12:37:25.184+0000',
startedBy: {
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
}
}
];
let componentHandler: any;
let fixture: ComponentFixture<ActivitiProcessInstanceListComponent>;
let component: ActivitiProcessInstanceListComponent;
let element: DebugElement;
let service: ActivitiProcessService;
let mockFilter = new FilterRepresentationModel({
appId: '1',
filter: {
name: '',
state: '',
sort: ''
}
});
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
DataTableModule
],
declarations: [ ActivitiProcessInstanceListComponent ], // declare the test component
declarations: [ ActivitiProcessInstanceListComponent ],
providers: [
ActivitiProcessService,
{provide: AlfrescoTranslationService, useClass: TranslationMock}
@@ -56,8 +67,13 @@ describe('ActivitiProcessInstanceListComponent', () => {
}).compileComponents().then(() => {
fixture = TestBed.createComponent(ActivitiProcessInstanceListComponent);
component = fixture.componentInstance;
element = fixture.debugElement;
service = element.injector.get(ActivitiProcessService);
service = fixture.debugElement.injector.get(ActivitiProcessService);
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered',
'upgradeElement'
]);
window['componentHandler'] = componentHandler;
});
}));
@@ -80,37 +96,194 @@ describe('ActivitiProcessInstanceListComponent', () => {
expect(component.data.getColumns().length).toEqual(1);
});
it('should fetch process instances when a filter is provided', () => {
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
component.filter = mockFilter;
fixture.detectChanges();
expect(getProcessInstancesSpy).toHaveBeenCalled();
it('should return an empty process list when no input parameters are passed', () => {
component.ngOnInit();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).toBeTruthy();
});
it('should NOT fetch process instances if filter not provided', () => {
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
it('should return the process instances list', (done) => {
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
component.appId = '1';
component.state = 'open';
component.processDefinitionKey = null;
component.onSuccess.subscribe( (res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
fixture.detectChanges();
expect(getProcessInstancesSpy).not.toHaveBeenCalled();
});
it('should return the process instances list filtered by processDefinitionKey', (done) => {
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
component.appId = '1';
component.state = 'open';
component.processDefinitionKey = 'fakeprocess';
component.onSuccess.subscribe( (res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
fixture.detectChanges();
});
it('should return a currentId null when the processList is empty', () => {
component.selectFirst();
expect(component.getCurrentId()).toBeNull();
});
it('should throw an exception when the response is wrong', (done) => {
spyOn(service, 'getProcessInstances').and.returnValue(Observable.throw('Fake server error'));
component.state = 'open';
component.onError.subscribe( (err) => {
expect(err).toBeDefined();
expect(err).toBe('Fake server error');
done();
});
fixture.detectChanges();
});
it('should reload processes when reload() is called', (done) => {
spyOn(service, 'getProcessInstances').and.returnValue(Observable.throw('Fake server error'));
component.state = 'open';
component.ngOnInit();
component.onSuccess.subscribe( (res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
component.reload();
});
it('should emit row click event', (done) => {
let row = new ObjectDataRow({
id: 999
});
let rowEvent = <DataRowEvent> {value: row};
component.rowClick.subscribe(taskId => {
expect(taskId).toEqual(999);
expect(component.getCurrentId()).toEqual(999);
done();
});
component.onRowClick(rowEvent);
});
describe('component changes', () => {
it('should fetch new process instances when filter changed', () => {
component.filter = new FilterRepresentationModel({});
fixture.detectChanges();
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
component.ngOnChanges({ filter: new SimpleChange(mockFilter, mockFilter) });
expect(getProcessInstancesSpy).toHaveBeenCalled();
beforeEach(() => {
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
component.data = new ObjectDataTableAdapter(
[],
[
{type: 'text', key: 'fake-id', title: 'Name'}
]
);
});
it('should NOT fetch new process instances when properties apart from filter changed', () => {
component.filter = mockFilter;
fixture.detectChanges();
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
it('should NOT reload the process list when no parameters changed', () => {
expect(component.isListEmpty()).toBeTruthy();
component.ngOnChanges({});
expect(getProcessInstancesSpy).not.toHaveBeenCalled();
expect(component.isListEmpty()).toBeTruthy();
});
});
it('should reload the list when the appId parameter changes', (done) => {
const appId = '1';
let change = new SimpleChange(null, appId);
component.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
component.ngOnChanges({'appId': change});
});
it('should reload the list when the processDefinitionKey parameter changes', (done) => {
const processDefinitionKey = 'fakeprocess';
let change = new SimpleChange(null, processDefinitionKey);
component.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
component.ngOnChanges({'processDefinitionKey': change});
});
it('should reload the list when the state parameter changes', (done) => {
const state = 'open';
let change = new SimpleChange(null, state);
component.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
component.ngOnChanges({'state': change});
});
it('should reload the list when the sort parameter changes', (done) => {
const sort = 'desc';
let change = new SimpleChange(null, sort);
component.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
component.ngOnChanges({'sort': change});
});
it('should reload the process list when the name parameter changes', (done) => {
const name = 'FakeTaskName';
let change = new SimpleChange(null, name);
component.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
done();
});
component.ngOnChanges({'name': change});
});
});
});