|
1 | | -import React from 'react'; |
| 1 | +import React, { useEffect } from 'react'; |
2 | 2 |
|
3 | 3 | import { Alert } from 'react-native'; |
4 | 4 |
|
5 | 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'; |
@@ -263,4 +264,42 @@ describe('MessageInput', () => { |
263 | 264 | expect(queryByTestId('send-message-disallowed-indicator')).toBeTruthy(); |
264 | 265 | }); |
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 | + }); |
266 | 305 | }); |
0 commit comments