@@ -4,7 +4,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
44import Onyx from 'react-native-onyx' ;
55import useReportIsArchived from '@hooks/useReportIsArchived' ;
66import DateUtils from '@libs/DateUtils' ;
7- import { getReportActionMessageText } from '@libs/ReportActionsUtils' ;
7+ import { getOriginalMessage , getReportActionMessageText } from '@libs/ReportActionsUtils' ;
88import { getAllReportErrors } from '@libs/ReportUtils' ;
99import SidebarUtils from '@libs/SidebarUtils' ;
1010import initOnyxDerivedValues from '@userActions/OnyxDerived' ;
@@ -14,7 +14,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
1414import type { Policy , Report , ReportAction , ReportActions , Transaction , TransactionViolation , TransactionViolations } from '@src/types/onyx' ;
1515import type { ReportCollectionDataSet } from '@src/types/onyx/Report' ;
1616import type { TransactionViolationsCollectionDataSet } from '@src/types/onyx/TransactionViolation' ;
17- import { chatReportR14932 } from '../../__mocks__/reportData/reports' ;
17+ import { actionR14932 as mockIOUAction } from '../../__mocks__/reportData/actions' ;
18+ import { chatReportR14932 , iouReportR14932 } from '../../__mocks__/reportData/reports' ;
1819import createRandomPolicy from '../utils/collections/policies' ;
1920import createRandomReportAction from '../utils/collections/reportActions' ;
2021import createRandomReport from '../utils/collections/reports' ;
@@ -1126,6 +1127,69 @@ describe('SidebarUtils', () => {
11261127 oneTransactionThreadReport : undefined ,
11271128 } ) ;
11281129
1130+ expect ( result ?. alternateText ) . toBe ( `You: ${ getReportActionMessageText ( lastAction ) } ` ) ;
1131+ } ) ;
1132+ it ( 'returns the last action message as an alternate text if the expense report is the one expense report' , async ( ) => {
1133+ const IOUTransactionID = `${ ONYXKEYS . COLLECTION . TRANSACTION } TRANSACTION_IOU` as const ;
1134+
1135+ iouReportR14932 . reportID = '5' ;
1136+ chatReportR14932 . reportID = '6' ;
1137+ iouReportR14932 . lastActorAccountID = undefined ;
1138+
1139+ const report : Report = {
1140+ ...createRandomReport ( 1 ) ,
1141+ chatType : 'policyExpenseChat' ,
1142+ pendingAction : null ,
1143+ isOwnPolicyExpenseChat : true ,
1144+ parentReportID : iouReportR14932 . reportID ,
1145+ parentReportActionID : mockIOUAction . reportActionID ,
1146+ lastActorAccountID : undefined ,
1147+ } ;
1148+
1149+ const linkedCreateAction : ReportAction = {
1150+ ...mockIOUAction ,
1151+ originalMessage : { ...getOriginalMessage ( mockIOUAction ) , IOUTransactionID} ,
1152+ childReportID : report . reportID ,
1153+ reportActionID : '3' ,
1154+ } ;
1155+
1156+ const lastAction : ReportAction = {
1157+ ...createRandomReportAction ( 1 ) ,
1158+ message : [
1159+ {
1160+ type : 'COMMENT' ,
1161+ html : 'test action' ,
1162+ text : 'test action' ,
1163+ } ,
1164+ ] ,
1165+ originalMessage : {
1166+ whisperedTo : [ ] ,
1167+ } ,
1168+
1169+ created : DateUtils . getDBTime ( ) ,
1170+ lastModified : DateUtils . getDBTime ( ) ,
1171+ shouldShow : true ,
1172+ pendingAction : null ,
1173+ actionName : CONST . REPORT . ACTIONS . TYPE . ADD_COMMENT ,
1174+ actorAccountID : undefined ,
1175+ } ;
1176+
1177+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReportR14932 . reportID } ` , iouReportR14932 ) ;
1178+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportR14932 . reportID } ` , chatReportR14932 ) ;
1179+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ report . reportID } ` , report ) ;
1180+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ report . reportID } ` , { [ lastAction . reportActionID ] : lastAction } ) ;
1181+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ iouReportR14932 . reportID } ` , { [ linkedCreateAction . reportActionID ] : linkedCreateAction } ) ;
1182+
1183+ const result = SidebarUtils . getOptionData ( {
1184+ report : iouReportR14932 ,
1185+ reportAttributes : undefined ,
1186+ reportNameValuePairs : { } ,
1187+ personalDetails : { } ,
1188+ policy : undefined ,
1189+ parentReportAction : undefined ,
1190+ oneTransactionThreadReport : undefined ,
1191+ } ) ;
1192+
11291193 expect ( result ?. alternateText ) . toBe ( `You: ${ getReportActionMessageText ( lastAction ) } ` ) ;
11301194 } ) ;
11311195 } ) ;
0 commit comments