[ACS-5155] tags message about required field displayed after discarding changes (#8550)

* ACS-5155 Hide required error after discarding changes

* ACS-5155 Removed redundant variables
This commit is contained in:
AleksanderSklorz
2023-05-11 09:05:51 +02:00
committed by GitHub
parent 42322f8a9f
commit 3dc1f1149f
2 changed files with 29 additions and 1 deletions

View File

@@ -300,7 +300,7 @@ describe('TagsCreatorComponent', () => {
describe('Errors', () => {
function getFirstError(): string {
const error = fixture.debugElement.query(By.directive(MatError));
return error.nativeElement.textContent;
return error?.nativeElement.textContent;
}
it('should show error for only spaces', fakeAsync(() => {
@@ -309,12 +309,26 @@ describe('TagsCreatorComponent', () => {
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.EMPTY_TAG');
}));
it('should show error for only spaces if tags are changed', fakeAsync(() => {
typeTag(' ');
component.tags = ['new tag 1', 'new tag 2'];
fixture.detectChanges();
expect(getFirstError()).toBe('TAG.TAGS_CREATOR.ERRORS.EMPTY_TAG');
}));
it('should show error for required', fakeAsync(() => {
typeTag('');
const error = getFirstError();
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.REQUIRED');
}));
it('should not show error for required if tags are changed', fakeAsync(() => {
typeTag('');
component.tags = ['new tag 1', 'new tag 2'];
fixture.detectChanges();
expect(getFirstError()).toBeUndefined();
}));
it('should show error when duplicated already added tag', fakeAsync(() => {
const tag = 'Some tag';
@@ -325,6 +339,17 @@ describe('TagsCreatorComponent', () => {
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.ALREADY_ADDED_TAG');
}));
it('should show error when duplicated already added tag if tags are changed', fakeAsync(() => {
const tag = 'Some tag';
addTagToAddedList(tag);
typeTag(tag);
component.tags = ['Some tag'];
fixture.detectChanges();
expect(getFirstError()).toBe('TAG.TAGS_CREATOR.ERRORS.ALREADY_ADDED_TAG');
}));
it('should show error when duplicated already existing tag', fakeAsync(() => {
const tag = 'Some tag';

View File

@@ -84,6 +84,9 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
this._existingTags = null;
this.loadTags(this.tagNameControl.value);
this.tagNameControl.updateValueAndValidity();
if (this.tagNameControl.errors?.required) {
this.tagNameControl.markAsUntouched();
}
}
get tags(): string[] {