diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.html b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.html index c58472b989..76c2a0426a 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.html +++ b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.html @@ -8,6 +8,7 @@ { element = fixture.nativeElement; }); + afterEach(() => { + fixture.destroy(); + }); + + it('should have enabled validation if field is NOT readOnly', () => { + const readOnly = false; + widget.field = new FormFieldModel( new FormModel({ taskId: '' }, null, readOnly), { + type: FormFieldTypes.GROUP, + value: [] + }); + fixture.detectChanges(); + + expect(widget.validate).toBeTruthy(); + }); + describe('when is required', () => { beforeEach(() => { @@ -83,13 +98,15 @@ describe('GroupCloudWidgetComponent', () => { describe('when is readOnly', () => { + const readOnly = true; + it('should single chip be disabled', async () => { const mockSpaghetti: IdentityGroupModel[] = [{ id: 'bolognese', name: 'Bolognese' }]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { type: FormFieldTypes.GROUP, value: mockSpaghetti }); @@ -113,7 +130,7 @@ describe('GroupCloudWidgetComponent', () => { { id: 'carbonara', name: 'Carbonara' } ]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { type: FormFieldTypes.GROUP, value: mockSpaghetti }); @@ -131,6 +148,16 @@ describe('GroupCloudWidgetComponent', () => { expect(disabledGroupChips.item(0)).toBeTruthy(); expect(disabledGroupChips.item(1)).toBeTruthy(); }); + + it('should have disabled validation', () => { + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + type: FormFieldTypes.GROUP, + value: [] + }); + fixture.detectChanges(); + + expect(widget.validate).toBeFalsy(); + }); }); describe('when form model has left labels', () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.ts index d192ae84a1..d4cae49e4d 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.ts @@ -51,6 +51,7 @@ export class GroupCloudWidgetComponent extends WidgetComponent implements OnInit title: string; preSelectGroup: IdentityGroupModel[]; search: FormControl; + validate = false; constructor(formService: FormService) { super(formService); @@ -62,6 +63,7 @@ export class GroupCloudWidgetComponent extends WidgetComponent implements OnInit this.mode = this.field.optionType as ComponentSelectionMode; this.title = this.field.placeholder; this.preSelectGroup = this.field.value ? this.field.value : []; + this.validate = this.field.readOnly ? false : true; } // eslint-disable-next-line @typescript-eslint/no-unused-expressions this.search = new FormControl({value: '', disabled: this.field.readOnly}, []), diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.html b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.html index a95be10411..9776467022 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.html +++ b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.html @@ -6,10 +6,10 @@
{ spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(mockShepherdsPie); }); + afterEach(() => { + fixture.destroy(); + }); + it('should preselect the current user', () => { - widget.field = new FormFieldModel(new FormModel(), { value: null, selectLoggedUser: true }); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.PEOPLE, + value: null, + selectLoggedUser: true + }); fixture.detectChanges(); expect(widget.preSelectUsers).toEqual([mockShepherdsPie]); expect(identityUserService.getCurrentUserInfo).toHaveBeenCalled(); }); it('should not preselect the current user if value exist', () => { - widget.field = new FormFieldModel(new FormModel(), { value: [mockYorkshirePudding], selectLoggedUser: true }); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.PEOPLE, + value: [mockYorkshirePudding], + selectLoggedUser: true + }); fixture.detectChanges(); expect(widget.preSelectUsers).toEqual([mockYorkshirePudding]); expect(identityUserService.getCurrentUserInfo).not.toHaveBeenCalled(); }); + it('should have enabled validation if field is NOT readOnly', () => { + const readOnly = false; + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + type: FormFieldTypes.PEOPLE, + value: [] + }); + fixture.detectChanges(); + + expect(widget.validate).toBeTruthy(); + }); + describe('when is required', () => { beforeEach(() => { @@ -102,6 +125,8 @@ describe('PeopleCloudWidgetComponent', () => { describe('when is readOnly', () => { + const readOnly = true; + it('should single chip be disabled', async () => { const mockSpaghetti: IdentityUserModel[] = [{ id: 'bolognese', @@ -109,8 +134,8 @@ describe('PeopleCloudWidgetComponent', () => { email: 'bolognese@example.com' }]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { - type: FormFieldTypes.GROUP, + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + type: FormFieldTypes.PEOPLE, value: mockSpaghetti }); @@ -123,8 +148,8 @@ describe('PeopleCloudWidgetComponent', () => { fixture.detectChanges(); await fixture.whenStable(); - const disabledGroupChip: HTMLElement = element.querySelector('.mat-chip-disabled'); - expect(disabledGroupChip).toBeTruthy(); + const disabledPeopleChip: HTMLElement = element.querySelector('.mat-chip-disabled'); + expect(disabledPeopleChip).toBeTruthy(); }); it('should multi chips be disabled', async () => { @@ -133,8 +158,8 @@ describe('PeopleCloudWidgetComponent', () => { { id: 'carbonara', username: 'Carbonara', email: 'carbonara@example.com' } ]; - widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, true), { - type: FormFieldTypes.GROUP, + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + type: FormFieldTypes.PEOPLE, value: mockSpaghetti }); @@ -147,9 +172,19 @@ describe('PeopleCloudWidgetComponent', () => { fixture.detectChanges(); await fixture.whenStable(); - const disabledGroupChips = element.querySelectorAll('.mat-chip-disabled'); - expect(disabledGroupChips.item(0)).toBeTruthy(); - expect(disabledGroupChips.item(1)).toBeTruthy(); + const disabledPeopleChips = element.querySelectorAll('.mat-chip-disabled'); + expect(disabledPeopleChips.item(0)).toBeTruthy(); + expect(disabledPeopleChips.item(1)).toBeTruthy(); + }); + + it('should have disabled validation', () => { + widget.field = new FormFieldModel( new FormModel({ taskId: ''}, null, readOnly), { + type: FormFieldTypes.PEOPLE, + value: [] + }); + fixture.detectChanges(); + + expect(widget.validate).toBeFalsy(); }); }); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.ts index e6f11e8127..3442840911 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.ts @@ -54,6 +54,7 @@ export class PeopleCloudWidgetComponent extends WidgetComponent implements OnIni preSelectUsers: IdentityUserModel[]; search: FormControl; groupsRestriction: string[]; + validate = false; constructor(formService: FormService, private identityUserService: IdentityUserService) { super(formService); @@ -66,6 +67,7 @@ export class PeopleCloudWidgetComponent extends WidgetComponent implements OnIni this.title = this.field.placeholder; this.preSelectUsers = this.field.value ? this.field.value : []; this.groupsRestriction = this.field.groupsRestriction; + this.validate = this.field.readOnly ? false : true; } // eslint-disable-next-line @typescript-eslint/no-unused-expressions this.search = new FormControl({value: '', disabled: this.field.readOnly}, []),