From 1e63cadc2ecaab9b6c5b434b4f17fab8fb3ac14a Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Thu, 14 Mar 2024 01:49:27 +0700 Subject: [PATCH 1/3] disable thread in archived room --- src/libs/ReportUtils.ts | 4 +- .../report/ContextMenu/ContextMenuActions.tsx | 2 +- tests/unit/ReportUtilsTest.js | 66 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8dc1c9967f13..8a0b341da873 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5144,10 +5144,11 @@ 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 */ -function shouldDisableThread(reportAction: OnyxEntry, reportID: string): boolean { +function shouldDisableThread(reportAction: OnyxEntry, reportID: string, isArchivedRoom = false): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); @@ -5158,6 +5159,7 @@ function shouldDisableThread(reportAction: OnyxEntry, reportID: st CONST.REPORT.ACTIONS.THREAD_DISABLED.some((action: string) => action === reportAction?.actionName) || isSplitBillAction || (isDeletedAction && !reportAction?.childVisibleActionCount) || + (isArchivedRoom && !reportAction?.childVisibleActionCount) || (isWhisperAction && !isReportPreviewAction && !isIOUAction) || isThreadFirstChat(reportAction, reportID) ); diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index c5ab9bbff1f5..214a7f18a1ff 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -194,7 +194,7 @@ const ContextMenuActions: ContextMenuAction[] = [ if (type !== CONST.CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; } - return !ReportUtils.shouldDisableThread(reportAction, reportID); + return !ReportUtils.shouldDisableThread(reportAction, reportID, isArchivedRoom); }, onPress: (closePopover, {reportAction, reportID}) => { if (closePopover) { diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index 9fbea1df862e..0b2213e23400 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'; @@ -703,4 +704,69 @@ 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', () => { + const reportAction = { + childVisibleActionCount: 1, + }; + expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).toBeFalsy(); + + reportAction.childVisibleActionCount = 0; + expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).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(); + }); + }); }); From 220ee46e5207241e26a4ef17d5d1fef1bbba499b Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Thu, 14 Mar 2024 02:17:38 +0700 Subject: [PATCH 2/3] fix lint errors --- src/libs/ReportUtils.ts | 4 +- tests/unit/ReportUtilsTest.js | 130 +++++++++++++++++----------------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8a0b341da873..f8616ddf639b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5148,7 +5148,7 @@ function hasUpdatedTotal(report: OnyxEntry): boolean { * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ -function shouldDisableThread(reportAction: OnyxEntry, reportID: string, isArchivedRoom = false): boolean { +function shouldDisableThread(reportAction: OnyxEntry, reportID: string, isArchivedReport = false): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); @@ -5159,7 +5159,7 @@ function shouldDisableThread(reportAction: OnyxEntry, reportID: st CONST.REPORT.ACTIONS.THREAD_DISABLED.some((action: string) => action === reportAction?.actionName) || isSplitBillAction || (isDeletedAction && !reportAction?.childVisibleActionCount) || - (isArchivedRoom && !reportAction?.childVisibleActionCount) || + (isArchivedReport && !reportAction?.childVisibleActionCount) || (isWhisperAction && !isReportPreviewAction && !isIOUAction) || isThreadFirstChat(reportAction, reportID) ); diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index 0b2213e23400..84c7cbe46aed 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -639,6 +639,71 @@ 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', () => { + const reportAction = { + childVisibleActionCount: 1, + }; + expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).toBeFalsy(); + + reportAction.childVisibleActionCount = 0; + expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).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'}, @@ -704,69 +769,4 @@ 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', () => { - const reportAction = { - childVisibleActionCount: 1, - }; - expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).toBeFalsy(); - - reportAction.childVisibleActionCount = 0; - expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).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(); - }); - }); }); From 5f1add8cd6582557e285174d8a59de4b121ad9d2 Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Fri, 15 Mar 2024 04:12:28 +0700 Subject: [PATCH 3/3] remove isArchivedReport param --- src/libs/ReportUtils.ts | 3 ++- .../report/ContextMenu/ContextMenuActions.tsx | 2 +- tests/unit/ReportUtilsTest.js | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f8616ddf639b..5596d6d001c7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5148,12 +5148,13 @@ function hasUpdatedTotal(report: OnyxEntry): boolean { * - The action is a whisper action and it's neither a report preview nor IOU action * - The action is the thread's first chat */ -function shouldDisableThread(reportAction: OnyxEntry, reportID: string, isArchivedReport = false): boolean { +function shouldDisableThread(reportAction: OnyxEntry, reportID: string): boolean { const isSplitBillAction = ReportActionsUtils.isSplitBillAction(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); 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) || diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 214a7f18a1ff..c5ab9bbff1f5 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -194,7 +194,7 @@ const ContextMenuActions: ContextMenuAction[] = [ if (type !== CONST.CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; } - return !ReportUtils.shouldDisableThread(reportAction, reportID, isArchivedRoom); + return !ReportUtils.shouldDisableThread(reportAction, reportID); }, onPress: (closePopover, {reportAction, reportID}) => { if (closePopover) { diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index 84c7cbe46aed..d32a663caa1e 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -679,13 +679,20 @@ describe('ReportUtils', () => { }); it('should disable on archived reports and not-thread actions', () => { - const reportAction = { - childVisibleActionCount: 1, - }; - expect(ReportUtils.shouldDisableThread(reportAction, reportID, true)).toBeFalsy(); + 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, true)).toBeTruthy(); + 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", () => {