Skip to content

Commit

Permalink
Adjust filter function
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Jun 3, 2024
1 parent cfa8873 commit 6b70b7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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)]);
});
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/shared/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down

0 comments on commit 6b70b7d

Please sign in to comment.