Skip to content

Commit 4042ec1

Browse files
committed
test: fix more broken tests
1 parent ba4cb1f commit 4042ec1

File tree

21 files changed

+313
-150
lines changed

21 files changed

+313
-150
lines changed

package/src/__tests__/offline-support/optimistic-update.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,20 @@ export const OptimisticUpdates = () => {
270270
it('pending task should exist if sendMessage request fails', async () => {
271271
const newMessage = generateMessage();
272272

273+
jest.spyOn(channel.messageComposer, 'compose').mockResolvedValue({
274+
localMessage: newMessage,
275+
message: newMessage,
276+
options: {},
277+
});
278+
273279
render(
274280
<Chat client={chatClient} enableOfflineSupport>
275-
<Channel channel={channel} initialValue={newMessage.text}>
281+
<Channel channel={channel}>
276282
<CallbackEffectWithContext
277283
callback={async ({ sendMessage }) => {
278284
useMockedApis(chatClient, [erroredPostApi()]);
279285
try {
280-
await sendMessage({ customMessageData: newMessage });
286+
await sendMessage();
281287
} catch (e) {
282288
// do nothing
283289
}
@@ -446,6 +452,12 @@ export const OptimisticUpdates = () => {
446452
it('send message pending task should be executed after connection is recovered', async () => {
447453
const newMessage = generateMessage();
448454

455+
jest.spyOn(channel.messageComposer, 'compose').mockResolvedValue({
456+
localMessage: newMessage,
457+
message: newMessage,
458+
options: {},
459+
});
460+
449461
// initialValue is needed as a prop to trick the message input ctx into thinking
450462
// we are sending a message.
451463
render(
@@ -455,7 +467,7 @@ export const OptimisticUpdates = () => {
455467
callback={async ({ sendMessage }) => {
456468
useMockedApis(chatClient, [erroredPostApi()]);
457469
try {
458-
await sendMessage({ customMessageData: newMessage });
470+
await sendMessage();
459471
} catch (e) {
460472
// do nothing
461473
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@ import {
1010
waitFor,
1111
} from '@testing-library/react-native';
1212

13+
import { OverlayProvider } from '../../../contexts';
1314
import { initiateClientWithChannels } from '../../../mock-builders/api/initiateClientWithChannels';
1415
import { Channel } from '../../Channel/Channel';
1516
import { Chat } from '../../Chat/Chat';
1617
import { AutoCompleteInput } from '../AutoCompleteInput';
1718

1819
const renderComponent = ({ channelProps, client, props }) => {
1920
return render(
20-
<Chat client={client}>
21-
<Channel {...channelProps}>
22-
<AutoCompleteInput {...props} />
23-
</Channel>
24-
</Chat>,
21+
<OverlayProvider>
22+
<Chat client={client}>
23+
<Channel {...channelProps}>
24+
<AutoCompleteInput {...props} />
25+
</Channel>
26+
</Chat>
27+
</OverlayProvider>,
2528
);
2629
};
2730

2831
describe('AutoCompleteInput', () => {
2932
let client;
3033
let channel;
3134

32-
beforeAll(async () => {
35+
beforeEach(async () => {
3336
const { client: chatClient, channels } = await initiateClientWithChannels();
3437
client = chatClient;
3538
channel = channels[0];

package/src/components/AutoCompleteInput/__tests__/AutoCompleteSuggestionList.test.js

Whitespace-only changes.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ const ContextConsumer = ({ context, fn }) => {
4848
return <View testID='children' />;
4949
};
5050

51+
const channelType = 'messaging';
52+
const channelId = 'test-channel';
53+
const channelCid = `${channelType}:${channelId}`;
5154
let chatClient;
5255
let channel;
5356

5457
const user = generateUser({ id: 'id', name: 'name' });
55-
const messages = [generateMessage({ user })];
58+
const messages = [generateMessage({ cid: channelCid, user })];
5659

5760
const renderComponent = (props = {}, callback = () => {}, context = ChannelContext) =>
5861
render(
@@ -70,8 +73,11 @@ describe('Channel', () => {
7073
beforeEach(async () => {
7174
const members = [generateMember({ user })];
7275
const mockedChannel = generateChannelResponse({
76+
cid: channelCid,
77+
id: channelId,
7378
members,
7479
messages,
80+
type: channelType,
7581
});
7682
chatClient = await getTestClientWithUser(user);
7783
useMockedApis(chatClient, [getOrCreateChannelApi(mockedChannel)]);

package/src/components/Message/MessageSimple/__tests__/MessageContent.test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getTestClientWithUser } from '../../../../mock-builders/mock';
1616
import { Channel } from '../../../Channel/Channel';
1717
import { Chat } from '../../../Chat/Chat';
1818
import { Message } from '../../Message';
19-
import { MessageContent } from '../../MessageSimple/MessageContent';
19+
import { MessageContent } from '../MessageContent';
2020

2121
describe('MessageContent', () => {
2222
let channel;
@@ -39,13 +39,11 @@ describe('MessageContent', () => {
3939

4040
renderMessage = (options) =>
4141
render(
42-
<ChannelsStateProvider>
43-
<Chat client={chatClient}>
44-
<Channel channel={channel}>
45-
<Message groupStyles={['bottom']} {...options} />
46-
</Channel>
47-
</Chat>
48-
</ChannelsStateProvider>,
42+
<Chat client={chatClient}>
43+
<Channel channel={channel}>
44+
<Message groupStyles={['bottom']} {...options} />
45+
</Channel>
46+
</Chat>,
4947
);
5048
});
5149

package/src/components/Message/MessageSimple/__tests__/MessageSimple.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ describe('MessageSimple', () => {
160160
renderMessage({ groupStyles: ['top'], message });
161161

162162
await waitFor(() => {
163-
console.log(screen.getByTestId('message-simple-wrapper').props.style[1]);
164163
expect(screen.getByTestId('message-simple-wrapper').props.style[1]).toMatchObject({});
165164
});
166165
});
@@ -185,7 +184,6 @@ describe('MessageSimple', () => {
185184
renderMessage({ message });
186185

187186
await waitFor(() => {
188-
console.log(screen.getByTestId('message-content-wrapper').props.style);
189187
expect(screen.getByTestId('message-content-wrapper').props.style[2]).toMatchObject({
190188
borderWidth: 0,
191189
});
@@ -199,7 +197,6 @@ describe('MessageSimple', () => {
199197
renderMessage({ message });
200198

201199
await waitFor(() => {
202-
console.log(screen.getByTestId('message-content-wrapper').props.style);
203200
expect(screen.getByTestId('message-content-wrapper').props.style[2]).toMatchObject({
204201
borderWidth: 0,
205202
});

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { act, render, screen, userEvent, waitFor } from '@testing-library/react-native';
3+
import { act, cleanup, render, screen, userEvent, waitFor } from '@testing-library/react-native';
44

55
import { OverlayProvider } from '../../../contexts';
66

@@ -26,12 +26,17 @@ describe('AttachButton', () => {
2626
let client;
2727
let channel;
2828

29-
beforeAll(async () => {
29+
beforeEach(async () => {
3030
const { client: chatClient, channels } = await initiateClientWithChannels();
3131
client = chatClient;
3232
channel = channels[0];
3333
});
3434

35+
afterEach(() => {
36+
jest.clearAllMocks();
37+
cleanup();
38+
});
39+
3540
it('should render an disabled AttachButton', async () => {
3641
const handleOnPress = jest.fn();
3742
const channelProps = { channel };

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import React from 'react';
22

3-
import { render, screen, userEvent, waitFor } from '@testing-library/react-native';
3+
import { cleanup, render, screen, userEvent, waitFor } from '@testing-library/react-native';
44

55
import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
66
import { ProgressIndicatorTypes } from '../../../utils/utils';
77

88
import { AttachmentUploadProgressIndicator } from '../components/AttachmentPreview/AttachmentUploadProgressIndicator';
99

1010
describe('AttachmentUploadProgressIndicator', () => {
11+
afterEach(() => {
12+
jest.clearAllMocks();
13+
cleanup();
14+
});
15+
1116
it('should render an inactive AttachmentUploadProgressIndicator', async () => {
1217
const action = jest.fn();
1318

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react-native';
3+
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react-native';
44

55
import { OverlayProvider } from '../../../contexts';
66
import { initiateClientWithChannels } from '../../../mock-builders/api/initiateClientWithChannels';
@@ -44,13 +44,15 @@ describe('AudioAttachmentUploadPreview render', () => {
4444
let client;
4545
let channel;
4646

47-
beforeAll(async () => {
47+
beforeEach(async () => {
4848
const { client: chatClient, channels } = await initiateClientWithChannels();
4949
client = chatClient;
5050
channel = channels[0];
5151
});
5252

5353
afterEach(() => {
54+
jest.clearAllMocks();
55+
cleanup();
5456
act(() => {
5557
channel.messageComposer.attachmentManager.initState();
5658
});

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { act, render, screen, userEvent, waitFor } from '@testing-library/react-native';
3+
import { act, cleanup, render, screen, userEvent, waitFor } from '@testing-library/react-native';
44

55
import { OverlayProvider } from '../../../contexts';
66

@@ -25,12 +25,17 @@ describe('CommandsButton', () => {
2525
let client;
2626
let channel;
2727

28-
beforeAll(async () => {
28+
beforeEach(async () => {
2929
const { client: chatClient, channels } = await initiateClientWithChannels();
3030
client = chatClient;
3131
channel = channels[0];
3232
});
3333

34+
afterEach(() => {
35+
jest.clearAllMocks();
36+
cleanup();
37+
});
38+
3439
it('should render component', async () => {
3540
const props = {};
3641
renderComponent({ channel, client, props });

0 commit comments

Comments
 (0)