You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorMonthlyKSv2Not a priorityReviewingHas a PR in review
The SettlementButton component is quite complex (and important!), and I struggled to review changes made to part of it due to its complexity.
Solution
Let's clean up this important component! In order:
Add automated UI tests covering the business logic for this component. customText and secondLineText alone have many permutations of conditions and expected results. These can be captured and documented by automated tests, which will help developers understand this component and more confidently make changes.
Remove manual memoization to make it compile with React Compiler. There are 25 instances of this warning:
This component hasn't been memoized by React Compiler.
Reason: Existing memoization could not be preserved
This manual memoization is making the component more complex and longer.
(exploration needed) Break it down into smaller, distinct components (by report type?) (i.e: using composition). It looks like there's significant differences in behavior for invoices vs expense reports vs IOU reports. Rather than having all three wrapped up in one component, let's DRY the common parts into a shared hook and keep the other parts separate, using the correct component for each type.
@abbasifaizan70 your proposal focuses too much on one specific aspect of this component (background highlight color). While I'm glad you found a bug, I'd suggest that you report it separately or incorporate it into a more comprehensive proposal to add test coverage and clean up the implementation of SettlementButton
🚨 Edited by proposal-police: This proposal was edited at 2026-01-12 21:03:56 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
The SettlementButton component has 0% test coverage, 25 React Compiler warnings, and complex conditional logic that is difficult to review and maintain.
What is the root cause of that problem?
The customText and secondLineText props have complex conditional logic with many branches that lack test coverage. Additionally, paymentButtonOptions contains ~200 lines of business logic determining which payment options appear.
// If there is pay as business option, we should show the submenu items instead.
buttonOptions.push(...getInvoicesOptions(true));
}
}
if(shouldShowApproveButton){
buttonOptions.push(approveButtonOption);
}
returnbuttonOptions;
// We don't want to reorder the options when the preferred payment method changes while the button is still visible except for component initialization when the last payment method is not initialized yet.
// We need to be sure that onPress should be wrapped in an useCallback to prevent unnecessary updates.
describe('customText',()=>{it('displays "Pay" when shouldUseShortForm is true',async()=>{render(<SettlementButtonWrapper><SettlementButtonshouldUseShortFormonPress={jest.fn()}// ... required props/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();expect(screen.getByText(translateLocal('iou.pay'))).toBeTruthy();});it('displays "Pay elsewhere" for ELSEWHERE payment method',async()=>{awaitact(async()=>{awaitOnyx.merge(ONYXKEYS.NVP_LAST_PAYMENT_METHOD,{[policyID]: {[reportType]: CONST.IOU.PAYMENT_TYPE.ELSEWHERE}});});render(<SettlementButtonWrapper><SettlementButton{...props}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();expect(screen.getByText(translateLocal('iou.payElsewhere',{formattedAmount: '$100'}))).toBeTruthy();});});
Test cases for subtitle (secondLineText) by report type:
describe('secondLineText',()=>{describe('Expense Reports',()=>{it('shows bank account for expense report with policy achAccount',async()=>{awaitact(async()=>{awaitOnyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`,{achAccount: {accountNumber: '1234',bankAccountID: 1}});awaitOnyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`,{type: CONST.REPORT.TYPE.EXPENSE,policyID: POLICY_ID});});render(<SettlementButtonWrapper><SettlementButton{...expenseReportProps}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();expect(screen.getByText(/1234/)).toBeTruthy();// Bank account last 4});});describe('Invoice Reports',()=>{it('shows business bank label for invoice with business account',async()=>{awaitact(async()=>{awaitOnyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`,{type: CONST.REPORT.TYPE.INVOICE});// Set up business bank account});render(<SettlementButtonWrapper><SettlementButton{...invoiceProps}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();expect(screen.getByText(translateLocal('iou.invoiceBusinessBank','5678'))).toBeTruthy();});});describe('IOU Reports',()=>{it('shows Wallet for IOU with EXPENSIFY payment method',async()=>{awaitact(async()=>{awaitOnyx.merge(ONYXKEYS.NVP_LAST_PAYMENT_METHOD,{[CONST.POLICY.ID_FAKE]: {iou: CONST.IOU.PAYMENT_TYPE.EXPENSIFY}});awaitOnyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT_LIST,[{bankAccountID: 1}]);});render(<SettlementButtonWrapper><SettlementButton{...iouProps}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();expect(screen.getByText(translateLocal('common.wallet'))).toBeTruthy();});});});
Test cases for payment options dropdown:
describe('paymentButtonOptions',()=>{it('shows wallet option for IOU with supported currency',async()=>{awaitact(async()=>{awaitOnyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`,{type: CONST.REPORT.TYPE.IOU,currency: 'USD'});});render(<SettlementButtonWrapper><SettlementButton{...iouProps}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();// Open dropdown and verify wallet option existsfireEvent.press(screen.getByTestId('settlement-button-dropdown'));expect(screen.getByText(translateLocal('iou.settleWallet',{formattedAmount: ''}))).toBeTruthy();});it('does NOT show wallet option for expense reports',async()=>{awaitact(async()=>{awaitOnyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`,{type: CONST.REPORT.TYPE.EXPENSE});});render(<SettlementButtonWrapper><SettlementButton{...expenseProps}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();fireEvent.press(screen.getByTestId('settlement-button-dropdown'));expect(screen.queryByText(translateLocal('iou.settleWallet',{formattedAmount: ''}))).toBeNull();});it('shows only Approve button when shouldHidePaymentOptions and shouldShowApproveButton',async()=>{render(<SettlementButtonWrapper><SettlementButtonshouldHidePaymentOptionsshouldShowApproveButton{...props}/></SettlementButtonWrapper>);awaitwaitForBatchedUpdatesWithAct();expect(screen.getByText(translateLocal('iou.approve',{formattedAmount: '$100'}))).toBeTruthy();});});
2. Remove Manual Memoization (25 instances)
Strategy for each memoization type:
Hook
Count
Action
Simple derived values (lastPaymentMethod)
~5
Remove useMemo, use direct expression
Callbacks passed to children (checkForNecessaryAction)
~8
Keep useCallback, React Compiler will optimize
Complex computations (paymentButtonOptions)
~12
Keep useMemo with simplified deps
Example - simple derived value:
// Remove useMemo for simple derivationsconstlastPaymentMethod=iouReport?.type
? getLastPolicyPaymentMethod(policyIDKey,personalPolicyID,lastPaymentMethods,iouReport.type,isIOUReport(iouReport))
: undefined;
If the UI tests reveal that getSecondaryText logic is particularly hard to test through the UI, we can optionally extract it to SettlementButtonUtils.ts for supplementary unit tests:
@TaduJR extracting pure functions and using "normal" unit functions could work, but could we instead use UI tests with @testing-library/react-native (see examples in tests/ui) to write UI tests that directly cover SettlementButton? I think that might be better in that it directly covers the component, handling potential oddities surrounding React lifecycle, incorrect memoization, etc...
P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorMonthlyKSv2Not a priorityReviewingHas a PR in review
Activity
melvin-bot commentedon Jan 12, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (
External)melvin-bot commentedon Jan 12, 2026
Triggered auto assignment to @stephanieelliott (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.roryabraham commentedon Jan 12, 2026
The primary goal/requirement of this issue is Test Coverage - the other refactorings are kind of a bonus and secondary to the tests.
abbasifaizan70 commentedon Jan 12, 2026
roryabraham commentedon Jan 12, 2026
@abbasifaizan70 your proposal focuses too much on one specific aspect of this component (background highlight color). While I'm glad you found a bug, I'd suggest that you report it separately or incorporate it into a more comprehensive proposal to add test coverage and clean up the implementation of SettlementButton
roryabraham commentedon Jan 12, 2026
Interestingly, your proposal doesn't actually even target the same component referenced in the issue description, so I'm going to mark it as off-topic
TaduJR commentedon Jan 12, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-01-12 21:03:56 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
The
SettlementButtoncomponent has 0% test coverage, 25 React Compiler warnings, and complex conditional logic that is difficult to review and maintain.What is the root cause of that problem?
The
customTextandsecondLineTextprops have complex conditional logic with many branches that lack test coverage. Additionally,paymentButtonOptionscontains ~200 lines of business logic determining which payment options appear.getCustomText()decision tree (3 branches):App/src/components/SettlementButton/index.tsx
Lines 492 to 502 in 4947e55
shouldUseShortForm'iou.pay'lastPaymentMethod === ELSEWHERE'iou.payElsewhere''iou.settlePayment'getSecondaryText()decision tree:App/src/components/SettlementButton/index.tsx
Lines 504 to 551 in 4947e55
shouldUseShortFormundefinedlastPaymentMethod === ELSEWHEREundefinedundefinedshouldHidePaymentOptions && (shouldShowApproveButton || onlyShowPayElsewhere)undefinedlastPaymentPolicyexistslastPaymentPolicy.name(EXPENSIFY || hasIntentToPay) && isInvoiceReport+ Business bank'iou.invoiceBusinessBank'(EXPENSIFY || hasIntentToPay) && isInvoiceReport+ Personal bank'iou.invoicePersonalBank'(EXPENSIFY || hasIntentToPay) && (isExpenseReport || isInvoiceReport)+ no personal banksundefined(EXPENSIFY || hasIntentToPay) && (isExpenseReport || isInvoiceReport)+ has personal banks'common.wallet'lastPaymentMethod === EXPENSIFY+ IOU report + has personal banks'common.wallet'(VBBA || hasIntentToPay) && policy.achAccount.accountNumber'bankAccountLastFour'(policy)(VBBA || hasIntentToPay) && policy.achAccount+ no display accountundefined(VBBA || hasIntentToPay) && policy.achAccount+ has display account'bankAccountLastFour'(display)'bankAccountLastFour'undefinedpaymentButtonOptionskey conditions:App/src/components/SettlementButton/index.tsx
Lines 248 to 444 in 4947e55
canUseWallet(IOU only, currency supported)canUseBusinessBankAccount(expense/IOU)canUsePersonalBankAccountshouldShowApproveButton && shouldHidePaymentOptionsonlyShowPayElsewhereisInvoiceReportWhat changes do you think we should make in order to solve the problem?
1. Add UI Tests with @testing-library/react-native (Primary)
Create
tests/ui/components/SettlementButtonTest.tsxfollowing the existing pattern inIOURequestStepConfirmationPageTest.tsx:https://github.com/Expensify/App/blob/4947e55428f663a0d7e00bbfced3da4e985e2989/tests/ui/components/IOURequestStepConfirmationPageTest.tsx
Test setup with Onyx mocking:
Test cases for button text (
customText):Test cases for subtitle (
secondLineText) by report type:Test cases for payment options dropdown:
2. Remove Manual Memoization (25 instances)
Strategy for each memoization type:
lastPaymentMethod)checkForNecessaryAction)paymentButtonOptions)Example - simple derived value:
Example - complex computation with stable deps:
3. Optional: Extract Helper for Complex Logic
If the UI tests reveal that
getSecondaryTextlogic is particularly hard to test through the UI, we can optionally extract it toSettlementButtonUtils.tsfor supplementary unit tests:https://github.com/Expensify/App/blob/4947e55428f663a0d7e00bbfced3da4e985e2989/src/libs/SettlementButtonUtils.ts
This would be in addition to (not instead of) the UI tests.
roryabraham commentedon Jan 12, 2026
@TaduJR extracting pure functions and using "normal" unit functions could work, but could we instead use UI tests with
@testing-library/react-native(see examples intests/ui) to write UI tests that directly coverSettlementButton? I think that might be better in that it directly covers the component, handling potential oddities surrounding React lifecycle, incorrect memoization, etc...78 remaining items
melvin-bot commentedon May 25, 2026
This issue has not been updated in over 15 days. @mallenexpensify, @roryabraham, @linhvovan29546, @TaduJR eroding to Monthly issue.
P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!
melvin-bot commentedon Jul 22, 2026
@mallenexpensify, @roryabraham, @linhvovan29546, @TaduJR, this Monthly task hasn't been acted upon in 6 weeks; closing.
If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.
linhvovan29546 commentedon Jul 28, 2026
@roryabraham Could you please reopen the issue? Tks
melvin-bot commentedon Oct 2, 2026
@mallenexpensify, @roryabraham, @linhvovan29546, @TaduJR, this Monthly task hasn't been acted upon in 6 weeks; closing.
If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.
expensify-chore-bot commentedon Nov 30, 2026
@mallenexpensify, @roryabraham, @linhvovan29546, @TaduJR, this Monthly task hasn't been acted upon in 6 weeks; closing.
If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.