diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index c557229aca72..1de9fc14dfbc 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -704,6 +704,7 @@ function ReportScreen({ {shouldShowReportActionList && ( | null = null; + /** * Sets up a test with a logged in user that has one unread chat from another user. Returns the test instance. */ function signInAndGetAppWithUnreadChat(): Promise { // Render the App and sign in as a test user. - render(); + renderResult = render(); return waitForBatchedUpdatesWithAct() .then(async () => { await waitForBatchedUpdatesWithAct(); @@ -462,7 +465,57 @@ describe('Unread Indicators', () => { expect(screen.getAllByText('C User')[0]).toBeOnTheScreen(); expect(displayNameTexts[1]?.props?.style?.fontWeight).toBe(FontUtils.fontWeight.bold); expect(screen.getByText('B User')).toBeOnTheScreen(); - })); + }) + ); + it('Delete a chat message and verify the unread indicator is moved', async () => { + const getUnreadIndicator = () => { + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + return screen.queryAllByLabelText(newMessageLineIndicatorHintText); + } + + return signInAndGetAppWithUnreadChat() + .then(() => navigateToSidebarOption(0)) + .then(async () => await act(() => transitionEndCB?.())) + .then(async () => { + const reportActionsViewWrapper = await renderResult?.findByTestId('reportActionsViewWrapper'); + if(reportActionsViewWrapper) { + act(() => { + fireEvent(reportActionsViewWrapper, 'onLayout', { nativeEvent: { layout: { x: 0, y: 0, width: 100, height: 100 } } }); + }) + } + return waitForBatchedUpdates(); + }) + .then(() => { + // Verify the new line indicator is present, and it's before the action with ID 4 + const unreadIndicator = getUnreadIndicator(); + expect(unreadIndicator).toHaveLength(1); + const reportActionID = unreadIndicator[0]?.props?.['data-action-id']; + expect(reportActionID).toBe('4'); + + // simulate delete comment event from Pusher + PusherHelper.emitOnyxUpdate([ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, + value: { + '4': { + message: [] + } + } + }, + ]); + return waitForBatchedUpdates(); + }) + .then(() => { + // Verify the new line indicator is now before the action with ID 5 + return waitFor(() => { + const unreadIndicator = getUnreadIndicator(); + expect(unreadIndicator).toHaveLength(1); + const reportActionID = unreadIndicator[0]?.props?.['data-action-id']; + expect(reportActionID).toBe('5'); + }) + }) + }) xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () => signInAndGetAppWithUnreadChat()