@@ -13,6 +13,7 @@ import {
1313 getUnitRateValue ,
1414 isUserInvitedToWorkspace ,
1515 shouldShowPolicy ,
16+ sortWorkspacesBySelected ,
1617} from '@libs/PolicyUtils' ;
1718import { isWorkspaceEligibleForReportChange } from '@libs/ReportUtils' ;
1819import CONST from '@src/CONST' ;
@@ -854,4 +855,25 @@ describe('PolicyUtils', () => {
854855 expect ( tagList . name ) . toEqual ( expected ) ;
855856 } ) ;
856857 } ) ;
858+ describe ( 'sortWorkspacesBySelected' , ( ) => {
859+ it ( 'should order workspaces with selected workspace first' , ( ) => {
860+ const workspace1 = { policyID : '1' , name : 'Workspace 1' } ;
861+ const workspace2 = { policyID : '2' , name : 'Workspace 2' } ;
862+ const selectedWorkspace1 = { policyID : '3' , name : 'Workspace 3' } ;
863+ const selectedWorkspace2 = { policyID : '4' , name : 'Workspace 4' } ;
864+ expect ( sortWorkspacesBySelected ( workspace1 , workspace2 , [ '3' , '4' ] , TestHelper . localeCompare ) ) . toBe ( - 1 ) ;
865+ expect ( sortWorkspacesBySelected ( workspace1 , selectedWorkspace1 , [ '3' , '4' ] , TestHelper . localeCompare ) ) . toBe ( 1 ) ;
866+ expect ( sortWorkspacesBySelected ( selectedWorkspace1 , selectedWorkspace2 , [ '3' , '4' ] , TestHelper . localeCompare ) ) . toBe ( - 1 ) ;
867+ } ) ;
868+
869+ it ( 'should order workspaces using name if no workspace is selected' , ( ) => {
870+ const workspace1 = { policyID : '1' , name : 'Workspace 1' } ;
871+ const workspace2 = { policyID : '2' , name : 'Workspace 2' } ;
872+ const workspace3 = { policyID : '3' , name : 'Workspace 3' } ;
873+ const workspace4 = { policyID : '4' , name : 'Workspace 4' } ;
874+ expect ( sortWorkspacesBySelected ( workspace1 , workspace2 , undefined , TestHelper . localeCompare ) ) . toBe ( - 1 ) ;
875+ expect ( sortWorkspacesBySelected ( workspace1 , workspace3 , undefined , TestHelper . localeCompare ) ) . toBe ( - 1 ) ;
876+ expect ( sortWorkspacesBySelected ( workspace3 , workspace4 , undefined , TestHelper . localeCompare ) ) . toBe ( - 1 ) ;
877+ } ) ;
878+ } ) ;
857879} ) ;
0 commit comments