From 50e3c285231313ee169c892c51181765204ceb1d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 17 Dec 2024 15:12:22 +0800 Subject: [PATCH 1/2] fix new line doesn't move to the next msg when the unread msg is deleted --- src/pages/home/report/ReportActionsList.tsx | 4 +-- tests/ui/UnreadIndicatorsTest.tsx | 40 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 6364095d81c8..c6cf9c8de453 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -262,10 +262,8 @@ function ReportActionsList({ return true; } - const isWithinVisibleThreshold = scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD ? message.created < (userActiveSince.current ?? '') : true; - // If the unread marker should be hidden or is not within the visible area, don't show the unread marker. - if (ReportActionsUtils.shouldHideNewMarker(message) || !isWithinVisibleThreshold) { + if (ReportActionsUtils.shouldHideNewMarker(message)) { return false; } diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index f7f4574b1d29..295bfff0ae10 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -547,4 +547,44 @@ describe('Unread Indicators', () => { }) ); }); + + it('Move the new line indicator to the next message when the unread message is deleted', async () => { + let reportActions: OnyxEntry; + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, + callback: (val) => (reportActions = val), + }); + await signInAndGetAppWithUnreadChat(); + await navigateToSidebarOption(0); + + Report.addComment(REPORT_ID, 'Comment 1'); + + await waitForBatchedUpdates(); + + const firstNewReportAction = reportActions ? CollectionUtils.lastItem(reportActions) : undefined; + + if (firstNewReportAction) { + Report.markCommentAsUnread(REPORT_ID, firstNewReportAction?.created); + + await waitForBatchedUpdates(); + + Report.addComment(REPORT_ID, 'Comment 2'); + + await waitForBatchedUpdates(); + + Report.deleteReportComment(REPORT_ID, firstNewReportAction); + + await waitForBatchedUpdates(); + } + + const secondNewReportAction = reportActions ? CollectionUtils.lastItem(reportActions) : undefined; + + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); + expect(unreadIndicator).toHaveLength(1); + const reportActionID = unreadIndicator.at(0)?.props?.['data-action-id'] as string; + expect(reportActionID).toBe(secondNewReportAction?.reportActionID); + + Onyx.disconnect(connection); + }); }); From e25e32ffcf20c82f9d690fb29c0221882b700f65 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 19 Dec 2024 11:07:08 +0800 Subject: [PATCH 2/2] lint --- src/pages/home/report/ReportActionsList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index c6cf9c8de453..806b2405390d 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -168,7 +168,7 @@ function ReportActionsList({ const [isVisible, setIsVisible] = useState(Visibility.isVisible); const isFocused = useIsFocused(); - const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); + const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID}); useEffect(() => { @@ -183,7 +183,7 @@ function ReportActionsList({ const readActionSkipped = useRef(false); const hasHeaderRendered = useRef(false); const hasFooterRendered = useRef(false); - const linkedReportActionID = route?.params?.reportActionID ?? '-1'; + const linkedReportActionID = route?.params?.reportActionID; const lastAction = sortedVisibleReportActions.at(0); const sortedVisibleReportActionsObjects: OnyxTypes.ReportActions = useMemo(