From 41729462ba6b1e81adfe1db92caac2a68d9b67bf Mon Sep 17 00:00:00 2001
From: nkdengineer <nkdengineer@outlook.com>
Date: Tue, 15 Jul 2025 23:34:51 +0700
Subject: [PATCH 1/4] Fix flaky test UnreadIndicatorsTest

---
 tests/ui/UnreadIndicatorsTest.tsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx
index 627fcb0bf164..1881bcef7a59 100644
--- a/tests/ui/UnreadIndicatorsTest.tsx
+++ b/tests/ui/UnreadIndicatorsTest.tsx
@@ -187,10 +187,12 @@ describe('Unread Indicators', () => {
 
     beforeEach(() => {
         jest.clearAllMocks();
-        Onyx.clear();
-
+    
+        global.fetch = TestHelper.getGlobalFetchMock();
         // Unsubscribe to pusher channels
         PusherHelper.teardown();
+    
+        return Onyx.clear().then(waitForBatchedUpdates);
     });
 
     it('Display bold in the LHN for unread chat and new line indicator above the chat message when we navigate to it', () =>

From 08c91e6518f7d153a2d4f7ec3ad724b7015f3669 Mon Sep 17 00:00:00 2001
From: nkdengineer <nkdengineer@outlook.com>
Date: Tue, 15 Jul 2025 23:50:08 +0700
Subject: [PATCH 2/4] fix lint

---
 tests/ui/UnreadIndicatorsTest.tsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx
index 1881bcef7a59..8a461d9cacb6 100644
--- a/tests/ui/UnreadIndicatorsTest.tsx
+++ b/tests/ui/UnreadIndicatorsTest.tsx
@@ -187,11 +187,11 @@ describe('Unread Indicators', () => {
 
     beforeEach(() => {
         jest.clearAllMocks();
-    
+
         global.fetch = TestHelper.getGlobalFetchMock();
         // Unsubscribe to pusher channels
         PusherHelper.teardown();
-    
+
         return Onyx.clear().then(waitForBatchedUpdates);
     });
 

From 2eef02bc894c39a21e703a275e5dc8777cdc69ee Mon Sep 17 00:00:00 2001
From: nkdengineer <nkdengineer@outlook.com>
Date: Wed, 23 Jul 2025 14:14:00 +0700
Subject: [PATCH 3/4] Add new tips to writing jest test

---
 tests/README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/README.md b/tests/README.md
index edf0cec9b295..9ef720fd3671 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -7,7 +7,7 @@
 - Much of the logic in the app is asynchronous in nature. [`react-native-onyx`](https://github.com/expensify/react-native-onyx) writes data async before updating subscribers.
 - [Actions](https://github.com/Expensify/App#actions) do not typically return a `Promise` and therefore can't always be "awaited" before running an assertion.
 - To test a result after some asynchronous code has run we can use [`Onyx.connect()`](https://github.com/Expensify/react-native-onyx/blob/2c94a94e51fab20330f7bd5381b72ea6c25553d9/lib/Onyx.js#L217-L231) and the helper method [`waitForBatchedUpdates()`](https://github.com/Expensify/ReactNativeChat/blob/ca2fa88a5789b82463d35eddc3d57f70a7286868/tests/utils/waitForBatchedUpdates.js#L1-L9) which returns a `Promise` and will ensure that all other `Promises` have finished running before resolving.
-- **Important Note:** When writing any asynchronous Jest test it's very important that your test itself **return a `Promise`**.
+- **Important Note:** When writing any asynchronous Jest test it's very important that your test itself **return a `Promise`**. In hooks like BeforeEach, BeforeAll, AfterAll, etc., you also need to return a promise or use async/await if they perform any asynchronous calls.
 
 ## Mocking Network Requests
 

From 581f7a2cc965b3be9a3c67066f0718b54b932aca Mon Sep 17 00:00:00 2001
From: nkdengineer <nkdengineer@outlook.com>
Date: Mon, 11 Aug 2025 15:37:36 +0700
Subject: [PATCH 4/4] fix fail test

---
 src/libs/actions/IOU.ts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index 6f6e21fbd2a9..54e5d1fdfcd2 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -2516,6 +2516,7 @@ function buildOnyxDataForTrackExpense({
                 onyxMethod: Onyx.METHOD.MERGE,
                 key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
                 value: {
+                    lastReadTime: actionableTrackExpenseWhisper.created,
                     lastVisibleActionCreated: actionableTrackExpenseWhisper.created,
                     lastMessageText: CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE,
                 },
