@@ -390,6 +390,83 @@ describe('ForYouSection', () => {
390390 expect ( mockNavigate ) . not . toHaveBeenCalled ( ) ;
391391 } ) ;
392392
393+ it ( 'opens the flagged expense thread when a lone flagged expense sits inside a multi-transaction report' , async ( ) => {
394+ // Repro of the deploy blocker: an OPEN expense report with two transactions where only one is still
395+ // flagged. transactionCount is 2, so pressing the row must open the flagged expense's thread rather
396+ // than the whole report (which would show both the flagged and unflagged expenses).
397+ await act ( async ( ) => {
398+ setTodoCounts ( BASE_TODOS ) ;
399+ await Onyx . set (
400+ `${ ONYXKEYS . COLLECTION . REPORT } r1` ,
401+ createMockReport ( {
402+ reportID : 'r1' ,
403+ type : CONST . REPORT . TYPE . EXPENSE ,
404+ ownerAccountID : ACCOUNT_ID ,
405+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
406+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
407+ transactionCount : 2 ,
408+ } ) ,
409+ ) ;
410+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } t1` , { transactionID : 't1' , reportID : 'r1' , amount : 100 , currency : 'USD' , created : '2024-01-01' , merchant : 'Test Merchant' } ) ;
411+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } t2` , { transactionID : 't2' , reportID : 'r1' , amount : 200 , currency : 'USD' , created : '2024-01-01' , merchant : 'Test Merchant' } ) ;
412+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } t1` , [
413+ { type : CONST . VIOLATION_TYPES . VIOLATION , name : CONST . VIOLATIONS . MISSING_CATEGORY } ,
414+ ] as TransactionViolations ) ;
415+ } ) ;
416+ await waitForBatchedUpdatesWithAct ( ) ;
417+
418+ renderForYouSection ( ) ;
419+ await waitForBatchedUpdatesWithAct ( ) ;
420+
421+ pressFirstBeginButton ( ) ;
422+
423+ expect ( mockNavigateToTransactionThread ) . toHaveBeenCalledTimes ( 1 ) ;
424+ expect ( mockNavigateToTransactionThread ) . toHaveBeenCalledWith (
425+ expect . objectContaining ( {
426+ transactionID : 't1' ,
427+ report : expect . objectContaining ( { reportID : 'r1' } ) ,
428+ siblingTransactionIDs : [ 't1' ] ,
429+ backTo : ROUTES . HOME ,
430+ } ) ,
431+ ) ;
432+ // The whole-report route must not be used when the report holds more than one transaction.
433+ expect ( mockNavigate ) . not . toHaveBeenCalled ( ) ;
434+ } ) ;
435+
436+ it ( 'opens the report directly when the lone flagged expense is the report only transaction' , async ( ) => {
437+ // A genuine one-transaction report keeps the shortcut: the transaction thread would be a redundant
438+ // duplicate of the report, so navigate straight to the expense report.
439+ await act ( async ( ) => {
440+ setTodoCounts ( BASE_TODOS ) ;
441+ await Onyx . set (
442+ `${ ONYXKEYS . COLLECTION . REPORT } r1` ,
443+ createMockReport ( {
444+ reportID : 'r1' ,
445+ type : CONST . REPORT . TYPE . EXPENSE ,
446+ ownerAccountID : ACCOUNT_ID ,
447+ stateNum : CONST . REPORT . STATE_NUM . OPEN ,
448+ statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
449+ transactionCount : 1 ,
450+ } ) ,
451+ ) ;
452+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } t1` , { transactionID : 't1' , reportID : 'r1' , amount : 100 , currency : 'USD' , created : '2024-01-01' , merchant : 'Test Merchant' } ) ;
453+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } t1` , [
454+ { type : CONST . VIOLATION_TYPES . VIOLATION , name : CONST . VIOLATIONS . MISSING_CATEGORY } ,
455+ ] as TransactionViolations ) ;
456+ } ) ;
457+ await waitForBatchedUpdatesWithAct ( ) ;
458+
459+ renderForYouSection ( ) ;
460+ await waitForBatchedUpdatesWithAct ( ) ;
461+
462+ pressFirstBeginButton ( ) ;
463+
464+ // Wide layout (default in beforeEach) → EXPENSE_REPORT_RHP.
465+ expect ( mockNavigate ) . toHaveBeenCalledTimes ( 1 ) ;
466+ expect ( mockNavigate ) . toHaveBeenCalledWith ( ROUTES . EXPENSE_REPORT_RHP . getRoute ( { reportID : 'r1' , backTo : ROUTES . HOME } ) ) ;
467+ expect ( mockNavigateToTransactionThread ) . not . toHaveBeenCalled ( ) ;
468+ } ) ;
469+
393470 it ( 'does not render the review row or navigate when a violated transaction is not on a current-user OPEN expense report' , async ( ) => {
394471 await act ( async ( ) => {
395472 setTodoCounts ( BASE_TODOS ) ;
0 commit comments