From a1e38142f54b2e19c39ea18f8df8fd332ceb9de1 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Tue, 10 Sep 2024 17:48:58 +0530 Subject: [PATCH 1/6] Fix notification preference where we should default to hidden --- src/libs/ReportUtils.ts | 7 +++++-- src/libs/actions/Report.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fb75fc57c876..5ca118c2df55 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1166,8 +1166,11 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry): V /** * Get the notification preference given a report */ -function getReportNotificationPreference(report: OnyxEntry): ValueOf { - return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report); +function getReportNotificationPreference(report: OnyxEntry, shouldDefaltToHidden = true): ValueOf { + if (!shouldDefaltToHidden) { + return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report); + } + return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; } const CONCIERGE_ACCOUNT_ID_STRING = CONST.ACCOUNT_ID.CONCIERGE.toString(); diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 147b07f650b2..40a7059b54b9 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2871,7 +2871,7 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, - value: {[report.parentReportActionID]: {childReportNotificationPreference: ReportUtils.getReportNotificationPreference(report)}}, + value: {[report.parentReportActionID]: {childReportNotificationPreference: ReportUtils.getReportNotificationPreference(report, false)}}, }); } From f93d13c1246891e3db7f296d7a4f488f760a904c Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Tue, 10 Sep 2024 18:38:59 +0530 Subject: [PATCH 2/6] Fix test part 1 --- tests/ui/UnreadIndicatorsTest.tsx | 10 ++++++++-- tests/unit/SidebarTest.ts | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 011f1e01668f..c9cdd81cf9ba 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -140,7 +140,10 @@ function signInAndGetAppWithUnreadChat(): Promise { lastReadTime: reportAction3CreatedDate, lastVisibleActionCreated: reportAction9CreatedDate, lastMessageText: 'Test', - participants: {[USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}}, + participants: { + [USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + [USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, lastActorAccountID: USER_B_ACCOUNT_ID, type: CONST.REPORT.TYPE.CHAT, }); @@ -301,7 +304,10 @@ describe('Unread Indicators', () => { lastVisibleActionCreated: DateUtils.getDBTime(utcToZonedTime(NEW_REPORT_FIST_MESSAGE_CREATED_DATE, 'UTC').valueOf()), lastMessageText: 'Comment 1', lastActorAccountID: USER_C_ACCOUNT_ID, - participants: {[USER_C_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}}, + participants: { + [USER_C_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + [USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, type: CONST.REPORT.TYPE.CHAT, }, }, diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index 6913d39b7f34..a6e39b504b19 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -7,6 +7,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction'; import * as LHNTestUtils from '../utils/LHNTestUtils'; +import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; @@ -15,6 +16,9 @@ jest.mock('@src/libs/Permissions'); jest.mock('@src/hooks/useActiveWorkspaceFromNavigationState'); jest.mock('@src/components/Icon/Expensicons'); +const TEST_USER_ACCOUNT_ID = 1; +const TEST_USER_LOGIN = 'email1@test.com'; + describe('Sidebar', () => { beforeAll(() => Onyx.init({ @@ -27,7 +31,7 @@ describe('Sidebar', () => { // Wrap Onyx each onyx action with waitForBatchedUpdates wrapOnyxWithWaitForBatchedUpdates(Onyx); // Initialize the network key for OfflineWithFeedback - return Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); + return TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN).then(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false})); }); // Clear out Onyx after each test so that each test starts with a clean slate From d8be6e4b855c7e8f98d9cecb185d04db38b34073 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Tue, 10 Sep 2024 19:06:11 +0530 Subject: [PATCH 3/6] Fix test part 2 --- tests/ui/PaginationTest.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ui/PaginationTest.tsx b/tests/ui/PaginationTest.tsx index 6e867fbb239b..9d120433daa1 100644 --- a/tests/ui/PaginationTest.tsx +++ b/tests/ui/PaginationTest.tsx @@ -198,7 +198,10 @@ async function signInAndGetApp(): Promise { reportID: REPORT_ID, reportName: CONST.REPORT.DEFAULT_REPORT_NAME, lastMessageText: 'Test', - participants: {[USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}}, + participants: { + [USER_B_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + [USER_A_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, lastActorAccountID: USER_B_ACCOUNT_ID, type: CONST.REPORT.TYPE.CHAT, }); From c2116802a7f4756fb3c8cdf19b9ceafd5a8a6f65 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 11 Sep 2024 22:37:01 +0530 Subject: [PATCH 4/6] Fix jest test part 3 --- .../__mocks__/index.native.ts | 13 + .../useResponsiveLayout/__mocks__/index.ts | 13 + tests/unit/SidebarOrderTest.ts | 514 +++++++----------- tests/utils/TestHelper.ts | 10 +- 4 files changed, 222 insertions(+), 328 deletions(-) create mode 100644 src/hooks/useResponsiveLayout/__mocks__/index.native.ts create mode 100644 src/hooks/useResponsiveLayout/__mocks__/index.ts diff --git a/src/hooks/useResponsiveLayout/__mocks__/index.native.ts b/src/hooks/useResponsiveLayout/__mocks__/index.native.ts new file mode 100644 index 000000000000..1311f184881b --- /dev/null +++ b/src/hooks/useResponsiveLayout/__mocks__/index.native.ts @@ -0,0 +1,13 @@ +export default function useResponsiveLayout() { + return { + shouldUseNarrowLayout: false, + isSmallScreenWidth: false, + isInNarrowPaneModal: false, + isExtraSmallScreenHeight: false, + isExtraSmallScreenWidth: false, + isMediumScreenWidth: false, + onboardingIsMediumOrLargerScreenWidth: true, + isLargeScreenWidth: true, + isSmallScreen: false, + }; +} diff --git a/src/hooks/useResponsiveLayout/__mocks__/index.ts b/src/hooks/useResponsiveLayout/__mocks__/index.ts new file mode 100644 index 000000000000..1311f184881b --- /dev/null +++ b/src/hooks/useResponsiveLayout/__mocks__/index.ts @@ -0,0 +1,13 @@ +export default function useResponsiveLayout() { + return { + shouldUseNarrowLayout: false, + isSmallScreenWidth: false, + isInNarrowPaneModal: false, + isExtraSmallScreenHeight: false, + isExtraSmallScreenWidth: false, + isMediumScreenWidth: false, + onboardingIsMediumOrLargerScreenWidth: true, + isLargeScreenWidth: true, + isSmallScreen: false, + }; +} diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index b8a507289e8d..20b2b9c1f371 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -4,9 +4,11 @@ import * as Report from '@libs/actions/Report'; import DateUtils from '@libs/DateUtils'; import * as Localize from '@libs/Localize'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import * as LHNTestUtils from '../utils/LHNTestUtils'; +import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; @@ -14,22 +16,7 @@ import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatch jest.mock('@libs/Permissions'); jest.mock('@components/Icon/Expensicons'); jest.mock('@src/hooks/useActiveWorkspaceFromNavigationState'); - -const ONYXKEYS = { - PERSONAL_DETAILS_LIST: 'personalDetailsList', - IS_LOADING_APP: 'isLoadingApp', - NVP_PRIORITY_MODE: 'nvp_priorityMode', - SESSION: 'session', - BETAS: 'betas', - COLLECTION: { - REPORT: 'report_', - REPORT_ACTIONS: 'reportActions_', - POLICY: 'policy_', - REPORT_DRAFT_COMMENT: 'reportDraftComment_', - }, - NETWORK: 'network', - IS_LOADING_REPORT_DATA: 'isLoadingReportData', -} as const; +jest.mock('@src/hooks/useResponsiveLayout'); describe('Sidebar', () => { beforeAll(() => @@ -43,7 +30,7 @@ describe('Sidebar', () => { // Wrap Onyx each onyx action with waitForBatchedUpdates wrapOnyxWithWaitForBatchedUpdates(Onyx); // Initialize the network key for OfflineWithFeedback - return Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); + return TestHelper.signInWithTestUser(1, 'email1@test.com', undefined, undefined, 'One', '').then(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false})); }); // Clear out Onyx after each test so that each test starts with a clean slate @@ -106,7 +93,7 @@ describe('Sidebar', () => { // Then the component should be rendered with an item for the report .then(() => { - expect(screen.queryAllByText('One, Two')).toHaveLength(1); + expect(screen.queryAllByText('Email Two')).toHaveLength(1); }) ); }); @@ -114,8 +101,8 @@ describe('Sidebar', () => { it('orders items with most recently updated on top', () => { // Given three unread reports in the recently updated order of 3, 2, 1 const report1 = LHNTestUtils.getFakeReport([1, 2], 3); - const report2 = LHNTestUtils.getFakeReport([3, 4], 2); - const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + const report2 = LHNTestUtils.getFakeReport([1, 3], 2); + const report3 = LHNTestUtils.getFakeReport([1, 4], 1); // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); @@ -148,9 +135,9 @@ describe('Sidebar', () => { const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('Three, Four'); - expect(displayNames[2]).toHaveTextContent('One, Two'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); + expect(displayNames[2]).toHaveTextContent('Email Two'); }) ); }); @@ -162,8 +149,8 @@ describe('Sidebar', () => { const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), }; - const report2 = LHNTestUtils.getFakeReport([3, 4], 2); - const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + const report2 = LHNTestUtils.getFakeReport([1, 3], 2); + const report3 = LHNTestUtils.getFakeReport([1, 4], 1); // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); @@ -201,9 +188,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('One, Two'); // this has `hasDraft` flag enabled so it will be on top - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Two'); // this has `hasDraft` flag enabled so it will be on top + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Three'); }) ); }); @@ -211,8 +198,8 @@ describe('Sidebar', () => { it('reorders the reports to always have the most recently updated one on top', () => { // Given three reports in the recently updated order of 3, 2, 1 const report1 = LHNTestUtils.getFakeReport([1, 2], 3); - const report2 = LHNTestUtils.getFakeReport([3, 4], 2); - const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + const report2 = LHNTestUtils.getFakeReport([1, 3], 2); + const report3 = LHNTestUtils.getFakeReport([1, 4], 1); // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); @@ -252,9 +239,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('One, Two'); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Two'); + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Three'); }) ); }); @@ -262,12 +249,12 @@ describe('Sidebar', () => { it('reorders the reports to have a newly created task report on top', () => { // Given three reports in the recently updated order of 3, 2, 1 const report1 = LHNTestUtils.getFakeReport([1, 2], 4); - const report2 = LHNTestUtils.getFakeReport([3, 4], 3); - const report3 = LHNTestUtils.getFakeReport([5, 6], 2); + const report2 = LHNTestUtils.getFakeReport([1, 3], 3); + const report3 = LHNTestUtils.getFakeReport([1, 4], 2); const taskReportName = 'Buy Grocery'; const taskReport: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8], 1), + ...LHNTestUtils.getFakeReport([1, 2], 1), type: CONST.REPORT.TYPE.TASK, reportName: taskReportName, managerID: 2, @@ -307,9 +294,9 @@ describe('Sidebar', () => { const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); expect(displayNames[0]).toHaveTextContent(taskReportName); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - expect(displayNames[3]).toHaveTextContent('One, Two'); + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Two'); }) ); }); @@ -317,32 +304,42 @@ describe('Sidebar', () => { it('reorders the reports to have a newly created iou report on top', () => { // Given three reports in the recently updated order of 3, 2, 1 const report1 = LHNTestUtils.getFakeReport([1, 2], 4); - const report2 = LHNTestUtils.getFakeReport([3, 4], 3); + const report2 = LHNTestUtils.getFakeReport([1, 3], 3); const report3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6], 2), - hasOutstandingChildRequest: false, + ...LHNTestUtils.getFakeReport([1, 4], 2), + hasOutstandingChildRequest: true, // This has to be added after the IOU report is generated iouReportID: undefined, }; const iouReport: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8], 1), + ...LHNTestUtils.getFakeReport([1, 4], 1), type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 2, - hasOutstandingChildRequest: true, + ownerAccountID: 1, + managerID: 4, + hasOutstandingChildRequest: false, total: 10000, currency: 'USD', chatReportID: report3.reportID, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + participants: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 1: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + // eslint-disable-next-line @typescript-eslint/naming-convention + 4: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, }; report3.iouReportID = iouReport.reportID; // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); - Report.addComment(report2.reportID, 'Hi, this is a comment'); Report.addComment(report3.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); const reportCollectionDataSet: ReportCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, @@ -353,7 +350,7 @@ describe('Sidebar', () => { return ( waitForBatchedUpdates() - .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks(report3.reportID)) + .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks(iouReport.reportID)) // When Onyx is updated with the data and the sidebar re-renders .then(() => @@ -370,10 +367,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Email Two owes $100.00'); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - expect(displayNames[3]).toHaveTextContent('One, Two'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Four owes $100.00'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Two'); }) ); }); @@ -381,35 +378,46 @@ describe('Sidebar', () => { it('reorders the reports to have a newly created expense report on top', () => { // Given three reports in the recently updated order of 3, 2, 1 const report1 = LHNTestUtils.getFakeReport([1, 2], 4); - const report2 = LHNTestUtils.getFakeReport([3, 4], 3); - const fakeReport = LHNTestUtils.getFakeReportWithPolicy([5, 6], 2); + const report2 = LHNTestUtils.getFakeReport([1, 3], 3); + const fakeReport = LHNTestUtils.getFakeReportWithPolicy([1, 4], 2); const fakePolicy = LHNTestUtils.getFakePolicy(fakeReport.policyID); const report3: OnyxTypes.Report = { ...fakeReport, - hasOutstandingChildRequest: false, + hasOutstandingChildRequest: true, // This has to be added after the IOU report is generated iouReportID: undefined, }; const expenseReport: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8], 1), + ...LHNTestUtils.getFakeReport([1, 4], 1), type: CONST.REPORT.TYPE.EXPENSE, - ownerAccountID: 7, - managerID: 7, - policyName: 'Workspace', + ownerAccountID: 1, + managerID: 4, + policyName: fakePolicy.name, + policyID: fakeReport.policyID, total: -10000, currency: 'USD', stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, chatReportID: report3.reportID, parentReportID: report3.reportID, + participants: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 1: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + // eslint-disable-next-line @typescript-eslint/naming-convention + 4: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, }; report3.iouReportID = expenseReport.reportID; // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); - Report.addComment(report2.reportID, 'Hi, this is a comment'); Report.addComment(report3.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); const reportCollectionDataSet: ReportCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, @@ -420,7 +428,7 @@ describe('Sidebar', () => { return ( waitForBatchedUpdates() - .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks(report3.reportID)) + .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks(expenseReport.reportID)) // When Onyx is updated with the data and the sidebar re-renders .then(() => @@ -438,10 +446,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Workspace owes $100.00'); - expect(displayNames[1]).toHaveTextContent('Email Five'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - expect(displayNames[3]).toHaveTextContent('One, Two'); + expect(displayNames[0]).toHaveTextContent('Email One'); + expect(displayNames[1]).toHaveTextContent('Workspace-Test-001 owes $100.00'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Two'); }) ); }); @@ -452,9 +460,9 @@ describe('Sidebar', () => { // And the currently viewed report is the second report const report1 = LHNTestUtils.getFakeReport([1, 2], 3); const report2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([3, 4], 2), + ...LHNTestUtils.getFakeReport([1, 3], 2), }; - const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + const report3 = LHNTestUtils.getFakeReport([1, 4], 1); // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); @@ -488,7 +496,7 @@ describe('Sidebar', () => { .then(() => { // The changing of a route itself will re-render the component in the App, but since we are not performing this test // inside the navigator and it has no access to the routes we need to trigger an update to the SidebarLinks manually. - LHNTestUtils.getDefaultRenderedSidebarLinks('1'); + LHNTestUtils.getDefaultRenderedSidebarLinks(report1.reportID); return waitForBatchedUpdates(); }) @@ -498,9 +506,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Three, Four'); - expect(displayNames[1]).toHaveTextContent('Five, Six'); - expect(displayNames[2]).toHaveTextContent('One, Two'); + expect(displayNames[0]).toHaveTextContent('Email Three'); + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Two'); }) ); }); @@ -587,46 +595,58 @@ describe('Sidebar', () => { ); }); - it('sorts chats by pinned > IOU > draft', () => { - // Given three reports in the recently updated order of 3, 2, 1 - // with the current user set to email9@ (someone not participating in any of the chats) + it('sorts chats by pinned / GBR > draft > rest', () => { + // Given three reports in the recently updated order of 4, 3, 2, 1 // with a report that has a draft, a report that is pinned, and - // an outstanding IOU report that doesn't belong to the current user + // an outstanding IOU report that belong to the current user const report1: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([1, 2], 3), + ...LHNTestUtils.getFakeReport([1, 2], 4), isPinned: true, }; const report2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([3, 4], 2), + ...LHNTestUtils.getFakeReport([1, 3], 3), }; const report3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6], 1), - hasOutstandingChildRequest: false, + ...LHNTestUtils.getFakeReport([1, 4], 2), + hasOutstandingChildRequest: true, // This has to be added after the IOU report is generated iouReportID: undefined, }; + const report4 = LHNTestUtils.getFakeReport([1, 5], 1); + Report.addComment(report4.reportID, 'Hi, this is a comment'); + const iouReport: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8]), + ...LHNTestUtils.getFakeReport([1, 4]), type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 2, - hasOutstandingChildRequest: true, + ownerAccountID: 1, + managerID: 4, + hasOutstandingChildRequest: false, total: 10000, currency: 'USD', chatReportID: report3.reportID, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + participants: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 1: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + // eslint-disable-next-line @typescript-eslint/naming-convention + 4: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, }; report3.iouReportID = iouReport.reportID; const currentReportId = report2.reportID; - const currentlyLoggedInUserAccountID = 9; const reportCollectionDataSet: ReportCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, [`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2, [`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3, + [`${ONYXKEYS.COLLECTION.REPORT}${report4.reportID}`]: report4, [`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`]: iouReport, }; @@ -640,24 +660,24 @@ describe('Sidebar', () => { [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.IS_LOADING_APP]: false, - [ONYXKEYS.SESSION]: {accountID: currentlyLoggedInUserAccountID}, [`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report2.reportID}`]: 'Report2 draft comment', ...reportCollectionDataSet, }), ) - // Then the reports are ordered by Pinned > IOU > Draft + // Then the reports are ordered by Pinned / GBR > Draft > Rest // there is a pencil icon // there is a pinned icon .then(() => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(3); + expect(displayNames).toHaveLength(4); expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(1); expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(1); - expect(displayNames[0]).toHaveTextContent('Email Two owes $100.00'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Two'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Five'); }) ); }); @@ -670,15 +690,15 @@ describe('Sidebar', () => { isPinned: true, }; const report2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([3, 4], 2), + ...LHNTestUtils.getFakeReport([1, 3], 2), isPinned: true, }; const report3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6], 1), + ...LHNTestUtils.getFakeReport([1, 4], 1), isPinned: true, }; const report4: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8], 0), + ...LHNTestUtils.getFakeReport([1, 5], 0), isPinned: true, }; @@ -707,9 +727,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); + expect(displayNames[2]).toHaveTextContent('Email Two'); }) // When a new report is added @@ -720,10 +740,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Seven, Eight'); - expect(displayNames[3]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Five'); + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Two'); }) ); }); @@ -735,13 +755,13 @@ describe('Sidebar', () => { ...LHNTestUtils.getFakeReport([1, 2], 3), }; const report2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([3, 4], 2), + ...LHNTestUtils.getFakeReport([1, 3], 2), }; const report3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6], 1), + ...LHNTestUtils.getFakeReport([1, 4], 1), }; const report4: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8], 0), + ...LHNTestUtils.getFakeReport([1, 5], 0), }; const reportCollectionDataSet: ReportCollectionDataSet = { @@ -776,9 +796,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); + expect(displayNames[2]).toHaveTextContent('Email Two'); }) // When a new report is added @@ -796,10 +816,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Seven, Eight'); - expect(displayNames[3]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Five'); + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Two'); }) ); }); @@ -814,8 +834,8 @@ describe('Sidebar', () => { // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; - const report2 = LHNTestUtils.getFakeReport([3, 4]); - const report3 = LHNTestUtils.getFakeReport([5, 6]); + const report2 = LHNTestUtils.getFakeReport([1, 3]); + const report3 = LHNTestUtils.getFakeReport([1, 4]); // Each report has at least one ADD_COMMENT action so should be rendered in the LNH Report.addComment(report1.reportID, 'Hi, this is a comment'); @@ -851,20 +871,63 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); expect(displayNames[2]).toHaveTextContent('Report (archived)'); }) ); }); + + it('orders nonArchived reports by displayName if created timestamps are the same', () => { + // Given three nonArchived reports created at the same time + const report1 = LHNTestUtils.getFakeReport([1, 2]); + const report2 = LHNTestUtils.getFakeReport([1, 3]); + const report3: OnyxTypes.Report = LHNTestUtils.getFakeReport([1, 4]); + + // Each report has at least one ADD_COMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); + + const reportCollectionDataSet: ReportCollectionDataSet = { + [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, + [`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2, + [`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3, + }; + + return ( + waitForBatchedUpdates() + .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0')) + + // When Onyx is updated with the data and the sidebar re-renders + .then(() => + Onyx.multiSet({ + [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, + [ONYXKEYS.IS_LOADING_APP]: false, + ...reportCollectionDataSet, + }), + ) + + // Then the reports are ordered alphabetically since their lastVisibleActionCreated are the same + .then(() => { + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); + expect(displayNames).toHaveLength(3); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); + expect(displayNames[2]).toHaveTextContent('Email Two'); + }) + ); + }); }); describe('in #focus mode', () => { it('alphabetizes chats', () => { const report1 = {...LHNTestUtils.getFakeReport([1, 2], 3, true), lastMessageText: 'test'}; - const report2 = {...LHNTestUtils.getFakeReport([3, 4], 2, true), lastMessageText: 'test'}; - const report3 = {...LHNTestUtils.getFakeReport([5, 6], 1, true), lastMessageText: 'test'}; - const report4 = {...LHNTestUtils.getFakeReport([7, 8], 0, true), lastMessageText: 'test'}; + const report2 = {...LHNTestUtils.getFakeReport([1, 3], 2, true), lastMessageText: 'test'}; + const report3 = {...LHNTestUtils.getFakeReport([1, 4], 1, true), lastMessageText: 'test'}; + const report4 = {...LHNTestUtils.getFakeReport([1, 5], 0, true), lastMessageText: 'test'}; const reportCollectionDataSet: ReportCollectionDataSet = { [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, @@ -891,9 +954,9 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); + expect(displayNames[2]).toHaveTextContent('Email Two'); }) // When a new report is added @@ -904,10 +967,10 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Seven, Eight'); - expect(displayNames[3]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Five'); + expect(displayNames[1]).toHaveTextContent('Email Four'); + expect(displayNames[2]).toHaveTextContent('Email Three'); + expect(displayNames[3]).toHaveTextContent('Email Two'); }) ); }); @@ -924,10 +987,10 @@ describe('Sidebar', () => { private_isArchived: DateUtils.getDBTime(), }; const report2 = { - ...LHNTestUtils.getFakeReport([3, 4], 2, true), + ...LHNTestUtils.getFakeReport([1, 3], 2, true), lastMessageText: 'test', }; - const report3 = {...LHNTestUtils.getFakeReport([5, 6], 1, true), lastMessageText: 'test'}; + const report3 = {...LHNTestUtils.getFakeReport([1, 4], 1, true), lastMessageText: 'test'}; // Given the user is in all betas const betas = [CONST.BETAS.DEFAULT_ROOMS]; @@ -958,206 +1021,11 @@ describe('Sidebar', () => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('Three, Four'); + expect(displayNames[0]).toHaveTextContent('Email Four'); + expect(displayNames[1]).toHaveTextContent('Email Three'); expect(displayNames[2]).toHaveTextContent('Report (archived)'); }) ); }); - - it('orders IOU reports by displayName if amounts are the same', () => { - // Given three IOU reports containing the same IOU amounts - const report1: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([1, 2]), - - // This has to be added after the IOU report is generated - iouReportID: undefined, - }; - const report2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([3, 4]), - - // This has to be added after the IOU report is generated - iouReportID: undefined, - }; - const report3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6]), - - // This has to be added after the IOU report is generated - iouReportID: undefined, - }; - const report4: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6]), - - // This has to be added after the IOU report is generated - iouReportID: undefined, - }; - const report5: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6]), - - // This has to be added after the IOU report is generated - iouReportID: undefined, - }; - const iouReport1: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([7, 8]), - type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 2, - hasOutstandingChildRequest: true, - total: 10000, - currency: 'USD', - chatReportID: report3.reportID, - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - }; - const iouReport2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([9, 10]), - type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 3, - hasOutstandingChildRequest: true, - total: 10000, - currency: 'USD', - chatReportID: report3.reportID, - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - }; - const iouReport3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([11, 12]), - type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 4, - hasOutstandingChildRequest: true, - total: 100000, - currency: 'USD', - chatReportID: report3.reportID, - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - }; - const iouReport4: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([11, 12]), - type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 5, - hasOutstandingChildRequest: true, - total: 10000, - currency: 'USD', - chatReportID: report3.reportID, - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - }; - const iouReport5: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([11, 12]), - type: CONST.REPORT.TYPE.IOU, - ownerAccountID: 2, - managerID: 6, - hasOutstandingChildRequest: true, - total: 10000, - currency: 'USD', - chatReportID: report3.reportID, - stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, - statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - }; - - report1.iouReportID = iouReport1.reportID; - report2.iouReportID = iouReport2.reportID; - report3.iouReportID = iouReport3.reportID; - report4.iouReportID = iouReport4.reportID; - report5.iouReportID = iouReport5.reportID; - - const currentlyLoggedInUserAccountID = 13; - - const reportCollectionDataSet: ReportCollectionDataSet = { - [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, - [`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2, - [`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3, - [`${ONYXKEYS.COLLECTION.REPORT}${report4.reportID}`]: report4, - [`${ONYXKEYS.COLLECTION.REPORT}${report5.reportID}`]: report5, - [`${ONYXKEYS.COLLECTION.REPORT}${iouReport1.reportID}`]: iouReport1, - [`${ONYXKEYS.COLLECTION.REPORT}${iouReport2.reportID}`]: iouReport2, - [`${ONYXKEYS.COLLECTION.REPORT}${iouReport3.reportID}`]: iouReport3, - [`${ONYXKEYS.COLLECTION.REPORT}${iouReport4.reportID}`]: iouReport4, - [`${ONYXKEYS.COLLECTION.REPORT}${iouReport5.reportID}`]: iouReport5, - }; - - return ( - waitForBatchedUpdates() - .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0')) - // When Onyx is updated with the data and the sidebar re-renders - .then(() => - Onyx.multiSet({ - [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, - [ONYXKEYS.IS_LOADING_APP]: false, - [ONYXKEYS.SESSION]: {accountID: currentlyLoggedInUserAccountID}, - ...reportCollectionDataSet, - }), - ) - - // Then the reports with the same amount are ordered alphabetically - .then(() => { - const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(5); - expect(displayNames[0]).toHaveTextContent('Email Five owes $100.00'); - expect(displayNames[1]).toHaveTextContent('Email Four owes $1,000.00'); - expect(displayNames[2]).toHaveTextContent('Email Six owes $100.00'); - expect(displayNames[3]).toHaveTextContent('Email Three owes $100.00'); - expect(displayNames[4]).toHaveTextContent('Email Two owes $100.00'); - }) - ); - }); - - it('orders nonArchived reports by displayName if created timestamps are the same', () => { - // Given three nonArchived reports created at the same time - const lastVisibleActionCreated = DateUtils.getDBTime(); - const report1: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([1, 2]), - lastVisibleActionCreated, - }; - const report2: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([3, 4]), - lastVisibleActionCreated, - }; - const report3: OnyxTypes.Report = { - ...LHNTestUtils.getFakeReport([5, 6]), - lastVisibleActionCreated, - }; - - // Each report has at least one ADD_COMMENT action so should be rendered in the LNH - Report.addComment(report1.reportID, 'Hi, this is a comment'); - Report.addComment(report2.reportID, 'Hi, this is a comment'); - Report.addComment(report3.reportID, 'Hi, this is a comment'); - - const reportCollectionDataSet: ReportCollectionDataSet = { - [`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1, - [`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2, - [`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3, - }; - - return ( - waitForBatchedUpdates() - .then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0')) - - // When Onyx is updated with the data and the sidebar re-renders - .then(() => - Onyx.multiSet({ - [ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, - [ONYXKEYS.IS_LOADING_APP]: false, - ...reportCollectionDataSet, - }), - ) - - // Then the reports are ordered alphabetically since their lastVisibleActionCreated are the same - .then(() => { - const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); - const displayNames = screen.queryAllByLabelText(hintText); - expect(displayNames).toHaveLength(3); - expect(displayNames[0]).toHaveTextContent('Five, Six'); - expect(displayNames[1]).toHaveTextContent('One, Two'); - expect(displayNames[2]).toHaveTextContent('Three, Four'); - }) - ); - }); }); }); diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 84ea2b2aafbe..4ecfd1a2a007 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -47,15 +47,15 @@ function setupApp() { }); } -function buildPersonalDetails(login: string, accountID: number, firstName = 'Test'): PersonalDetails { +function buildPersonalDetails(login: string, accountID: number, firstName = 'Test', lastName = 'User'): PersonalDetails { return { accountID, login, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', avatarThumbnail: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', - displayName: `${firstName} User`, + displayName: `${firstName}${lastName ? '' : ` ${lastName}`}`, firstName, - lastName: 'User', + lastName, pronouns: '', timezone: CONST.DEFAULT_TIME_ZONE, phoneNumber: '', @@ -66,7 +66,7 @@ function buildPersonalDetails(login: string, accountID: number, firstName = 'Tes * Simulate signing in and make sure all API calls in this flow succeed. Every time we add * a mockImplementationOnce() we are altering what Network.post() will return. */ -function signInWithTestUser(accountID = 1, login = 'test@user.com', password = 'Password1', authToken = 'asdfqwerty', firstName = 'Test') { +function signInWithTestUser(accountID = 1, login = 'test@user.com', password = 'Password1', authToken = 'asdfqwerty', firstName = 'Test', lastName = 'User') { const originalXhr = HttpUtils.xhr; HttpUtils.xhr = jest.fn().mockImplementation(() => { @@ -90,7 +90,7 @@ function signInWithTestUser(accountID = 1, login = 'test@user.com', password = ' onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.PERSONAL_DETAILS_LIST, value: { - [accountID]: buildPersonalDetails(login, accountID, firstName), + [accountID]: buildPersonalDetails(login, accountID, firstName, lastName), }, }, ], From c9b41ad6bb12054769684ddfed219160284f3b66 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 11 Sep 2024 22:41:21 +0530 Subject: [PATCH 5/6] Fix jest test part 4 --- tests/unit/SidebarOrderTest.ts | 2 +- tests/utils/TestHelper.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index 20b2b9c1f371..225cf6d2194d 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -30,7 +30,7 @@ describe('Sidebar', () => { // Wrap Onyx each onyx action with waitForBatchedUpdates wrapOnyxWithWaitForBatchedUpdates(Onyx); // Initialize the network key for OfflineWithFeedback - return TestHelper.signInWithTestUser(1, 'email1@test.com', undefined, undefined, 'One', '').then(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false})); + return TestHelper.signInWithTestUser(1, 'email1@test.com', undefined, undefined, 'One').then(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false})); }); // Clear out Onyx after each test so that each test starts with a clean slate diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 4ecfd1a2a007..84ea2b2aafbe 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -47,15 +47,15 @@ function setupApp() { }); } -function buildPersonalDetails(login: string, accountID: number, firstName = 'Test', lastName = 'User'): PersonalDetails { +function buildPersonalDetails(login: string, accountID: number, firstName = 'Test'): PersonalDetails { return { accountID, login, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', avatarThumbnail: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png', - displayName: `${firstName}${lastName ? '' : ` ${lastName}`}`, + displayName: `${firstName} User`, firstName, - lastName, + lastName: 'User', pronouns: '', timezone: CONST.DEFAULT_TIME_ZONE, phoneNumber: '', @@ -66,7 +66,7 @@ function buildPersonalDetails(login: string, accountID: number, firstName = 'Tes * Simulate signing in and make sure all API calls in this flow succeed. Every time we add * a mockImplementationOnce() we are altering what Network.post() will return. */ -function signInWithTestUser(accountID = 1, login = 'test@user.com', password = 'Password1', authToken = 'asdfqwerty', firstName = 'Test', lastName = 'User') { +function signInWithTestUser(accountID = 1, login = 'test@user.com', password = 'Password1', authToken = 'asdfqwerty', firstName = 'Test') { const originalXhr = HttpUtils.xhr; HttpUtils.xhr = jest.fn().mockImplementation(() => { @@ -90,7 +90,7 @@ function signInWithTestUser(accountID = 1, login = 'test@user.com', password = ' onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.PERSONAL_DETAILS_LIST, value: { - [accountID]: buildPersonalDetails(login, accountID, firstName, lastName), + [accountID]: buildPersonalDetails(login, accountID, firstName), }, }, ], From 593c33a56aba6b4e5ee9da95543bc1b4863cb2c3 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 11 Sep 2024 23:06:03 +0530 Subject: [PATCH 6/6] Fix perf test attempt 1 --- tests/perf-test/SidebarLinks.perf-test.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/SidebarLinks.perf-test.tsx b/tests/perf-test/SidebarLinks.perf-test.tsx index 0b851a56f2ad..9a385c1917fb 100644 --- a/tests/perf-test/SidebarLinks.perf-test.tsx +++ b/tests/perf-test/SidebarLinks.perf-test.tsx @@ -59,7 +59,11 @@ describe('SidebarLinks', () => { // Initialize the network key for OfflineWithFeedback Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); - Onyx.clear().then(waitForBatchedUpdates); + TestHelper.signInWithTestUser(1, 'email1@test.com', undefined, undefined, 'One').then(waitForBatchedUpdates); + }); + + afterEach(() => { + Onyx.clear(); }); test('[SidebarLinks] should render Sidebar with 500 reports stored', async () => { @@ -87,7 +91,7 @@ describe('SidebarLinks', () => { * Query for display names of participants [1, 2]. * This will ensure that the sidebar renders a list of items. */ - await screen.findAllByText('One, Two'); + await screen.findAllByText('Email Two'); }; await waitForBatchedUpdates();