@@ -7796,15 +7796,16 @@ describe('OptionsListUtils', () => {
77967796 } ) ;
77977797 } ) ;
77987798
7799- describe ( 'getSearchOptions with sortedActions' , ( ) => {
7800- it ( 'should forward sortedActions through getSearchOptions without errors' , async ( ) => {
7801- const reportID = 'search-sorted-1' ;
7802- const iouReportID = 'search-iou-1' ;
7799+ describe ( 'getValidOptions with sortedActions' , ( ) => {
7800+ it ( 'returns lastIOUCreationDate from the latest IOU action linked via REPORT_PREVIEW' , async ( ) => {
7801+ const reportID = 'gvo-sorted-1' ;
7802+ const iouReportID = 'gvo-iou-1' ;
7803+ const expectedDate = '2025-06-15 10:30:00.000' ;
78037804
78047805 const report : Report = {
78057806 ...createRegularChat ( Number ( reportID ) , [ 1 ] ) ,
78067807 reportID,
7807- reportName : 'Search Sorted Test ' ,
7808+ reportName : 'Expense Chat ' ,
78087809 lastVisibleActionCreated : '2025-06-15 10:00:00.000' ,
78097810 lastActorAccountID : 1 ,
78107811 lastMessageText : 'Test' ,
@@ -7822,13 +7823,13 @@ describe('OptionsListUtils', () => {
78227823 const iouAction : ReportAction = {
78237824 ...createRandomReportAction ( 2 ) ,
78247825 actionName : CONST . REPORT . ACTIONS . TYPE . IOU ,
7825- lastModified : '2025-06-15 10:30:00.000' ,
7826+ lastModified : expectedDate ,
78267827 } as ReportAction ;
78277828
78287829 const inputOption : SearchOption < Report > = {
78297830 item : report ,
78307831 reportID,
7831- text : 'Search Sorted Test ' ,
7832+ text : 'Expense Chat ' ,
78327833 isUnread : false ,
78337834 participantsList : [ ] ,
78347835 keyForList : reportID ,
@@ -7855,22 +7856,74 @@ describe('OptionsListUtils', () => {
78557856 [ iouReportID ] : [ iouAction ] ,
78567857 } ;
78577858
7858- const results = getSearchOptions ( {
7859- options : { reports : [ inputOption ] , personalDetails : [ ] } ,
7860- draftComments : { } ,
7861- betas : [ CONST . BETAS . ALL ] ,
7862- loginList,
7863- policyCollection : allPolicies ,
7864- currentUserAccountID : CURRENT_USER_ACCOUNT_ID ,
7865- currentUserEmail : CURRENT_USER_EMAIL ,
7859+ const results = getValidOptions ( { reports : [ inputOption ] , personalDetails : [ ] } , allPolicies , { } , loginList , CURRENT_USER_ACCOUNT_ID , CURRENT_USER_EMAIL , undefined , {
7860+ includeRecentReports : true ,
7861+ includeMultipleParticipantReports : true ,
7862+ action : CONST . IOU . ACTION . CREATE ,
78667863 sortedActions,
7867- conciergeReportID : undefined ,
78687864 } ) ;
78697865
78707866 expect ( results . recentReports . length ) . toBe ( 1 ) ;
7867+ expect ( results . recentReports . at ( 0 ) ?. lastIOUCreationDate ) . toBe ( expectedDate ) ;
7868+ } ) ;
7869+
7870+ it ( 'returns undefined lastIOUCreationDate when sortedActions has no matching IOU actions' , async ( ) => {
7871+ const reportID = 'gvo-sorted-2' ;
7872+
7873+ const report : Report = {
7874+ ...createRegularChat ( Number ( reportID ) , [ 1 ] ) ,
7875+ reportID,
7876+ reportName : 'Chat with no IOU' ,
7877+ lastVisibleActionCreated : '2025-06-15 10:00:00.000' ,
7878+ lastActorAccountID : 1 ,
7879+ lastMessageText : 'Test' ,
7880+ } ;
7881+
7882+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` , report ) ;
7883+ await waitForBatchedUpdates ( ) ;
7884+
7885+ const commentAction : ReportAction = {
7886+ ...createRandomReportAction ( 1 ) ,
7887+ actionName : CONST . REPORT . ACTIONS . TYPE . ADD_COMMENT ,
7888+ } as ReportAction ;
7889+
7890+ const inputOption : SearchOption < Report > = {
7891+ item : report ,
7892+ reportID,
7893+ text : 'Chat with no IOU' ,
7894+ isUnread : false ,
7895+ participantsList : [ ] ,
7896+ keyForList : reportID ,
7897+ isChatRoom : true ,
7898+ policyID : '123' ,
7899+ lastMessageText : 'Test' ,
7900+ lastVisibleActionCreated : report . lastVisibleActionCreated ,
7901+ notificationPreference : 'always' ,
7902+ accountID : 0 ,
7903+ login : '' ,
7904+ alternateText : '' ,
7905+ subtitle : '' ,
7906+ firstName : '' ,
7907+ lastName : '' ,
7908+ icons : [ ] ,
7909+ isSelected : false ,
7910+ isDisabled : false ,
7911+ brickRoadIndicator : null ,
7912+ isBold : false ,
7913+ } ;
7914+
7915+ const results = getValidOptions ( { reports : [ inputOption ] , personalDetails : [ ] } , allPolicies , { } , loginList , CURRENT_USER_ACCOUNT_ID , CURRENT_USER_EMAIL , undefined , {
7916+ includeRecentReports : true ,
7917+ action : CONST . IOU . ACTION . CREATE ,
7918+ sortedActions : { [ reportID ] : [ commentAction ] } ,
7919+ } ) ;
7920+
7921+ expect ( results . recentReports . at ( 0 ) ?. lastIOUCreationDate ) . toBeUndefined ( ) ;
78717922 } ) ;
7923+ } ) ;
78727924
7873- it ( 'should handle undefined sortedActions via getSearchOptions' , async ( ) => {
7925+ describe ( 'getSearchOptions with sortedActions' , ( ) => {
7926+ it ( 'should not have lastIOUCreationDate when sortedActions is undefined' , async ( ) => {
78747927 const reportID = 'search-sorted-2' ;
78757928
78767929 const report : Report = {
0 commit comments