diff --git a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts index 79bd67f658..899d254285 100644 --- a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts +++ b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts @@ -526,6 +526,13 @@ describe('ObjectiveDialogComponent', () => { expect(component.objectiveForm.getRawValue().alignment).toEqual(null); }); + it('should return team and objective with same text in alignment possibilities', async () => { + component.input.nativeElement.value = 'puzzle'; + component.alignmentPossibilities$ = of([alignmentPossibility1, alignmentPossibility2]); + component.filter(); + expect(component.filteredOptions$.getValue()).toEqual([alignmentPossibility1, alignmentPossibility2]); + }); + it('should load existing objective alignment to objectiveForm', async () => { objectiveService.getAlignmentPossibilities.mockReturnValue(of([alignmentPossibility1, alignmentPossibility2])); component.generateAlignmentPossibilities(3, objectiveWithAlignment, null); @@ -577,14 +584,14 @@ describe('ObjectiveDialogComponent', () => { expect(component.filteredOptions$.getValue()).toEqual([modifiedAlignmentPossibility]); // Search for two objects - component.input.nativeElement.value = 'we'; + component.input.nativeElement.value = 'buy'; component.alignmentPossibilities$ = of([alignmentPossibility1, alignmentPossibility2]); component.filter(); let modifiedAlignmentPossibilities = [ { teamId: 1, teamName: 'Puzzle ITC', - alignmentObjectDtos: [alignmentObject2, alignmentObject3], + alignmentObjectDtos: [alignmentObject3], }, { teamId: 2, @@ -609,7 +616,7 @@ describe('ObjectiveDialogComponent', () => { 'objective', ); expect(alignmentObject!.objectId).toEqual(1); - expect(alignmentObject!.objectTitle).toEqual('We want to increase the income'); + expect(alignmentObject!.objectTitle).toEqual('We want to increase the income puzzle buy'); // keyResult alignmentObject = component.findAlignmentObject([alignmentPossibility1, alignmentPossibility2], 1, 'keyResult'); diff --git a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts index ddcfbbdb6d..a8e4b8e09b 100644 --- a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts +++ b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts @@ -299,6 +299,10 @@ export class ObjectiveFormComponent implements OnInit { filter() { let filterValue = this.input.nativeElement.value.toLowerCase(); this.alignmentPossibilities$.subscribe((alignmentPossibilities: AlignmentPossibility[]) => { + let matchingTeams = alignmentPossibilities.filter((possibility: AlignmentPossibility) => + possibility.teamName.toLowerCase().includes(filterValue), + ); + let filteredObjects: AlignmentPossibilityObject[] = alignmentPossibilities.flatMap( (alignmentPossibility: AlignmentPossibility) => alignmentPossibility.alignmentObjectDtos.filter((alignmentPossibilityObject: AlignmentPossibilityObject) => @@ -323,15 +327,8 @@ export class ObjectiveFormComponent implements OnInit { ), })); - if (optionList.length == 0) { - this.filteredOptions$.next( - alignmentPossibilities.filter((possibility: AlignmentPossibility) => - possibility.teamName.toLowerCase().includes(filterValue), - ), - ); - } else { - this.filteredOptions$.next(optionList); - } + let finalArray = matchingTeams.concat(optionList); + this.filteredOptions$.next([...new Set(finalArray)]); }); } diff --git a/frontend/src/app/shared/testData.ts b/frontend/src/app/shared/testData.ts index 86093db50f..17790a00c0 100644 --- a/frontend/src/app/shared/testData.ts +++ b/frontend/src/app/shared/testData.ts @@ -635,13 +635,13 @@ export const keyResultActions: KeyResultMetric = { export const alignmentObject1: AlignmentPossibilityObject = { objectId: 1, - objectTitle: 'We want to increase the income', + objectTitle: 'We want to increase the income puzzle buy', objectType: 'objective', }; export const alignmentObject2: AlignmentPossibilityObject = { objectId: 2, - objectTitle: 'Our office has more plants for we', + objectTitle: 'Our office has more plants for', objectType: 'objective', };