From b71a844689f64d0c594438c9a03b064a67cb8b34 Mon Sep 17 00:00:00 2001 From: Arjun Date: Mon, 2 Sep 2024 20:59:06 +0530 Subject: [PATCH] fix: getRecentProjects() method of add-edit-expense page (#3194) --- src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts | 5 +++-- src/app/fyle/add-edit-expense/add-edit-expense.page.ts | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts index 58c5915927..9c48f6a1f8 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts @@ -61,6 +61,7 @@ import { unflattenedExpWoProject, unflattenedExpenseWithCCCGroupId2, unflattenedTxnData, + unflattenedTxnWithCategory, } from 'src/app/core/mock-data/unflattened-txn.data'; import { CostCenter } from 'src/app/core/models/v1/cost-center.model'; import { AccountsService } from 'src/app/core/services/accounts.service'; @@ -814,8 +815,8 @@ export function TestCases5(getTestBed) { component.activeCategories$ = of(sortedCategory); component.recentlyUsedValues$ = of(recentlyUsedRes); component.isProjectCategoryRestrictionsEnabled$ = of(true); + component.etxn$ = of(unflattenedTxnWithCategory); authService.getEou.and.resolveTo(apiEouRes); - component.fg.controls.category.setValue(orgCategoryData); recentlyUsedItemsService.getRecentlyUsedProjects.and.returnValue(of(recentlyUsedProjectRes)); fixture.detectChanges(); @@ -825,7 +826,7 @@ export function TestCases5(getTestBed) { expect(recentlyUsedItemsService.getRecentlyUsedProjects).toHaveBeenCalledOnceWith({ recentValues: recentlyUsedRes, eou: apiEouRes, - categoryIds: component.fg.controls.category.value && component.fg.controls.category.value.id, + categoryIds: [`${unflattenedTxnWithCategory.tx.org_category_id}`], isProjectCategoryRestrictionsEnabled: true, activeCategoryList: sortedCategory, }); diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts index 9f676f840d..429e4c9302 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts @@ -1621,14 +1621,14 @@ export class AddEditExpensePage implements OnInit { eou: this.authService.getEou(), activeCategories: this.activeCategories$, isProjectCategoryRestrictionsEnabled: this.isProjectCategoryRestrictionsEnabled$, + selectedCategoryId: this.etxn$.pipe(map((etxn) => etxn.tx.org_category_id)), }).pipe( - switchMap(({ recentValues, eou, activeCategories, isProjectCategoryRestrictionsEnabled }) => { - const formControl = this.getFormControl('category') as { value: OrgCategory }; - const categoryId = formControl.value && (formControl.value.id as unknown as string[]); + switchMap(({ recentValues, eou, activeCategories, isProjectCategoryRestrictionsEnabled, selectedCategoryId }) => { + const categoryId = `${selectedCategoryId}` || null; return this.recentlyUsedItemsService.getRecentlyUsedProjects({ recentValues, eou, - categoryIds: categoryId, + categoryIds: [categoryId], isProjectCategoryRestrictionsEnabled, activeCategoryList: activeCategories, });