From a3915600ae66bbf926dd7c23ad1fcc1826eac31c Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Mon, 5 May 2025 16:22:25 +0530 Subject: [PATCH 1/4] exclude deleted actions when mark unread from LHN --- src/libs/actions/Report.ts | 1 + tests/ui/UnreadIndicatorsTest.tsx | 33 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 9d0f51c8321c..b2d51ff823a5 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1592,6 +1592,7 @@ function markCommentAsUnread(reportID: string | undefined, reportAction: ReportA // Find the latest report actions from other users const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => { if ( + !ReportActionsUtils.isDeletedAction(current) && current.actorAccountID !== currentUserAccountID && (!latest || current.created > latest.created) && // Whisper action doesn't affect lastVisibleActionCreated, so skip whisper action except actionable mention whisper diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 43e4ae0e8a78..eaafdbd0e72d 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -677,4 +677,37 @@ describe('Unread Indicators', () => { const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(0); }); + it('Mark the chat as unread on clicking "Mark as unread" on an item in LHN when the last message of the chat was deleted', async () => { + await signInAndGetAppWithUnreadChat(); + await navigateToSidebarOption(0); + const reportAction1 = { + reportActionID: '1', + message: {html: ''}, // set to empty string to simulate a deleted message + created: '2025-05-02T00:00:00.000Z', + actorAccountID: USER_B_ACCOUNT_ID, + } as unknown as ReportAction; + const reportAction2 = { + reportActionID: '2', + message: {html: 'Comment 2'}, + created: '2025-05-01T00:00:00.000Z', + actorAccountID: USER_B_ACCOUNT_ID, + } as unknown as ReportAction; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [reportAction1.reportActionID]: reportAction1, + [reportAction2.reportActionID]: reportAction2, + }); + + markCommentAsUnread(REPORT_ID, {reportActionID: -1} as unknown as ReportAction); // Marking the chat as unread from LHN passing a dummy reportActionID + + await waitForBatchedUpdates(); + + navigateToSidebar(); + + await waitForBatchedUpdates(); + + const hintText = translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(hintText, {includeHiddenElements: true}); + expect(displayNameTexts).toHaveLength(1); + expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); + }); }); From 77462e6d9e6facd55354be1a401876ce8f0e282d Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Mon, 5 May 2025 18:52:38 +0530 Subject: [PATCH 2/4] make the test more robust --- tests/ui/UnreadIndicatorsTest.tsx | 41 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index eaafdbd0e72d..691427cf1a93 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -677,36 +677,35 @@ describe('Unread Indicators', () => { const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(0); }); - it('Mark the chat as unread on clicking "Mark as unread" on an item in LHN when the last message of the chat was deleted', async () => { + it('Mark the chat as unread on clicking "Mark as unread" on an item in LHN when the last message of the chat was deleted by another user', async () => { await signInAndGetAppWithUnreadChat(); - await navigateToSidebarOption(0); - const reportAction1 = { - reportActionID: '1', - message: {html: ''}, // set to empty string to simulate a deleted message - created: '2025-05-02T00:00:00.000Z', - actorAccountID: USER_B_ACCOUNT_ID, - } as unknown as ReportAction; - const reportAction2 = { - reportActionID: '2', - message: {html: 'Comment 2'}, - created: '2025-05-01T00:00:00.000Z', - actorAccountID: USER_B_ACCOUNT_ID, - } as unknown as ReportAction; + + await navigateToSidebar(); + + const reportAction11CreatedDate = format(addSeconds(TEN_MINUTES_AGO, 110), CONST.DATE.FNS_DB_FORMAT_STRING); + const reportAction11 = TestHelper.buildTestReportComment(reportAction11CreatedDate, USER_B_ACCOUNT_ID, '11'); + const reportAction12CreatedDate = format(addSeconds(TEN_MINUTES_AGO, 120), CONST.DATE.FNS_DB_FORMAT_STRING); + const reportAction12 = TestHelper.buildTestReportComment(reportAction12CreatedDate, USER_B_ACCOUNT_ID, '12'); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { - [reportAction1.reportActionID]: reportAction1, - [reportAction2.reportActionID]: reportAction2, + 11: reportAction11, + 12: reportAction12, }); - markCommentAsUnread(REPORT_ID, {reportActionID: -1} as unknown as ReportAction); // Marking the chat as unread from LHN passing a dummy reportActionID + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, { + lastVisibleActionCreated: reportAction12CreatedDate, + }); - await waitForBatchedUpdates(); + reportAction12.message[0].html = ''; // Simulate the server response for deleting the last message - navigateToSidebar(); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, { + lastVisibleActionCreated: reportAction11CreatedDate, + }); - await waitForBatchedUpdates(); + markCommentAsUnread(REPORT_ID, {reportActionID: -1} as unknown as ReportAction); // Marking the chat as unread from LHN passing a dummy reportActionID + await waitForBatchedUpdates(); const hintText = translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNameTexts = screen.queryAllByLabelText(hintText, {includeHiddenElements: true}); + const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); expect((displayNameTexts.at(0)?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); }); From 9bc445d3de793da0f7250d2c724929c265d78c38 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Mon, 5 May 2025 19:19:16 +0530 Subject: [PATCH 3/4] fix lint --- tests/ui/UnreadIndicatorsTest.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 691427cf1a93..939e34f586ea 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -695,7 +695,10 @@ describe('Unread Indicators', () => { lastVisibleActionCreated: reportAction12CreatedDate, }); - reportAction12.message[0].html = ''; // Simulate the server response for deleting the last message + let message = reportAction12.message.at(0); + if (message) { + message.html = ''; // Simulate the server response for deleting the last message + } await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, { lastVisibleActionCreated: reportAction11CreatedDate, From 1a8eef09bcb93e87927e548b0bae999b83d34e41 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Mon, 5 May 2025 19:24:00 +0530 Subject: [PATCH 4/4] fix lint --- tests/ui/UnreadIndicatorsTest.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 939e34f586ea..8ab34648abfa 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -695,7 +695,7 @@ describe('Unread Indicators', () => { lastVisibleActionCreated: reportAction12CreatedDate, }); - let message = reportAction12.message.at(0); + const message = reportAction12.message.at(0); if (message) { message.html = ''; // Simulate the server response for deleting the last message }