Improve test coverage

This commit is contained in:
mauriziovitale84 2016-09-22 17:06:17 +01:00
parent 63a7b27eed
commit a2e5bca63e
2 changed files with 18 additions and 2 deletions

View File

@ -21,7 +21,7 @@ import {
expect, expect,
beforeEach beforeEach
} from '@angular/core/testing'; } from '@angular/core/testing';
import { SimpleChange } from '@angular/core';
import { ActivitiTaskList } from './activiti-tasklist.component'; import { ActivitiTaskList } from './activiti-tasklist.component';
import { ActivitiTaskListService } from '../services/activiti-tasklist.service'; import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
import { UserTaskFilterRepresentationModel } from '../models/filter.model'; import { UserTaskFilterRepresentationModel } from '../models/filter.model';
@ -120,6 +120,11 @@ describe('ActivitiTaskList', () => {
taskList.ngOnInit(); taskList.ngOnInit();
}); });
it('should return a currentId null when the taskList is empty', () => {
taskList.selectFirstTask();
expect(taskList.getCurrentTaskId()).toBeNull();
});
it('should throw an exception when the response is wrong', (done) => { it('should throw an exception when the response is wrong', (done) => {
spyOn(taskList.activiti, 'getTotalTasks').and.returnValue(Observable.fromPromise(fakeErrorTaskPromise)); spyOn(taskList.activiti, 'getTotalTasks').and.returnValue(Observable.fromPromise(fakeErrorTaskPromise));
taskList.taskFilter = new UserTaskFilterRepresentationModel({filter: { state: 'open', assignment: 'fake-assignee'}}); taskList.taskFilter = new UserTaskFilterRepresentationModel({filter: { state: 'open', assignment: 'fake-assignee'}});
@ -140,10 +145,21 @@ describe('ActivitiTaskList', () => {
taskList.rowClick.subscribe(taskId => { taskList.rowClick.subscribe(taskId => {
expect(taskId).toEqual(999); expect(taskId).toEqual(999);
expect(taskList.getCurrentTaskId()).toEqual(999);
done(); done();
}); });
taskList.onRowClick(rowEvent); taskList.onRowClick(rowEvent);
}); });
it('should reload task list by filter on binding changes', () => {
spyOn(taskList, 'load').and.stub();
const taskFilter = new UserTaskFilterRepresentationModel({filter: { state: 'open', assignment: 'fake-assignee'}});
let change = new SimpleChange(null, taskFilter);
taskList.ngOnChanges({ 'taskFilter': change });
expect(taskList.load).toHaveBeenCalled();
});
}); });

View File

@ -146,7 +146,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
/** /**
* Select the first task of a tasklist if present * Select the first task of a tasklist if present
*/ */
private selectFirstTask() { selectFirstTask() {
if (!this.isTaskListEmpty()) { if (!this.isTaskListEmpty()) {
this.currentTaskId = this.data.getRows()[0].getValue('id'); this.currentTaskId = this.data.getRows()[0].getValue('id');
} else { } else {