mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -300,7 +300,7 @@ describe('TagsCreatorComponent', () => {
|
|||||||
describe('Errors', () => {
|
describe('Errors', () => {
|
||||||
function getFirstError(): string {
|
function getFirstError(): string {
|
||||||
const error = fixture.debugElement.query(By.directive(MatError));
|
const error = fixture.debugElement.query(By.directive(MatError));
|
||||||
return error.nativeElement.textContent;
|
return error?.nativeElement.textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should show error for only spaces', fakeAsync(() => {
|
it('should show error for only spaces', fakeAsync(() => {
|
||||||
@@ -309,12 +309,26 @@ describe('TagsCreatorComponent', () => {
|
|||||||
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.EMPTY_TAG');
|
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(() => {
|
it('should show error for required', fakeAsync(() => {
|
||||||
typeTag('');
|
typeTag('');
|
||||||
const error = getFirstError();
|
const error = getFirstError();
|
||||||
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.REQUIRED');
|
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(() => {
|
it('should show error when duplicated already added tag', fakeAsync(() => {
|
||||||
const tag = 'Some tag';
|
const tag = 'Some tag';
|
||||||
|
|
||||||
@@ -325,6 +339,17 @@ describe('TagsCreatorComponent', () => {
|
|||||||
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.ALREADY_ADDED_TAG');
|
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(() => {
|
it('should show error when duplicated already existing tag', fakeAsync(() => {
|
||||||
const tag = 'Some tag';
|
const tag = 'Some tag';
|
||||||
|
|
||||||
|
@@ -84,6 +84,9 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
|
|||||||
this._existingTags = null;
|
this._existingTags = null;
|
||||||
this.loadTags(this.tagNameControl.value);
|
this.loadTags(this.tagNameControl.value);
|
||||||
this.tagNameControl.updateValueAndValidity();
|
this.tagNameControl.updateValueAndValidity();
|
||||||
|
if (this.tagNameControl.errors?.required) {
|
||||||
|
this.tagNameControl.markAsUntouched();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get tags(): string[] {
|
get tags(): string[] {
|
||||||
|
Reference in New Issue
Block a user