diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts index 392f2dd03c..2d3741de59 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts @@ -1111,6 +1111,10 @@ export function TestCases1(getTestBed) { }); describe('splitExpCategoryHandler():', () => { + beforeEach(() => { + component.pendingTransactionAllowedToReportAndSplit = true; + }); + it('should call method to display split expense modal and split by category', () => { setFormValid(); @@ -1128,9 +1132,23 @@ export function TestCases1(getTestBed) { expect(component.showFormValidationErrors).toHaveBeenCalledTimes(1); }); + + it('should show toast message if pendingTransactionAllowedToReportAndSplit is false', () => { + spyOn(component, 'showTransactionPendingToast'); + + component.pendingTransactionAllowedToReportAndSplit = false; + + component.splitExpCategoryHandler(); + + expect(component.showTransactionPendingToast).toHaveBeenCalledTimes(1); + }); }); describe('splitExpProjectHandler():', () => { + beforeEach(() => { + component.pendingTransactionAllowedToReportAndSplit = true; + }); + it('should call method to display split expense modal and split by project', () => { setFormValid(); @@ -1148,11 +1166,26 @@ export function TestCases1(getTestBed) { expect(component.showFormValidationErrors).toHaveBeenCalledTimes(1); }); + + it('should show toast message if pendingTransactionAllowedToReportAndSplit is false', () => { + spyOn(component, 'showTransactionPendingToast'); + + component.pendingTransactionAllowedToReportAndSplit = false; + + component.splitExpProjectHandler(); + + expect(component.showTransactionPendingToast).toHaveBeenCalledTimes(1); + }); }); describe('splitExpCostCenterHandler():', () => { + beforeEach(() => { + component.pendingTransactionAllowedToReportAndSplit = true; + }); + it('should call method to display split expense modal and split by cost centers', () => { setFormValid(); + spyOn(component, 'openSplitExpenseModal'); component.splitExpCostCenterHandler(); @@ -1167,6 +1200,16 @@ export function TestCases1(getTestBed) { expect(component.showFormValidationErrors).toHaveBeenCalledTimes(1); }); + + it('should show toast message if pendingTransactionAllowedToReportAndSplit is false', () => { + spyOn(component, 'showTransactionPendingToast'); + + component.pendingTransactionAllowedToReportAndSplit = false; + + component.splitExpCostCenterHandler(); + + expect(component.showTransactionPendingToast).toHaveBeenCalledTimes(1); + }); }); describe('getActionSheetOptions():', () => { 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 67b50bbe5e..825ca36257 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 @@ -968,29 +968,49 @@ export class AddEditExpensePage implements OnInit { } splitExpCategoryHandler(): void { - if (this.fg.valid) { - this.openSplitExpenseModal('categories'); + if (this.pendingTransactionAllowedToReportAndSplit) { + if (this.fg.valid) { + this.openSplitExpenseModal('categories'); + } else { + this.showFormValidationErrors(); + } } else { - this.showFormValidationErrors(); + this.showTransactionPendingToast(); } } splitExpProjectHandler(): void { - if (this.fg.valid) { - this.openSplitExpenseModal('projects'); + if (this.pendingTransactionAllowedToReportAndSplit) { + if (this.fg.valid) { + this.openSplitExpenseModal('projects'); + } else { + this.showFormValidationErrors(); + } } else { - this.showFormValidationErrors(); + this.showTransactionPendingToast(); } } splitExpCostCenterHandler(): void { - if (this.fg.valid) { - this.openSplitExpenseModal('cost centers'); + if (this.pendingTransactionAllowedToReportAndSplit) { + if (this.fg.valid) { + this.openSplitExpenseModal('cost centers'); + } else { + this.showFormValidationErrors(); + } } else { - this.showFormValidationErrors(); + this.showTransactionPendingToast(); } } + showTransactionPendingToast(): void { + this.showSnackBarToast( + { message: "Can't split as the Transaction status is pending. Please wait until it's Posted." }, + 'failure', + ['msb-failure'] + ); + } + getActionSheetOptions(): Observable<{ text: string; handler: () => void }[]> { return forkJoin({ orgSettings: this.orgSettingsService.get(),