Skip to content

Commit 3c2aa69

Browse files
committed
test: fix more tests and remove isValidMessage tests as its already handled on LLC
1 parent aadd78f commit 3c2aa69

File tree

4 files changed

+231
-218
lines changed

4 files changed

+231
-218
lines changed
Lines changed: 30 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22

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

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

7-
import { useMessagesContext } from '../../../contexts';
87
import * as AttachmentPickerUtils from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
98
import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider';
109

1110
import { initiateClientWithChannels } from '../../../mock-builders/api/initiateClientWithChannels';
12-
import {
13-
generateFileAttachment,
14-
generateImageAttachment,
15-
} from '../../../mock-builders/generator/attachment';
11+
1612
import { NativeHandlers } from '../../../native';
1713
import { AttachmentPickerSelectionBar } from '../../AttachmentPicker/components/AttachmentPickerSelectionBar';
1814
import { CameraSelectorIcon } from '../../AttachmentPicker/components/CameraSelectorIcon';
@@ -33,27 +29,8 @@ jest.spyOn(AttachmentPickerUtils, 'useAttachmentPickerContext').mockImplementati
3329
FileSelectorIcon,
3430
ImageSelectorIcon,
3531
openPicker: jest.fn(),
36-
selectedFiles: [
37-
generateFileAttachment({ name: 'Dummy.pdf', size: 500000000 }),
38-
generateFileAttachment({ name: 'Dummy.pdf', size: 600000000 }),
39-
],
40-
selectedImages: [
41-
generateImageAttachment({
42-
file: { height: 100, uri: 'https://picsum.photos/200/300', width: 100 },
43-
size: 500000000,
44-
uri: 'https://picsum.photos/200/300',
45-
}),
46-
generateImageAttachment({
47-
file: { height: 100, uri: 'https://picsum.photos/200/300', width: 100 },
48-
size: 600000000,
49-
uri: 'https://picsum.photos/200/300',
50-
}),
51-
],
5232
selectedPicker: 'images',
5333
setBottomInset: jest.fn(),
54-
setMaxNumberOfFiles: jest.fn(),
55-
setSelectedFiles: jest.fn(),
56-
setSelectedImages: jest.fn(),
5734
setSelectedPicker: jest.fn(),
5835
setTopInset: jest.fn(),
5936
})),
@@ -88,11 +65,15 @@ describe('MessageInput', () => {
8865
});
8966

