Skip to content

Commit 6622c1f

Browse files
committed
chore: add test for the editing state as well
1 parent 118302d commit 6622c1f

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

package/src/components/MessageInput/__tests__/MessageInput.test.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22

33
import { Alert } from 'react-native';
44

55
import { act, cleanup, fireEvent, render, userEvent, waitFor } from '@testing-library/react-native';
66

7+
import { useMessagesContext } from '../../../contexts';
78
import * as AttachmentPickerUtils from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
89
import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider';
910
import { getOrCreateChannelApi } from '../../../mock-builders/api/getOrCreateChannel';
@@ -263,4 +264,42 @@ describe('MessageInput', () => {
263264
expect(queryByTestId('send-message-disallowed-indicator')).toBeTruthy();
264265
});
265266
});
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+
});
266305
});

0 commit comments

Comments
 (0)