Skip to content

Commit d9abcb5

Browse files
committed
Adjust filter function
1 parent 91391d7 commit d9abcb5

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ describe('ObjectiveDialogComponent', () => {
526526
expect(component.objectiveForm.getRawValue().alignment).toEqual(null);
527527
});
528528

529+
it('should return team and objective with same text in alignment possibilities', async () => {
530+
component.input.nativeElement.value = 'puzzle';
531+
component.alignmentPossibilities$ = of([alignmentPossibility1, alignmentPossibility2]);
532+
component.filter();
533+
expect(component.filteredOptions$.getValue()).toEqual([alignmentPossibility1, alignmentPossibility2]);
534+
});
535+
529536
it('should load existing objective alignment to objectiveForm', async () => {
530537
objectiveService.getAlignmentPossibilities.mockReturnValue(of([alignmentPossibility1, alignmentPossibility2]));
531538
component.generateAlignmentPossibilities(3, objectiveWithAlignment, null);
@@ -577,14 +584,14 @@ describe('ObjectiveDialogComponent', () => {
577584
expect(component.filteredOptions$.getValue()).toEqual([modifiedAlignmentPossibility]);
578585

579586
// Search for two objects
580-
component.input.nativeElement.value = 'we';
587+
component.input.nativeElement.value = 'buy';
581588
component.alignmentPossibilities$ = of([alignmentPossibility1, alignmentPossibility2]);
582589
component.filter();
583590
let modifiedAlignmentPossibilities = [
584591
{
585592
teamId: 1,
586593
teamName: 'Puzzle ITC',
587-
alignmentObjectDtos: [alignmentObject2, alignmentObject3],
594+
alignmentObjectDtos: [alignmentObject3],
588595
},
589596
{
590597
teamId: 2,
@@ -609,7 +616,7 @@ describe('ObjectiveDialogComponent', () => {
609616
'objective',
610617
);
611618
expect(alignmentObject!.objectId).toEqual(1);
612-
expect(alignmentObject!.objectTitle).toEqual('We want to increase the income');
619+
expect(alignmentObject!.objectTitle).toEqual('We want to increase the income puzzle buy');
613620

614621
// keyResult
615622
alignmentObject = component.findAlignmentObject([alignmentPossibility1, alignmentPossibility2], 1, 'keyResult');

frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ export class ObjectiveFormComponent implements OnInit {
299299
filter() {
300300
let filterValue = this.input.nativeElement.value.toLowerCase();
301301
this.alignmentPossibilities$.subscribe((alignmentPossibilities: AlignmentPossibility[]) => {
302+
let matchingTeams = alignmentPossibilities.filter((possibility: AlignmentPossibility) =>
303+
possibility.teamName.toLowerCase().includes(filterValue),
304+
);
305+
302306
let filteredObjects: AlignmentPossibilityObject[] = alignmentPossibilities.flatMap(
303307
(alignmentPossibility: AlignmentPossibility) =>
304308
alignmentPossibility.alignmentObjectDtos.filter((alignmentPossibilityObject: AlignmentPossibilityObject) =>
@@ -323,15 +327,8 @@ export class ObjectiveFormComponent implements OnInit {
323327
),
324328
}));
325329

326-
if (optionList.length == 0) {
327-
this.filteredOptions$.next(
328-
alignmentPossibilities.filter((possibility: AlignmentPossibility) =>
329-
possibility.teamName.toLowerCase().includes(filterValue),
330-
),
331-
);
332-
} else {
333-
this.filteredOptions$.next(optionList);
334-
}
330+
let finalArray = matchingTeams.concat(optionList);
331+
this.filteredOptions$.next([...new Set(finalArray)]);
335332
});
336333
}
337334

frontend/src/app/shared/testData.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,13 @@ export const keyResultActions: KeyResultMetric = {
635635

636636
export const alignmentObject1: AlignmentPossibilityObject = {
637637
objectId: 1,
638-
objectTitle: 'We want to increase the income',
638+
objectTitle: 'We want to increase the income puzzle buy',
639639
objectType: 'objective',
640640
};
641641

642642
export const alignmentObject2: AlignmentPossibilityObject = {
643643
objectId: 2,
644-
objectTitle: 'Our office has more plants for we',
644+
objectTitle: 'Our office has more plants for',
645645
objectType: 'objective',
646646
};
647647

0 commit comments

Comments
 (0)