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

fix search invoice page doesn't display merchant text "expense" #53349

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getTransactionItemCommonFormattedProperties(
const formattedTotal = TransactionUtils.getAmount(transactionItem, isExpenseReport);
const date = transactionItem?.modifiedCreated ? transactionItem.modifiedCreated : transactionItem?.created;
const merchant = TransactionUtils.getMerchant(transactionItem);
const formattedMerchant = merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || merchant === CONST.TRANSACTION.DEFAULT_MERCHANT ? '' : merchant;
const formattedMerchant = merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT ? '' : merchant;

return {
formattedFrom,
Expand Down Expand Up @@ -106,7 +106,7 @@ function getShouldShowMerchant(data: OnyxTypes.SearchResults['data']): boolean {
if (isTransactionEntry(key)) {
const item = data[key];
const merchant = item.modifiedMerchant ? item.modifiedMerchant : item.merchant ?? '';
return merchant !== '' && merchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT && merchant !== CONST.TRANSACTION.DEFAULT_MERCHANT;
return merchant !== '' && merchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
}
return false;
});
Expand Down Expand Up @@ -374,7 +374,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx
...reportItem,
action: getAction(data, key),
keyForList: reportItem.reportID,
from: data.personalDetailsList?.[reportItem.accountID ?? -1],
from: data.personalDetailsList?.[reportItem.accountID ?? CONST.DEFAULT_NUMBER_ID],
to: reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails,
transactions,
reportName: isIOUReport ? getIOUReportName(data, reportItem) : reportItem.reportName,
Expand Down
110 changes: 110 additions & 0 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import type {TransactionListItemType} from '@components/SelectionList/types';
import CONST from '@src/CONST';
import * as SearchUIUtils from '@src/libs/SearchUIUtils';
import type * as OnyxTypes from '@src/types/onyx';

const fakeAccountID = 18439984;
const fakePolicyID = 'A1B2C3';
const fakeReportID = '123456789';
const fakeTransactionID = '1';

const fakeSearchResults: OnyxTypes.SearchResults = {
data: {
personalDetailsList: {
[fakeAccountID]: {
accountID: fakeAccountID,
avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png',
displayName: 'test',
login: '[email protected]',
},
},
[`policy_${fakePolicyID}`]: {
approvalMode: 'OPTIONAL',
autoReimbursement: {
limit: 0,
},
autoReimbursementLimit: 0,
autoReporting: true,
autoReportingFrequency: 'instant',
preventSelfApproval: false,
owner: '[email protected]',
reimbursementChoice: 'reimburseManual',
role: 'admin',
type: 'team',
},
[`report_${fakeReportID}`]: {
accountID: fakeAccountID,
action: 'view',
chatReportID: '1706144653204915',
created: '2024-12-21 13:05:20',
currency: 'USD',
isOneTransactionReport: true,
isPolicyExpenseChat: false,
isWaitingOnBankAccount: false,
managerID: fakeAccountID,
nonReimbursableTotal: 0,
ownerAccountID: fakeAccountID,
policyID: fakePolicyID,
reportID: fakeReportID,
reportName: 'Expense Report #123',
stateNum: 1,
statusNum: 1,
total: -5000,
type: 'expense',
unheldTotal: -5000,
},
[`transactions_${fakeTransactionID}`]: {
accountID: fakeAccountID,
action: 'view',
amount: -5000,
canDelete: true,
canHold: true,
canUnhold: false,
category: '',
comment: {
comment: '',
},
created: '2024-12-21',
currency: 'USD',
hasEReceipt: false,
isFromOneTransactionReport: true,
managerID: fakeAccountID,
description: '',
hasViolation: false,
merchant: 'Expense',
modifiedAmount: 0,
modifiedCreated: '',
modifiedCurrency: '',
modifiedMerchant: 'Expense',
parentTransactionID: '',
policyID: fakePolicyID,
reportID: fakeReportID,
reportType: 'expense',
tag: '',
transactionID: fakeTransactionID,
transactionThreadReportID: '456',
transactionType: 'cash',
},
},
search: {
columnsToShow: {
shouldShowCategoryColumn: true,
shouldShowTagColumn: false,
shouldShowTaxColumn: false,
},
hasMoreResults: false,
hasResults: true,
offset: 0,
status: 'all',
isLoading: false,
type: 'expense',
},
};
const transactionSections = SearchUIUtils.getSections('expense', 'all', fakeSearchResults.data, fakeSearchResults.search) as TransactionListItemType[];
const tests = transactionSections.map((transactionList) => [{transactionListItem: transactionList, expectedMerchant: CONST.TRANSACTION.DEFAULT_MERCHANT}]);

describe('SearchUIUtils', () => {
test.each(tests)('Transaction list item with "Expense" merchant', ({transactionListItem, expectedMerchant}) => {
expect(transactionListItem.merchant).toEqual(expectedMerchant);
});
});
Loading