From d1a6f483e3a79c324ce7eb79970399508d98dba0 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 16:30:34 +0700 Subject: [PATCH 01/24] add unit test for report should be displayed in LHN --- src/libs/ReportUtils.ts | 2 +- tests/ui/LHNItemsPresence.tsx | 73 ++++++++++++- tests/unit/ReportUtilsTest.ts | 187 ++++++++++++++++++++++++++++++++++ tests/utils/LHNTestUtils.tsx | 11 +- 4 files changed, 267 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b8a59fffdf389..e260c7c37e1ae 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6248,7 +6248,7 @@ function isUnread(report: OnyxEntry): boolean { } if (isEmptyReport(report)) { - return false; + return true; } // lastVisibleActionCreated and lastReadTime are both datetime strings and can be compared directly const lastVisibleActionCreated = report.lastVisibleActionCreated ?? ''; diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 6693c90adaa04..0594546ff8830 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -1,11 +1,15 @@ import {screen} from '@testing-library/react-native'; import type {ComponentType} from 'react'; import Onyx from 'react-native-onyx'; +import type {OnyxMultiSetInput} from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import * as Localize from '@libs/Localize'; +import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; +import * as TransactionUtils from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList} from '@src/types/onyx'; +import type {PersonalDetailsList, ViolationName} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as TestHelper from '../utils/TestHelper'; @@ -48,6 +52,7 @@ jest.mock('@components/withCurrentUserPersonalDetails', () => { const TEST_USER_ACCOUNT_ID = 1; const TEST_USER_LOGIN = 'test@test.com'; const betas = [CONST.BETAS.DEFAULT_ROOMS]; +const TEST_POLICY_ID = '1'; const signUpWithTestUser = () => { TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN); @@ -64,10 +69,58 @@ const getDisplayNames = () => { }; // Reusable function to setup a mock report. Feel free to add more parameters as needed. -const createReport = (isPinned = false, participants = [1, 2], messageCount = 1) => { +const createReport = ( + isPinned = false, + participants = [1, 2], + messageCount = 1, + chatType: ValueOf | undefined = undefined, + policyID: string = CONST.POLICY.ID_FAKE, +) => { return { ...LHNTestUtils.getFakeReport(participants, messageCount), isPinned, + chatType, + policyID, + }; +}; + +const createFakeTransactionViolation = (violationName: ViolationName = CONST.VIOLATIONS.HOLD, showInReview = true) => { + return LHNTestUtils.getFakeTransactionViolation(violationName, showInReview); +}; + +const createReportWithRBR = (): OnyxMultiSetInput => { + const report = createReport(undefined, undefined, undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, TEST_POLICY_ID); + const expenseReport = ReportUtils.buildOptimisticExpenseReport(report.reportID, TEST_POLICY_ID, 100, 122, 'USD'); + const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); + const expenseCreatedAction = ReportUtils.buildOptimisticIOUReportAction( + 'create', + 100, + 'USD', + '', + [], + expenseTransaction.transactionID, + undefined, + expenseReport.reportID, + undefined, + false, + false, + undefined, + undefined, + ); + const transactionViolation = createFakeTransactionViolation(); + + return { + [ONYXKEYS.COLLECTION.REPORT]: { + [expenseReport.reportID]: expenseReport, + [report.reportID]: report, + }, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`]: { + [expenseCreatedAction.reportActionID]: expenseCreatedAction, + }, + [ONYXKEYS.COLLECTION.TRANSACTION]: { + [expenseTransaction.transactionID]: expenseTransaction, + }, + [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${expenseTransaction.transactionID}`]: [transactionViolation], }; }; @@ -80,14 +133,15 @@ describe('SidebarLinksData', () => { }); // Helper to initialize common state - const initializeState = async (reportData: ReportCollectionDataSet) => { + const initializeState = async (reportData?: ReportCollectionDataSet, otherData?: OnyxMultiSetInput) => { await waitForBatchedUpdates(); await Onyx.multiSet({ [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD, [ONYXKEYS.BETAS]: betas, [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.IS_LOADING_APP]: false, - ...reportData, + ...(reportData ?? {}), + ...(otherData ?? {}), }); }; @@ -174,6 +228,17 @@ describe('SidebarLinksData', () => { // TODO add the proper assertion for the pinned report. }); + + it('should display the report with violations', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const onyxData = createReportWithRBR(); + + await initializeState(undefined); + await Onyx.multiSet(onyxData); + + expect(getOptionRows()).toHaveLength(1); + }); }); describe('Report that should NOT be included in the LHN', () => { diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index dc752ae73b1c4..c64d3d1fd2a25 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -5,6 +5,7 @@ import Onyx from 'react-native-onyx'; import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; +import * as TransactionUtils from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; @@ -1180,4 +1181,190 @@ describe('ReportUtils', () => { }); }); }); + + describe('shouldReportBeInOptionList tests', () => { + afterEach(() => Onyx.clear()); + + it('should return true when the report is current active report', () => { + const report = LHNTestUtils.getFakeReport(); + const currentReportId = report.reportID; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeTruthy(); + }); + + it('should return true when the report has outstanding violations', async () => { + const expenseReport = ReportUtils.buildOptimisticExpenseReport('212', '123', 100, 122, 'USD'); + const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); + const expenseCreatedAction1 = ReportUtils.buildOptimisticIOUReportAction( + 'create', + 100, + 'USD', + '', + [], + expenseTransaction.transactionID, + undefined, + expenseReport.reportID, + undefined, + false, + false, + undefined, + undefined, + ); + const expenseCreatedAction2 = ReportUtils.buildOptimisticIOUReportAction( + 'create', + 100, + 'USD', + '', + [], + expenseTransaction.transactionID, + undefined, + expenseReport.reportID, + undefined, + false, + false, + undefined, + undefined, + ); + const transactionThreadReport = ReportUtils.buildTransactionThread(expenseCreatedAction1, expenseReport); + const currentReportId = '1'; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, { + [expenseCreatedAction1.reportActionID]: expenseCreatedAction1, + [expenseCreatedAction2.reportActionID]: expenseCreatedAction2, + }); + expect( + ReportUtils.shouldReportBeInOptionList({ + report: transactionThreadReport, + currentReportId, + isInFocusMode, + betas, + policies: {}, + doesReportHaveViolations: true, + excludeEmptyChats: false, + }), + ).toBeTruthy(); + }); + + it('should return true when the report needing user action', () => { + const chatReport: Report = { + ...LHNTestUtils.getFakeReport(), + hasOutstandingChildRequest: true, + }; + const currentReportId = '3'; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report: chatReport, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeTruthy(); + }); + + it('should return true when the report has valid draft comment', async () => { + const report = LHNTestUtils.getFakeReport(); + const currentReportId = '3'; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, 'fake draft'); + + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeTruthy(); + }); + + it('should return true when the report is pinned', () => { + const report: Report = { + ...LHNTestUtils.getFakeReport(), + isPinned: true, + }; + const currentReportId = '3'; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeTruthy(); + }); + + it('should return true when the report is unread and we are in the focus mode', async () => { + const report: Report = { + ...LHNTestUtils.getFakeReport(), + lastReadTime: '1', + lastVisibleActionCreated: '2', + type: CONST.REPORT.TYPE.CHAT, + participants: { + '1': { + notificationPreference: 'always', + }, + }, + lastMessageText: 'fake', + }; + const currentReportId = '3'; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + + await Onyx.merge(ONYXKEYS.SESSION, { + accountID: 1, + }); + + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeTruthy(); + }); + + it('should return true when the report is an archived report and we are in the default mode', async () => { + const archivedReport: Report = { + ...LHNTestUtils.getFakeReport(), + reportID: '1', + private_isArchived: DateUtils.getDBTime(), + }; + const reportNameValuePairs = { + type: 'chat', + private_isArchived: true, + }; + const currentReportId = '3'; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`, reportNameValuePairs); + + expect( + ReportUtils.shouldReportBeInOptionList({ + report: archivedReport, + currentReportId, + isInFocusMode, + betas, + policies: {}, + doesReportHaveViolations: false, + excludeEmptyChats: false, + }), + ).toBeTruthy(); + }); + + it('should return true when the report is selfDM', () => { + const report: Report = { + ...LHNTestUtils.getFakeReport(), + chatType: CONST.REPORT.CHAT_TYPE.SELF_DM, + }; + const currentReportId = '3'; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + const includeSelfDM = true; + expect( + ReportUtils.shouldReportBeInOptionList({ + report, + currentReportId, + isInFocusMode, + betas, + policies: {}, + doesReportHaveViolations: false, + excludeEmptyChats: false, + includeSelfDM, + }), + ).toBeTruthy(); + }); + }); }); diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx index 73d10365c2727..955ef6ff0e631 100644 --- a/tests/utils/LHNTestUtils.tsx +++ b/tests/utils/LHNTestUtils.tsx @@ -14,7 +14,7 @@ import * as ReportUtils from '@libs/ReportUtils'; import ReportActionItemSingle from '@pages/home/report/ReportActionItemSingle'; import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData'; import CONST from '@src/CONST'; -import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; +import type {PersonalDetailsList, Policy, Report, ReportAction, TransactionViolation, ViolationName} from '@src/types/onyx'; import type ReportActionName from '@src/types/onyx/ReportActionName'; import waitForBatchedUpdatesWithAct from './waitForBatchedUpdatesWithAct'; @@ -244,6 +244,14 @@ function getFakePolicy(id = '1', name = 'Workspace-Test-001'): Policy { }; } +function getFakeTransactionViolation(violationName: ViolationName, showInReview = true): TransactionViolation { + return { + type: CONST.VIOLATION_TYPES.VIOLATION, + name: violationName, + showInReview, + }; +} + /** * @param millisecondsInThePast the number of milliseconds in the past for the last message timestamp (to order reports by most recent messages) */ @@ -354,4 +362,5 @@ export { getFakeReportWithPolicy, getFakePolicy, getFakeAdvancedReportAction, + getFakeTransactionViolation, }; From 6ff0ea32c1f81d717e5f3323e8c7afa25ac04a29 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 16:33:03 +0700 Subject: [PATCH 02/24] revert change --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e260c7c37e1ae..b8a59fffdf389 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6248,7 +6248,7 @@ function isUnread(report: OnyxEntry): boolean { } if (isEmptyReport(report)) { - return true; + return false; } // lastVisibleActionCreated and lastReadTime are both datetime strings and can be compared directly const lastVisibleActionCreated = report.lastVisibleActionCreated ?? ''; From a9dc5b2a6bca8041557165d697592aa441e7f4b4 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 16:38:04 +0700 Subject: [PATCH 03/24] add batch update --- tests/ui/LHNItemsPresence.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 0594546ff8830..6d5f88c5c832a 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -235,6 +235,8 @@ describe('SidebarLinksData', () => { const onyxData = createReportWithRBR(); await initializeState(undefined); + await waitForBatchedUpdatesWithAct(); + await Onyx.multiSet(onyxData); expect(getOptionRows()).toHaveLength(1); From 1c8ac5b27188b9ad38de7e5f15b167d399452495 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 16:50:17 +0700 Subject: [PATCH 04/24] fix policy expense chat daat --- tests/ui/LHNItemsPresence.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 6d5f88c5c832a..81608cbc72cff 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -89,7 +89,7 @@ const createFakeTransactionViolation = (violationName: ViolationName = CONST.VIO }; const createReportWithRBR = (): OnyxMultiSetInput => { - const report = createReport(undefined, undefined, undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, TEST_POLICY_ID); + const report = createReport(true, undefined, undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, TEST_POLICY_ID); const expenseReport = ReportUtils.buildOptimisticExpenseReport(report.reportID, TEST_POLICY_ID, 100, 122, 'USD'); const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); const expenseCreatedAction = ReportUtils.buildOptimisticIOUReportAction( @@ -234,10 +234,7 @@ describe('SidebarLinksData', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); const onyxData = createReportWithRBR(); - await initializeState(undefined); - await waitForBatchedUpdatesWithAct(); - - await Onyx.multiSet(onyxData); + await initializeState(undefined, onyxData); expect(getOptionRows()).toHaveLength(1); }); From 2392000d6ea4a90d1360e782e3d97c6f2786093c Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:12:07 +0700 Subject: [PATCH 05/24] config test report with violation --- .../LHNOptionsList/OptionRowLHN.tsx | 1 + tests/ui/LHNItemsPresence.tsx | 73 ++++++++----------- tests/utils/LHNTestUtils.tsx | 11 +++ 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 3e3f4d1b8e5d8..178a174ffbabf 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -307,6 +307,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti {hasBrickError && ( diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 81608cbc72cff..14c2426e684da 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -5,11 +5,9 @@ import type {OnyxMultiSetInput} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import * as Localize from '@libs/Localize'; -import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; -import * as TransactionUtils from '@src/libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList, ViolationName} from '@src/types/onyx'; +import type {PersonalDetailsList, Report, ViolationName} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as TestHelper from '../utils/TestHelper'; @@ -88,42 +86,6 @@ const createFakeTransactionViolation = (violationName: ViolationName = CONST.VIO return LHNTestUtils.getFakeTransactionViolation(violationName, showInReview); }; -const createReportWithRBR = (): OnyxMultiSetInput => { - const report = createReport(true, undefined, undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, TEST_POLICY_ID); - const expenseReport = ReportUtils.buildOptimisticExpenseReport(report.reportID, TEST_POLICY_ID, 100, 122, 'USD'); - const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); - const expenseCreatedAction = ReportUtils.buildOptimisticIOUReportAction( - 'create', - 100, - 'USD', - '', - [], - expenseTransaction.transactionID, - undefined, - expenseReport.reportID, - undefined, - false, - false, - undefined, - undefined, - ); - const transactionViolation = createFakeTransactionViolation(); - - return { - [ONYXKEYS.COLLECTION.REPORT]: { - [expenseReport.reportID]: expenseReport, - [report.reportID]: report, - }, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`]: { - [expenseCreatedAction.reportActionID]: expenseCreatedAction, - }, - [ONYXKEYS.COLLECTION.TRANSACTION]: { - [expenseTransaction.transactionID]: expenseTransaction, - }, - [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${expenseTransaction.transactionID}`]: [transactionViolation], - }; -}; - describe('SidebarLinksData', () => { beforeAll(() => { Onyx.init({ @@ -232,11 +194,40 @@ describe('SidebarLinksData', () => { it('should display the report with violations', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); - const onyxData = createReportWithRBR(); - await initializeState(undefined, onyxData); + // And the report is initialized in Onyx. + const report: Report = { + ...createReport(true, undefined, undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, TEST_POLICY_ID), + ownerAccountID: TEST_USER_ACCOUNT_ID, + }; + + await initializeState(report); + // The report should appear in the sidebar because it’s pinned. expect(getOptionRows()).toHaveLength(1); + + const expenseReport: Report = { + ...createReport(true, undefined, undefined, undefined, TEST_POLICY_ID), + ownerAccountID: TEST_USER_ACCOUNT_ID, + type: CONST.REPORT.TYPE.EXPENSE, + }; + + const transaction = LHNTestUtils.getFakeTransaction(expenseReport.reportID); + const transactionViolation = createFakeTransactionViolation(); + + await Onyx.multiSet({ + [ONYXKEYS.COLLECTION.REPORT]: { + [expenseReport.reportID]: expenseReport, + }, + [ONYXKEYS.COLLECTION.TRANSACTION]: { + [transaction.transactionID]: transaction, + }, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, [transactionViolation]); + + // And the draft icon should be shown, indicating there is unsent content. + expect(screen.getByTestId('RBR Icon')).toBeOnTheScreen(); }); }); diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx index 955ef6ff0e631..1a3fc3d07f282 100644 --- a/tests/utils/LHNTestUtils.tsx +++ b/tests/utils/LHNTestUtils.tsx @@ -124,6 +124,7 @@ const fakePersonalDetails: PersonalDetailsList = { let lastFakeReportID = 0; let lastFakeReportActionID = 0; +let lastFakeTransactionID = 0; /** * @param millisecondsInThePast the number of milliseconds in the past for the last message timestamp (to order reports by most recent messages) @@ -191,6 +192,15 @@ function getFakeReportAction(actor = 'email1@test.com', millisecondsInThePast = }; } +function getFakeTransaction(expenseReportID: string, amount = 1, currency: string = CONST.CURRENCY.USD) { + return { + transactionID: `${++lastFakeTransactionID}`, + amount, + currency, + reportID: expenseReportID, + }; +} + function getAdvancedFakeReport(isArchived: boolean, isUserCreatedPolicyRoom: boolean, hasAddWorkspaceError: boolean, isUnread: boolean, isPinned: boolean): Report { return { ...getFakeReport([1, 2], 0, isUnread), @@ -363,4 +373,5 @@ export { getFakePolicy, getFakeAdvancedReportAction, getFakeTransactionViolation, + getFakeTransaction, }; From 6b24505b76acb632fe0c3f1c1012e22c50efbf46 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:12:39 +0700 Subject: [PATCH 06/24] add batch update --- tests/ui/LHNItemsPresence.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 14c2426e684da..68198f2a9e67a 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -205,6 +205,7 @@ describe('SidebarLinksData', () => { // The report should appear in the sidebar because it’s pinned. expect(getOptionRows()).toHaveLength(1); + await waitForBatchedUpdatesWithAct(); const expenseReport: Report = { ...createReport(true, undefined, undefined, undefined, TEST_POLICY_ID), From 7c204433c1a0dce37c2d81094f1cd11aa4d91b04 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:17:01 +0700 Subject: [PATCH 07/24] implement correct init state --- tests/ui/LHNItemsPresence.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 68198f2a9e67a..dcb781df4f46a 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -201,7 +201,9 @@ describe('SidebarLinksData', () => { ownerAccountID: TEST_USER_ACCOUNT_ID, }; - await initializeState(report); + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); // The report should appear in the sidebar because it’s pinned. expect(getOptionRows()).toHaveLength(1); From ffc90fd1f540121a1d2084f18e3af4acc96d5af0 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:25:41 +0700 Subject: [PATCH 08/24] use merge instead of multi set --- tests/ui/LHNItemsPresence.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index dcb781df4f46a..266b8292c27fb 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -218,15 +218,8 @@ describe('SidebarLinksData', () => { const transaction = LHNTestUtils.getFakeTransaction(expenseReport.reportID); const transactionViolation = createFakeTransactionViolation(); - await Onyx.multiSet({ - [ONYXKEYS.COLLECTION.REPORT]: { - [expenseReport.reportID]: expenseReport, - }, - [ONYXKEYS.COLLECTION.TRANSACTION]: { - [transaction.transactionID]: transaction, - }, - }); - + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, [transactionViolation]); // And the draft icon should be shown, indicating there is unsent content. From 8f29f00a88ce2befd6170a01b2db77885c0b5c02 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:37:57 +0700 Subject: [PATCH 09/24] fix RBR test --- tests/ui/LHNItemsPresence.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 266b8292c27fb..831bacdd3fb45 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -209,20 +209,20 @@ describe('SidebarLinksData', () => { expect(getOptionRows()).toHaveLength(1); await waitForBatchedUpdatesWithAct(); + // And the report is initialized in Onyx. const expenseReport: Report = { - ...createReport(true, undefined, undefined, undefined, TEST_POLICY_ID), + ...createReport(false, undefined, undefined, undefined, TEST_POLICY_ID), ownerAccountID: TEST_USER_ACCOUNT_ID, type: CONST.REPORT.TYPE.EXPENSE, }; - const transaction = LHNTestUtils.getFakeTransaction(expenseReport.reportID); const transactionViolation = createFakeTransactionViolation(); - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + // When the report has outstanding violations await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, [transactionViolation]); - // And the draft icon should be shown, indicating there is unsent content. + // The RBR icon should be shown expect(screen.getByTestId('RBR Icon')).toBeOnTheScreen(); }); }); From 5426b2730a93f04e50699ebece49d899bd26d276 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:44:29 +0700 Subject: [PATCH 10/24] add pin icon test for pinned report --- tests/ui/LHNItemsPresence.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 831bacdd3fb45..487c29a208009 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -188,7 +188,8 @@ describe('SidebarLinksData', () => { // Then the report should appear in the sidebar because it’s pinned. expect(getOptionRows()).toHaveLength(1); - // TODO add the proper assertion for the pinned report. + // And the pin icon should be shown + expect(screen.getByTestId('Pin Icon')).toBeOnTheScreen(); }); it('should display the report with violations', async () => { @@ -209,7 +210,6 @@ describe('SidebarLinksData', () => { expect(getOptionRows()).toHaveLength(1); await waitForBatchedUpdatesWithAct(); - // And the report is initialized in Onyx. const expenseReport: Report = { ...createReport(false, undefined, undefined, undefined, TEST_POLICY_ID), ownerAccountID: TEST_USER_ACCOUNT_ID, From b68d2e63fd45f0c24c8ddb48909a1e7d13aa92d9 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:45:32 +0700 Subject: [PATCH 11/24] merge expense report --- tests/ui/LHNItemsPresence.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 487c29a208009..e1d2207b06cde 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -219,6 +219,7 @@ describe('SidebarLinksData', () => { const transactionViolation = createFakeTransactionViolation(); // When the report has outstanding violations + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, [transactionViolation]); From 431a93d0911c550fe581a3597aafae3d7b85244a Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 17:53:10 +0700 Subject: [PATCH 12/24] add GRB report test --- .../LHNOptionsList/OptionRowLHN.tsx | 1 + tests/ui/LHNItemsPresence.tsx | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 178a174ffbabf..596afc0ba6c02 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -322,6 +322,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti {shouldShowGreenDotIndicator && ( diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index e1d2207b06cde..9adc406fb4c31 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -226,6 +226,26 @@ describe('SidebarLinksData', () => { // The RBR icon should be shown expect(screen.getByTestId('RBR Icon')).toBeOnTheScreen(); }); + + it('should display the report with needing user action', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report: Report = { + ...createReport(false), + hasOutstandingChildRequest: true, + }; + + // And the report is initialized in Onyx. + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + // Then the report should appear in the sidebar because it requires attention from the user + expect(getOptionRows()).toHaveLength(1); + + // And a green dot icon should be shown + expect(screen.getByTestId('GBR Icon')).toBeOnTheScreen(); + }); }); describe('Report that should NOT be included in the LHN', () => { From 5669518bf25d4ada19c6b2933201b44ca43a904d Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 18:02:44 +0700 Subject: [PATCH 13/24] add test for unread chat --- tests/ui/LHNItemsPresence.tsx | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 9adc406fb4c31..4e5674a64f402 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -1,10 +1,12 @@ import {screen} from '@testing-library/react-native'; import type {ComponentType} from 'react'; +import type {TextStyle} from 'react-native'; import Onyx from 'react-native-onyx'; import type {OnyxMultiSetInput} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import * as Localize from '@libs/Localize'; +import FontUtils from '@styles/utils/FontUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Report, ViolationName} from '@src/types/onyx'; @@ -73,9 +75,10 @@ const createReport = ( messageCount = 1, chatType: ValueOf | undefined = undefined, policyID: string = CONST.POLICY.ID_FAKE, + isUnread = false, ) => { return { - ...LHNTestUtils.getFakeReport(participants, messageCount), + ...LHNTestUtils.getFakeReport(participants, messageCount, isUnread), isPinned, chatType, policyID, @@ -246,6 +249,31 @@ describe('SidebarLinksData', () => { // And a green dot icon should be shown expect(screen.getByTestId('GBR Icon')).toBeOnTheScreen(); }); + + it('should display the unread report in the focuse mode with the bold text', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report: Report = { + ...createReport(undefined, undefined, undefined, undefined, undefined, true), + hasOutstandingChildRequest: true, + }; + + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + await waitForBatchedUpdatesWithAct(); + + // And the user is in focus mode + await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); + + // The report should appear in the sidebar because it's unread + expect(getOptionRows()).toHaveLength(1); + + // And the text is bold + const displayNameText = getDisplayNames()?.at(0); + expect((displayNameText?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); + }); }); describe('Report that should NOT be included in the LHN', () => { From a7a650b7064bd7b53c01e64cd4ed3e656be6c8b3 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 18:12:26 +0700 Subject: [PATCH 14/24] fix unread chat test and add archived report test --- tests/ui/LHNItemsPresence.tsx | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 4e5674a64f402..d50cfe76f165c 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -5,6 +5,7 @@ import Onyx from 'react-native-onyx'; import type {OnyxMultiSetInput} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; +import DateUtils from '@libs/DateUtils'; import * as Localize from '@libs/Localize'; import FontUtils from '@styles/utils/FontUtils'; import CONST from '@src/CONST'; @@ -255,7 +256,11 @@ describe('SidebarLinksData', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(undefined, undefined, undefined, undefined, undefined, true), - hasOutstandingChildRequest: true, + participants: { + [TEST_USER_ACCOUNT_ID]: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + }, + }, }; await initializeState({ @@ -274,6 +279,34 @@ describe('SidebarLinksData', () => { const displayNameText = getDisplayNames()?.at(0); expect((displayNameText?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); }); + + it('should disaply the archived report in the default mode', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const archivedReport: Report = { + ...createReport(false), + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: DateUtils.getDBTime(), + }; + const reportNameValuePairs = { + type: 'chat', + // eslint-disable-next-line @typescript-eslint/naming-convention + private_isArchived: true, + }; + + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${archivedReport.reportID}`]: archivedReport, + }); + + await waitForBatchedUpdatesWithAct(); + + // And the user is in the default mode + await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.DEFAULT); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`, reportNameValuePairs); + + // The report should appear in the sidebar because it's archived + expect(getOptionRows()).toHaveLength(1); + }); }); describe('Report that should NOT be included in the LHN', () => { From 2945e75decced0c074ab52c3629807ec4b685f91 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 18:25:36 +0700 Subject: [PATCH 15/24] fix unread test --- tests/ui/LHNItemsPresence.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index d50cfe76f165c..11040c9c5a26a 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -254,14 +254,7 @@ describe('SidebarLinksData', () => { it('should display the unread report in the focuse mode with the bold text', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); - const report: Report = { - ...createReport(undefined, undefined, undefined, undefined, undefined, true), - participants: { - [TEST_USER_ACCOUNT_ID]: { - notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, - }, - }, - }; + const report: Report = createReport(undefined, undefined, undefined, undefined, undefined, true); await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, From 88456950f79bd9747b0e0e091ee9508d37705ce0 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 20:52:20 +0700 Subject: [PATCH 16/24] fix unread report test --- tests/ui/LHNItemsPresence.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 11040c9c5a26a..8bfb2b09da19b 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -254,7 +254,10 @@ describe('SidebarLinksData', () => { it('should display the unread report in the focuse mode with the bold text', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); - const report: Report = createReport(undefined, undefined, undefined, undefined, undefined, true); + const report: Report = { + ...createReport(undefined, undefined, undefined, undefined, undefined, true), + lastMessageText: 'fake last message', + }; await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, From c44e3e4d049a77d105c33210bcedfe16361f75a2 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 21:00:38 +0700 Subject: [PATCH 17/24] add selfDM report test --- tests/ui/LHNItemsPresence.tsx | 64 +++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 8bfb2b09da19b..7d1712e7de1f1 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -251,31 +251,6 @@ describe('SidebarLinksData', () => { expect(screen.getByTestId('GBR Icon')).toBeOnTheScreen(); }); - it('should display the unread report in the focuse mode with the bold text', async () => { - // When the SidebarLinks are rendered. - LHNTestUtils.getDefaultRenderedSidebarLinks(); - const report: Report = { - ...createReport(undefined, undefined, undefined, undefined, undefined, true), - lastMessageText: 'fake last message', - }; - - await initializeState({ - [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - }); - - await waitForBatchedUpdatesWithAct(); - - // And the user is in focus mode - await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); - - // The report should appear in the sidebar because it's unread - expect(getOptionRows()).toHaveLength(1); - - // And the text is bold - const displayNameText = getDisplayNames()?.at(0); - expect((displayNameText?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); - }); - it('should disaply the archived report in the default mode', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); @@ -303,6 +278,45 @@ describe('SidebarLinksData', () => { // The report should appear in the sidebar because it's archived expect(getOptionRows()).toHaveLength(1); }); + + it('should display the selfDM report by default', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report = createReport(true, undefined, undefined, undefined, CONST.REPORT.CHAT_TYPE.SELF_DM, undefined); + + // And the selfDM is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + // The selfDM report should appear in the sidebar by default + expect(getOptionRows()).toHaveLength(1); + }); + + it('should display the unread report in the focuse mode with the bold text', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report: Report = { + ...createReport(undefined, undefined, undefined, undefined, undefined, true), + lastMessageText: 'fake last message', + }; + + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + await waitForBatchedUpdatesWithAct(); + + // And the user is in focus mode + await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); + + // The report should appear in the sidebar because it's unread + expect(getOptionRows()).toHaveLength(1); + + // And the text is bold + const displayNameText = getDisplayNames()?.at(0); + expect((displayNameText?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); + }); }); describe('Report that should NOT be included in the LHN', () => { From 8bd5ccb90fd0ddf984bffd322e4ff7b1781f00b2 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 2 Dec 2024 21:09:11 +0700 Subject: [PATCH 18/24] add lastActorAccountID to unread chat --- tests/ui/LHNItemsPresence.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 7d1712e7de1f1..6609a426b725b 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -299,6 +299,7 @@ describe('SidebarLinksData', () => { const report: Report = { ...createReport(undefined, undefined, undefined, undefined, undefined, true), lastMessageText: 'fake last message', + lastActorAccountID: TEST_USER_ACCOUNT_ID, }; await initializeState({ From 8aae28e49e905884aa2e4ed3685bfb834dfab3c1 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 5 Dec 2024 01:52:02 +0700 Subject: [PATCH 19/24] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 6609a426b725b..e07e411314ea1 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -293,7 +293,7 @@ describe('SidebarLinksData', () => { expect(getOptionRows()).toHaveLength(1); }); - it('should display the unread report in the focuse mode with the bold text', async () => { + it('should display the unread report in the focus mode with the bold text', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { From 776e838e53efee2bedd5aa4ac0a3e256a28e9d5a Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 5 Dec 2024 01:57:50 +0700 Subject: [PATCH 20/24] use toHaveStyle check --- tests/ui/LHNItemsPresence.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index e07e411314ea1..1574b045e79de 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -1,6 +1,5 @@ import {screen} from '@testing-library/react-native'; import type {ComponentType} from 'react'; -import type {TextStyle} from 'react-native'; import Onyx from 'react-native-onyx'; import type {OnyxMultiSetInput} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; @@ -316,7 +315,7 @@ describe('SidebarLinksData', () => { // And the text is bold const displayNameText = getDisplayNames()?.at(0); - expect((displayNameText?.props?.style as TextStyle)?.fontWeight).toBe(FontUtils.fontWeight.bold); + expect(displayNameText).toHaveStyle({fontWeight: FontUtils.fontWeight.bold}); }); }); From 7da2c0010635c79f7c8ede58aeef4114106aa580 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 15:51:28 +0700 Subject: [PATCH 21/24] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 1574b045e79de..8551f5021445a 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -230,7 +230,7 @@ describe('SidebarLinksData', () => { expect(screen.getByTestId('RBR Icon')).toBeOnTheScreen(); }); - it('should display the report with needing user action', async () => { + it('should display the report awaiting user action', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { From 4f07f11f390f9fd7f0b410b538861e3ebf58da66 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 15:51:35 +0700 Subject: [PATCH 22/24] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 8551f5021445a..5a93a43487dbb 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -250,7 +250,7 @@ describe('SidebarLinksData', () => { expect(screen.getByTestId('GBR Icon')).toBeOnTheScreen(); }); - it('should disaply the archived report in the default mode', async () => { + it('should display the archived report in the default mode', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const archivedReport: Report = { From e02a4ac5ecaf582b4c3bebe27bb66ee24f482a5b Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 15:57:34 +0700 Subject: [PATCH 23/24] add some other test cases --- tests/ui/LHNItemsPresence.tsx | 10 ++++++++++ tests/unit/ReportUtilsTest.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 5a93a43487dbb..4ddf4102539eb 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -316,6 +316,16 @@ describe('SidebarLinksData', () => { // And the text is bold const displayNameText = getDisplayNames()?.at(0); expect(displayNameText).toHaveStyle({fontWeight: FontUtils.fontWeight.bold}); + + await waitForBatchedUpdatesWithAct(); + + // When the report is marked as read + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, { + lastReadTime: report.lastVisibleActionCreated, + }); + + // The repot should not disapper in the sidebar because we are in the focus mode + expect(getOptionRows()).toHaveLength(0); }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index c64d3d1fd2a25..bf36041c72232 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1344,6 +1344,35 @@ describe('ReportUtils', () => { ).toBeTruthy(); }); + it('should return false when the report is an archived report and we are in the focus mode', async () => { + const archivedReport: Report = { + ...LHNTestUtils.getFakeReport(), + reportID: '1', + private_isArchived: DateUtils.getDBTime(), + }; + const reportNameValuePairs = { + type: 'chat', + private_isArchived: true, + }; + const currentReportId = '3'; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`, reportNameValuePairs); + + expect( + ReportUtils.shouldReportBeInOptionList({ + report: archivedReport, + currentReportId, + isInFocusMode, + betas, + policies: {}, + doesReportHaveViolations: false, + excludeEmptyChats: false, + }), + ).toBeFalsy(); + }); + it('should return true when the report is selfDM', () => { const report: Report = { ...LHNTestUtils.getFakeReport(), From 3d24897e30406177c355c6fae7806896f50572bb Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 17:15:15 +0700 Subject: [PATCH 24/24] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 4ddf4102539eb..b7e14bb5bd824 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -324,7 +324,7 @@ describe('SidebarLinksData', () => { lastReadTime: report.lastVisibleActionCreated, }); - // The repot should not disapper in the sidebar because we are in the focus mode + // The report should not disappear in the sidebar because we are in the focus mode expect(getOptionRows()).toHaveLength(0); }); });