@@ -19,12 +19,12 @@ afterEach(cleanup); // eslint-disable-line
1919
2020const alice = generateUser ( ) ;
2121
22- async function renderComponent ( typing = { } ) {
22+ async function renderComponent ( typing = { } , threadList , value = { } ) {
2323 const client = await getTestClientWithUser ( alice ) ;
2424
2525 return render (
26- < ChannelContext . Provider value = { { client, typing } } >
27- < TypingIndicator />
26+ < ChannelContext . Provider value = { { client, typing, ... value } } >
27+ < TypingIndicator threadList = { threadList } />
2828 </ ChannelContext . Provider > ,
2929 ) ;
3030}
@@ -139,4 +139,92 @@ describe('TypingIndicator', () => {
139139
140140 expect ( tree ) . toMatchInlineSnapshot ( `null` ) ;
141141 } ) ;
142+
143+ describe ( 'TypingIndicator in thread' , ( ) => {
144+ let client ;
145+ let ch ;
146+ let channel ;
147+
148+ beforeEach ( async ( ) => {
149+ client = await getTestClientWithUser ( ) ;
150+ ch = generateChannel ( { config : { typing_events : true } } ) ;
151+ useMockedApis ( client , [ getOrCreateChannelApi ( ch ) ] ) ;
152+ channel = client . channel ( 'messaging' , ch . id ) ;
153+ await channel . watch ( ) ;
154+ } ) ;
155+
156+ afterEach ( cleanup ) ;
157+
158+ it ( 'should render TypingIndicator if user is typing in thread' , async ( ) => {
159+ const { container } = await renderComponent (
160+ { example : { parent_id : 'sample-thread' , user : 'test-user' } } ,
161+ true ,
162+ {
163+ client,
164+ channel,
165+ thread : { id : 'sample-thread' } ,
166+ } ,
167+ ) ;
168+
169+ expect (
170+ container . firstChild . classList . contains (
171+ 'str-chat__typing-indicator--typing' ,
172+ ) ,
173+ ) . toBe ( true ) ;
174+ } ) ;
175+
176+ it ( 'should not render TypingIndicator in main channel if user is typing in thread' , async ( ) => {
177+ const { container } = await renderComponent (
178+ { example : { parent_id : 'sample-thread' , user : 'test-user' } } ,
179+ false ,
180+ {
181+ client,
182+ channel,
183+ thread : { id : 'sample-thread' } ,
184+ } ,
185+ ) ;
186+
187+ expect (
188+ container . firstChild . classList . contains (
189+ 'str-chat__typing-indicator--typing' ,
190+ ) ,
191+ ) . toBe ( false ) ;
192+ } ) ;
193+
194+ it ( 'should not render TypingIndicator in thread if user is typing in main channel' , async ( ) => {
195+ const { container } = await renderComponent (
196+ { example : { user : 'test-user' } } ,
197+ true ,
198+ {
199+ client,
200+ channel,
201+ thread : { id : 'sample-thread' } ,
202+ } ,
203+ ) ;
204+
205+ expect (
206+ container . firstChild . classList . contains (
207+ 'str-chat__typing-indicator--typing' ,
208+ ) ,
209+ ) . toBe ( false ) ;
210+ } ) ;
211+
212+ it ( 'should not render TypingIndicator in thread if user is typing in another thread' , async ( ) => {
213+ const { container } = await renderComponent (
214+ { example : { parent_id : 'sample-thread-2' , user : 'test-user' } } ,
215+ true ,
216+ {
217+ client,
218+ channel,
219+ thread : { id : 'sample-thread' } ,
220+ } ,
221+ ) ;
222+
223+ expect (
224+ container . firstChild . classList . contains (
225+ 'str-chat__typing-indicator--typing' ,
226+ ) ,
227+ ) . toBe ( false ) ;
228+ } ) ;
229+ } ) ;
142230} ) ;
0 commit comments