From 52acd0a216afa3cfc833f67edb04ef6b95c20f26 Mon Sep 17 00:00:00 2001 From: Yasa-Nataliya Date: Mon, 25 Sep 2023 13:44:01 +0530 Subject: [PATCH] [ACS-5645] added test cases for tags component --- .../categories-management.component.spec.ts | 6 ++-- .../tags-creator.component.spec.ts | 28 +++++++++++++++++++ .../tags-creator/tags-creator.component.ts | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts b/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts index c4ce59e01f..fee092e9c9 100644 --- a/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts +++ b/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts @@ -240,16 +240,16 @@ describe('CategoriesManagementComponent', () => { }); }); - describe('isEmpty', () => { + describe('isCategoryEmpty', () => { it('should return true when categories is not empty', () => { component.categories = [category3, category4]; - const result = component.isEmpty; + const result = component.isCategoryEmpty; expect(result).toBeTrue(); }); it('should return false when categories is empty', () => { component.categories = []; - const result = component.isEmpty; + const result = component.isCategoryEmpty; expect(result).toBeFalse(); }); }); 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 958b7b67b8..ae30c8920e 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 @@ -322,6 +322,34 @@ describe('TagsCreatorComponent', () => { expect(getNameInput()).toBe(document.activeElement as HTMLInputElement); })); + describe('isNameTagsVisible', () => { + it('should return true when tagNameControlVisible is true', () => { + component.tagNameControlVisible = true; + const result = component.isNameTagsVisible; + expect(result).toBeTrue(); + }); + + it('should return false when tagNameControlVisible is false and tags length is 0', () => { + component.tagNameControlVisible = false; + component.tags = []; + const result = component.isNameTagsVisible; + expect(result).toBeFalse(); + }); + }); + + describe('isTagsEmpty', () => { + it('should return true when tags is not empty', () => { + component.tags = ['new tag 1', 'new tag 2']; + const result = component.isTagsEmpty; + expect(result).toBeTrue(); + }); + it('should return false when tags is empty', () => { + component.tags = []; + const result = component.isTagsEmpty; + expect(result).toBeFalse(); + }); + }); + describe('Errors', () => { /** * Get first error 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 fbb0188606..5b33bc681f 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 @@ -104,7 +104,7 @@ export class TagsCreatorComponent implements OnInit, OnDestroy { if (tagNameControlVisible) { this._existingTagsPanelVisible = true; setTimeout(() => { - this.tagNameInputElement.nativeElement.scrollIntoView(); + this.tagNameInputElement?.nativeElement?.scrollIntoView(); }); } else { this._existingTagsPanelVisible = false;