@@ -882,6 +882,77 @@ describe('SidebarUtils', () => {
882882 ) ;
883883 } ) ;
884884
885+ it ( 'returns correct messageText for a single user DM chat' , async ( ) => {
886+ const MOCK_REPORT : Report = {
887+ ...LHNTestUtils . getFakeReport ( ) ,
888+ chatType : undefined ,
889+ type : 'chat' ,
890+ } ;
891+ const participantPersonalDetailList : PersonalDetails [ ] = [
892+ { accountID :
1 , displayName :
'Email One' , avatar :
'https://example.com/one.png' , login :
'[email protected] ' } as unknown as PersonalDetails , 893+ ] ;
894+
895+ await waitForBatchedUpdates ( ) ;
896+ await act ( async ( ) => {
897+ await Onyx . multiSet ( {
898+ [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : LHNTestUtils . fakePersonalDetails ,
899+ } ) ;
900+ } ) ;
901+
902+ const result = SidebarUtils . getWelcomeMessage ( MOCK_REPORT , undefined , participantPersonalDetailList , localeCompare ) ;
903+ expect ( result . messageText ) . toBe ( 'This chat is with Email One.' ) ;
904+ expect ( result . messageHtml ) . toContain ( '<user-details accountid="1">Email One</user-details>' ) ;
905+ } ) ;
906+
907+ it ( 'returns correct messageText for two users in a group chat' , async ( ) => {
908+ const MOCK_REPORT : Report = {
909+ ...LHNTestUtils . getFakeReport ( ) ,
910+ chatType : 'group' ,
911+ type : 'chat' ,
912+ } ;
913+ const participantPersonalDetailList : PersonalDetails [ ] = [
914+ { accountID :
1 , displayName :
'Email One' , avatar :
'https://example.com/one.png' , login :
'[email protected] ' } as unknown as PersonalDetails , 915+ { accountID :
2 , displayName :
'Email Two' , avatar :
'https://example.com/two.png' , login :
'[email protected] ' } as unknown as PersonalDetails , 916+ ] ;
917+
918+ await waitForBatchedUpdates ( ) ;
919+ await act ( async ( ) => {
920+ await Onyx . multiSet ( {
921+ [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : LHNTestUtils . fakePersonalDetails ,
922+ } ) ;
923+ } ) ;
924+
925+ const result = SidebarUtils . getWelcomeMessage ( MOCK_REPORT , undefined , participantPersonalDetailList , localeCompare ) ;
926+ expect ( result . messageText ) . toMatch ( / ^ T h i s c h a t i s w i t h .+ a n d .+ \. $ / ) ;
927+ expect ( result . messageText ) . toContain ( ' and ' ) ;
928+ expect ( result . messageText ) . not . toContain ( '<user-details' ) ;
929+ } ) ;
930+
931+ it ( 'returns correct messageText for three users in a group chat' , async ( ) => {
932+ const MOCK_REPORT : Report = {
933+ ...LHNTestUtils . getFakeReport ( ) ,
934+ chatType : 'group' ,
935+ type : 'chat' ,
936+ } ;
937+ const participantPersonalDetailList : PersonalDetails [ ] = [
938+ { accountID :
1 , displayName :
'Email One' , avatar :
'https://example.com/one.png' , login :
'[email protected] ' } as unknown as PersonalDetails , 939+ { accountID :
2 , displayName :
'Email Two' , avatar :
'https://example.com/two.png' , login :
'[email protected] ' } as unknown as PersonalDetails , 940+ { accountID :
3 , displayName :
'Email Three' , avatar :
'https://example.com/three.png' , login :
'[email protected] ' } as unknown as PersonalDetails , 941+ ] ;
942+
943+ await waitForBatchedUpdates ( ) ;
944+ await act ( async ( ) => {
945+ await Onyx . multiSet ( {
946+ [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : LHNTestUtils . fakePersonalDetails ,
947+ } ) ;
948+ } ) ;
949+
950+ const result = SidebarUtils . getWelcomeMessage ( MOCK_REPORT , undefined , participantPersonalDetailList , localeCompare ) ;
951+ expect ( result . messageText ) . toMatch ( / ^ T h i s c h a t i s w i t h .+ , .+ , a n d .+ \. $ / ) ;
952+ expect ( result . messageText ) . toContain ( ', and ' ) ;
953+ expect ( result . messageText ) . not . toContain ( '<user-details' ) ;
954+ } ) ;
955+
885956 it ( 'returns a welcome message for an archived chat room' , ( ) => {
886957 const MOCK_REPORT : Report = {
887958 ...LHNTestUtils . getFakeReport ( ) ,
0 commit comments