From be5f3ea7ae44450314df1889e105a9acde19dd00 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 31 Jan 2025 18:06:45 +0300 Subject: [PATCH] order selfdm on top --- src/libs/OptionsListUtils.ts | 2 +- tests/unit/OptionsListUtilsTest.ts | 39 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a8e23888db0d..b4a0005db6b3 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1079,7 +1079,7 @@ function orderReportOptionsWithSearch( } if (option.isSelfDM) { - return 0; + return -1; } if (preferRecentExpenseReports && !!option?.lastIOUCreationDate) { return 1; diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 19ebf261bd7a..f72d61e11359 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -372,6 +372,32 @@ describe('OptionsListUtils', () => { }, }; + const REPORTS_WITH_SELFDM: OnyxCollection = { + 16: { + lastReadTime: '2021-01-14 11:25:39.302', + lastVisibleActionCreated: '2022-11-22 03:26:02.022', + isPinned: false, + reportID: '16', + participants: { + 2: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, + reportName: 'Expense Report', + type: CONST.REPORT.TYPE.EXPENSE, + }, + 17: { + lastReadTime: '2021-01-14 11:25:39.302', + lastVisibleActionCreated: '2022-11-22 03:26:02.022', + isPinned: false, + reportID: '17', + participants: { + 2: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, + reportName: '', + type: CONST.REPORT.TYPE.CHAT, + chatType: CONST.REPORT.CHAT_TYPE.SELF_DM, + }, + }; + const PERSONAL_DETAILS_WITH_CONCIERGE: PersonalDetailsList = { ...PERSONAL_DETAILS, '999': { @@ -1074,6 +1100,19 @@ describe('OptionsListUtils', () => { expect(filteredOptions.personalDetails.length).toBe(2); expect(matchingEntries.length).toBe(1); }); + + it('should order self dm always on top if the search matches with the self dm login', () => { + const searchTerm = 'tonystark@expensify.com'; + + const OPTIONS_WITH_SELFDM = OptionsListUtils.createOptionList(PERSONAL_DETAILS, REPORTS_WITH_SELFDM); + + // When search term matches with self dm login + const options = OptionsListUtils.getSearchOptions(OPTIONS_WITH_SELFDM, [CONST.BETAS.ALL]); + const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, searchTerm); + + // Then the self dm should be on top. + expect(filteredOptions.recentReports.at(0)?.isSelfDM).toBe(true); + }); }); describe('canCreateOptimisticPersonalDetailOption', () => {