|
1 | 1 | import {getSearchBulkEditPolicyID} from '@libs/SearchUIUtils'; |
| 2 | +import CONST from '@src/CONST'; |
2 | 3 | import ONYXKEYS from '@src/ONYXKEYS'; |
3 | 4 | import type {Report, SearchResults, Transaction} from '@src/types/onyx'; |
4 | | -import {withSnapshotReports, withSnapshotTransactions} from '../../src/pages/Search/SearchEditMultiple/SearchEditMultipleUtils'; |
| 5 | +import {areAllTransactionsExpenseCompatible, withSnapshotReports, withSnapshotTransactions} from '../../src/pages/Search/SearchEditMultiple/SearchEditMultipleUtils'; |
5 | 6 |
|
6 | 7 | const POLICY_A = 'policyA'; |
7 | 8 | const POLICY_B = 'policyB'; |
@@ -130,4 +131,48 @@ describe('SearchEditMultipleUtils', () => { |
130 | 131 | expect(result).toBe(POLICY_A); |
131 | 132 | }); |
132 | 133 | }); |
| 134 | + |
| 135 | + describe('areAllTransactionsExpenseCompatible', () => { |
| 136 | + const expenseReport = {reportID: 'expenseReport1', type: CONST.REPORT.TYPE.EXPENSE} as Report; |
| 137 | + const iouReport = {reportID: 'iouReport1', type: CONST.REPORT.TYPE.IOU} as Report; |
| 138 | + const invoiceReport = {reportID: 'invoiceReport1', type: CONST.REPORT.TYPE.INVOICE} as Report; |
| 139 | + |
| 140 | + it('returns true when every reported transaction is on an expense report', () => { |
| 141 | + const contexts = [ |
| 142 | + {transaction: makeTransaction(TRANSACTION_ID_1, 'expenseReport1'), report: expenseReport}, |
| 143 | + {transaction: makeTransaction(TRANSACTION_ID_2, 'expenseReport1'), report: expenseReport}, |
| 144 | + ]; |
| 145 | + expect(areAllTransactionsExpenseCompatible(contexts)).toBe(true); |
| 146 | + }); |
| 147 | + |
| 148 | + it('returns true for unreported (track) transactions', () => { |
| 149 | + const contexts = [{transaction: makeTransaction(TRANSACTION_ID_1, CONST.REPORT.UNREPORTED_REPORT_ID), report: undefined}]; |
| 150 | + expect(areAllTransactionsExpenseCompatible(contexts)).toBe(true); |
| 151 | + }); |
| 152 | + |
| 153 | + it('returns false when any reported transaction is on an IOU report', () => { |
| 154 | + const contexts = [ |
| 155 | + {transaction: makeTransaction(TRANSACTION_ID_1, 'expenseReport1'), report: expenseReport}, |
| 156 | + {transaction: makeTransaction(TRANSACTION_ID_2, 'iouReport1'), report: iouReport}, |
| 157 | + ]; |
| 158 | + expect(areAllTransactionsExpenseCompatible(contexts)).toBe(false); |
| 159 | + }); |
| 160 | + |
| 161 | + it('returns false when a mix of unreported and IOU transactions is selected', () => { |
| 162 | + const contexts = [ |
| 163 | + {transaction: makeTransaction(TRANSACTION_ID_1, CONST.REPORT.UNREPORTED_REPORT_ID), report: undefined}, |
| 164 | + {transaction: makeTransaction(TRANSACTION_ID_2, 'iouReport1'), report: iouReport}, |
| 165 | + ]; |
| 166 | + expect(areAllTransactionsExpenseCompatible(contexts)).toBe(false); |
| 167 | + }); |
| 168 | + |
| 169 | + it('returns true for invoice reports (not IOU)', () => { |
| 170 | + const contexts = [{transaction: makeTransaction(TRANSACTION_ID_1, 'invoiceReport1'), report: invoiceReport}]; |
| 171 | + expect(areAllTransactionsExpenseCompatible(contexts)).toBe(true); |
| 172 | + }); |
| 173 | + |
| 174 | + it('returns true for an empty selection', () => { |
| 175 | + expect(areAllTransactionsExpenseCompatible([])).toBe(true); |
| 176 | + }); |
| 177 | + }); |
133 | 178 | }); |
0 commit comments