Skip to content

Commit 876fb93

Browse files
committed
apply review suggestions
1 parent 687a6b4 commit 876fb93

4 files changed

Lines changed: 6 additions & 33 deletions

File tree

src/pages/iou/request/step/IOURequestStepScan/hooks/useReceiptScan.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ function useReceiptScan({
7171
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
7272
const draftTransactionIDs = Object.keys(allTransactionDrafts ?? {});
7373
const [isMultiScanEnabled, setIsMultiScanEnabled] = useState(false);
74+
const isStartingScan = routeName === SCREENS.MONEY_REQUEST.CREATE;
7475

7576
const isEditing = action === CONST.IOU.ACTION.EDIT;
7677
const isReplacingReceipt = (isEditing && hasReceipt(initialTransaction)) || (!!initialTransaction?.receipt && !!backTo);
77-
const isStartingScan = routeName === SCREENS.MONEY_REQUEST.CREATE;
7878
const shouldAcceptMultipleFiles = !isEditing && !backTo;
7979
const shouldGenerateTransactionThreadReport = !isBetaEnabled(CONST.BETAS.NO_OPTIMISTIC_TRANSACTION_THREADS);
8080
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);

src/pages/iou/request/step/IOURequestStepScan/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type UseReceiptScanParams = {
3939
backToReport: string | undefined;
4040

4141
/** The route name to determine if scan is starting */
42-
routeName: string;
42+
routeName: IOURequestStepScanProps['route']['name'];
4343

4444
/** Callback to replace receipt and navigate back when editing */
4545
updateScanAndNavigate: (file: FileObject, source: string) => void;
@@ -56,7 +56,7 @@ type UseMobileReceiptScanParams = {
5656
iouType: IOUType;
5757

5858
/** Whether multi-scan is enabled */
59-
isMultiScanEnabled?: boolean;
59+
isMultiScanEnabled: boolean;
6060

6161
/** Whether the user is starting a scan request */
6262
isStartingScan: boolean;

tests/ui/IOURequestStepScanTest.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ describe('IOURequestStepScan', () => {
172172
const POLICY_ID = 'policy-1';
173173
const TRANSACTION_ID_1 = '101';
174174

175-
await act(async () => {
176-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, createMinimalReport(REPORT_ID, POLICY_ID));
177-
});
178-
await waitForBatchedUpdates();
179-
180175
render(
181176
<OnyxListItemProvider>
182177
<LocaleContextProvider>
@@ -193,7 +188,7 @@ describe('IOURequestStepScan', () => {
193188
transactionID: TRANSACTION_ID_1,
194189
pageIndex: 0,
195190
},
196-
} as unknown as PlatformStackScreenProps<MoneyRequestNavigatorParamList, typeof SCREENS.MONEY_REQUEST.STEP_SCAN>['route']
191+
} as unknown as PlatformStackScreenProps<MoneyRequestNavigatorParamList, typeof SCREENS.MONEY_REQUEST.CREATE>['route']
197192
}
198193
navigation={{} as never}
199194
/>
@@ -204,13 +199,14 @@ describe('IOURequestStepScan', () => {
204199

205200
await waitForBatchedUpdatesWithAct();
206201
fireEvent.press(screen.getByLabelText('multi-scan'));
207-
await waitForBatchedUpdatesWithAct();
202+
await waitForBatchedUpdates();
208203
const transaction1 = createRandomTransaction(1);
209204
transaction1.reportID = REPORT_ID;
210205
transaction1.transactionID = TRANSACTION_ID_1;
211206
transaction1.receipt = {source: 'file://first-receipt.png', state: CONST.IOU.RECEIPT_STATE.OPEN};
212207

213208
await act(async () => {
209+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, createMinimalReport(REPORT_ID, POLICY_ID));
214210
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${TRANSACTION_ID_1}`, transaction1);
215211
});
216212
await waitForBatchedUpdates();

tests/unit/hooks/useReceiptScan.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -296,29 +296,6 @@ describe('useReceiptScan', () => {
296296
expect(result.current.receiptFiles).toHaveLength(1);
297297
expect(result.current.receiptFiles.at(0)).toEqual(receiptFile);
298298
});
299-
300-
it('should clear receiptFiles when isMultiScanEnabled changes from true to false', async () => {
301-
const {result} = renderHook(() => useReceiptScan(params));
302-
await waitForBatchedUpdatesWithAct();
303-
304-
await act(async () => {
305-
result.current.setIsMultiScanEnabled(true);
306-
});
307-
await waitForBatchedUpdatesWithAct();
308-
309-
const receiptFile = {file: {uri: 'picture.jpg'}, source: 'file://picture.jpg', transactionID: INITIAL_TRANSACTION_ID};
310-
await act(async () => {
311-
result.current.setReceiptFiles([receiptFile]);
312-
});
313-
await waitForBatchedUpdatesWithAct();
314-
expect(result.current.receiptFiles).toHaveLength(1);
315-
316-
await act(async () => {
317-
result.current.setIsMultiScanEnabled(false);
318-
});
319-
await waitForBatchedUpdatesWithAct();
320-
expect(result.current.isMultiScanEnabled).toBe(false);
321-
});
322299
});
323300

324301
describe('processReceipts', () => {

0 commit comments

Comments
 (0)