Skip to content

Commit

Permalink
feat: Added Split expenses restrictions in add edit expense (#2786)
Browse files Browse the repository at this point in the history
* feat: Added edit expense

* feat: test fixes

* feat: split exception added

* feat: feature turned off by default

* feat: reverted unnecessary changes in test

* moved repeated code to before each
  • Loading branch information
Suraj Kumar authored Feb 28, 2024
1 parent 377416d commit 0094007
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
43 changes: 43 additions & 0 deletions src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -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():', () => {
Expand Down
38 changes: 29 additions & 9 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 0094007

Please sign in to comment.