|
1 |
| -import React from 'react'; |
| 1 | +import React, { useEffect } from 'react'; |
2 | 2 |
|
3 | 3 | import { Alert } from 'react-native';
|
4 | 4 |
|
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'; |
6 | 6 |
|
| 7 | +import { useMessagesContext } from '../../../contexts'; |
7 | 8 | import * as AttachmentPickerUtils from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
|
8 | 9 | import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider';
|
9 | 10 | import { getOrCreateChannelApi } from '../../../mock-builders/api/getOrCreateChannel';
|
@@ -188,4 +189,117 @@ describe('MessageInput', () => {
|
188 | 189 | expect(Alert.alert).toHaveBeenCalledWith('Hold to start recording.');
|
189 | 190 | });
|
190 | 191 | });
|
| 192 | + |
| 193 | + it('should render the SendMessageDisallowedIndicator if the send-message capability is not present', async () => { |
| 194 | + await initializeChannel(generateChannelResponse()); |
| 195 | + |
| 196 | + const { queryByTestId } = render( |
| 197 | + <Chat client={chatClient}> |
| 198 | + <Channel audioRecordingEnabled channel={channel}> |
| 199 | + <MessageInput /> |
| 200 | + </Channel> |
| 201 | + </Chat>, |
| 202 | + ); |
| 203 | + |
| 204 | + await waitFor(() => { |
| 205 | + expect(queryByTestId('send-message-disallowed-indicator')).toBeNull(); |
| 206 | + }); |
| 207 | + |
| 208 | + act(() => { |
| 209 | + chatClient.dispatchEvent({ |
| 210 | + cid: channel.data.cid, |
| 211 | + own_capabilities: channel.data.own_capabilities.filter( |
| 212 | + (capability) => capability !== 'send-message', |
| 213 | + ), |
| 214 | + type: 'capabilities.changed', |
| 215 | + }); |
| 216 | + }); |
| 217 | + |
| 218 | + await waitFor(() => { |
| 219 | + expect(queryByTestId('send-message-disallowed-indicator')).toBeTruthy(); |
| 220 | + }); |
| 221 | + }); |
| 222 | + |
| 223 | + it('should not render the SendMessageDisallowedIndicator if the channel is frozen and the send-message capability is present', async () => { |
| 224 | + await initializeChannel(generateChannelResponse({ channel: { frozen: true } })); |
| 225 | + |
| 226 | + const { queryByTestId } = render( |
| 227 | + <Chat client={chatClient}> |
| 228 | + <Channel audioRecordingEnabled channel={channel}> |
| 229 | + <MessageInput /> |
| 230 | + </Channel> |
| 231 | + </Chat>, |
| 232 | + ); |
| 233 | + |
| 234 | + await waitFor(() => { |
| 235 | + expect(queryByTestId('send-message-disallowed-indicator')).toBeNull(); |
| 236 | + }); |
| 237 | + }); |
| 238 | + |
| 239 | + it('should render the SendMessageDisallowedIndicator in a frozen channel only if the send-message capability is not present', async () => { |
| 240 | + await initializeChannel(generateChannelResponse({ channel: { frozen: true } })); |
| 241 | + |
| 242 | + const { queryByTestId } = render( |
| 243 | + <Chat client={chatClient}> |
| 244 | + <Channel audioRecordingEnabled channel={channel}> |
| 245 | + <MessageInput /> |
| 246 | + </Channel> |
| 247 | + </Chat>, |
| 248 | + ); |
| 249 | + |
| 250 | + act(() => { |
| 251 | + chatClient.dispatchEvent({ |
| 252 | + channel: { |
| 253 | + ...channel.data, |
| 254 | + own_capabilities: channel.data.own_capabilities.filter( |
| 255 | + (capability) => capability !== 'send-message', |
| 256 | + ), |
| 257 | + }, |
| 258 | + cid: channel.data.cid, |
| 259 | + type: 'channel.updated', |
| 260 | + }); |
| 261 | + }); |
| 262 | + |
| 263 | + await waitFor(() => { |
| 264 | + expect(queryByTestId('send-message-disallowed-indicator')).toBeTruthy(); |
| 265 | + }); |
| 266 | + }); |
| 267 | + |
| 268 | + const EditingStateMessageInput = () => { |
| 269 | + const { setEditingState } = useMessagesContext(); |
| 270 | + useEffect(() => { |
| 271 | + setEditingState({ id: 'some-message-id' }); |
| 272 | + }, []); |
| 273 | + return <MessageInput />; |
| 274 | + }; |
| 275 | + |
| 276 | + it('should not render the SendMessageDisallowedIndicator if we are editing a message, regardless of capabilities', async () => { |
| 277 | + await initializeChannel(generateChannelResponse()); |
| 278 | + |
| 279 | + const { queryByTestId } = render( |
| 280 | + <Chat client={chatClient}> |
| 281 | + <Channel audioRecordingEnabled channel={channel}> |
| 282 | + <EditingStateMessageInput /> |
| 283 | + </Channel> |
| 284 | + </Chat>, |
| 285 | + ); |
| 286 | + |
| 287 | + await waitFor(() => { |
| 288 | + expect(queryByTestId('send-message-disallowed-indicator')).toBeNull(); |
| 289 | + }); |
| 290 | + |
| 291 | + act(() => { |
| 292 | + chatClient.dispatchEvent({ |
| 293 | + cid: channel.data.cid, |
| 294 | + own_capabilities: channel.data.own_capabilities.filter( |
| 295 | + (capability) => capability !== 'send-message', |
| 296 | + ), |
| 297 | + type: 'capabilities.changed', |
| 298 | + }); |
| 299 | + }); |
| 300 | + |
| 301 | + await waitFor(() => { |
| 302 | + expect(queryByTestId('send-message-disallowed-indicator')).toBeNull(); |
| 303 | + }); |
| 304 | + }); |
191 | 305 | });
|
0 commit comments