@@ -9301,6 +9301,104 @@ describe('ReportUtils', () => {
93019301 expect(result?.reportAction?.reportActionID).toBe('current-user-task');
93029302 });
93039303
9304+ it('should return the IOU badge when the IOU action is older than the task action', async () => {
9305+ const iouReportID = 'iou-report-for-priority';
9306+
9307+ const taskAction: ReportAction = {
9308+ reportActionID: 'task-action-newer',
9309+ actionName: CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
9310+ childType: CONST.REPORT.TYPE.TASK,
9311+ childReportID: 'task-report-priority',
9312+ childManagerAccountID: currentUserAccountID,
9313+ created: '2024-01-02 00:00:00',
9314+ originalMessage: {
9315+ assigneeAccountID: currentUserAccountID,
9316+ cardID: 99001,
9317+ },
9318+ };
9319+
9320+ const iouAction: ReportAction = {
9321+ reportActionID: 'iou-action-older',
9322+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9323+ childType: CONST.REPORT.TYPE.IOU,
9324+ childReportID: iouReportID,
9325+ childManagerAccountID: currentUserAccountID,
9326+ created: '2024-01-01 00:00:00',
9327+ message: [{html: 'iou preview', text: 'iou preview', type: 'COMMENT'}],
9328+ };
9329+
9330+ const workspaceChat = {
9331+ ...createPolicyExpenseChat(42001),
9332+ hasOutstandingChildTask: true,
9333+ hasOutstandingChildRequest: true,
9334+ iouReportID,
9335+ };
9336+
9337+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat);
9338+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChat.reportID}`, {
9339+ [taskAction.reportActionID]: taskAction,
9340+ [iouAction.reportActionID]: iouAction,
9341+ });
9342+ await waitForBatchedUpdates();
9343+
9344+ const {result: isReportArchived} = renderHook(() => useReportIsArchived(workspaceChat.reportID));
9345+ const result = getReasonAndReportActionThatRequiresAttention(workspaceChat, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9346+
9347+ // The IOU action is older, so its badge should take priority over the task badge
9348+ expect(result?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.HAS_CHILD_REPORT_AWAITING_ACTION);
9349+ expect(result?.reportAction?.reportActionID).toBe('iou-action-older');
9350+ expect(result?.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.PAY);
9351+ });
9352+
9353+ it('should return the Task badge when the task action is older than the IOU action', async () => {
9354+ const iouReportID = 'iou-report-for-priority-2';
9355+
9356+ const taskAction: ReportAction = {
9357+ reportActionID: 'task-action-older',
9358+ actionName: CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
9359+ childType: CONST.REPORT.TYPE.TASK,
9360+ childReportID: 'task-report-priority-2',
9361+ childManagerAccountID: currentUserAccountID,
9362+ created: '2024-01-01 00:00:00',
9363+ originalMessage: {
9364+ assigneeAccountID: currentUserAccountID,
9365+ cardID: 99002,
9366+ },
9367+ };
9368+
9369+ const iouAction: ReportAction = {
9370+ reportActionID: 'iou-action-newer',
9371+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9372+ childType: CONST.REPORT.TYPE.IOU,
9373+ childReportID: iouReportID,
9374+ childManagerAccountID: currentUserAccountID,
9375+ created: '2024-01-02 00:00:00',
9376+ message: [{html: 'iou preview', text: 'iou preview', type: 'COMMENT'}],
9377+ };
9378+
9379+ const workspaceChat = {
9380+ ...createPolicyExpenseChat(42002),
9381+ hasOutstandingChildTask: true,
9382+ hasOutstandingChildRequest: true,
9383+ iouReportID,
9384+ };
9385+
9386+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat);
9387+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChat.reportID}`, {
9388+ [taskAction.reportActionID]: taskAction,
9389+ [iouAction.reportActionID]: iouAction,
9390+ });
9391+ await waitForBatchedUpdates();
9392+
9393+ const {result: isReportArchived} = renderHook(() => useReportIsArchived(workspaceChat.reportID));
9394+ const result = getReasonAndReportActionThatRequiresAttention(workspaceChat, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9395+
9396+ // The task action is older, so the task badge should take priority
9397+ expect(result?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.IS_WAITING_FOR_ASSIGNEE_TO_COMPLETE_ACTION);
9398+ expect(result?.reportAction?.reportActionID).toBe('task-action-older');
9399+ expect(result?.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.TASK);
9400+ });
9401+
93049402 it('should return the earliest matching report action for invoice rooms with missing bank account', async () => {
93059403 const invoiceRoomID = '50000';
93069404 const olderChildReportID = '50001';
0 commit comments