Skip to content

Commit

Permalink
fix readonly form in complete task (#3857)
Browse files Browse the repository at this point in the history
  • Loading branch information
eromano committed Oct 3, 2018
1 parent 98327be commit 488ce94
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 36 deletions.
6 changes: 3 additions & 3 deletions lib/core/form/components/form.component.html
Expand Up @@ -3,7 +3,7 @@
</ng-content>
</div>

<div *ngIf="hasForm()" class="{{form.className}} adf-form-container">
<div *ngIf="hasForm()" class="{{form.className}} adf-form-container" [ngClass]="{'adf-readonly-form': readOnly }">
<mat-card>
<mat-card-header>
<mat-card-title>
Expand All @@ -19,7 +19,7 @@ <h4>
<mat-icon>refresh</mat-icon>
</button>
</div>
<span *ngIf="isTitleEnabled()" class="adf-form-title">{{form.taskName}}</span>
<span *ngIf="isTitleEnabled()" class="adf-form-title">{{form.taskName}}</span>

</h4>
</mat-card-title>
Expand All @@ -43,7 +43,7 @@ <h4>
[disabled]="!isOutcomeButtonEnabled(outcome)"
[class.adf-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)"
(click)="onOutcomeClicked(outcome)">
{{outcome.name | uppercase | translate}}
{{outcome.name | translate | uppercase }}
</button>
</mat-card-actions>
</mat-card>
Expand Down
2 changes: 1 addition & 1 deletion lib/core/form/components/start-form.component.html
Expand Up @@ -26,7 +26,7 @@ <h2 *ngIf="isTitleEnabled()" class="mdl-card__title-text">{{form.taskName}}</h2>
[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}}
</button>
</mat-card-content>
<mat-card-actions *ngIf="showRefreshButton">
Expand Down
Expand Up @@ -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}}
</button>
</adf-start-form>
</mat-card-content>
<mat-card-content *ngIf="hasErrorMessage()">
<mat-card-subtitle class="error-message" id="no-process-message">
{{'ADF_PROCESS_LIST.START_PROCESS.NO_PROCESS_DEFINITIONS' | translate}}
{{'ADF_PROCESS_LIST.START_PROCESS.NO_PROCESS_DEFINITIONS' | translate | uppercase}}
</mat-card-subtitle>
</mat-card-content>
<mat-card-actions *ngIf="!hasStartForm()">
Expand All @@ -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}}
</button>
<button
color="primary"
Expand All @@ -80,7 +80,7 @@
data-automation-id="btn-start"
id="button-start"
class="btn-start">
{{'ADF_PROCESS_LIST.START_PROCESS.FORM.ACTION.START' | translate}}
{{'ADF_PROCESS_LIST.START_PROCESS.FORM.ACTION.START' | translate | uppercase}}
</button>
</mat-card-actions>
</mat-card>
Expand Up @@ -30,7 +30,7 @@ <h2 class="activiti-task-details__header">
[showCompleteButton]="showFormCompleteButton"
[disableCompleteButton]="!isCompleteButtonEnabled()"
[showSaveButton]="isSaveButtonVisible()"
[readOnly]="readOnlyForm"
[readOnly]="internalReadOnlyForm"
[fieldValidators]="fieldValidators"
(formSaved)='onFormSaved($event)'
(formCompleted)='onFormCompleted($event)'
Expand Down Expand Up @@ -103,7 +103,7 @@ <h2 class="activiti-task-details__header">
</adf-task-header>
<adf-people *ngIf="showInvolvePeople" #people
[people]="taskPeople"
[readOnly]="readOnlyForm"
[readOnly]="internalReadOnlyForm"
[taskId]="taskDetails.id">
</adf-people>
</adf-info-drawer-tab>
Expand Down
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
});

Expand Down Expand Up @@ -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');
});

Expand All @@ -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');
});
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 488ce94

Please sign in to comment.