From 93c5619e232a45a6853ee09f40bc395d83f95cea Mon Sep 17 00:00:00 2001 From: Tomasz Gnyp <49343696+tomgny@users.noreply.github.com> Date: Tue, 28 Jun 2022 12:48:50 +0200 Subject: [PATCH] [AAE-9314] Fix preselected user display in completed task (#7688) * [AAE-9314] Fix preselected user display in completed task * [AAE-9314] add unit tests * Trigger travis --- .../widgets/group/group-cloud.widget.spec.ts | 56 +++++++++++++++++- .../people/people-cloud.widget.spec.ts | 57 ++++++++++++++++++- .../group/components/group-cloud.component.ts | 2 - .../components/people-cloud.component.ts | 2 - 4 files changed, 109 insertions(+), 8 deletions(-) diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts index b8c4f3e3c2..2139396267 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { FormFieldModel, FormFieldTypes, FormModel, setupTestBed } from '@alfresco/adf-core'; +import { FormFieldModel, FormFieldTypes, FormModel, IdentityGroupModel, setupTestBed } from '@alfresco/adf-core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { GroupCloudWidgetComponent } from './group-cloud.widget'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; @@ -65,7 +65,7 @@ describe('GroupCloudWidgetComponent', () => { expect(asterisk.textContent).toEqual('*'); }); - it('should be invalid if no default option after interaction', async () => { + it('should be invalid if no option is selected after interaction', async () => { fixture.detectChanges(); await fixture.whenStable(); @@ -81,6 +81,58 @@ describe('GroupCloudWidgetComponent', () => { }); }); + describe('when is readOnly', () => { + + it('should single chip be disabled', async () => { + const mockSpaghetti: IdentityGroupModel[] = [{ + id: 'bolognese', + name: 'Bolognese' + }]; + + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { + type: FormFieldTypes.GROUP, + value: mockSpaghetti + }); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled'); + expect(disabledFormField).toBeTruthy(); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledGroupChip: HTMLElement = element.querySelector('.mat-chip-disabled'); + expect(disabledGroupChip).toBeTruthy(); + }); + + it('should multi chips be disabled', async () => { + const mockSpaghetti: IdentityGroupModel[] = [ + { id: 'bolognese', name: 'Bolognese' }, + { id: 'carbonara', name: 'Carbonara' } + ]; + + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { + type: FormFieldTypes.GROUP, + value: mockSpaghetti + }); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled'); + expect(disabledFormField).toBeTruthy(); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledGroupChips = element.querySelectorAll('.mat-chip-disabled'); + expect(disabledGroupChips.item(0)).toBeTruthy(); + expect(disabledGroupChips.item(1)).toBeTruthy(); + }); + }); + describe('when form model has left labels', () => { it('should have left labels classes on leftLabels true', async () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts index 15cea99c19..8e702c1e20 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserService, setupTestBed } from '@alfresco/adf-core'; +import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserModel, IdentityUserService, setupTestBed } from '@alfresco/adf-core'; import { TranslateModule } from '@ngx-translate/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PeopleCloudWidgetComponent } from './people-cloud.widget'; @@ -84,7 +84,7 @@ describe('PeopleCloudWidgetComponent', () => { expect(asterisk.textContent).toEqual('*'); }); - it('should be invalid if no default option after interaction', async () => { + it('should be invalid if no option is selected after interaction', async () => { fixture.detectChanges(); await fixture.whenStable(); @@ -100,6 +100,59 @@ describe('PeopleCloudWidgetComponent', () => { }); }); + describe('when is readOnly', () => { + + it('should single chip be disabled', async () => { + const mockSpaghetti: IdentityUserModel[] = [{ + id: 'bolognese', + username: 'Bolognese', + email: 'bolognese@example.com' + }]; + + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { + type: FormFieldTypes.GROUP, + value: mockSpaghetti + }); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled'); + expect(disabledFormField).toBeTruthy(); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledGroupChip: HTMLElement = element.querySelector('.mat-chip-disabled'); + expect(disabledGroupChip).toBeTruthy(); + }); + + it('should multi chips be disabled', async () => { + const mockSpaghetti: IdentityUserModel[] = [ + { id: 'bolognese', username: 'Bolognese', email: 'bolognese@example.com' }, + { id: 'carbonara', username: 'Carbonara', email: 'carbonara@example.com' } + ]; + + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { + type: FormFieldTypes.GROUP, + value: mockSpaghetti + }); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledFormField: HTMLElement = element.querySelector('.mat-form-field-disabled'); + expect(disabledFormField).toBeTruthy(); + + fixture.detectChanges(); + await fixture.whenStable(); + + const disabledGroupChips = element.querySelectorAll('.mat-chip-disabled'); + expect(disabledGroupChips.item(0)).toBeTruthy(); + expect(disabledGroupChips.item(1)).toBeTruthy(); + }); + }); + describe('when form model has left labels', () => { it('should have left labels classes on leftLabels true', async () => { diff --git a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts index 3fa2a16891..b79746b060 100644 --- a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.ts @@ -27,7 +27,6 @@ import { SimpleChanges, OnChanges, OnDestroy, - ChangeDetectionStrategy, SimpleChange } from '@angular/core'; import { FormControl } from '@angular/forms'; @@ -50,7 +49,6 @@ import { ComponentSelectionMode } from '../../types'; ]) ]) ], - changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy { diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts index a23c9b2211..f1d019f8ce 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.ts @@ -26,7 +26,6 @@ import { SimpleChanges, OnChanges, OnDestroy, - ChangeDetectionStrategy, ViewChild, ElementRef, SimpleChange } from '@angular/core'; import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; @@ -54,7 +53,6 @@ import { ComponentSelectionMode } from '../../types'; ]) ], providers: [FullNamePipe], - changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None })