Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import {createRandomReport} from '../utils/collections/reports';
import createRandomTransaction from '../utils/collections/transaction';
import PusherHelper from '../utils/PusherHelper';
import * as TestHelper from '../utils/TestHelper';
import {navigateToSidebarOption} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';

// We need a large timeout here as we are lazy loading React Navigation screens and this test is running against the entire mounted App
jest.setTimeout(120000);
jest.setTimeout(240000);

jest.mock('@react-navigation/native');
jest.mock('../../src/libs/Notification/LocalNotification');
Expand Down Expand Up @@ -92,6 +91,15 @@ function navigateToSidebar(): Promise<void> {
return waitForBatchedUpdates();
}

async function navigateToSidebarOptionWithoutAct(index: number): Promise<void> {
const optionRow = screen.queryAllByAccessibilityHint(TestHelper.getNavigateToChatHintRegex()).at(index);
if (!optionRow) {
return;
}
fireEvent(optionRow, 'press');
await waitForBatchedUpdates();
}

function areYouOnChatListScreen(): boolean {
const hintText = TestHelper.translateLocal('sidebarScreen.listOfChats');
const sidebarLinks = screen.queryAllByLabelText(hintText, {includeHiddenElements: true});
Expand Down Expand Up @@ -261,7 +269,7 @@ describe('Unread Indicators', () => {
const displayNameText = screen.queryByLabelText(displayNameHintText);
expect((displayNameText?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold);

return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(async () => {
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
Expand Down Expand Up @@ -290,7 +298,7 @@ describe('Unread Indicators', () => {
it('Clear the new line indicator and bold when we navigate away from a chat that is now read', () =>
signInAndGetAppWithUnreadChat()
// Navigate to the unread chat from the sidebar
.then(() => navigateToSidebarOption(0))
.then(() => navigateToSidebarOptionWithoutAct(0))
.then(() => {
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
// Verify the unread indicator is present
Expand All @@ -308,7 +316,7 @@ describe('Unread Indicators', () => {
expect(areYouOnChatListScreen()).toBe(true);

// Tap on the chat again
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(() => {
// Sending event to clear the unread indicator cache, given that the test doesn't behave as the app
Expand All @@ -321,7 +329,7 @@ describe('Unread Indicators', () => {
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
expect(unreadIndicator).toHaveLength(0);
// Tap on the chat again
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(() => {
// Verify the unread indicator is not present
Expand Down Expand Up @@ -410,7 +418,7 @@ describe('Unread Indicators', () => {
expect(screen.getByText('C User')).toBeOnTheScreen();

// Tap the new report option and navigate back to the sidebar again via the back button
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(waitForBatchedUpdates)
.then(() => {
Expand All @@ -428,7 +436,7 @@ describe('Unread Indicators', () => {
xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () =>
signInAndGetAppWithUnreadChat()
// Navigate to the unread report
.then(() => navigateToSidebarOption(0))
.then(() => navigateToSidebarOptionWithoutAct(0))
.then(async () => {
const reportActions: OnyxEntry<ReportActions> = await new Promise((resolve) => {
const connection = Onyx.connect({
Expand All @@ -444,16 +452,19 @@ describe('Unread Indicators', () => {
markCommentAsUnread(REPORT_ID, reportActions, createdReportAction, USER_A_ACCOUNT_ID);
return waitForBatchedUpdates();
})
.then(() => {
.then(async () => {
// Verify the indicator appears above the last action
const newMessageLineIndicatorHintText = TestHelper.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('3');
// Scroll up and verify the new messages badge appears
// Scroll up and verify the new messages badge appears.
// Use waitForBatchedUpdates instead of waitFor to avoid wrapping in act(),
// which can hang under heavy CI load while draining scroll-triggered effects.
scrollUpToRevealNewMessagesBadge();
return waitFor(() => expect(isNewMessagesBadgeVisible()).toBe(true));
await waitForBatchedUpdates();
expect(isNewMessagesBadgeVisible()).toBe(true);
})
// Navigate to the sidebar
.then(navigateToSidebar)
Expand All @@ -466,7 +477,7 @@ describe('Unread Indicators', () => {
expect(screen.getByText('B User')).toBeOnTheScreen();

// Navigate to the report again and back to the sidebar
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(() => navigateToSidebar())
.then(() => {
Expand All @@ -478,16 +489,19 @@ describe('Unread Indicators', () => {
expect(screen.getByText('B User')).toBeOnTheScreen();

// Navigate to the report again and verify the new line indicator is missing
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(() => {
.then(async () => {
const newMessageLineIndicatorHintText = TestHelper.translateLocal('accessibilityHints.newMessageLineIndicator');
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
expect(unreadIndicator).toHaveLength(0);

// Scroll up and verify the "New messages" badge is hidden
// Scroll up and verify the "New messages" badge is hidden.
// Use waitForBatchedUpdates instead of waitFor to avoid wrapping in act(),
// which can hang under heavy CI load while draining scroll-triggered effects.
scrollUpToRevealNewMessagesBadge();
return waitFor(() => expect(isNewMessagesBadgeVisible()).toBe(false));
await waitForBatchedUpdates();
expect(isNewMessagesBadgeVisible()).toBe(false);
}));

it('Keep showing the new line indicator when a new message is created by the current user', () =>
Expand All @@ -497,7 +511,7 @@ describe('Unread Indicators', () => {
expect(areYouOnChatListScreen()).toBe(true);

// Navigate to the report and verify the indicator is present
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(async () => {
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
Expand Down Expand Up @@ -531,7 +545,7 @@ describe('Unread Indicators', () => {
expect(areYouOnChatListScreen()).toBe(true);

// Navigate to the chat and verify the new line indicator is present
return navigateToSidebarOption(0);
return navigateToSidebarOptionWithoutAct(0);
})
.then(() => {
const newMessageLineIndicatorHintText = TestHelper.translateLocal('accessibilityHints.newMessageLineIndicator');
Expand All @@ -541,7 +555,7 @@ describe('Unread Indicators', () => {
// Then back to the LHN - then back to the chat again and verify the new line indicator has cleared
return navigateToSidebar();
})
.then(() => navigateToSidebarOption(0))
.then(() => navigateToSidebarOptionWithoutAct(0))
.then(async () => {
const newMessageLineIndicatorHintText = TestHelper.translateLocal('accessibilityHints.newMessageLineIndicator');
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
Expand Down Expand Up @@ -584,7 +598,7 @@ describe('Unread Indicators', () => {
return (
signInAndGetAppWithUnreadChat()
// Navigate to the chat and simulate leaving a comment from the current user
.then(() => navigateToSidebarOption(0))
.then(() => navigateToSidebarOptionWithoutAct(0))
.then(async () => {
const report = await OnyxUtils.get(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`);
// Leave a comment as the current user
Expand Down Expand Up @@ -640,7 +654,7 @@ describe('Unread Indicators', () => {
callback: (val) => (reportActions = val),
});
await signInAndGetAppWithUnreadChat();
await navigateToSidebarOption(0);
await navigateToSidebarOptionWithoutAct(0);

const report = await OnyxUtils.get(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`);
addComment({
Expand Down Expand Up @@ -697,7 +711,7 @@ describe('Unread Indicators', () => {

await waitForBatchedUpdates();

await navigateToSidebarOption(0);
await navigateToSidebarOptionWithoutAct(0);

// When another user adds a new message
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {
Expand Down Expand Up @@ -744,7 +758,7 @@ describe('Unread Indicators', () => {
},
});

await navigateToSidebarOption(0);
await navigateToSidebarOptionWithoutAct(0);

const fakeTransaction = {
...createRandomTransaction(1),
Expand Down Expand Up @@ -839,7 +853,7 @@ describe('Unread Indicators', () => {

it('Mark the last comment as unread should set lastReadTime to the last action’s creation time', async () => {
await signInAndGetAppWithUnreadChat();
await navigateToSidebarOption(0);
await navigateToSidebarOptionWithoutAct(0);

const report = await OnyxUtils.get(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`);

Expand Down
Loading