[ADF-1689] fix task comment when the task is running (#2449)

* [ADF-1689] fix task comment when the task is running

* fix test
This commit is contained in:
Eugenio Romano 2017-10-09 00:01:22 +01:00 committed by GitHub
parent 7db1a29f04
commit e90fbcf9bc
6 changed files with 65 additions and 25 deletions

View File

@ -15,7 +15,9 @@
* limitations under the License.
*/
export let taskDetailsMock = {
import { TaskDetailsModel } from '../models/task-details.model';
export let taskDetailsMock = new TaskDetailsModel({
'id': '91',
'name': 'Request translation',
'description': null,
@ -47,9 +49,9 @@ export let taskDetailsMock = {
'memberOfCandidateUsers': false,
'managerOfCandidateGroup': false,
'memberOfCandidateGroup': false
};
});
export let taskFormMock = {
export let taskFormMock = new TaskDetailsModel({
'id': 4,
'name': 'Translation request',
'processDefinitionId': 'TranslationProcess:2:8',
@ -178,15 +180,15 @@ export let taskFormMock = {
'variables': [],
'gridsterForm': false,
'globalDateFormat': 'D-M-YYYY'
};
});
export let tasksMock = {
export let tasksMock = new TaskDetailsModel({
data: [
taskDetailsMock
]
};
});
export let noDataMock = {
export let noDataMock = new TaskDetailsModel({
data: [{
'size': 1,
'total': 1,
@ -198,4 +200,4 @@ export let noDataMock = {
'createdBy': {'id': 4004, 'firstName': 'gadget', 'lastName': 'inspector', 'email': 'gadget@inspector.com'}
}]
}]
};
});

View File

@ -89,7 +89,7 @@
<md-card *ngIf="showComments">
<md-card-content>
<adf-comments #activiticomments
[readOnly]="taskPeople?.length === 0"
[readOnly]="isReadOnlyComment()"
[taskId]="taskDetails.id">
</adf-comments>
</md-card-content>

View File

@ -287,31 +287,60 @@ describe('TaskDetailsComponent', () => {
describe('Comments', () => {
it('should comments NOT be readonly if is there are user involved', () => {
component.showComments = true;
component.showHeaderContent = true;
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [fakeUser];
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(false);
});
it('should comments be readonly if is there are no user involved', () => {
it('should comments be readonly if the task is complete and no user are involved', () => {
component.showComments = true;
component.showHeaderContent = true;
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [];
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
component.taskDetails.endDate = '2017-10-03T17:03:57.311+0000';
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(true);
});
it('should comments be readonly if the task is complete and user are NOT involved', () => {
component.showComments = true;
component.showHeaderContent = true;
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [];
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
component.taskDetails.endDate = '2017-10-03T17:03:57.311+0000';
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(true);
});
it('should comments NOT be readonly if the task is NOT complete and user are NOT involved', () => {
component.showComments = true;
component.showHeaderContent = true;
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [fakeUser];
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
component.taskDetails.endDate = null;
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(false);
});
it('should comments NOT be readonly if the task is complete and user are involved', () => {
component.showComments = true;
component.showHeaderContent = true;
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [fakeUser];
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
component.taskDetails.endDate = '2017-10-03T17:03:57.311+0000';
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(false);
});
it('should comments be present if showComments is true', () => {
component.showComments = true;
component.showHeaderContent = true;
component.taskPeople = [];
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [];
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
fixture.detectChanges();
expect(component.activiticomments).toBeDefined();
@ -319,8 +348,9 @@ describe('TaskDetailsComponent', () => {
it('should comments NOT be present if showComments is false', () => {
component.showComments = false;
component.taskPeople = [];
component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)});
component.taskPeople = [];
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
fixture.detectChanges();
expect(component.activiticomments).not.toBeDefined();

View File

@ -311,7 +311,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges {
}
onFormError(error: any): void {
this.errorDialogRef = this.dialog.open(this.errorDialog, { width: '500px' });
this.errorDialogRef = this.dialog.open(this.errorDialog, {width: '500px'});
this.onError.emit(error);
}
@ -356,11 +356,15 @@ export class TaskDetailsComponent implements OnInit, OnChanges {
this.showAssignee = false;
}
getTaskHeaderViewClass() {
getTaskHeaderViewClass(): string {
if (this.showAssignee) {
return 'assign-edit-view';
} else {
return 'default-view';
}
}
isReadOnlyComment(): boolean {
return (this.taskDetails && this.taskDetails.isCompleted()) && (this.taskPeople && this.taskPeople.length === 0);
}
}

View File

@ -105,7 +105,7 @@ export class TaskHeaderComponent implements OnChanges {
* Returns task's status
*/
getTaskStatus(): string {
return this.isCompleted() ? 'Completed' : 'Running';
return (this.taskDetails && this.taskDetails.isCompleted()) ? 'Completed' : 'Running';
}
/**

View File

@ -104,4 +104,8 @@ export class TaskDetailsModel {
return fullName.trim();
}
isCompleted(): boolean {
return !!this.endDate;
}
}