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)

This commit is contained in:
dominikiwanekhyland 2024-08-29 16:59:34 +02:00 committed by GitHub
parent 158baa7cc9
commit 18d81f6307
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View File

@ -28,7 +28,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { HarnessLoader } from '@angular/cdk/testing'; import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing'; import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
import { MatChipOptionHarness } from '@angular/material/chips/testing'; import { MatChipHarness } from '@angular/material/chips/testing';
describe('TagsCreatorComponent', () => { describe('TagsCreatorComponent', () => {
let fixture: ComponentFixture<TagsCreatorComponent>; let fixture: ComponentFixture<TagsCreatorComponent>;
@ -105,7 +105,7 @@ describe('TagsCreatorComponent', () => {
* @returns list of tags * @returns list of tags
*/ */
async function getAddedTags(): Promise<string[]> { async function getAddedTags(): Promise<string[]> {
const matChipHarness = await loader.getAllHarnesses(MatChipOptionHarness.with({ selector: '.adf-tags-chip' })); const matChipHarness = await loader.getAllHarnesses(MatChipHarness.with({ selector: '.adf-tags-chip' }));
const tagElements = []; const tagElements = [];
for (const matChip of matChipHarness) { for (const matChip of matChipHarness) {
tagElements.push(await matChip.getText()); tagElements.push(await matChip.getText());
@ -400,6 +400,23 @@ describe('TagsCreatorComponent', () => {
expect(error).toBe('TAG.TAGS_CREATOR.ERRORS.EXISTING_TAG'); 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(() => { it('should show error when deleting other Tag1 and Tag2 is typed and already existing tag', fakeAsync(() => {
const tag1 = 'Some tag'; const tag1 = 'Some tag';
const tag2 = 'Other tag'; const tag2 = 'Other tag';

View File

@ -182,7 +182,13 @@ export class TagsCreatorComponent implements OnInit, OnDestroy {
this.tagNameControl.valueChanges this.tagNameControl.valueChanges
.pipe( .pipe(
map((name: string) => name.trim()), map((name: string) => name.trim()),
distinctUntilChanged(), distinctUntilChanged((previous, current) => {
const valueNotChanged = previous === current;
if (valueNotChanged) {
this.exactTagSet$.next();
}
return valueNotChanged;
}),
tap((name: string) => { tap((name: string) => {
this._typing = true; this._typing = true;
if (name) { if (name) {