From 3dc1f1149fc389fcb89872afd05285aca4791a66 Mon Sep 17 00:00:00 2001 From: AleksanderSklorz <115619721+AleksanderSklorz@users.noreply.github.com> Date: Thu, 11 May 2023 09:05:51 +0200 Subject: [PATCH] [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 --- .../tags-creator.component.spec.ts | 27 ++++++++++++++++++- .../tags-creator/tags-creator.component.ts | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts index 374f4b178f..9c68ef9634 100644 --- a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts +++ b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.spec.ts @@ -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'; diff --git a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts index b338720381..ce70c6a361 100644 --- a/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts +++ b/lib/content-services/src/lib/tag/tags-creator/tags-creator.component.ts @@ -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[] {