From 2c5aa05a4b3d396fc33a1151c3e2517cd4317bc6 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Sun, 1 Dec 2024 12:21:43 +0700 Subject: [PATCH 1/6] fix search invoice page doesn't display merchant text --- src/libs/SearchUIUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index e100fb885fff..44b708d62fe3 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -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, @@ -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; }); From bcc73ad354f76579f6946895696e32d3042b7b66 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Sat, 21 Dec 2024 20:50:55 +0700 Subject: [PATCH 2/6] create new unit test file --- tests/unit/Search/SearchUIUtilsTest.ts | 106 +++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/unit/Search/SearchUIUtilsTest.ts diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts new file mode 100644 index 000000000000..f6de00c3b085 --- /dev/null +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -0,0 +1,106 @@ +import type {OnyxCollection} from 'react-native-onyx'; +import {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 fakeSearchResults: OnyxTypes.SearchResults = { + data: { + personalDetailsList: { + '1': { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', + displayName: 'test', + login: 'test1234@gmail.com', + }, + }, + policy_123: { + approvalMode: 'OPTIONAL', + approver: 'test1234@gmail.com', + autoReimbursement: { + limit: 0, + }, + autoReimbursementLimit: 0, + autoReporting: true, + autoReportingFrequency: 'instant', + owner: 'test1234@gmail.com', + preventSelfApproval: false, + reimbursementChoice: 'reimburseManual', + role: 'admin', + type: 'team', + }, + report_123: { + accountID: 1, + action: 'view', + chatReportID: '1706144653204915', + created: '2024-12-21 13:05:20', + currency: 'USD', + isOneTransactionReport: true, + isPolicyExpenseChat: false, + isWaitingOnBankAccount: false, + managerID: 1, + nonReimbursableTotal: 0, + ownerAccountID: 1, + policyID: '123', + private_isArchived: '', + reportID: '123', + reportName: 'Expense Report #123', + stateNum: 1, + statusNum: 1, + total: -5000, + type: 'expense', + unheldTotal: -5000, + }, + transactions_123: { + accountID: 1, + action: 'view', + amount: -5000, + canDelete: true, + canHold: true, + canUnhold: false, + category: '', + comment: { + comment: '', + }, + created: '2024-12-21', + currency: 'USD', + hasEReceipt: false, + isFromOneTransactionReport: true, + managerID: 1, + merchant: 'Expense', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: 'Expense', + parentTransactionID: '', + policyID: '123', + reportID: '123', + reportType: 'expense', + tag: '', + transactionID: '123', + 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); + }); +}); From 1059bef644d367d95f5ba62411c20f18e3e120a2 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Sun, 22 Dec 2024 09:28:35 +0700 Subject: [PATCH 3/6] fix eslint errors --- tests/unit/Search/SearchUIUtilsTest.ts | 28 ++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index f6de00c3b085..0fe7b4e54a4d 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1,5 +1,4 @@ -import type {OnyxCollection} from 'react-native-onyx'; -import {TransactionListItemType} from '@components/SelectionList/types'; +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'; @@ -7,30 +6,28 @@ import type * as OnyxTypes from '@src/types/onyx'; const fakeSearchResults: OnyxTypes.SearchResults = { data: { personalDetailsList: { - '1': { - accountID: 1, + '18439984': { + accountID: 18439984, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', displayName: 'test', login: 'test1234@gmail.com', }, }, - policy_123: { + policy_ABC123: { approvalMode: 'OPTIONAL', - approver: 'test1234@gmail.com', autoReimbursement: { limit: 0, }, autoReimbursementLimit: 0, autoReporting: true, autoReportingFrequency: 'instant', - owner: 'test1234@gmail.com', preventSelfApproval: false, reimbursementChoice: 'reimburseManual', role: 'admin', type: 'team', }, - report_123: { - accountID: 1, + report_ABC123: { + accountID: 18439984, action: 'view', chatReportID: '1706144653204915', created: '2024-12-21 13:05:20', @@ -38,9 +35,9 @@ const fakeSearchResults: OnyxTypes.SearchResults = { isOneTransactionReport: true, isPolicyExpenseChat: false, isWaitingOnBankAccount: false, - managerID: 1, + managerID: 18439984, nonReimbursableTotal: 0, - ownerAccountID: 1, + ownerAccountID: 18439984, policyID: '123', private_isArchived: '', reportID: '123', @@ -51,8 +48,8 @@ const fakeSearchResults: OnyxTypes.SearchResults = { type: 'expense', unheldTotal: -5000, }, - transactions_123: { - accountID: 1, + transactions_AB: { + accountID: 18439984, action: 'view', amount: -5000, canDelete: true, @@ -66,7 +63,9 @@ const fakeSearchResults: OnyxTypes.SearchResults = { currency: 'USD', hasEReceipt: false, isFromOneTransactionReport: true, - managerID: 1, + managerID: 18439984, + description: '', + hasViolation: false, merchant: 'Expense', modifiedAmount: 0, modifiedCreated: '', @@ -89,7 +88,6 @@ const fakeSearchResults: OnyxTypes.SearchResults = { shouldShowTaxColumn: false, }, hasMoreResults: false, - hasResults: true, offset: 0, status: 'all', isLoading: false, From 19aa4176b44bde7dd0893f61779d99128c772a7a Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Sun, 22 Dec 2024 12:00:12 +0700 Subject: [PATCH 4/6] fix eslint errors --- tests/unit/Search/SearchUIUtilsTest.ts | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 0fe7b4e54a4d..c8e403b66972 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -3,17 +3,22 @@ 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: { - '18439984': { - accountID: 18439984, + [fakeAccountID]: { + accountID: fakeAccountID, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', displayName: 'test', login: 'test1234@gmail.com', }, }, - policy_ABC123: { + [`policy_${fakePolicyID}`]: { approvalMode: 'OPTIONAL', autoReimbursement: { limit: 0, @@ -26,8 +31,8 @@ const fakeSearchResults: OnyxTypes.SearchResults = { role: 'admin', type: 'team', }, - report_ABC123: { - accountID: 18439984, + [`report_${fakeReportID}`]: { + accountID: fakeAccountID, action: 'view', chatReportID: '1706144653204915', created: '2024-12-21 13:05:20', @@ -35,12 +40,11 @@ const fakeSearchResults: OnyxTypes.SearchResults = { isOneTransactionReport: true, isPolicyExpenseChat: false, isWaitingOnBankAccount: false, - managerID: 18439984, + managerID: fakeAccountID, nonReimbursableTotal: 0, - ownerAccountID: 18439984, - policyID: '123', - private_isArchived: '', - reportID: '123', + ownerAccountID: fakeAccountID, + policyID: fakePolicyID, + reportID: fakeReportID, reportName: 'Expense Report #123', stateNum: 1, statusNum: 1, @@ -48,8 +52,8 @@ const fakeSearchResults: OnyxTypes.SearchResults = { type: 'expense', unheldTotal: -5000, }, - transactions_AB: { - accountID: 18439984, + [`transactions_${fakeTransactionID}`]: { + accountID: fakeAccountID, action: 'view', amount: -5000, canDelete: true, @@ -63,7 +67,7 @@ const fakeSearchResults: OnyxTypes.SearchResults = { currency: 'USD', hasEReceipt: false, isFromOneTransactionReport: true, - managerID: 18439984, + managerID: fakeAccountID, description: '', hasViolation: false, merchant: 'Expense', @@ -72,11 +76,11 @@ const fakeSearchResults: OnyxTypes.SearchResults = { modifiedCurrency: '', modifiedMerchant: 'Expense', parentTransactionID: '', - policyID: '123', - reportID: '123', + policyID: fakePolicyID, + reportID: fakeReportID, reportType: 'expense', tag: '', - transactionID: '123', + transactionID: fakeTransactionID, transactionThreadReportID: '456', transactionType: 'cash', }, From 6942bc50eb0b82737f435f27ec61c98e543ca583 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Sun, 22 Dec 2024 12:20:04 +0700 Subject: [PATCH 5/6] fix eslint and typescript errors --- tests/unit/Search/SearchUIUtilsTest.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index c8e403b66972..04c37b276146 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -27,6 +27,7 @@ const fakeSearchResults: OnyxTypes.SearchResults = { autoReporting: true, autoReportingFrequency: 'instant', preventSelfApproval: false, + owner: 'test1234@gmail.com', reimbursementChoice: 'reimburseManual', role: 'admin', type: 'team', @@ -92,6 +93,7 @@ const fakeSearchResults: OnyxTypes.SearchResults = { shouldShowTaxColumn: false, }, hasMoreResults: false, + hasResults: true, offset: 0, status: 'all', isLoading: false, From eaebfdf474dbcb006c098628d85b2a9ae028c678 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Wed, 25 Dec 2024 11:18:29 +0700 Subject: [PATCH 6/6] fix eslint error --- src/libs/SearchUIUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 46ade93566b7..849008e10b76 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -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,