From 65c770ea175a772af43b70788565135b6fd44be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Tue, 26 Nov 2024 13:27:30 +0100 Subject: [PATCH] fix sorting not working --- src/libs/OptionsListUtils.ts | 7 ++----- tests/unit/OptionsListUtilsTest.ts | 14 ++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 13b9380b679e..2c1bed293b28 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -641,6 +641,7 @@ function createOption( policyID: undefined, isOptimisticPersonalDetail: false, lastMessageText: '', + lastVisibleActionCreated: undefined, }; const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); @@ -677,6 +678,7 @@ function createOption( result.policyID = report.policyID; result.isSelfDM = ReportUtils.isSelfDM(report); result.notificationPreference = ReportUtils.getReportNotificationPreference(report); + result.lastVisibleActionCreated = report.lastVisibleActionCreated; const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); @@ -937,13 +939,8 @@ function orderReportOptions( return lodashOrderBy( options, [ - // Sort descending by lastVisibleActionCreated (option) => option?.lastVisibleActionCreated ?? 0, (option) => { - // TODO: what the fuck this is at the bottom already, is this even needed? i don't think so … - // if (option.private_isArchived) { - // return CONST.DATE.UNIX_EPOCH; // Keep archived at bottom - // } if (option.isPolicyExpenseChat && preferPolicyExpenseChat && option.policyID === activePolicyID) { return 0; } diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 279baed208e5..467fe6711def 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -669,7 +669,13 @@ describe('OptionsListUtils', () => { const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, searchText, {sortByReportTypeInSearch: true}); + // When sortByReportTypeInSearch is true, we expect all options to be part of the recentReports list: + expect(filteredOptions.personalDetails.length).toBe(0); + + // Expect to only find reports that matched our search text: expect(filteredOptions.recentReports.length).toBe(4); + + // This items should be ordered by most recent action (and other criteria such as whether they are archived): expect(filteredOptions.recentReports.at(0)?.text).toBe('Invisible Woman'); expect(filteredOptions.recentReports.at(1)?.text).toBe('Spider-Man'); expect(filteredOptions.recentReports.at(2)?.text).toBe('Black Widow'); @@ -944,15 +950,7 @@ describe('OptionsListUtils', () => { }); it('should return all matching reports and personal details (getOptions)', () => { - console.log({ - reports: OPTIONS.reports.length, - personalDetails: OPTIONS.personalDetails.length, - }); const options = OptionsListUtils.getOptions({reports: OPTIONS.reports, personalDetails: OPTIONS.personalDetails}); - console.log('after getOptions', { - reports: options.recentReports.length, - personalDetails: options.personalDetails.length, - }); const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, '.com', {maxRecentReportsToShow: 5}); expect(filteredOptions.personalDetails.length).toBe(2);