@@ -2,7 +2,12 @@ import {getSearchBulkEditPolicyID} from '@libs/SearchUIUtils';
22import CONST from '@src/CONST' ;
33import ONYXKEYS from '@src/ONYXKEYS' ;
44import type { Policy , Report , SearchResults , Transaction } from '@src/types/onyx' ;
5- import { isBulkEditTaxTrackingEnabled , withSnapshotReports , withSnapshotTransactions } from '../../src/pages/Search/SearchEditMultiple/SearchEditMultipleUtils' ;
5+ import {
6+ areAllTransactionsExpenseCompatible ,
7+ isBulkEditTaxTrackingEnabled ,
8+ withSnapshotReports ,
9+ withSnapshotTransactions ,
10+ } from '../../src/pages/Search/SearchEditMultiple/SearchEditMultipleUtils' ;
611
712const POLICY_A = 'policyA' ;
813const POLICY_B = 'policyB' ;
@@ -133,6 +138,50 @@ describe('SearchEditMultipleUtils', () => {
133138 } ) ;
134139 } ) ;
135140
141+ describe ( 'areAllTransactionsExpenseCompatible' , ( ) => {
142+ const expenseReport = { reportID : 'expenseReport1' , type : CONST . REPORT . TYPE . EXPENSE } as Report ;
143+ const iouReport = { reportID : 'iouReport1' , type : CONST . REPORT . TYPE . IOU } as Report ;
144+ const invoiceReport = { reportID : 'invoiceReport1' , type : CONST . REPORT . TYPE . INVOICE } as Report ;
145+
146+ it ( 'returns true when every reported transaction is on an expense report' , ( ) => {
147+ const contexts = [
148+ { transaction : makeTransaction ( TRANSACTION_ID_1 , 'expenseReport1' ) , report : expenseReport } ,
149+ { transaction : makeTransaction ( TRANSACTION_ID_2 , 'expenseReport1' ) , report : expenseReport } ,
150+ ] ;
151+ expect ( areAllTransactionsExpenseCompatible ( contexts ) ) . toBe ( true ) ;
152+ } ) ;
153+
154+ it ( 'returns true for unreported (track) transactions' , ( ) => {
155+ const contexts = [ { transaction : makeTransaction ( TRANSACTION_ID_1 , CONST . REPORT . UNREPORTED_REPORT_ID ) , report : undefined } ] ;
156+ expect ( areAllTransactionsExpenseCompatible ( contexts ) ) . toBe ( true ) ;
157+ } ) ;
158+
159+ it ( 'returns false when any reported transaction is on an IOU report' , ( ) => {
160+ const contexts = [
161+ { transaction : makeTransaction ( TRANSACTION_ID_1 , 'expenseReport1' ) , report : expenseReport } ,
162+ { transaction : makeTransaction ( TRANSACTION_ID_2 , 'iouReport1' ) , report : iouReport } ,
163+ ] ;
164+ expect ( areAllTransactionsExpenseCompatible ( contexts ) ) . toBe ( false ) ;
165+ } ) ;
166+
167+ it ( 'returns false when a mix of unreported and IOU transactions is selected' , ( ) => {
168+ const contexts = [
169+ { transaction : makeTransaction ( TRANSACTION_ID_1 , CONST . REPORT . UNREPORTED_REPORT_ID ) , report : undefined } ,
170+ { transaction : makeTransaction ( TRANSACTION_ID_2 , 'iouReport1' ) , report : iouReport } ,
171+ ] ;
172+ expect ( areAllTransactionsExpenseCompatible ( contexts ) ) . toBe ( false ) ;
173+ } ) ;
174+
175+ it ( 'returns true for invoice reports (not IOU)' , ( ) => {
176+ const contexts = [ { transaction : makeTransaction ( TRANSACTION_ID_1 , 'invoiceReport1' ) , report : invoiceReport } ] ;
177+ expect ( areAllTransactionsExpenseCompatible ( contexts ) ) . toBe ( true ) ;
178+ } ) ;
179+
180+ it ( 'returns true for an empty selection' , ( ) => {
181+ expect ( areAllTransactionsExpenseCompatible ( [ ] ) ) . toBe ( true ) ;
182+ } ) ;
183+ } ) ;
184+
136185 describe ( 'isBulkEditTaxTrackingEnabled' , ( ) => {
137186 const taxEnabledPolicy = { id : POLICY_A , tax : { trackingEnabled : true } } as unknown as Policy ;
138187 const taxDisabledPolicy = { id : POLICY_B , tax : { trackingEnabled : false } } as unknown as Policy ;
0 commit comments