Skip to content
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

[wave6] Polish the modified expense message when changing from partial amount #34939

Merged
merged 3 commits into from
Jan 23, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function getForReportAction(reportAction: ReportAction): string {
const hasModifiedMerchant = reportActionOriginalMessage && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;
if (hasModifiedAmount) {
const oldCurrency = reportActionOriginalMessage?.oldCurrency ?? '';
const oldAmount = CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.oldAmount ?? 0, oldCurrency);
const oldAmountValue = reportActionOriginalMessage?.oldAmount ?? 0;
const oldAmount = oldAmountValue > 0 ? CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.oldAmount ?? 0, oldCurrency) : '';

const currency = reportActionOriginalMessage?.currency ?? '';
const amount = CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.amount ?? 0, currency);
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/ModifiedExpenseMessageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ describe('ModifiedExpenseMessage', () => {
});
});

describe('when the amount is changed while the original value was partial', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
originalMessage: {
amount: 1800,
currency: CONST.CURRENCY.USD,
oldAmount: 0,
oldCurrency: CONST.CURRENCY.USD,
},
};

it('returns the correct text message', () => {
const expectedResult = `set the amount to $18.00.`;

const result = ModifiedExpenseMessage.getForReportAction(reportAction);

expect(result).toEqual(expectedResult);
});
});

describe('when the amount is changed and the description is removed', () => {
const reportAction = {
...createRandomReportAction(1),
Expand Down Expand Up @@ -169,6 +190,25 @@ describe('ModifiedExpenseMessage', () => {
});
});

describe('when the merchant is changed while the previous merchant was partial', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
originalMessage: {
merchant: 'KFC',
oldMerchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
},
};

it('returns the correct text message', () => {
const expectedResult = `set the merchant to "KFC".`;

const result = ModifiedExpenseMessage.getForReportAction(reportAction);

expect(result).toEqual(expectedResult);
});
});

describe('when the merchant and the description are removed', () => {
const reportAction = {
...createRandomReportAction(1),
Expand Down
Loading