@@ -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' , ( ) => {
@@ -1933,4 +1935,26 @@ describe('OptionsListUtils', () => {
19331935 expect ( result . at ( 1 ) ! . reportID ) . toBe ( '3' ) ;
19341936 } ) ;
19351937 } ) ;
1938+
1939+ describe ( 'sortAlphabetically' , ( ) => {
1940+ it ( 'should sort options alphabetically by text' , ( ) => {
1941+ const options : OptionData [ ] = [ { text : 'Banana' , reportID : '1' } as OptionData , { text : 'Apple' , reportID : '2' } as OptionData , { text : 'Cherry' , reportID : '3' } as OptionData ] ;
1942+ const sortedOptions = sortAlphabetically ( options , 'text' , localeCompare ) ;
1943+ expect ( sortedOptions . at ( 0 ) ?. reportID ) . toBe ( '2' ) ;
1944+ expect ( sortedOptions . at ( 1 ) ?. reportID ) . toBe ( '1' ) ;
1945+ expect ( sortedOptions . at ( 2 ) ?. reportID ) . toBe ( '3' ) ;
1946+ } ) ;
1947+
1948+ it ( 'should handle empty array' , ( ) => {
1949+ const sortedOptions = sortAlphabetically ( [ ] , 'abc' , localeCompare ) ;
1950+ expect ( sortedOptions ) . toEqual ( [ ] ) ;
1951+ } ) ;
1952+
1953+ it ( 'should handle single option' , ( ) => {
1954+ const options : OptionData [ ] = [ { text : 'Single' , reportID : '1' } as OptionData ] ;
1955+ const sortedOptions = sortAlphabetically ( options , 'text' , localeCompare ) ;
1956+ expect ( sortedOptions . length ) . toBe ( 1 ) ;
1957+ expect ( sortedOptions . at ( 0 ) ?. text ) . toBe ( 'Single' ) ;
1958+ } ) ;
1959+ } ) ;
19361960} ) ;
0 commit comments