diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7e242c91aef4..9ee97ff8a988 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5341,6 +5341,7 @@ function hasUpdatedTotal(report: OnyxEntry): boolean { * - The action is listed in the thread-disabled list * - The action is a split bill action * - The action is deleted and is not threaded + * - The report is archived and the action is not threaded * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ @@ -5350,11 +5351,13 @@ function shouldDisableThread(reportAction: OnyxEntry, reportID: st const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); const isIOUAction = ReportActionsUtils.isMoneyRequestAction(reportAction); const isWhisperAction = ReportActionsUtils.isWhisperAction(reportAction); + const isArchivedReport = isArchivedRoom(getReport(reportID)); return ( CONST.REPORT.ACTIONS.THREAD_DISABLED.some((action: string) => action === reportAction?.actionName) || isSplitBillAction || (isDeletedAction && !reportAction?.childVisibleActionCount) || + (isArchivedReport && !reportAction?.childVisibleActionCount) || (isWhisperAction && !isReportPreviewAction && !isIOUAction) || isThreadFirstChat(reportAction, reportID) ); diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index adfa35a57ad8..7b563d46b7eb 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import _ from 'underscore'; import CONST from '../../src/CONST'; +import * as NumberUtils from '../../src/libs/NumberUtils'; import * as ReportUtils from '../../src/libs/ReportUtils'; import ONYXKEYS from '../../src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; @@ -639,6 +640,78 @@ describe('ReportUtils', () => { }); }); + describe('shouldDisableThread', () => { + const reportID = '1'; + + it('should disable on thread-disabled actions', () => { + const reportAction = ReportUtils.buildOptimisticCreatedReportAction('email1@test.com'); + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + }); + + it('should disable thread on split bill actions', () => { + const reportAction = ReportUtils.buildOptimisticIOUReportAction( + CONST.IOU.REPORT_ACTION_TYPE.SPLIT, + 50000, + CONST.CURRENCY.USD, + '', + [{login: 'email1@test.com'}, {login: 'email2@test.com'}], + NumberUtils.rand64(), + ); + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + }); + + it('should disable on deleted and not-thread actions', () => { + const reportAction = { + message: [ + { + translationKey: '', + type: 'COMMENT', + html: '', + text: '', + isEdited: true, + }, + ], + childVisibleActionCount: 1, + }; + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeFalsy(); + + reportAction.childVisibleActionCount = 0; + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + }); + + it('should disable on archived reports and not-thread actions', () => { + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { + statusNum: CONST.REPORT.STATUS_NUM.CLOSED, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + }) + .then(() => waitForBatchedUpdates()) + .then(() => { + const reportAction = { + childVisibleActionCount: 1, + }; + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeFalsy(); + + reportAction.childVisibleActionCount = 0; + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + }); + }); + + it("should disable on a whisper action and it's neither a report preview nor IOU action", () => { + const reportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE, + whisperedToAccountIDs: [123456], + }; + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + }); + + it('should disable on thread first chat', () => { + const reportAction = { + childReportID: reportID, + }; + expect(ReportUtils.shouldDisableThread(reportAction, reportID)).toBeTruthy(); + }); + }); + describe('getAllAncestorReportActions', () => { const reports = [ {reportID: '1', lastReadTime: '2024-02-01 04:56:47.233', reportName: 'Report'},