@@ -13,6 +13,7 @@ import {translateLocal} from '@libs/Localize';
1313import { getIOUActionForReportID } from '@libs/ReportActionsUtils' ;
1414import PureReportActionItem from '@pages/home/report/PureReportActionItem' ;
1515import CONST from '@src/CONST' ;
16+ import type { TranslationPaths } from '@src/languages/types' ;
1617import * as ReportActionUtils from '@src/libs/ReportActionsUtils' ;
1718import ONYXKEYS from '@src/ONYXKEYS' ;
1819import type { ReportAction } from '@src/types/onyx' ;
@@ -101,40 +102,57 @@ describe('PureReportActionItem', () => {
101102 }
102103
103104 describe ( 'Automatic actions' , ( ) => {
104- it ( 'APPROVED action via workspace rules' , async ( ) => {
105- const action = createReportAction ( CONST . REPORT . ACTIONS . TYPE . APPROVED , { automaticAction : true } ) ;
105+ const testCases = [
106+ {
107+ testTitle : 'APPROVED action via workspace rules' ,
108+ actionName : CONST . REPORT . ACTIONS . TYPE . APPROVED ,
109+ originalMessageExtras : { automaticAction : true } ,
110+ translationKey : 'iou.automaticallyApproved' ,
111+ } ,
112+ {
113+ testTitle : 'FORWARDED action via workspace rules' ,
114+ actionName : CONST . REPORT . ACTIONS . TYPE . FORWARDED ,
115+ originalMessageExtras : { automaticAction : true } ,
116+ translationKey : 'iou.automaticallyForwarded' ,
117+ } ,
118+ {
119+ testTitle : 'SUBMITTED action via harvesting' ,
120+ actionName : CONST . REPORT . ACTIONS . TYPE . SUBMITTED ,
121+ originalMessageExtras : { harvesting : true } ,
122+ translationKey : 'iou.automaticallySubmitted' ,
123+ } ,
124+ {
125+ testTitle : 'SUBMITTED_AND_CLOSED action via harvesting' ,
126+ actionName : CONST . REPORT . ACTIONS . TYPE . SUBMITTED_AND_CLOSED ,
127+ originalMessageExtras : { harvesting : true } ,
128+ translationKey : 'iou.automaticallySubmitted' ,
129+ } ,
130+ ] ;
131+
132+ const parseTextWithTrailingLink = ( translatedText : string ) => {
133+ const match = translatedText . match ( / ^ ( .* ?) ( < a [ ^ > ] * > ) ( .* ?) ( < \/ a > ) $ / ) ;
134+ if ( ! match ) {
135+ return null ;
136+ }
137+ const [ , textBeforeLink , , linkText ] = match ;
138+ return { textBeforeLink, linkText} ;
139+ } ;
140+
141+ it . each ( testCases ) ( '$testTitle' , async ( { actionName, originalMessageExtras, translationKey} ) => {
142+ const action = createReportAction ( actionName , originalMessageExtras ) ;
106143 renderItemWithAction ( action ) ;
107144 await waitForBatchedUpdatesWithAct ( ) ;
108145
109146 expect ( screen . getByText ( actorEmail ) ) . toBeOnTheScreen ( ) ;
110- expect ( screen . getByText ( translateLocal ( 'iou.automaticallyApproved' ) ) ) . toBeOnTheScreen ( ) ;
111- } ) ;
112-
113- it ( 'FORWARDED action via workspace rules' , async ( ) => {
114- const action = createReportAction ( CONST . REPORT . ACTIONS . TYPE . FORWARDED , { automaticAction : true } ) ;
115- renderItemWithAction ( action ) ;
116- await waitForBatchedUpdatesWithAct ( ) ;
117-
118- expect ( screen . getByText ( actorEmail ) ) . toBeOnTheScreen ( ) ;
119- expect ( screen . getByText ( translateLocal ( 'iou.automaticallyForwarded' ) ) ) . toBeOnTheScreen ( ) ;
120- } ) ;
121-
122- it ( 'SUBMITTED action via harvesting' , async ( ) => {
123- const action = createReportAction ( CONST . REPORT . ACTIONS . TYPE . SUBMITTED , { harvesting : true } ) ;
124- renderItemWithAction ( action ) ;
125- await waitForBatchedUpdatesWithAct ( ) ;
126-
127- expect ( screen . getByText ( actorEmail ) ) . toBeOnTheScreen ( ) ;
128- expect ( screen . getByText ( translateLocal ( 'iou.automaticallySubmitted' ) ) ) . toBeOnTheScreen ( ) ;
129- } ) ;
130147
131- it ( 'SUBMITTED_AND_CLOSED action via harvesting' , async ( ) => {
132- const action = createReportAction ( CONST . REPORT . ACTIONS . TYPE . SUBMITTED_AND_CLOSED , { harvesting : true } ) ;
133- renderItemWithAction ( action ) ;
134- await waitForBatchedUpdatesWithAct ( ) ;
148+ const parsedText = parseTextWithTrailingLink ( translateLocal ( translationKey as TranslationPaths ) ) ;
149+ if ( ! parsedText ) {
150+ throw new Error ( 'Text cannot be parsed, translation failed' ) ;
151+ }
135152
136- expect ( screen . getByText ( actorEmail ) ) . toBeOnTheScreen ( ) ;
137- expect ( screen . getByText ( translateLocal ( 'iou.automaticallySubmitted' ) ) ) . toBeOnTheScreen ( ) ;
153+ const { textBeforeLink, linkText} = parsedText ;
154+ expect ( screen . getByText ( textBeforeLink ) ) . toBeOnTheScreen ( ) ;
155+ expect ( screen . getByText ( linkText ) ) . toBeOnTheScreen ( ) ;
138156 } ) ;
139157 } ) ;
140158
0 commit comments