@@ -69,6 +69,15 @@ describe('ChannelPreview', () => {
6969 ) ;
7070 } ;
7171
72+ const generateChannelWrapper = ( overrides : Record < string , unknown > ) =>
73+ generateChannel ( {
74+ countUnread : jest . fn ( ) . mockReturnValue ( 0 ) ,
75+ initialized : true ,
76+ lastMessage : jest . fn ( ) . mockReturnValue ( generateMessage ( ) ) ,
77+ muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
78+ ...overrides ,
79+ } ) ;
80+
7281 const useInitializeChannel = async ( c : GetOrCreateChannelApiParams ) => {
7382 useMockedApis ( chatClient , [ getOrCreateChannelApi ( c ) ] ) ;
7483
@@ -89,9 +98,8 @@ describe('ChannelPreview', () => {
8998 it ( "should not update the unread count if the event's cid does not match the channel's cid" , async ( ) => {
9099 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
91100
92- const c = generateChannel ( {
101+ const c = generateChannelWrapper ( {
93102 countUnread : jest . fn ( ) . mockReturnValue ( 10 ) ,
94- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
95103 on : channelOnMock ,
96104 } ) ;
97105
@@ -117,9 +125,8 @@ describe('ChannelPreview', () => {
117125 it ( 'should update the unread count to 0' , async ( ) => {
118126 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
119127
120- const c = generateChannel ( {
128+ const c = generateChannelWrapper ( {
121129 countUnread : jest . fn ( ) . mockReturnValue ( 10 ) ,
122- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
123130 on : channelOnMock ,
124131 } ) ;
125132
@@ -147,9 +154,7 @@ describe('ChannelPreview', () => {
147154 it ( "should not update the unread count if the event's cid is undefined" , async ( ) => {
148155 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
149156
150- const c = generateChannel ( {
151- countUnread : jest . fn ( ) . mockReturnValue ( 0 ) ,
152- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
157+ const c = generateChannelWrapper ( {
153158 on : channelOnMock ,
154159 } ) ;
155160
@@ -182,9 +187,7 @@ describe('ChannelPreview', () => {
182187 it ( "should not update the unread count if the event's cid does not match the channel's cid" , async ( ) => {
183188 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
184189
185- const c = generateChannel ( {
186- countUnread : jest . fn ( ) . mockReturnValue ( 0 ) ,
187- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
190+ const c = generateChannelWrapper ( {
188191 on : channelOnMock ,
189192 } ) ;
190193
@@ -217,9 +220,7 @@ describe('ChannelPreview', () => {
217220 it ( "should not update the unread count if the event's user id does not match the client's user id" , async ( ) => {
218221 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
219222
220- const c = generateChannel ( {
221- countUnread : jest . fn ( ) . mockReturnValue ( 0 ) ,
222- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
223+ const c = generateChannelWrapper ( {
223224 on : channelOnMock ,
224225 } ) ;
225226
@@ -255,12 +256,10 @@ describe('ChannelPreview', () => {
255256 await useInitializeChannel ( c ) ;
256257 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
257258
258- const testChannel = {
259+ const testChannel = generateChannelWrapper ( {
259260 ...channel ,
260- countUnread : jest . fn ( ) . mockReturnValue ( 0 ) ,
261- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
262261 on : channelOnMock ,
263- } ;
262+ } ) ;
264263
265264 const { getByTestId } = render ( < TestComponent /> ) ;
266265
@@ -291,9 +290,9 @@ describe('ChannelPreview', () => {
291290 it ( 'should update the unread count to 0 if the channel is muted' , async ( ) => {
292291 const channelOnMock = jest . fn ( ) . mockReturnValue ( { unsubscribe : jest . fn ( ) } ) ;
293292
294- const c = generateChannel ( {
293+ const c = generateChannelWrapper ( {
295294 countUnread : jest . fn ( ) . mockReturnValue ( 10 ) ,
296- muteStatus : jest . fn ( ) . mockReturnValue ( { muted : false } ) ,
295+ muteStatus : jest . fn ( ) . mockReturnValue ( { muted : true } ) ,
297296 on : channelOnMock ,
298297 } ) ;
299298
@@ -304,7 +303,7 @@ describe('ChannelPreview', () => {
304303 await waitFor ( ( ) => getByTestId ( 'channel-id' ) ) ;
305304
306305 await waitFor ( ( ) => {
307- expect ( getByTestId ( 'unread-count' ) ) . toHaveTextContent ( '10 ' ) ;
306+ expect ( getByTestId ( 'unread-count' ) ) . toHaveTextContent ( '0 ' ) ;
308307 } ) ;
309308
310309 act ( ( ) => {
0 commit comments