From 488ce948bebfc17ab50fcf983b318eb85d3353eb Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Wed, 3 Oct 2018 19:01:02 +0100 Subject: [PATCH] fix readonly form in complete task (#3857) --- lib/core/form/components/form.component.html | 6 +- .../form/components/start-form.component.html | 2 +- .../components/start-process.component.html | 8 +- .../components/task-details.component.html | 4 +- .../components/task-details.component.spec.ts | 80 +++++++++++++------ 5 files changed, 64 insertions(+), 36 deletions(-) diff --git a/lib/core/form/components/form.component.html b/lib/core/form/components/form.component.html index eb02080825..8ffc2dede4 100644 --- a/lib/core/form/components/form.component.html +++ b/lib/core/form/components/form.component.html @@ -3,7 +3,7 @@ -
+
@@ -19,7 +19,7 @@ refresh
- {{form.taskName}} + {{form.taskName}} @@ -43,7 +43,7 @@ [disabled]="!isOutcomeButtonEnabled(outcome)" [class.adf-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)" (click)="onOutcomeClicked(outcome)"> - {{outcome.name | uppercase | translate}} + {{outcome.name | translate | uppercase }} diff --git a/lib/core/form/components/start-form.component.html b/lib/core/form/components/start-form.component.html index 4b87295554..5093ea90e7 100644 --- a/lib/core/form/components/start-form.component.html +++ b/lib/core/form/components/start-form.component.html @@ -26,7 +26,7 @@ [class.mdl-button--colored]="!outcome.isSystem" [class.adf-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)" (click)="onOutcomeClicked(outcome)"> - {{outcome.name| uppercase | translate}} + {{ outcome.name | translate | uppercase}} diff --git a/lib/process-services/process-list/components/start-process.component.html b/lib/process-services/process-list/components/start-process.component.html index df6e72c47a..6dcedf1e64 100644 --- a/lib/process-services/process-list/components/start-process.component.html +++ b/lib/process-services/process-list/components/start-process.component.html @@ -54,13 +54,13 @@ mat-button (click)="cancelStartProcess()" id="cancel_process"> - {{'ADF_PROCESS_LIST.START_PROCESS.FORM.ACTION.CANCEL'| translate}} + {{'ADF_PROCESS_LIST.START_PROCESS.FORM.ACTION.CANCEL'| translate | uppercase}} - {{'ADF_PROCESS_LIST.START_PROCESS.NO_PROCESS_DEFINITIONS' | translate}} + {{'ADF_PROCESS_LIST.START_PROCESS.NO_PROCESS_DEFINITIONS' | translate | uppercase}} @@ -69,7 +69,7 @@ *ngIf="!hasStartForm()" (click)="cancelStartProcess()" id="cancel_process"> - {{'ADF_PROCESS_LIST.START_PROCESS.FORM.ACTION.CANCEL'| translate}} + {{'ADF_PROCESS_LIST.START_PROCESS.FORM.ACTION.CANCEL'| translate | uppercase}} diff --git a/lib/process-services/task-list/components/task-details.component.html b/lib/process-services/task-list/components/task-details.component.html index 9501396ed3..61de49f3f0 100644 --- a/lib/process-services/task-list/components/task-details.component.html +++ b/lib/process-services/task-list/components/task-details.component.html @@ -30,7 +30,7 @@ [showCompleteButton]="showFormCompleteButton" [disableCompleteButton]="!isCompleteButtonEnabled()" [showSaveButton]="isSaveButtonVisible()" - [readOnly]="readOnlyForm" + [readOnly]="internalReadOnlyForm" [fieldValidators]="fieldValidators" (formSaved)='onFormSaved($event)' (formCompleted)='onFormCompleted($event)' @@ -103,7 +103,7 @@ diff --git a/lib/process-services/task-list/components/task-details.component.spec.ts b/lib/process-services/task-list/components/task-details.component.spec.ts index 87353ee1d8..077f353eda 100644 --- a/lib/process-services/task-list/components/task-details.component.spec.ts +++ b/lib/process-services/task-list/components/task-details.component.spec.ts @@ -20,12 +20,27 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { of, throwError } from 'rxjs'; -import { FormModel, FormOutcomeEvent, FormOutcomeModel, FormService, setupTestBed, BpmUserService } from '@alfresco/adf-core'; +import { + FormModel, + FormOutcomeEvent, + FormOutcomeModel, + FormService, + setupTestBed, + BpmUserService +} from '@alfresco/adf-core'; import { CommentProcessService, LogService, AuthenticationService } from '@alfresco/adf-core'; import { UserProcessModel } from '@alfresco/adf-core'; import { TaskDetailsModel } from '../models/task-details.model'; -import { noDataMock, taskDetailsMock, standaloneTaskWithForm, standaloneTaskWithoutForm, taskFormMock, tasksMock, taskDetailsWithOutAssigneeMock } from '../../mock'; +import { + noDataMock, + taskDetailsMock, + standaloneTaskWithForm, + standaloneTaskWithoutForm, + taskFormMock, + tasksMock, + taskDetailsWithOutAssigneeMock +} from '../../mock'; import { TaskListService } from './../services/tasklist.service'; import { TaskDetailsComponent } from './task-details.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; @@ -82,12 +97,12 @@ describe('TaskDetailsComponent', () => { commentProcessService = TestBed.get(CommentProcessService); authService = TestBed.get(AuthenticationService); - spyOn(authService, 'getBpmLoggedUser').and.returnValue(of({ email: 'fake-email'})); + spyOn(authService, 'getBpmLoggedUser').and.returnValue(of({ email: 'fake-email' })); spyOn(commentProcessService, 'getTaskComments').and.returnValue(of([ - {message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, - {message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, - {message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}} + { message: 'Test1', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }, + { message: 'Test2', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }, + { message: 'Test3', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } } ])); fixture = TestBed.createComponent(TaskDetailsComponent); @@ -130,12 +145,25 @@ describe('TaskDetailsComponent', () => { expect(fixture.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.MESSAGES.NONE'); }); - it('shoud display a form when the task has an associated form', () => { + it('shoud display a form when the task has an associated form', (done) => { component.taskId = '123'; fixture.detectChanges(); fixture.whenStable().then(() => { fixture.detectChanges(); expect(fixture.debugElement.query(By.css('adf-form'))).not.toBeNull(); + done(); + }); + }); + + it('shoud display a form in readonly when the task has an associated form and readOnlyForm is true', (done) => { + component.readOnlyForm = true; + component.taskId = '123'; + fixture.detectChanges(); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('adf-form'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('.adf-readonly-form'))).not.toBeNull(); + done(); }); }); @@ -222,7 +250,7 @@ describe('TaskDetailsComponent', () => { })); it('should fetch new task details when taskId changed', () => { - component.ngOnChanges({'taskId': change}); + component.ngOnChanges({ 'taskId': change }); expect(getTaskDetailsSpy).toHaveBeenCalledWith('456'); }); @@ -237,13 +265,13 @@ describe('TaskDetailsComponent', () => { it('should NOT fetch new task details when taskId changed to null', async(() => { fixture.detectChanges(); fixture.whenStable().then(() => { - component.ngOnChanges({'taskId': nullChange}); + component.ngOnChanges({ 'taskId': nullChange }); expect(getTaskDetailsSpy).not.toHaveBeenCalled(); }); })); it('should set a placeholder message when taskId changed to null', () => { - component.ngOnChanges({'taskId': nullChange}); + component.ngOnChanges({ 'taskId': nullChange }); fixture.detectChanges(); expect(fixture.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.MESSAGES.NONE'); }); @@ -361,7 +389,7 @@ describe('TaskDetailsComponent', () => { 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.ngOnChanges({ 'taskId': new SimpleChange('123', '456', true) }); component.taskPeople = []; component.taskDetails = new TaskDetailsModel(taskDetailsMock); component.taskDetails.endDate = new Date('2017-10-03T17:03:57.311+0000'); @@ -373,7 +401,7 @@ describe('TaskDetailsComponent', () => { 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.ngOnChanges({ 'taskId': new SimpleChange('123', '456', true) }); component.taskPeople = []; component.taskDetails = new TaskDetailsModel(taskDetailsMock); component.taskDetails.endDate = new Date('2017-10-03T17:03:57.311+0000'); @@ -385,7 +413,7 @@ describe('TaskDetailsComponent', () => { 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.ngOnChanges({ 'taskId': new SimpleChange('123', '456', true) }); component.taskPeople = [fakeUser]; component.taskDetails = new TaskDetailsModel(taskDetailsMock); component.taskDetails.endDate = null; @@ -397,7 +425,7 @@ describe('TaskDetailsComponent', () => { 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.ngOnChanges({ 'taskId': new SimpleChange('123', '456', true) }); component.taskPeople = [fakeUser]; component.taskDetails = new TaskDetailsModel(taskDetailsMock); component.taskDetails.endDate = new Date('2017-10-03T17:03:57.311+0000'); @@ -409,7 +437,7 @@ describe('TaskDetailsComponent', () => { it('should comments be present if showComments is true', () => { component.showComments = true; component.showHeaderContent = true; - component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)}); + component.ngOnChanges({ 'taskId': new SimpleChange('123', '456', true) }); component.taskPeople = []; component.taskDetails = new TaskDetailsModel(taskDetailsMock); @@ -419,7 +447,7 @@ describe('TaskDetailsComponent', () => { it('should comments NOT be present if showComments is false', () => { component.showComments = false; - component.ngOnChanges({'taskId': new SimpleChange('123', '456', true)}); + component.ngOnChanges({ 'taskId': new SimpleChange('123', '456', true) }); component.taskPeople = []; component.taskDetails = new TaskDetailsModel(taskDetailsMock); @@ -437,16 +465,16 @@ describe('TaskDetailsComponent', () => { it('should return an observable with user search results', (done) => { spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(of([{ - id: 1, - firstName: 'fake-test-1', - lastName: 'fake-last-1', - email: 'fake-test-1@test.com' - }, { - id: 2, - firstName: 'fake-test-2', - lastName: 'fake-last-2', - email: 'fake-test-2@test.com' - }])); + id: 1, + firstName: 'fake-test-1', + lastName: 'fake-last-1', + email: 'fake-test-1@test.com' + }, { + id: 2, + firstName: 'fake-test-2', + lastName: 'fake-last-2', + email: 'fake-test-2@test.com' + }])); component.peopleSearch.subscribe((users) => { expect(users.length).toBe(2);