Skip to content

Commit

Permalink
fix: updating the expense observable on adding or removing receipt (#…
Browse files Browse the repository at this point in the history
…3067)

* updating the expense observale on additing or removing receipt

* fixed unit tests
  • Loading branch information
devendrafyle authored Jun 11, 2024
1 parent b5e09d1 commit 25c72b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ export function TestCases3(getTestBed) {
component.mode = 'edit';
component.attachedReceiptsCount = 0;
spyOn(component, 'getExpenseAttachments').and.returnValue(of(fileObject4));
expensesService.getExpenseById.and.returnValue(of(platformExpenseWithExtractedData));
spyOn(component.loadAttachments$, 'next');
loaderService.showLoader.and.resolveTo();
loaderService.hideLoader.and.resolveTo();
Expand Down Expand Up @@ -1020,6 +1021,7 @@ export function TestCases3(getTestBed) {
mode: 'ios',
});
expect(component.loadAttachments$.next).toHaveBeenCalledOnceWith();
expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('tx3qHxFNgRcZ');
expect(component.attachedReceiptsCount).toEqual(1);
}));

Expand Down Expand Up @@ -1420,6 +1422,7 @@ export function TestCases3(getTestBed) {
transactionOutboxService.fileUpload.and.resolveTo(mockFileData[0]);
activatedRoute.snapshot.params.id = mockFileData[0].transaction_id;
expensesService.attachReceiptToExpense.and.returnValue(of(platformExpenseWithExtractedData));
expensesService.getExpenseById.and.returnValue(of(platformExpenseWithExtractedData));
spyOn(component, 'parseFile').and.returnValue(null);
spyOn(component.loadAttachments$, 'next');
fixture.detectChanges();
Expand All @@ -1435,6 +1438,7 @@ export function TestCases3(getTestBed) {
mockFileData[0].transaction_id,
mockFileData[0].id
);
expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txbO4Xaj4N53');
expect(component.loadAttachments$.next).toHaveBeenCalledOnceWith();
expect(trackingService.fileUploadComplete).toHaveBeenCalledOnceWith({
mode: 'edit',
Expand Down
11 changes: 9 additions & 2 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4447,8 +4447,11 @@ export class AddEditExpensePage implements OnInit {
}
});
} else {
const editExpenseAttachments$ = this.etxn$.pipe(
switchMap((etxn) => (etxn.tx.id ? this.platformExpense$ : of({}))),
this.platformExpense$ = this.etxn$.pipe(
switchMap((etxn) => this.expensesService.getExpenseById(etxn.tx.id).pipe(shareReplay(1)))
);

const editExpenseAttachments$ = this.platformExpense$.pipe(
map((expense: PlatformExpense) => expense.file_ids?.length || 0)
);

Expand Down Expand Up @@ -4651,6 +4654,10 @@ export class AddEditExpensePage implements OnInit {
};
};

this.platformExpense$ = this.etxn$.pipe(
switchMap((etxn) => this.expensesService.getExpenseById(etxn.tx.id).pipe(shareReplay(1)))
);

if (this.mode === 'add') {
if (data && data.attachments) {
this.newExpenseDataUrls = data.attachments;
Expand Down

0 comments on commit 25c72b4

Please sign in to comment.