@@ -2,7 +2,7 @@ import React from 'react';
22
33import { Alert } from 'react-native' ;
44
5- import { cleanup , fireEvent , render , userEvent , waitFor } from '@testing-library/react-native' ;
5+ import { act , cleanup , fireEvent , render , userEvent , waitFor } from '@testing-library/react-native' ;
66
77import * as AttachmentPickerUtils from '../../../contexts/attachmentPickerContext/AttachmentPickerContext' ;
88import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider' ;
@@ -188,4 +188,83 @@ describe('MessageInput', () => {
188188 expect ( Alert . alert ) . toHaveBeenCalledWith ( 'Hold to start recording.' ) ;
189189 } ) ;
190190 } ) ;
191+
192+ it ( 'should render the SendMessageDisallowedIndicator if the send-message capability is not present' , async ( ) => {
193+ await initializeChannel ( generateChannelResponse ( ) ) ;
194+
195+ const { queryByTestId } = render (
196+ < Chat client = { chatClient } >
197+ < Channel audioRecordingEnabled channel = { channel } >
198+ < MessageInput />
199+ </ Channel >
200+ </ Chat > ,
201+ ) ;
202+
203+ await waitFor ( ( ) => {
204+ expect ( queryByTestId ( 'send-message-disallowed-indicator' ) ) . toBeNull ( ) ;
205+ } ) ;
206+
207+ act ( ( ) => {
208+ chatClient . dispatchEvent ( {
209+ cid : channel . data . cid ,
210+ own_capabilities : channel . data . own_capabilities . filter (
211+ ( capability ) => capability !== 'send-message' ,
212+ ) ,
213+ type : 'capabilities.changed' ,
214+ } ) ;
215+ } ) ;
216+
217+ await waitFor ( ( ) => {
218+ expect ( queryByTestId ( 'send-message-disallowed-indicator' ) ) . toBeTruthy ( ) ;
219+ } ) ;
220+ } ) ;
221+
222+ it ( 'should not render the SendMessageDisallowedIndicator if the channel is frozen and the send-message capability is present' , async ( ) => {
223+ await initializeChannel ( generateChannelResponse ( { channel : { frozen : true } } ) ) ;
224+
225+ const { queryByTestId } = render (
226+ < Chat client = { chatClient } >
227+ < Channel audioRecordingEnabled channel = { channel } >
228+ < MessageInput />
229+ </ Channel >
230+ </ Chat > ,
231+ ) ;
232+
233+ await waitFor ( ( ) => {
234+ expect ( queryByTestId ( 'send-message-disallowed-indicator' ) ) . toBeNull ( ) ;
235+ } ) ;
236+ } ) ;
237+
238+ it ( 'should render the SendMessageDisallowedIndicator only if the send-message capability is not present' , async ( ) => {
239+ await initializeChannel ( generateChannelResponse ( { channel : { frozen : true } } ) ) ;
240+
241+ const { queryByTestId } = render (
242+ < Chat client = { chatClient } >
243+ < Channel audioRecordingEnabled channel = { channel } >
244+ < MessageInput />
245+ </ Channel >
246+ </ Chat > ,
247+ ) ;
248+
249+ await waitFor ( ( ) => {
250+ expect ( queryByTestId ( 'send-message-disallowed-indicator' ) ) . toBeNull ( ) ;
251+ } ) ;
252+
253+ act ( ( ) => {
254+ chatClient . dispatchEvent ( {
255+ channel : {
256+ ...channel . data ,
257+ own_capabilities : channel . data . own_capabilities . filter (
258+ ( capability ) => capability !== 'send-message' ,
259+ ) ,
260+ } ,
261+ cid : channel . data . cid ,
262+ type : 'channel.updated' ,
263+ } ) ;
264+ } ) ;
265+
266+ await waitFor ( ( ) => {
267+ expect ( queryByTestId ( 'send-message-disallowed-indicator' ) ) . toBeTruthy ( ) ;
268+ } ) ;
269+ } ) ;
191270} ) ;
0 commit comments