AAE-20282 fix submit button enabled when required people/groups widget empty (#9334)

This commit is contained in:
Robert Duda
2024-02-14 16:25:30 +01:00
committed by GitHub
parent 2175b4bdab
commit 1b3b419f72
4 changed files with 40 additions and 6 deletions

View File

@@ -130,6 +130,23 @@ describe('GroupCloudWidgetComponent', () => {
expect(element.querySelector('.adf-invalid')).toBeTruthy(); expect(element.querySelector('.adf-invalid')).toBeTruthy();
}); });
it('should be invalid after deselecting all groups', async () => {
widget.onChangedGroup([{id: 'test-id', name: 'test-name'}]);
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-error-text')).toBeFalsy();
const removeGroupIcon = element.querySelector('[data-automation-id="adf-cloud-group-chip-remove-icon-test-name"]');
removeGroupIcon.dispatchEvent(new Event('click'));
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-error-text')).toBeTruthy();
expect(element.querySelector('.adf-error-text').textContent).toContain('ADF_CLOUD_GROUPS.ERROR.NOT_FOUND');
});
}); });
describe('when is readOnly', () => { describe('when is readOnly', () => {

View File

@@ -89,13 +89,13 @@ export class GroupCloudWidgetComponent extends WidgetComponent implements OnInit
}); });
} }
ngOnDestroy() { ngOnDestroy(): void {
this.onDestroy$.next(true); this.onDestroy$.next(true);
this.onDestroy$.complete(); this.onDestroy$.complete();
} }
onChangedGroup(groups) { onChangedGroup(groups: IdentityGroupModel[]): void {
this.field.value = [...groups]; this.field.value = groups?.length ? [...groups] : null;
this.onFieldChanged(this.field); this.onFieldChanged(this.field);
} }

View File

@@ -158,6 +158,23 @@ describe('PeopleCloudWidgetComponent', () => {
expect(element.querySelector('.adf-invalid')).toBeTruthy(); expect(element.querySelector('.adf-invalid')).toBeTruthy();
}); });
it('should be invalid after deselecting all people', async () => {
widget.onChangedUser([{id: 'test-id', username: 'test-name'}]);
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-error-text')).toBeFalsy();
const removeGroupIcon = element.querySelector('[data-automation-id="adf-people-cloud-chip-remove-icon-test-name"]');
removeGroupIcon.dispatchEvent(new Event('click'));
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-error-text')).toBeTruthy();
expect(element.querySelector('.adf-error-text').textContent).toContain('ADF_CLOUD_USERS.ERROR.NOT_FOUND');
});
}); });
describe('when is readOnly', () => { describe('when is readOnly', () => {

View File

@@ -99,13 +99,13 @@ export class PeopleCloudWidgetComponent extends WidgetComponent implements OnIni
} }
} }
ngOnDestroy() { ngOnDestroy(): void {
this.onDestroy$.next(true); this.onDestroy$.next(true);
this.onDestroy$.complete(); this.onDestroy$.complete();
} }
onChangedUser(users) { onChangedUser(users: IdentityUserModel[]): void {
this.field.value = [...users]; this.field.value = users?.length ? [...users] : null;
this.onFieldChanged(this.field); this.onFieldChanged(this.field);
} }