@@ -13,7 +13,6 @@ import {chatReportR14932 as mockChatReport, iouReportR14932 as mockIOUReport} fr
1313import CONST from '../../src/CONST' ;
1414import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils' ;
1515import {
16- findLastReportActions ,
1716 getAddedCardFeedMessage ,
1817 getAssignedCompanyCardMessage ,
1918 getAutoPayApprovedReportsEnabledMessage ,
@@ -4433,135 +4432,6 @@ describe('ReportActionsUtils', () => {
44334432 } ) ;
44344433 } ) ;
44354434
4436- describe ( 'findLastReportActions' , ( ) => {
4437- const makeAction = ( overrides : Partial < ReportAction > ) : ReportAction =>
4438- ( {
4439- actionName : CONST . REPORT . ACTIONS . TYPE . ADD_COMMENT ,
4440- reportActionID : '1' ,
4441- reportID : 'testReportID' ,
4442- created : '2024-01-01 00:00:00.000' ,
4443- person : [ { type : 'TEXT' , style : 'strong' , text : 'Actor' } ] ,
4444- message : [ { html : 'hello' , text : 'hello' , type : 'COMMENT' } ] ,
4445- ...overrides ,
4446- } ) as ReportAction ;
4447-
4448- it ( 'returns undefined for both when reportActions is undefined' , ( ) => {
4449- const result = findLastReportActions ( undefined ) ;
4450- expect ( result . lastVisibleAction ) . toBeUndefined ( ) ;
4451- expect ( result . lastActionForDisplay ) . toBeUndefined ( ) ;
4452- } ) ;
4453-
4454- it ( 'returns undefined for both when reportActions is empty' , ( ) => {
4455- const result = findLastReportActions ( { } ) ;
4456- expect ( result . lastVisibleAction ) . toBeUndefined ( ) ;
4457- expect ( result . lastActionForDisplay ) . toBeUndefined ( ) ;
4458- } ) ;
4459-
4460- it ( 'returns the single visible action for both when there is only one ADD_COMMENT action' , ( ) => {
4461- const action = makeAction ( { reportActionID : '1' , created : '2024-01-01 00:00:00.000' } ) ;
4462- const result = findLastReportActions ( { [ action . reportActionID ] : action } ) ;
4463- expect ( result . lastVisibleAction ) . toBe ( action ) ;
4464- expect ( result . lastActionForDisplay ) . toBe ( action ) ;
4465- } ) ;
4466-
4467- it ( 'returns undefined for lastActionForDisplay but not lastVisibleAction when only action is CREATED' , ( ) => {
4468- const created = makeAction ( { actionName : CONST . REPORT . ACTIONS . TYPE . CREATED , reportActionID : '1' , created : '2024-01-01 00:00:00.000' } ) ;
4469- const result = findLastReportActions ( { [ created . reportActionID ] : created } ) ;
4470- expect ( result . lastVisibleAction ) . toBe ( created ) ;
4471- expect ( result . lastActionForDisplay ) . toBeUndefined ( ) ;
4472- } ) ;
4473-
4474- it ( 'returns the newest of multiple visible actions' , ( ) => {
4475- const older = makeAction ( { reportActionID : '1' , created : '2024-01-01 00:00:00.000' } ) ;
4476- const newer = makeAction ( { reportActionID : '2' , created : '2024-01-02 00:00:00.000' } ) ;
4477- const result = findLastReportActions ( {
4478- [ older . reportActionID ] : older ,
4479- [ newer . reportActionID ] : newer ,
4480- } ) ;
4481- expect ( result . lastVisibleAction ) . toBe ( newer ) ;
4482- expect ( result . lastActionForDisplay ) . toBe ( newer ) ;
4483- } ) ;
4484-
4485- it ( 'skips deleted actions (no pendingAction, empty html) for both results' , ( ) => {
4486- const visible = makeAction ( { reportActionID : '1' , created : '2024-01-01 00:00:00.000' } ) ;
4487- const deleted = makeAction ( {
4488- reportActionID : '2' ,
4489- created : '2024-01-02 00:00:00.000' ,
4490- message : [ { html : '' , text : '' , type : 'COMMENT' } ] ,
4491- pendingAction : undefined ,
4492- } ) ;
4493- const result = findLastReportActions ( {
4494- [ visible . reportActionID ] : visible ,
4495- [ deleted . reportActionID ] : deleted ,
4496- } ) ;
4497- expect ( result . lastVisibleAction ) . toBe ( visible ) ;
4498- expect ( result . lastActionForDisplay ) . toBe ( visible ) ;
4499- } ) ;
4500-
4501- it ( 'excludes actions with errors from lastActionForDisplay but not from lastVisibleAction' , ( ) => {
4502- const clean = makeAction ( { reportActionID : '1' , created : '2024-01-01 00:00:00.000' } ) ;
4503- const withErrors = makeAction ( {
4504- reportActionID : '2' ,
4505- created : '2024-01-02 00:00:00.000' ,
4506- errors : { someError : 'error message' } ,
4507- } ) ;
4508- const result = findLastReportActions ( {
4509- [ clean . reportActionID ] : clean ,
4510- [ withErrors . reportActionID ] : withErrors ,
4511- } ) ;
4512- expect ( result . lastVisibleAction ) . toBe ( withErrors ) ;
4513- expect ( result . lastActionForDisplay ) . toBe ( clean ) ;
4514- } ) ;
4515-
4516- it ( 'agrees with getSortedReportActionsForDisplay for lastVisibleAction across multiple actions' , ( ) => {
4517- const actionA = makeAction ( { reportActionID : 'actionA' , created : '2024-01-01 00:00:00.000' } ) ;
4518- const actionB = makeAction ( { reportActionID : 'actionB' , created : '2024-01-03 00:00:00.000' } ) ;
4519- const actionC = makeAction ( { reportActionID : 'actionC' , created : '2024-01-02 00:00:00.000' } ) ;
4520- const actions : ReportActions = {
4521- actionA,
4522- actionB,
4523- actionC,
4524- } ;
4525- const { lastVisibleAction} = findLastReportActions ( actions ) ;
4526- const fromSort = getSortedReportActionsForDisplay ( actions ) . at ( 0 ) ;
4527- expect ( lastVisibleAction ?. reportActionID ) . toBe ( fromSort ?. reportActionID ) ;
4528- } ) ;
4529-
4530- it ( 'agrees with the old getSortedReportActions+filter approach for lastActionForDisplay' , ( ) => {
4531- const actionA = makeAction ( { reportActionID : 'actionA' , created : '2024-01-01 00:00:00.000' } ) ;
4532- const actionB = makeAction ( { reportActionID : 'actionB' , created : '2024-01-03 00:00:00.000' } ) ;
4533- const actionC = makeAction ( {
4534- reportActionID : 'actionC' ,
4535- created : '2024-01-02 00:00:00.000' ,
4536- errors : { someError : 'error' } ,
4537- } ) ;
4538- const actions : ReportActions = { actionA, actionB, actionC} ;
4539- const { lastActionForDisplay} = findLastReportActions ( actions ) ;
4540- const fromOldApproach = getSortedReportActions ( Object . values ( actions ) ) . findLast (
4541- ( a ) => isReportActionVisibleAsLastAction ( a ) && a . actionName !== CONST . REPORT . ACTIONS . TYPE . CREATED ,
4542- ) ;
4543- expect ( lastActionForDisplay ?. reportActionID ) . toBe ( fromOldApproach ?. reportActionID ) ;
4544- } ) ;
4545-
4546- it ( 'respects canUserPerformWriteAction when determining visibility' , ( ) => {
4547- const normalAction = makeAction ( { reportActionID : '1' , created : '2024-01-01 00:00:00.000' } ) ;
4548- // An actionable mention whisper is hidden when canUserPerformWriteAction is false
4549- const joinRequestAction = makeAction ( {
4550- reportActionID : '2' ,
4551- created : '2024-01-02 00:00:00.000' ,
4552- actionName : CONST . REPORT . ACTIONS . TYPE . ACTIONABLE_MENTION_WHISPER ,
4553- } ) ;
4554-
4555- const withWrite = findLastReportActions ( { [ normalAction . reportActionID ] : normalAction , [ joinRequestAction . reportActionID ] : joinRequestAction } , true ) ;
4556- const withoutWrite = findLastReportActions ( { [ normalAction . reportActionID ] : normalAction , [ joinRequestAction . reportActionID ] : joinRequestAction } , false ) ;
4557-
4558- // With write permission: join request is visible, so it should be selected as newer
4559- expect ( withWrite . lastVisibleAction ?. reportActionID ) . toBe ( joinRequestAction . reportActionID ) ;
4560- // Without write permission: join request hidden, so only the normal action remains
4561- expect ( withoutWrite . lastVisibleAction ?. reportActionID ) . toBe ( normalAction . reportActionID ) ;
4562- } ) ;
4563- } ) ;
4564-
45654435 describe ( 'isOriginalReportDeleted' , ( ) => {
45664436 it ( 'should return true when action.isOriginalReportDeleted is true' , ( ) => {
45674437 const action = {
0 commit comments