9067
it('should render MessageInput', async () => {
91-
const openPicker = jest.fn();
92-
const closePicker = jest.fn();
93-
const attachmentValue = { closePicker, openPicker };
68+
const channelProps = { channel };
69+
70+
renderComponent({
71+
channelProps,
72+
client,
73+
props: {},
74+
});
9475

95-
const { getByTestId, queryByTestId, queryByText } = render(getComponent({ attachmentValue }));
76+
const { getByTestId, queryByTestId, queryByText } = screen;
9677

9778
fireEvent.press(getByTestId('attach-button'));
9879

@@ -106,15 +87,20 @@ describe('MessageInput', () => {
10687
});
10788

10889
it('should start the audio recorder on long press and cleanup on unmount', async () => {
109-
const props = {};
110-
const channelProps = { audioRecordingEnabled: true, channel };
90+
jest.clearAllMocks();
11191

112-
renderComponent({ channelProps, client, props });
92+
const userBot = userEvent.setup();
93+
94+
renderComponent({
95+
channelProps: { audioRecordingEnabled: true, channel },
96+
client,
97+
props: {},
98+
});
11399

114100
const { queryByTestId, unmount } = screen;
115101

116-
await act(() => {
117-
userEvent.longPress(queryByTestId('audio-button'), { duration: 1000 });
102+
act(() => {
103+
userBot.longPress(queryByTestId('audio-button'), { duration: 1000 });
118104
});
119105

120106
await waitFor(() => {
@@ -136,15 +122,20 @@ describe('MessageInput', () => {
136122
});
137123

138124
it('should trigger an alert if a normal press happened on audio recording', async () => {
139-
const props = {};
140-
const channelProps = { audioRecordingEnabled: true, channel };
125+
jest.clearAllMocks();
141126

142-
renderComponent({ channelProps, client, props });
127+
const userBot = userEvent.setup();
128+
129+
renderComponent({
130+
channelProps: { audioRecordingEnabled: true, channel },
131+
client,
132+
props: {},
133+
});
143134

144135
const { queryByTestId } = screen;
145136

146-
await act(() => {
147-
userEvent.press(queryByTestId('audio-button'));
137+
act(() => {
138+
userBot.press(queryByTestId('audio-button'));
148139
});
149140

150141
await waitFor(() => {
@@ -156,106 +147,4 @@ describe('MessageInput', () => {
156147
expect(Alert.alert).toHaveBeenCalledWith('Hold to start recording.');
157148
});
158149
});
159-
160-
it('should render the SendMessageDisallowedIndicator if the send-message capability is not present', async () => {
161-
const props = {};
162-
const channelProps = { audioRecordingEnabled: true, channel };
163-
164-
renderComponent({ channelProps, client, props });
165-
166-
const { queryByTestId } = screen;
167-
168-
await waitFor(() => {
169-
expect(queryByTestId('send-message-disallowed-indicator')).toBeNull();
170-
});
171-
172-
act(() => {
173-
client.dispatchEvent({
174-
cid: channel.data.cid,
175-
own_capabilities: channel.data.own_capabilities.filter(
176-
(capability) => capability !== 'send-message',
177-
),
178-
type: 'capabilities.changed',
179-
});
180-
});
181-
182-
await waitFor(() => {
183-
expect(queryByTestId('send-message-disallowed-indicator')).toBeTruthy();
184-
});
185-
});
186-
187-
it('should not render the SendMessageDisallowedIndicator if the channel is frozen and the send-message capability is present', async () => {
188-
const props = {};
189-
const channelProps = { channel };
190-
191-
renderComponent({ channelProps, client, props });
192-
193-
const { queryByTestId } = screen;
194-
195-
await waitFor(() => {
196-
expect(queryByTestId('send-message-disallowed-indicator')).toBeNull();
197-
});
198-
});
199-
200-
it('should render the SendMessageDisallowedIndicator in a frozen channel only if the send-message capability is not present', async () => {
201-
const props = {};
202-
const channelProps = { channel };
203-
204-
renderComponent({ channelProps, client, props });
205-
206-
const { queryByTestId } = screen;
207-
208-
act(() => {
209-
client.dispatchEvent({
210-
channel: {
211-
...channel.data,
212-
own_capabilities: channel.data.own_capabilities.filter(
213-
(capability) => capability !== 'send-message',
214-
),
215-
},
216-
cid: channel.data.cid,
217-
type: 'channel.updated',
218-
});
219-
});
220-
221-
await waitFor(() => {
222-
expect(queryByTestId('send-message-disallowed-indicator')).toBeTruthy();
223-
});
224-
});
225-
226-
const EditingStateMessageInput = () => {
227-
const { setEditingState } = useMessagesContext();
228-
useEffect(() => {
229-
setEditingState({ id: 'some-message-id' });
230-
}, [setEditingState]);
231-
return <MessageInput />;
232-
};
233-
234-
it('should not render the SendMessageDisallowedIndicator if we are editing a message, regardless of capabilities', async () => {
235-
const { queryByTestId } = render(
236-
<Chat client={client}>
237-
<Channel audioRecordingEnabled channel={channel}>
238-
<EditingStateMessageInput />
239-
</Channel>
240-
</Chat>,
241-
);
242-
243-
await waitFor(() => {
244-
expect(queryByTestId('send-message-disallowed-indicator')).toBeNull();
245-
});
246-
247-
act(() => {
248-
client.dispatchEvent({
249-
cid: channel.data.cid,
250-
own_capabilities: channel.data.own_capabilities.filter(
251-
(capability) => capability !== 'send-message',
252-
),
253-
type: 'capabilities.changed',
254-
});
255-
});
256-
257-
await waitFor(() => {
258-
expect(queryByTestId('send-message-disallowed-indicator')).toBeNull();
259-
});
260-
});
261150
});

0 commit comments

Comments
 (0)