@@ -5,19 +5,47 @@ import React from 'react';
55import { ChannelStateProvider } from '../../../context/ChannelStateContext' ;
66import { ChatProvider } from '../../../context/ChatContext' ;
77import { TranslationProvider } from '../../../context/TranslationContext' ;
8- import { useChannelDisplayName } from '../../ChannelPreview/hooks/useChannelDisplayName' ;
98import { ThreadHeader } from '../ThreadHeader' ;
109
11- jest . mock ( '../../ChannelPreview/hooks/useChannelDisplayName' , ( ) => ( {
12- useChannelDisplayName : jest . fn ( ) ,
10+ jest . mock ( '../../ChannelPreview/hooks/useChannelPreviewInfo' , ( ) => ( {
11+ useChannelPreviewInfo : jest . fn ( ( ) => ( { displayTitle : undefined } ) ) ,
12+ } ) ) ;
13+
14+ jest . mock ( '../../../store' , ( ) => ( {
15+ useStateStore : jest . fn ( ( ) => undefined ) ,
16+ } ) ) ;
17+
18+ jest . mock ( '../../../context/TypingContext' , ( ) => ( {
19+ useTypingContext : jest . fn ( ( ) => ( { typing : { } } ) ) ,
20+ } ) ) ;
21+
22+ jest . mock ( '../../TypingIndicator/TypingIndicatorHeader' , ( ) => ( {
23+ TypingIndicatorHeader : ( ) => < div > Typing...</ div > ,
24+ } ) ) ;
25+
26+ jest . mock ( '../../Button/ToggleSidebarButton' , ( ) => ( {
27+ ToggleSidebarButton : ( { children } ) => (
28+ < div data-testid = 'toggle-sidebar-button' > { children } </ div >
29+ ) ,
1330} ) ) ;
1431
1532jest . mock ( '../../Threads' , ( ) => ( {
1633 useThreadContext : jest . fn ( ( ) => undefined ) ,
1734} ) ) ;
1835
36+ jest . mock ( '../../ChatView' , ( ) => ( {
37+ useChatViewContext : jest . fn ( ( ) => ( { activeChatView : 'channels' } ) ) ,
38+ } ) ) ;
39+
40+ const {
41+ useChannelPreviewInfo,
42+ } = require ( '../../ChannelPreview/hooks/useChannelPreviewInfo' ) ;
43+ const { useChatViewContext } = require ( '../../ChatView' ) ;
44+ const { useThreadContext } = require ( '../../Threads' ) ;
45+
1946const alice = { id : 'alice' , name : 'Alice' } ;
2047const bob = { id : 'bob' , name : 'Bob' } ;
48+
2149const createThread = ( user ) => ( {
2250 id : `${ user ?. id ?? 'thread' } -message` ,
2351 reply_count : 2 ,
@@ -36,20 +64,38 @@ const createChannel = (overrides = {}) => ({
3664 ...overrides ,
3765} ) ;
3866
39- const renderComponent = ( { channelOverrides = { } , props = { } } = { } ) => {
40- const client = { off : jest . fn ( ) , on : jest . fn ( ) , userID : alice . id } ;
67+ const renderComponent = ( {
68+ activeChatView = 'channels' ,
69+ channelOverrides = { } ,
70+ props = { } ,
71+ threadContext = undefined ,
72+ } = { } ) => {
73+ const client = { off : jest . fn ( ) , on : jest . fn ( ) , user : alice , userID : alice . id } ;
4174 const thread = createThread ( alice ) ;
4275 const channel = createChannel ( channelOverrides ) ;
4376
77+ useChatViewContext . mockReturnValue ( {
78+ activeChatView,
79+ setActiveChatView : jest . fn ( ) ,
80+ } ) ;
81+ useThreadContext . mockReturnValue ( threadContext ) ;
82+
4483 return render (
45- < ChatProvider value = { { client, latestMessageDatesByChannels : { } } } >
46- < ChannelStateProvider value = { { channel } } >
84+ < ChatProvider
85+ value = { {
86+ client,
87+ closeMobileNav : jest . fn ( ) ,
88+ latestMessageDatesByChannels : { } ,
89+ navOpen : false ,
90+ openMobileNav : jest . fn ( ) ,
91+ } }
92+ >
93+ < ChannelStateProvider value = { { channel, thread } } >
4794 < TranslationProvider
4895 value = { {
4996 t : ( key , options ) => {
5097 if ( key === 'Thread' ) return 'Thread' ;
5198 if ( key === 'replyCount' ) return `${ options . count } replies` ;
52- if ( key === 'Direct message' ) return 'Direct message' ;
5399 if ( key === 'aria/Close thread' ) return 'Close thread' ;
54100
55101 return key ;
@@ -69,18 +115,18 @@ describe('ThreadHeader', () => {
69115 jest . clearAllMocks ( ) ;
70116 } ) ;
71117
72- it ( 'renders the channel display title in the subtitle' , async ( ) => {
73- useChannelDisplayName . mockReturnValue ( 'Bob' ) ;
118+ it ( 'renders the channel display title in the subtitle' , ( ) => {
119+ useChannelPreviewInfo . mockReturnValue ( { displayTitle : 'Bob' } ) ;
74120
75- await renderComponent ( ) ;
121+ renderComponent ( ) ;
76122
77123 expect ( screen . getByText ( 'Bob · 2 replies' ) ) . toBeInTheDocument ( ) ;
78124 } ) ;
79125
80- it ( 'falls back to the parent message author when the channel has no display title' , async ( ) => {
81- useChannelDisplayName . mockReturnValue ( undefined ) ;
126+ it ( 'falls back to the parent message author when the channel has no display title' , ( ) => {
127+ useChannelPreviewInfo . mockReturnValue ( { displayTitle : undefined } ) ;
82128
83- await renderComponent ( {
129+ renderComponent ( {
84130 channelOverrides : {
85131 state : {
86132 members : {
@@ -96,10 +142,10 @@ describe('ThreadHeader', () => {
96142 expect ( screen . getByText ( 'Alice · 2 replies' ) ) . toBeInTheDocument ( ) ;
97143 } ) ;
98144
99- it ( 'renders only the reply count when no title source is available' , async ( ) => {
100- useChannelDisplayName . mockReturnValue ( undefined ) ;
145+ it ( 'renders only the reply count when no title source is available' , ( ) => {
146+ useChannelPreviewInfo . mockReturnValue ( { displayTitle : undefined } ) ;
101147
102- await renderComponent ( {
148+ renderComponent ( {
103149 channelOverrides : {
104150 state : {
105151 members : {
@@ -115,4 +161,26 @@ describe('ThreadHeader', () => {
115161 expect ( screen . getByText ( '2 replies' ) ) . toBeInTheDocument ( ) ;
116162 expect ( screen . queryByText ( / ^ u n d e f i n e d · / ) ) . not . toBeInTheDocument ( ) ;
117163 } ) ;
164+
165+ it ( 'does not render the sidebar toggle in the channels view' , ( ) => {
166+ useChannelPreviewInfo . mockReturnValue ( { displayTitle : 'Bob' } ) ;
167+
168+ renderComponent ( {
169+ activeChatView : 'channels' ,
170+ threadContext : { id : 'thread-1' } ,
171+ } ) ;
172+
173+ expect ( screen . queryByTestId ( 'toggle-sidebar-button' ) ) . not . toBeInTheDocument ( ) ;
174+ } ) ;
175+
176+ it ( 'renders the sidebar toggle in the threads view' , ( ) => {
177+ useChannelPreviewInfo . mockReturnValue ( { displayTitle : 'Bob' } ) ;
178+
179+ renderComponent ( {
180+ activeChatView : 'threads' ,
181+ threadContext : { id : 'thread-1' } ,
182+ } ) ;
183+
184+ expect ( screen . getByTestId ( 'toggle-sidebar-button' ) ) . toBeInTheDocument ( ) ;
185+ } ) ;
118186} ) ;
0 commit comments