mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
@@ -16,19 +16,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing';
|
||||||
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 { Observable } from 'rxjs/Rx';
|
||||||
import { ObjectDataRow, DataRowEvent, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
|
import { ActivitiProcessInstanceListComponent } from './activiti-processlist.component';
|
||||||
|
|
||||||
|
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
|
||||||
|
import { DataTableModule, ObjectDataRow, DataRowEvent, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
|
||||||
|
|
||||||
import { TranslationMock } from './../assets/translation.service.mock';
|
import { TranslationMock } from './../assets/translation.service.mock';
|
||||||
|
import { ProcessInstance } from '../models/process-instance.model';
|
||||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||||
|
|
||||||
describe('ActivitiProcessInstanceListComponent', () => {
|
describe('ActivitiProcessInstanceListComponent', () => {
|
||||||
|
|
||||||
let fakeGlobalProcesses = [
|
let fakeGlobalProcesses = [
|
||||||
{
|
new ProcessInstance({
|
||||||
id: 1, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name',
|
id: 1, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name',
|
||||||
processDefinitionId: 'fakeprocess:5:7507',
|
processDefinitionId: 'fakeprocess:5:7507',
|
||||||
processDefinitionKey: 'fakeprocess',
|
processDefinitionKey: 'fakeprocess',
|
||||||
@@ -38,14 +40,14 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
|||||||
startedBy: {
|
startedBy: {
|
||||||
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
|
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
{
|
new ProcessInstance({
|
||||||
id: 2, name: '', description: null, category: null,
|
id: 2, name: '', description: null, category: null,
|
||||||
started: '2015-11-09T12:37:25.184+0000',
|
started: '2015-11-09T12:37:25.184+0000',
|
||||||
startedBy: {
|
startedBy: {
|
||||||
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
|
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
let componentHandler: any;
|
let componentHandler: any;
|
||||||
@@ -102,6 +104,17 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
|||||||
expect(component.isListEmpty()).toBeTruthy();
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit onSuccess event when process instances loaded', fakeAsync(() => {
|
||||||
|
let emitSpy = spyOn(component.onSuccess, 'emit');
|
||||||
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
|
component.appId = '1';
|
||||||
|
component.state = 'open';
|
||||||
|
component.processDefinitionKey = null;
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick();
|
||||||
|
expect(emitSpy).toHaveBeenCalledWith(fakeGlobalProcesses);
|
||||||
|
}));
|
||||||
|
|
||||||
it('should return the process instances list', (done) => {
|
it('should return the process instances list', (done) => {
|
||||||
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
component.appId = '1';
|
component.appId = '1';
|
||||||
@@ -152,6 +165,19 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit onSuccess event when reload() called', fakeAsync(() => {
|
||||||
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
|
component.appId = '1';
|
||||||
|
component.state = 'open';
|
||||||
|
component.processDefinitionKey = null;
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick();
|
||||||
|
let emitSpy = spyOn(component.onSuccess, 'emit');
|
||||||
|
component.reload();
|
||||||
|
tick();
|
||||||
|
expect(emitSpy).toHaveBeenCalledWith(fakeGlobalProcesses);
|
||||||
|
}));
|
||||||
|
|
||||||
it('should reload processes when reload() is called', (done) => {
|
it('should reload processes when reload() is called', (done) => {
|
||||||
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
component.data = new ObjectDataTableAdapter(
|
component.data = new ObjectDataTableAdapter(
|
||||||
@@ -173,6 +199,19 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
|||||||
component.reload();
|
component.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should avoid emitting onSuccess event when reload() called with emit=false', fakeAsync(() => {
|
||||||
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
|
component.appId = '1';
|
||||||
|
component.state = 'open';
|
||||||
|
component.processDefinitionKey = null;
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick();
|
||||||
|
let emitSpy = spyOn(component.onSuccess, 'emit');
|
||||||
|
component.reload(false);
|
||||||
|
tick();
|
||||||
|
expect(emitSpy).not.toHaveBeenCalled();
|
||||||
|
}));
|
||||||
|
|
||||||
it('should emit row click event', (done) => {
|
it('should emit row click event', (done) => {
|
||||||
let row = new ObjectDataRow({
|
let row = new ObjectDataRow({
|
||||||
id: 999
|
id: 999
|
||||||
|
@@ -19,6 +19,8 @@ import { Component, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChange
|
|||||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||||
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow } from 'ng2-alfresco-datatable';
|
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow } from 'ng2-alfresco-datatable';
|
||||||
import { TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
import { TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
||||||
|
|
||||||
|
import { ProcessInstance } from '../models/process-instance.model';
|
||||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -53,7 +55,7 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
|||||||
rowClick: EventEmitter<string> = new EventEmitter<string>();
|
rowClick: EventEmitter<string> = new EventEmitter<string>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
onSuccess: EventEmitter<any> = new EventEmitter<any>();
|
onSuccess: EventEmitter<ProcessInstance[]> = new EventEmitter<ProcessInstance[]>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
onError: EventEmitter<any> = new EventEmitter<any>();
|
onError: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
Reference in New Issue
Block a user