From 18d81f6307894168dd90a79a64723319bc0e058b Mon Sep 17 00:00:00 2001 From: dominikiwanekhyland <141320833+dominikiwanekhyland@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:59:34 +0200 Subject: [PATCH] ACS-8639 - [ACC ]Adding a space to the front/end of a tag name during tag creation removes the 'Tag already exists' validation message (#10138) --- .../tags-creator.component.spec.ts | 21 +++++++++++++++++-- .../tags-creator/tags-creator.component.ts | 8 ++++++- 2 files changed, 26 insertions(+), 3 deletions(-) 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 876ee2984a..4edfa89e52 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 @@ -28,7 +28,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing'; -import { MatChipOptionHarness } from '@angular/material/chips/testing'; +import { MatChipHarness } from '@angular/material/chips/testing'; describe('TagsCreatorComponent', () => { let fixture: ComponentFixture; @@ -105,7 +105,7 @@ describe('TagsCreatorComponent', () => { * @returns list of tags */ async function getAddedTags(): Promise { - const matChipHarness = await loader.getAllHarnesses(MatChipOptionHarness.with({ selector: '.adf-tags-chip' })); + const matChipHarness = await loader.getAllHarnesses(MatChipHarness.with({ selector: '.adf-tags-chip' })); const tagElements = []; for (const matChip of matChipHarness) { tagElements.push(await matChip.getText()); @@ -400,6 +400,23 @@ describe('TagsCreatorComponent', () => { expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.EXISTING_TAG'); })); + it('should show error when duplicated already existing tag with spaces', fakeAsync(() => { + const tag = 'Some tag'; + + spyOn(tagService, 'findTagByName').and.returnValue( + of({ + entry: { + tag, + id: 'tag-1' + } + }) + ); + typeTag(tag + ' '); + + const error = getFirstError(); + expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.EXISTING_TAG'); + })); + it('should show error when deleting other Tag1 and Tag2 is typed and already existing tag', fakeAsync(() => { const tag1 = 'Some tag'; const tag2 = 'Other 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 41efd96eee..b1fb1bcf2a 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 @@ -182,7 +182,13 @@ export class TagsCreatorComponent implements OnInit, OnDestroy { this.tagNameControl.valueChanges .pipe( map((name: string) => name.trim()), - distinctUntilChanged(), + distinctUntilChanged((previous, current) => { + const valueNotChanged = previous === current; + if (valueNotChanged) { + this.exactTagSet$.next(); + } + return valueNotChanged; + }), tap((name: string) => { this._typing = true; if (name) {