Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/Modal/Global/HoldMenuModalWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function HoldMenuModalWrapper({
requestType,
paymentType,
methodID,
nonHeldAmount = '0',
nonHeldAmount,
fullAmount,
hasNonHeldExpenses,
transactionCount,
Expand Down Expand Up @@ -88,7 +88,10 @@ function HoldMenuModalWrapper({
onClose={() => setIsVisible(false)}
isVisible={isVisible}
prompt={approvalPrompt}
firstOptionText={hasNonHeldExpenses ? `${translate(isApprove ? 'iou.approveOnly' : 'iou.payOnly')} ${nonHeldAmount}` : undefined}
// Callers pass `undefined` when the non-held amount isn't meaningfully different from the full amount,
// so gate on the amount itself rather than on `hasNonHeldExpenses` — otherwise a report whose unheld
// expenses net out to nothing offers a partial option for a zero amount.
firstOptionText={nonHeldAmount !== undefined ? `${translate(isApprove ? 'iou.approveOnly' : 'iou.payOnly')} ${nonHeldAmount}` : undefined}
secondOptionText={`${translate(isApprove ? 'iou.approve' : 'iou.pay')} ${fullAmount}`}
onFirstOptionSubmit={() => onSubmit(false)}
onSecondOptionSubmit={() => onSubmit(true)}
Expand Down
7 changes: 5 additions & 2 deletions src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ProcessMoneyReportHoldMenuProps = {
};

function ProcessMoneyReportHoldMenu({
nonHeldAmount = '0',
nonHeldAmount,
fullAmount,
onClose,
isVisible,
Expand Down Expand Up @@ -81,7 +81,10 @@ function ProcessMoneyReportHoldMenu({
onClose={onClose}
isVisible={isVisible}
prompt={promptText}
firstOptionText={hasNonHeldExpenses ? `${translate('iou.payOnly')} ${nonHeldAmount}` : undefined}
// Callers pass `undefined` when the non-held amount isn't meaningfully different from the full amount,
// so gate on the amount itself rather than on `hasNonHeldExpenses` — otherwise a report whose unheld
// expenses net out to nothing offers a partial option for a zero amount.
firstOptionText={nonHeldAmount !== undefined ? `${translate('iou.payOnly')} ${nonHeldAmount}` : undefined}
secondOptionText={`${translate('iou.pay')} ${fullAmount}`}
onFirstOptionSubmit={() => onSubmit(false)}
onSecondOptionSubmit={() => onSubmit(true)}
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/HoldMenuModalWrapperTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {render} from '@testing-library/react-native';

import type {DecisionModalProps} from '@components/DecisionModal';
import HoldMenuModalWrapper from '@components/Modal/Global/HoldMenuModalWrapper';

import CONST from '@src/CONST';

let mockDecisionModalProps: DecisionModalProps | undefined;

jest.mock('@components/DecisionModal', () => {
return (props: DecisionModalProps) => {
mockDecisionModalProps = props;
return null;
};
});

jest.mock('@hooks/useHoldMenuSubmit', () => ({
__esModule: true,
default: () => ({onSubmit: jest.fn(), isApprove: true}),
}));

jest.mock('@hooks/useOnyx', () => ({
__esModule: true,
default: () => [undefined],
}));

function renderWrapper(overrides: {nonHeldAmount?: string; hasNonHeldExpenses?: boolean}) {
return render(
<HoldMenuModalWrapper
closeModal={jest.fn()}
resolveModal={jest.fn()}
reportID="1"
chatReportID="2"
requestType={CONST.IOU.REPORT_ACTION_TYPE.APPROVE}
fullAmount="$100.00"
transactionCount={2}
{...overrides}
/>,
);
}

describe('HoldMenuModalWrapper', () => {
beforeEach(() => {
mockDecisionModalProps = undefined;
});

it('offers the partial approve option when a valid non-held amount is supplied', () => {
renderWrapper({nonHeldAmount: '$40.00', hasNonHeldExpenses: true});

expect(mockDecisionModalProps?.firstOptionText).toContain('$40.00');
});

it('omits the partial approve option when the non-held amount is not meaningful, even though non-held expenses exist', () => {
// The report still has an unheld expense, but its amount nets out against the held one, so the caller
// sends `undefined` rather than an amount. The modal must not fall back to rendering a zero amount.
renderWrapper({nonHeldAmount: undefined, hasNonHeldExpenses: true});

expect(mockDecisionModalProps?.firstOptionText).toBeUndefined();
});

it('omits the partial approve option when every expense is on hold', () => {
renderWrapper({nonHeldAmount: undefined, hasNonHeldExpenses: false});

expect(mockDecisionModalProps?.firstOptionText).toBeUndefined();
});
});
Loading