@@ -21,6 +21,7 @@ import {
2121 orderOptions ,
2222 orderWorkspaceOptions ,
2323 recentReportComparator ,
24+ sortAlphabetically ,
2425} from '@libs/OptionsListUtils' ;
2526import { canCreateTaskInReport , canUserPerformWriteAction , isCanceledTaskReport , isExpensifyOnlyParticipantInReport } from '@libs/ReportUtils' ;
2627import type { OptionData } from '@libs/ReportUtils' ;
@@ -29,6 +30,7 @@ import IntlStore from '@src/languages/IntlStore';
2930import ONYXKEYS from '@src/ONYXKEYS' ;
3031import type { PersonalDetails , Policy , Report } from '@src/types/onyx' ;
3132import { getFakeAdvancedReportAction } from '../utils/LHNTestUtils' ;
33+ import { localeCompare } from '../utils/TestHelper' ;
3234import waitForBatchedUpdates from '../utils/waitForBatchedUpdates' ;
3335
3436jest . mock ( '@rnmapbox/maps' , ( ) => {
@@ -1944,4 +1946,26 @@ describe('OptionsListUtils', () => {
19441946 expect ( result . at ( 1 ) ! . reportID ) . toBe ( '3' ) ;
19451947 } ) ;
19461948 } ) ;
1949+
1950+ describe ( 'sortAlphabetically' , ( ) => {
1951+ it ( 'should sort options alphabetically by text' , ( ) => {
1952+ const options : OptionData [ ] = [ { text : 'Banana' , reportID : '1' } as OptionData , { text : 'Apple' , reportID : '2' } as OptionData , { text : 'Cherry' , reportID : '3' } as OptionData ] ;
1953+ const sortedOptions = sortAlphabetically ( options , 'text' , localeCompare ) ;
1954+ expect ( sortedOptions . at ( 0 ) ?. reportID ) . toBe ( '2' ) ;
1955+ expect ( sortedOptions . at ( 1 ) ?. reportID ) . toBe ( '1' ) ;
1956+ expect ( sortedOptions . at ( 2 ) ?. reportID ) . toBe ( '3' ) ;
1957+ } ) ;
1958+
1959+ it ( 'should handle empty array' , ( ) => {
1960+ const sortedOptions = sortAlphabetically ( [ ] , 'abc' , localeCompare ) ;
1961+ expect ( sortedOptions ) . toEqual ( [ ] ) ;
1962+ } ) ;
1963+
1964+ it ( 'should handle single option' , ( ) => {
1965+ const options : OptionData [ ] = [ { text : 'Single' , reportID : '1' } as OptionData ] ;
1966+ const sortedOptions = sortAlphabetically ( options , 'text' , localeCompare ) ;
1967+ expect ( sortedOptions . length ) . toBe ( 1 ) ;
1968+ expect ( sortedOptions . at ( 0 ) ?. text ) . toBe ( 'Single' ) ;
1969+ } ) ;
1970+ } ) ;
19471971} ) ;
0 commit comments