@@ -33,6 +33,8 @@ jest.mock('../../EmptyStateIndicator', () => ({
3333 EmptyStateIndicator : jest . fn ( ) ,
3434} ) ) ;
3535
36+ const UNREAD_MESSAGES_SEPARATOR_TEST_ID = 'unread-messages-separator' ;
37+
3638let chatClient ;
3739let channel ;
3840const user1 = generateUser ( ) ;
@@ -448,7 +450,141 @@ describe('MessageList', () => {
448450 } ,
449451 } ) ;
450452 } ) ;
451- expect ( screen . queryByTestId ( 'unread-messages-separator' ) ) . toBeInTheDocument ( ) ;
453+ expect ( screen . queryByTestId ( UNREAD_MESSAGES_SEPARATOR_TEST_ID ) ) . toBeInTheDocument ( ) ;
454+ } ) ;
455+
456+ it ( 'should display unread messages separator in main msg list' , async ( ) => {
457+ const user = generateUser ( ) ;
458+ const messages = Array . from ( { length : 5 } ) . map ( ( _ , i ) =>
459+ generateMessage ( { created_at : new Date ( i + 1000 ) . toISOString ( ) } ) ,
460+ ) ;
461+ const {
462+ channels : [ channel ] ,
463+ client,
464+ } = await initClientWithChannels ( {
465+ channelsData : [
466+ {
467+ messages,
468+ read : [
469+ {
470+ last_read : messages [ 2 ] . created_at ,
471+ last_read_message_id : messages [ 2 ] . id ,
472+ unread_messages : 2 ,
473+ user,
474+ } ,
475+ ] ,
476+ } ,
477+ ] ,
478+ customUser : user ,
479+ } ) ;
480+
481+ const markReadSpy = jest . spyOn ( channel , 'markRead' ) . mockResolvedValue ( false ) ;
482+
483+ await act ( ( ) => {
484+ renderComponent ( {
485+ channelProps : { channel } ,
486+ chatClient : client ,
487+ msgListProps : { messages } ,
488+ } ) ;
489+ } ) ;
490+
491+ expect ( screen . queryByTestId ( UNREAD_MESSAGES_SEPARATOR_TEST_ID ) ) . toBeInTheDocument ( ) ;
492+ markReadSpy . mockRestore ( ) ;
493+ } ) ;
494+
495+ it ( 'should not display unread messages separator in read main msg list' , async ( ) => {
496+ const user = generateUser ( ) ;
497+ const messages = Array . from ( { length : 5 } ) . map ( ( _ , i ) =>
498+ generateMessage ( { created_at : new Date ( i + 1000 ) . toISOString ( ) } ) ,
499+ ) ;
500+
501+ const lastMessage = messages . slice ( - 1 ) [ 0 ] ;
502+ const {
503+ channels : [ channel ] ,
504+ client,
505+ } = await initClientWithChannels ( {
506+ channelsData : [
507+ {
508+ messages,
509+ read : [
510+ {
511+ last_read : lastMessage . created_at ,
512+ last_read_message_id : lastMessage . id ,
513+ unread_messages : 0 ,
514+ user,
515+ } ,
516+ ] ,
517+ } ,
518+ ] ,
519+ customUser : user ,
520+ } ) ;
521+
522+ const markReadSpy = jest . spyOn ( channel , 'markRead' ) . mockResolvedValue ( false ) ;
523+
524+ await act ( ( ) => {
525+ renderComponent ( {
526+ channelProps : { channel } ,
527+ chatClient : client ,
528+ msgListProps : { messages } ,
529+ } ) ;
530+ } ) ;
531+
532+ expect (
533+ screen . queryByTestId ( UNREAD_MESSAGES_SEPARATOR_TEST_ID ) ,
534+ ) . not . toBeInTheDocument ( ) ;
535+ markReadSpy . mockRestore ( ) ;
536+ } ) ;
537+
538+ it ( 'should not display unread messages separator in threads' , async ( ) => {
539+ const user = generateUser ( ) ;
540+ const messages = Array . from ( { length : 5 } ) . map ( ( _ , i ) =>
541+ generateMessage ( { created_at : new Date ( i + 1000 ) . toISOString ( ) } ) ,
542+ ) ;
543+ const parentMsg = messages [ 4 ] ;
544+ const lastReadMessage = messages [ 3 ] ;
545+ const replies = Array . from ( { length : 3 } ) . map ( ( ) =>
546+ generateMessage ( {
547+ created_at : new Date (
548+ new Date ( parentMsg . created_at ) . getTime ( ) + 1000 + 1 ,
549+ ) . toISOString ( ) ,
550+ parent_id : parentMsg . id ,
551+ } ) ,
552+ ) ;
553+ const {
554+ channels : [ channel ] ,
555+ client,
556+ } = await initClientWithChannels ( {
557+ channelsData : [
558+ {
559+ messages,
560+ read : [
561+ {
562+ last_read : lastReadMessage . created_at ,
563+ last_read_message_id : lastReadMessage . id ,
564+ unread_messages : 1 ,
565+ user,
566+ } ,
567+ ] ,
568+ } ,
569+ ] ,
570+ customUser : user ,
571+ } ) ;
572+
573+ await act ( ( ) => {
574+ renderComponent ( {
575+ channelProps : { channel } ,
576+ chatClient : client ,
577+ msgListProps : {
578+ disableDateSeparator : true ,
579+ messages : replies ,
580+ threadList : true ,
581+ } ,
582+ } ) ;
583+ } ) ;
584+
585+ expect (
586+ screen . queryByTestId ( UNREAD_MESSAGES_SEPARATOR_TEST_ID ) ,
587+ ) . not . toBeInTheDocument ( ) ;
452588 } ) ;
453589
454590 it ( 'should display custom unread messages separator when channel is marked unread' , async ( ) => {
0 commit comments