@@ -15,7 +15,7 @@ import type {
1515import Navigation from '@navigation/Navigation' ;
1616// eslint-disable-next-line no-restricted-syntax
1717import type * as ReportUserActions from '@userActions/Report' ;
18- import { createTransactionThreadReport , openReport } from '@userActions/Report' ;
18+ import { createTransactionThreadReport } from '@userActions/Report' ;
1919// eslint-disable-next-line no-restricted-syntax
2020import type * as SearchUtils from '@userActions/Search' ;
2121import { setOptimisticDataForTransactionThreadPreview , updateSearchResultsWithTransactionThreadReportID } from '@userActions/Search' ;
@@ -40,7 +40,6 @@ jest.mock('@src/libs/Navigation/Navigation', () => ({
4040jest . mock ( '@userActions/Report' , ( ) => ( {
4141 ...jest . requireActual < typeof ReportUserActions > ( '@userActions/Report' ) ,
4242 createTransactionThreadReport : jest . fn ( ) ,
43- openReport : jest . fn ( ) ,
4443} ) ) ;
4544jest . mock ( '@userActions/Search' , ( ) => ( {
4645 ...jest . requireActual < typeof SearchUtils > ( '@userActions/Search' ) ,
@@ -2754,28 +2753,29 @@ describe('SearchUIUtils', () => {
27542753 const threadReport = { reportID : threadReportID } ;
27552754 // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
27562755 const transactionListItem = transactionsListItems . at ( 0 ) as TransactionListItemType ;
2757- const iouReportAction = { reportActionID : 'action-123' } as OnyxTypes . ReportAction ;
2756+ const iouReportAction = { reportActionID : transactionListItem . moneyRequestReportActionID } as OnyxTypes . ReportAction ;
27582757 const hash = 12345 ;
27592758 const backTo = '/search/all' ;
27602759
2761- test ( 'Should create transaction thread report and navigate to it' , ( ) => {
2760+ test ( 'Should create transaction thread report and set optimistic data necessary for its preview' , ( ) => {
2761+ const setOptimisticDataForTransactionThreadMock = jest . spyOn ( require ( '@userActions/Search' ) , 'setOptimisticDataForTransactionThreadPreview' ) ;
27622762 ( createTransactionThreadReport as jest . Mock ) . mockReturnValue ( threadReport ) ;
27632763
2764- SearchUIUtils . createAndOpenSearchTransactionThread ( transactionListItem , iouReportAction , hash , backTo ) ;
2764+ SearchUIUtils . createAndOpenSearchTransactionThread ( transactionListItem , hash , backTo , undefined , false ) ;
27652765
2766+ expect ( setOptimisticDataForTransactionThreadMock ) . toHaveBeenCalled ( ) ;
27662767 expect ( createTransactionThreadReport ) . toHaveBeenCalledWith ( report1 , iouReportAction ) ;
27672768 expect ( updateSearchResultsWithTransactionThreadReportID ) . toHaveBeenCalledWith ( hash , transactionID , threadReportID ) ;
2768- expect ( Navigation . navigate ) . toHaveBeenCalledWith ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : threadReportID , backTo} ) ) ;
27692769 } ) ;
27702770
2771- test ( 'Should not load iou report if iouReportAction was provided ' , ( ) => {
2772- SearchUIUtils . createAndOpenSearchTransactionThread ( transactionListItem , iouReportAction , hash , backTo ) ;
2773- expect ( openReport ) . not . toHaveBeenCalled ( ) ;
2771+ test ( 'Should not navigate if shouldNavigate = false ' , ( ) => {
2772+ SearchUIUtils . createAndOpenSearchTransactionThread ( transactionListItem , hash , backTo , undefined , false ) ;
2773+ expect ( Navigation . navigate ) . not . toHaveBeenCalled ( ) ;
27742774 } ) ;
27752775
2776- test ( 'Should load iou report if iouReportAction was not provided ' , ( ) => {
2777- SearchUIUtils . createAndOpenSearchTransactionThread ( transactionListItem , undefined , hash , backTo ) ;
2778- expect ( openReport ) . toHaveBeenCalled ( ) ;
2776+ test ( 'Should handle navigation if shouldNavigate = true ' , ( ) => {
2777+ SearchUIUtils . createAndOpenSearchTransactionThread ( transactionListItem , hash , backTo , undefined , true ) ;
2778+ expect ( Navigation . navigate ) . toHaveBeenCalledWith ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : threadReportID , backTo } ) ) ;
27792779 } ) ;
27802780 } ) ;
27812781
0 commit comments