From ce0652e71a6548cf849740ad6fcad09b356c9824 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 4 Dec 2024 16:25:51 -0700 Subject: [PATCH 1/3] correctly filter transactions --- src/libs/actions/Search.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index bb64fe10db26..b92e2c5ce475 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -53,7 +53,7 @@ function handleActionButtonPress(hash: number, item: TransactionListItemType | R const allReportTransactions = ( isReportListItemType(item) ? Object.entries(data) - .filter(([itemKey, value]) => itemKey.startsWith(ONYXKEYS.COLLECTION.REPORT) && (value as SearchTransaction)?.reportID === item.reportID) + .filter(([itemKey, value]) => itemKey.startsWith(ONYXKEYS.COLLECTION.TRANSACTION) && (value as SearchTransaction)?.reportID === item.reportID) .map((report) => report[1]) : [data[`${ONYXKEYS.COLLECTION.TRANSACTION}${item.transactionID}`]] ) as SearchTransaction[]; From 5a24a0007fd58c33d1c22231292d3ab950c105bd Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 4 Dec 2024 16:52:41 -0700 Subject: [PATCH 2/3] simplify logic --- src/libs/actions/Search.ts | 10 +- .../Search/handleActionButtonPressTest.ts | 318 ++++++++++++++++++ 2 files changed, 320 insertions(+), 8 deletions(-) create mode 100644 tests/unit/Search/handleActionButtonPressTest.ts diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index b92e2c5ce475..74eea90b8275 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -50,15 +50,9 @@ function handleActionButtonPress(hash: number, item: TransactionListItemType | R // We need the transactionID to display the loading indicator for that list item's action. const transactionID = isTransactionListItemType(item) ? [item.transactionID] : undefined; const data = (allSnapshots?.[`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`]?.data ?? {}) as SearchResults['data']; - const allReportTransactions = ( - isReportListItemType(item) - ? Object.entries(data) - .filter(([itemKey, value]) => itemKey.startsWith(ONYXKEYS.COLLECTION.TRANSACTION) && (value as SearchTransaction)?.reportID === item.reportID) - .map((report) => report[1]) - : [data[`${ONYXKEYS.COLLECTION.TRANSACTION}${item.transactionID}`]] - ) as SearchTransaction[]; - + const allReportTransactions = (isReportListItemType(item) ? item.transactions : [data[`${ONYXKEYS.COLLECTION.TRANSACTION}${item.transactionID}`]]) as SearchTransaction[]; const hasHeldExpense = ReportUtils.hasHeldExpenses('', allReportTransactions); + if (hasHeldExpense) { goToItem(); return; diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts new file mode 100644 index 000000000000..dc3d5e8ed97b --- /dev/null +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -0,0 +1,318 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import Onyx from 'react-native-onyx'; +import {handleActionButtonPress} from '@libs/actions/Search'; +import ONYXKEYS from '@src/ONYXKEYS'; +import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; + +const currentSearchHash = 1; +const mockData = { + key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${1}`, + onyxMethod: 'set', + value: { + data: { + report_1350959062018695: { + accountID: 1206, + action: 'view', + chatReportID: '2108006919825366', + chatType: '', + created: '2024-12-04 23:18:33', + currency: 'USD', + invoiceReceiver: null, + isOneTransactionReport: false, + isPolicyExpenseChat: false, + isWaitingOnBankAccount: false, + managerID: 1206, + nonReimbursableTotal: 0, + ownerAccountID: 1206, + policyID: '48D7178DE42EE9F9', + private_isArchived: '', + reportID: '1350959062018695', + reportName: 'Expense Report #1350959062018695', + stateNum: 1, + statusNum: 1, + total: -13500, + type: 'expense', + unheldTotal: -12300, + }, + transactions_1049531721038862176: { + accountID: 1206, + action: 'view', + amount: -1200, + canDelete: true, + canHold: false, + canUnhold: true, + category: '', + comment: { + comment: '', + hold: '3042630993757922770', + }, + created: '2024-12-04', + currency: 'USD', + hasEReceipt: false, + isFromOneTransactionReport: false, + managerID: 1206, + merchant: 'qewr', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: '', + parentTransactionID: '', + policyID: '48D7178DE42EE9F9', + reportID: '1350959062018695', + reportType: 'expense', + tag: '', + transactionID: '1049531721038862176', + transactionThreadReportID: '2957345659269055', + transactionType: 'cash', + }, + transactions_5345995386715609966: { + accountID: 1206, + action: 'view', + amount: -12300, + canDelete: true, + canHold: true, + canUnhold: false, + category: '', + comment: { + comment: '', + }, + created: '2024-12-04', + currency: 'USD', + hasEReceipt: false, + isFromOneTransactionReport: false, + managerID: 1206, + merchant: 'fgdfgadfaf', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: '', + parentTransactionID: '', + policyID: '48D7178DE42EE9F9', + reportID: '1350959062018695', + reportType: 'expense', + tag: '', + transactionID: '5345995386715609966', + transactionThreadReportID: '740282333335072', + transactionType: 'cash', + }, + }, + }, +}; + +describe('handleActionButtonPress', () => { + beforeAll(() => { + Onyx.init({ + keys: ONYXKEYS, + initialKeyStates: mockData, + }); + return waitForBatchedUpdates(); + }); + + test('returns ', () => { + const goToItem = () => {}; + const reportItem = { + shouldAnimateInHighlight: false, + accountID: 1206, + action: 'approve', + chatReportID: '2108006919825366', + chatType: '', + created: '2024-12-04 23:18:33', + currency: 'USD', + isOneTransactionReport: false, + isPolicyExpenseChat: false, + isWaitingOnBankAccount: false, + managerID: 1206, + nonReimbursableTotal: 0, + ownerAccountID: 1206, + policyID: '48D7178DE42EE9F9', + private_isArchived: '', + reportID: '1350959062018695', + reportName: 'Expense Report #1350959062018695', + stateNum: 1, + statusNum: 1, + total: -13500, + type: 'expense', + unheldTotal: -12300, + keyForList: '1350959062018695', + from: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + to: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + transactions: [ + { + accountID: 1206, + action: 'view', + amount: -1200, + canDelete: true, + canHold: false, + canUnhold: true, + category: '', + comment: { + comment: '', + hold: '3042630993757922770', + }, + created: '2024-12-04', + currency: 'USD', + hasEReceipt: false, + isFromOneTransactionReport: false, + managerID: 1206, + merchant: 'qewr', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: '', + parentTransactionID: '', + policyID: '48D7178DE42EE9F9', + reportID: '1350959062018695', + reportType: 'expense', + tag: '', + transactionID: '1049531721038862176', + transactionThreadReportID: '2957345659269055', + transactionType: 'cash', + from: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + to: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + formattedFrom: 'aesf', + formattedTo: 'aesf', + formattedTotal: 1200, + formattedMerchant: 'qewr', + date: '2024-12-04', + shouldShowMerchant: true, + shouldShowCategory: true, + shouldShowTag: false, + shouldShowTax: false, + keyForList: '1049531721038862176', + shouldShowYear: false, + shouldAnimateInHighlight: false, + }, + { + accountID: 1206, + action: 'view', + amount: -12300, + canDelete: true, + canHold: true, + canUnhold: false, + category: '', + comment: { + comment: '', + }, + created: '2024-12-04', + currency: 'USD', + hasEReceipt: false, + isFromOneTransactionReport: false, + managerID: 1206, + merchant: 'fgdfgadfaf', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: '', + parentTransactionID: '', + policyID: '48D7178DE42EE9F9', + reportID: '1350959062018695', + reportType: 'expense', + tag: '', + transactionID: '5345995386715609966', + transactionThreadReportID: '740282333335072', + transactionType: 'cash', + from: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + to: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + formattedFrom: 'aesf', + formattedTo: 'aesf', + formattedTotal: 12300, + formattedMerchant: 'fgdfgadfaf', + date: '2024-12-04', + shouldShowMerchant: true, + shouldShowCategory: true, + shouldShowTag: false, + shouldShowTax: false, + keyForList: '5345995386715609966', + shouldShowYear: false, + shouldAnimateInHighlight: false, + }, + ], + isSelected: false, + }; + handleActionButtonPress(currentSearchHash, reportItem, goToItem); + }); +}); From 7b08d2ac70f706a181b05307109ae4feb3a2d81c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 4 Dec 2024 17:13:10 -0700 Subject: [PATCH 3/3] add unit test --- src/libs/actions/Search.ts | 3 +- src/types/onyx/SearchResults.ts | 6 +- .../Search/handleActionButtonPressTest.ts | 449 +++++++----------- 3 files changed, 178 insertions(+), 280 deletions(-) diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 74eea90b8275..c08a83088180 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -49,8 +49,7 @@ function handleActionButtonPress(hash: number, item: TransactionListItemType | R // The transactionIDList is needed to handle actions taken on `status:all` where transactions on single expense reports can be approved/paid. // We need the transactionID to display the loading indicator for that list item's action. const transactionID = isTransactionListItemType(item) ? [item.transactionID] : undefined; - const data = (allSnapshots?.[`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`]?.data ?? {}) as SearchResults['data']; - const allReportTransactions = (isReportListItemType(item) ? item.transactions : [data[`${ONYXKEYS.COLLECTION.TRANSACTION}${item.transactionID}`]]) as SearchTransaction[]; + const allReportTransactions = (isReportListItemType(item) ? item.transactions : [item]) as SearchTransaction[]; const hasHeldExpense = ReportUtils.hasHeldExpenses('', allReportTransactions); if (hasHeldExpense) { diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index bd5502e76a5f..6ecb2037d832 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -303,7 +303,7 @@ type SearchTransaction = { hasEReceipt?: boolean; /** The transaction description */ - description: string; + description?: string; /** The transaction sender ID */ accountID: number; @@ -311,8 +311,8 @@ type SearchTransaction = { /** The transaction recipient ID */ managerID: number; - /** If the transaction has a Ereceipt */ - hasViolation: boolean; + /** If the transaction has violations */ + hasViolation?: boolean; /** The transaction tax amount */ taxAmount?: number; diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index dc3d5e8ed97b..69af0e83849a 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -1,139 +1,91 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import Onyx from 'react-native-onyx'; +import type {ReportListItemType} from '@components/SelectionList/types'; import {handleActionButtonPress} from '@libs/actions/Search'; -import ONYXKEYS from '@src/ONYXKEYS'; -import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; -const currentSearchHash = 1; -const mockData = { - key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${1}`, - onyxMethod: 'set', - value: { - data: { - report_1350959062018695: { - accountID: 1206, - action: 'view', - chatReportID: '2108006919825366', - chatType: '', - created: '2024-12-04 23:18:33', - currency: 'USD', - invoiceReceiver: null, - isOneTransactionReport: false, - isPolicyExpenseChat: false, - isWaitingOnBankAccount: false, - managerID: 1206, - nonReimbursableTotal: 0, - ownerAccountID: 1206, - policyID: '48D7178DE42EE9F9', - private_isArchived: '', - reportID: '1350959062018695', - reportName: 'Expense Report #1350959062018695', - stateNum: 1, - statusNum: 1, - total: -13500, - type: 'expense', - unheldTotal: -12300, - }, - transactions_1049531721038862176: { - accountID: 1206, - action: 'view', - amount: -1200, - canDelete: true, - canHold: false, - canUnhold: true, - category: '', - comment: { - comment: '', - hold: '3042630993757922770', - }, - created: '2024-12-04', - currency: 'USD', - hasEReceipt: false, - isFromOneTransactionReport: false, - managerID: 1206, - merchant: 'qewr', - modifiedAmount: 0, - modifiedCreated: '', - modifiedCurrency: '', - modifiedMerchant: '', - parentTransactionID: '', - policyID: '48D7178DE42EE9F9', - reportID: '1350959062018695', - reportType: 'expense', - tag: '', - transactionID: '1049531721038862176', - transactionThreadReportID: '2957345659269055', - transactionType: 'cash', - }, - transactions_5345995386715609966: { - accountID: 1206, - action: 'view', - amount: -12300, - canDelete: true, - canHold: true, - canUnhold: false, - category: '', - comment: { - comment: '', - }, - created: '2024-12-04', - currency: 'USD', - hasEReceipt: false, - isFromOneTransactionReport: false, - managerID: 1206, - merchant: 'fgdfgadfaf', - modifiedAmount: 0, - modifiedCreated: '', - modifiedCurrency: '', - modifiedMerchant: '', - parentTransactionID: '', - policyID: '48D7178DE42EE9F9', - reportID: '1350959062018695', - reportType: 'expense', - tag: '', - transactionID: '5345995386715609966', - transactionThreadReportID: '740282333335072', - transactionType: 'cash', - }, +const mockReportItemWithHold = { + shouldAnimateInHighlight: false, + accountID: 1206, + action: 'approve', + chatReportID: '2108006919825366', + created: '2024-12-04 23:18:33', + currency: 'USD', + isOneTransactionReport: false, + isPolicyExpenseChat: false, + isWaitingOnBankAccount: false, + managerID: 1206, + nonReimbursableTotal: 0, + ownerAccountID: 1206, + policyID: '48D7178DE42EE9F9', + private_isArchived: '', + reportID: '1350959062018695', + reportName: 'Expense Report #1350959062018695', + stateNum: 1, + statusNum: 1, + total: -13500, + type: 'expense', + unheldTotal: -12300, + keyForList: '1350959062018695', + from: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', }, + phoneNumber: '', + validated: false, }, -}; - -describe('handleActionButtonPress', () => { - beforeAll(() => { - Onyx.init({ - keys: ONYXKEYS, - initialKeyStates: mockData, - }); - return waitForBatchedUpdates(); - }); - - test('returns ', () => { - const goToItem = () => {}; - const reportItem = { - shouldAnimateInHighlight: false, + to: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + firstName: 'aesf', + lastName: '', + login: 'apb@apb.com', + pronouns: '', + timezone: { + automatic: true, + selected: 'America/Edmonton', + }, + phoneNumber: '', + validated: false, + }, + transactions: [ + { accountID: 1206, - action: 'approve', - chatReportID: '2108006919825366', - chatType: '', - created: '2024-12-04 23:18:33', + action: 'view', + amount: -1200, + canDelete: true, + canHold: false, + canUnhold: true, + category: '', + comment: { + comment: '', + hold: '3042630993757922770', + }, + created: '2024-12-04', currency: 'USD', - isOneTransactionReport: false, - isPolicyExpenseChat: false, - isWaitingOnBankAccount: false, + hasEReceipt: false, + isFromOneTransactionReport: false, managerID: 1206, - nonReimbursableTotal: 0, - ownerAccountID: 1206, + merchant: 'qewr', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: '', + parentTransactionID: '', policyID: '48D7178DE42EE9F9', - private_isArchived: '', reportID: '1350959062018695', - reportName: 'Expense Report #1350959062018695', - stateNum: 1, - statusNum: 1, - total: -13500, - type: 'expense', - unheldTotal: -12300, - keyForList: '1350959062018695', + reportType: 'expense', + tag: '', + transactionID: '1049531721038862176', + transactionThreadReportID: '2957345659269055', + transactionType: 'cash', from: { accountID: 1206, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', @@ -164,155 +116,102 @@ describe('handleActionButtonPress', () => { phoneNumber: '', validated: false, }, - transactions: [ - { - accountID: 1206, - action: 'view', - amount: -1200, - canDelete: true, - canHold: false, - canUnhold: true, - category: '', - comment: { - comment: '', - hold: '3042630993757922770', - }, - created: '2024-12-04', - currency: 'USD', - hasEReceipt: false, - isFromOneTransactionReport: false, - managerID: 1206, - merchant: 'qewr', - modifiedAmount: 0, - modifiedCreated: '', - modifiedCurrency: '', - modifiedMerchant: '', - parentTransactionID: '', - policyID: '48D7178DE42EE9F9', - reportID: '1350959062018695', - reportType: 'expense', - tag: '', - transactionID: '1049531721038862176', - transactionThreadReportID: '2957345659269055', - transactionType: 'cash', - from: { - accountID: 1206, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', - displayName: 'aesf', - firstName: 'aesf', - lastName: '', - login: 'apb@apb.com', - pronouns: '', - timezone: { - automatic: true, - selected: 'America/Edmonton', - }, - phoneNumber: '', - validated: false, - }, - to: { - accountID: 1206, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', - displayName: 'aesf', - firstName: 'aesf', - lastName: '', - login: 'apb@apb.com', - pronouns: '', - timezone: { - automatic: true, - selected: 'America/Edmonton', - }, - phoneNumber: '', - validated: false, - }, - formattedFrom: 'aesf', - formattedTo: 'aesf', - formattedTotal: 1200, - formattedMerchant: 'qewr', - date: '2024-12-04', - shouldShowMerchant: true, - shouldShowCategory: true, - shouldShowTag: false, - shouldShowTax: false, - keyForList: '1049531721038862176', - shouldShowYear: false, - shouldAnimateInHighlight: false, - }, - { - accountID: 1206, - action: 'view', - amount: -12300, - canDelete: true, - canHold: true, - canUnhold: false, - category: '', - comment: { - comment: '', - }, - created: '2024-12-04', - currency: 'USD', - hasEReceipt: false, - isFromOneTransactionReport: false, - managerID: 1206, - merchant: 'fgdfgadfaf', - modifiedAmount: 0, - modifiedCreated: '', - modifiedCurrency: '', - modifiedMerchant: '', - parentTransactionID: '', - policyID: '48D7178DE42EE9F9', - reportID: '1350959062018695', - reportType: 'expense', - tag: '', - transactionID: '5345995386715609966', - transactionThreadReportID: '740282333335072', - transactionType: 'cash', - from: { - accountID: 1206, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', - displayName: 'aesf', - firstName: 'aesf', - lastName: '', - login: 'apb@apb.com', - pronouns: '', - timezone: { - automatic: true, - selected: 'America/Edmonton', - }, - phoneNumber: '', - validated: false, - }, - to: { - accountID: 1206, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', - displayName: 'aesf', - firstName: 'aesf', - lastName: '', - login: 'apb@apb.com', - pronouns: '', - timezone: { - automatic: true, - selected: 'America/Edmonton', - }, - phoneNumber: '', - validated: false, - }, - formattedFrom: 'aesf', - formattedTo: 'aesf', - formattedTotal: 12300, - formattedMerchant: 'fgdfgadfaf', - date: '2024-12-04', - shouldShowMerchant: true, - shouldShowCategory: true, - shouldShowTag: false, - shouldShowTax: false, - keyForList: '5345995386715609966', - shouldShowYear: false, - shouldAnimateInHighlight: false, + formattedFrom: 'aesf', + formattedTo: 'aesf', + formattedTotal: 1200, + formattedMerchant: 'qewr', + date: '2024-12-04', + shouldShowMerchant: true, + shouldShowCategory: true, + shouldShowTag: false, + shouldShowTax: false, + keyForList: '1049531721038862176', + shouldShowYear: false, + shouldAnimateInHighlight: false, + }, + { + accountID: 1206, + action: 'view', + amount: -12300, + canDelete: true, + canHold: true, + canUnhold: false, + category: '', + comment: { + comment: '', + }, + created: '2024-12-04', + currency: 'USD', + hasEReceipt: false, + isFromOneTransactionReport: false, + managerID: 1206, + merchant: 'fgdfgadfaf', + modifiedAmount: 0, + modifiedCreated: '', + modifiedCurrency: '', + modifiedMerchant: '', + parentTransactionID: '', + policyID: '48D7178DE42EE9F9', + reportID: '1350959062018695', + reportType: 'expense', + tag: '', + transactionID: '5345995386715609966', + transactionThreadReportID: '740282333335072', + transactionType: 'cash', + from: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + login: 'apb@apb.com', + }, + to: { + accountID: 1206, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', + displayName: 'aesf', + }, + formattedFrom: 'aesf', + formattedTo: 'aesf', + formattedTotal: 12300, + formattedMerchant: 'fgdfgadfaf', + date: '2024-12-04', + shouldShowMerchant: true, + shouldShowCategory: true, + shouldShowTag: false, + shouldShowTax: false, + keyForList: '5345995386715609966', + shouldShowYear: false, + shouldAnimateInHighlight: false, + }, + ], + isSelected: false, +} as ReportListItemType; + +const updatedMockReportItem = { + ...mockReportItemWithHold, + transactions: mockReportItemWithHold.transactions.map((transaction, index) => { + if (index === 0) { + return { + ...transaction, + comment: { + comment: '', }, - ], - isSelected: false, - }; - handleActionButtonPress(currentSearchHash, reportItem, goToItem); + }; + } + return transaction; + }), +}; + +describe('handleActionButtonPress', () => { + const searchHash = 1; + test('Should navigate to item when report has one transaction on hold', () => { + const goToItem = jest.fn(() => {}); + handleActionButtonPress(searchHash, mockReportItemWithHold, goToItem); + expect(goToItem).toHaveBeenCalledTimes(1); + }); + + test('Should not navigate to item when the hold is removed', () => { + const goToItem = jest.fn(() => {}); + handleActionButtonPress(searchHash, updatedMockReportItem, goToItem); + expect(goToItem).toHaveBeenCalledTimes(0); }); });