From b7f75efb4686cb6677a286f096af7988b0442765 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 10 Jun 2024 23:48:05 +0700 Subject: [PATCH] fix: update lint for test Signed-off-by: dominictb --- src/pages/home/ReportScreen.tsx | 2 +- tests/ui/UnreadIndicatorsTest.tsx | 97 ++++++++++++++----------------- 2 files changed, 46 insertions(+), 53 deletions(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 1de9fc14dfbc..3de4200080b0 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -704,7 +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. - renderResult = render(); + render(); return waitForBatchedUpdatesWithAct() .then(async () => { await waitForBatchedUpdatesWithAct(); @@ -465,57 +462,53 @@ 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 () => act(() => transitionEndCB?.())) + .then(async () => { + const reportActionsViewWrapper = await screen.findByTestId('report-actions-view-wrapper'); + if (reportActionsViewWrapper) { + fireEvent(reportActionsViewWrapper, 'onLayout', {nativeEvent: {layout: {x: 0, y: 0, width: 100, height: 100}}}); + } + return waitForBatchedUpdates(); }) - ); - 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 + .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 + waitFor(() => { 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'); - }) - }) - }) + expect(reportActionID).toBe('5'); + }), + ); + }); xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () => signInAndGetAppWithUnreadChat()