Skip to content

Commit 753cc05

Browse files
committed
Clear sortKeyCache per cycle and add i18n sort key tests
1 parent a217baf commit 753cc05

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/libs/SidebarUtils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ function categorizeReportsForLHN(
472472
reportAttributes: ReportAttributesDerivedValue['reports'] | undefined,
473473
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
474474
) {
475+
sortKeyCache.clear();
476+
475477
const pinnedAndGBRReports: MiniReport[] = [];
476478
const errorReports: MiniReport[] = [];
477479
const draftReports: MiniReport[] = [];
@@ -1415,7 +1417,12 @@ function getRoomWelcomeMessage(
14151417
}
14161418

14171419
// Exported for unit testing only. Do not use directly in production code.
1418-
export {categorizeReportsForLHN as _categorizeReportsForLHN, sortCategorizedReports as _sortCategorizedReports, combineReportCategories as _combineReportCategories};
1420+
export {
1421+
categorizeReportsForLHN as _categorizeReportsForLHN,
1422+
sortCategorizedReports as _sortCategorizedReports,
1423+
combineReportCategories as _combineReportCategories,
1424+
buildSortKey as _buildSortKey,
1425+
};
14191426

14201427
export default {
14211428
getOptionData,

tests/unit/SidebarUtilsTest.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {getLastActorDisplayName} from '@libs/OptionsListUtils';
1010
import type * as PolicyUtils from '@libs/PolicyUtils';
1111
import {getOriginalMessage, getReportActionMessageText} from '@libs/ReportActionsUtils';
1212
import {formatReportLastMessageText, generateReportID, getAllReportErrors, getReasonAndReportActionThatRequiresAttention, getReportPreviewMessage} from '@libs/ReportUtils';
13-
import SidebarUtils, {_categorizeReportsForLHN, _combineReportCategories, _sortCategorizedReports} from '@libs/SidebarUtils';
13+
import SidebarUtils, {_buildSortKey, _categorizeReportsForLHN, _combineReportCategories, _sortCategorizedReports} from '@libs/SidebarUtils';
1414
import initOnyxDerivedValues from '@userActions/OnyxDerived';
1515
import CONST from '@src/CONST';
1616
import IntlStore from '@src/languages/IntlStore';
@@ -3367,6 +3367,30 @@ describe('SidebarUtils', () => {
33673367
});
33683368
});
33693369

3370+
describe('buildSortKey', () => {
3371+
it('should sort accented characters by Unicode code point, not locale-aware order', () => {
3372+
// Given names with accented characters
3373+
const cafeAccented = _buildSortKey('Café');
3374+
const cafePlain = _buildSortKey('Cafe');
3375+
3376+
// Then accented "é" sorts after plain "e" by code point
3377+
expect(cafeAccented > cafePlain).toBe(true);
3378+
});
3379+
3380+
it('should be case-insensitive', () => {
3381+
expect(_buildSortKey('Alpha')).toBe(_buildSortKey('alpha'));
3382+
expect(_buildSortKey('ZEBRA')).toBe(_buildSortKey('zebra'));
3383+
});
3384+
3385+
it('should zero-pad numeric segments for natural sort order', () => {
3386+
const report2 = _buildSortKey('Report 2');
3387+
const report10 = _buildSortKey('Report 10');
3388+
3389+
// Then "Report 2" sorts before "Report 10"
3390+
expect(report2 < report10).toBe(true);
3391+
});
3392+
});
3393+
33703394
describe('combineReportCategories', () => {
33713395
it('should combine categories in correct order', () => {
33723396
// Given the reports are created

0 commit comments

Comments
 (0)