-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new flow of add-edit expense page #3453
base: feat_split_expense
Are you sure you want to change the base?
Conversation
WalkthroughThe expense splitting functionality in the Changes
Suggested labels
Suggested reviewers
Possibly related PRs
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts
(10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build (12.x)
🔇 Additional comments (1)
src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts (1)
Line range hint
1182-1214
: Superstar level consolidation of split handlers!The refactoring of multiple split handlers into a single
splitExpenseHandler
simplifies the code. The test coverage looks comprehensive, checking:
- Valid form submission
- Form validation errors
- Pending transaction restrictions
const splitConfig = { | ||
category: { | ||
is_visible: !!expenseFieldObjData.org_category_id, | ||
value: component.getFormValues().category, | ||
is_mandatory: expenseFieldObjData.org_category_id?.is_mandatory || false, | ||
}, | ||
project: { | ||
is_visible: !!expenseFieldObjData.project_id, | ||
value: component.getFormValues().project, | ||
is_mandatory: expenseFieldObjData.project_id?.is_mandatory || false, | ||
}, | ||
costCenter: { | ||
is_visible: !!expenseFieldObjData.cost_center_id, | ||
value: component.getFormValues().costCenter, | ||
is_mandatory: expenseFieldObjData.cost_center_id?.is_mandatory || false, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Mind-blowing refactor, but let's make the splitConfig more robust!
The splitConfig object structure looks good, but we can make it even better by extracting it into a reusable interface.
interface SplitFieldConfig {
is_visible: boolean;
value: any;
is_mandatory: boolean;
}
interface SplitConfig {
category: SplitFieldConfig;
project: SplitFieldConfig;
costCenter: SplitFieldConfig;
}
it('should get all action sheet options', (done) => { | ||
orgSettingsService.get.and.returnValue( | ||
of({ | ||
...orgSettingsData, | ||
expense_settings: { ...orgSettingsData.expense_settings, split_expense_settings: { enabled: true } }, | ||
}) | ||
); | ||
component.activeCategories$ = of(sortedCategory); | ||
component.costCenters$ = of(expectedCCdata); | ||
projectsService.getAllActive.and.returnValue(of(projectsV1Data)); | ||
component.filteredCategories$ = of(categorieListRes); | ||
component.txnFields$ = of(expenseFieldObjData); | ||
component.isCccExpense = 'tx3qHxFNgRcZ'; | ||
component.canDismissCCCE = true; | ||
component.isCorporateCreditCardEnabled = true; | ||
component.canRemoveCardExpense = true; | ||
component.isExpenseMatchedForDebitCCCE = true; | ||
spyOn(component, 'splitExpCategoryHandler'); | ||
spyOn(component, 'splitExpProjectHandler'); | ||
spyOn(component, 'splitExpCostCenterHandler'); | ||
spyOn(component, 'splitExpenseHandler'); | ||
spyOn(component, 'markPersonalHandler'); | ||
spyOn(component, 'markDismissHandler'); | ||
spyOn(component, 'removeCCCHandler'); | ||
launchDarklyService.getVariation.and.returnValue(of(true)); | ||
fixture.detectChanges(); | ||
|
||
let actionSheetOptions; | ||
|
||
component.getActionSheetOptions().subscribe((res) => { | ||
actionSheetOptions = res; | ||
expect(res.length).toEqual(5); | ||
expect(res.length).toEqual(4); | ||
expect(orgSettingsService.get).toHaveBeenCalledTimes(1); | ||
expect(projectsService.getAllActive).toHaveBeenCalledTimes(1); | ||
expect(launchDarklyService.getVariation).toHaveBeenCalledOnceWith( | ||
'show_project_mapped_categories_in_split_expense', | ||
false | ||
); | ||
}); | ||
|
||
actionSheetOptions[0].handler(); | ||
expect(component.splitExpCategoryHandler).toHaveBeenCalledTimes(1); | ||
expect(component.splitExpenseHandler).toHaveBeenCalledTimes(1); | ||
actionSheetOptions[1].handler(); | ||
expect(component.splitExpProjectHandler).toHaveBeenCalledTimes(1); | ||
actionSheetOptions[2].handler(); | ||
expect(component.markPersonalHandler).toHaveBeenCalledTimes(1); | ||
actionSheetOptions[3].handler(); | ||
actionSheetOptions[2].handler(); | ||
expect(component.markDismissHandler).toHaveBeenCalledTimes(1); | ||
actionSheetOptions[4].handler(); | ||
actionSheetOptions[3].handler(); | ||
expect(component.removeCCCHandler).toHaveBeenCalledTimes(1); | ||
expect(component.splitExpCostCenterHandler).not.toHaveBeenCalled(); | ||
done(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Action sheet options test needs more power!
While the test covers the basic scenarios, we should add test cases for:
- Error handling when orgSettings call fails
- Edge cases when some action handlers throw errors
Add these test cases:
it('should handle orgSettings error gracefully', (done) => {
orgSettingsService.get.and.returnValue(throwError(() => new Error('Network error')));
component.getActionSheetOptions().subscribe({
error: (err) => {
expect(err.message).toBe('Network error');
done();
}
});
});
it('should handle action handler errors', (done) => {
orgSettingsService.get.and.returnValue(of({
...orgSettingsData,
expense_settings: { split_expense_settings: { enabled: true } }
}));
spyOn(component, 'splitExpenseHandler').and.throwError('Handler error');
component.getActionSheetOptions().subscribe((res) => {
expect(() => res[0].handler()).toThrow('Handler error');
done();
});
});
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved with a question
projects: projects$, | ||
txnFields: this.txnFields$.pipe(take(1)), | ||
filteredCategories: this.filteredCategories$.pipe(take(1)), | ||
showProjectMappedCategoriesInSplitExpense: this.launchDarklyService.getVariation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this LD flag be checked in the split expense screen?
@@ -709,16 +726,33 @@ export function TestCases1(getTestBed) { | |||
component.fg.controls.report.setValue(expectedReportsPaginated[0]); | |||
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedExpData)); | |||
fixture.detectChanges(); | |||
const splitConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't u define this at common place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comment
Clickup
https://app.clickup.com/t/86cxubdrz
New flow of add-edit expense page
Summary by CodeRabbit
openSplitExpenseModal
method to utilize a streamlined configuration approach.splitExpenseHandler
.