Skip to content

Commit cf4bc69

Browse files
committed
fix: flaky tests, netinfo issues and bump more versions
1 parent b79a24d commit cf4bc69

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"@op-engineering/op-sqlite": "^11.4.8",
108108
"@react-native-community/eslint-config": "3.2.0",
109109
"@react-native-community/eslint-plugin": "1.3.0",
110-
"@react-native-community/netinfo": "^11.3.2",
110+
"@react-native-community/netinfo": "^11.4.1",
111111
"@react-native/babel-preset": "0.78.0",
112112
"@testing-library/jest-native": "^5.4.3",
113113
"@testing-library/react-native": "13.1.0",

package/src/components/ChannelPreview/__tests__/ChannelPreview.test.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ describe('ChannelPreview', () => {
124124

125125
it('should update the unread count to 0', async () => {
126126
const channelOnMock = jest.fn().mockReturnValue({ unsubscribe: jest.fn() });
127+
const countUnreadMock = jest.fn();
128+
129+
countUnreadMock.mockReturnValue(10);
127130

128131
const c = generateChannelWrapper({
129-
countUnread: jest.fn().mockReturnValue(10),
132+
countUnread: countUnreadMock,
130133
on: channelOnMock,
131134
});
132135

@@ -140,6 +143,8 @@ describe('ChannelPreview', () => {
140143
expect(getByTestId('unread-count')).toHaveTextContent('10');
141144
});
142145

146+
countUnreadMock.mockReturnValue(0);
147+
143148
act(() => {
144149
dispatchNotificationMarkRead(chatClient, channel || {});
145150
});
@@ -288,20 +293,27 @@ describe('ChannelPreview', () => {
288293
});
289294

290295
it('should update the unread count to 0 if the channel is muted', async () => {
291-
const channelOnMock = jest.fn().mockReturnValue({ unsubscribe: jest.fn() });
296+
const someOtherUser = generateUser({ id: 'not-me' });
292297

293-
const c = generateChannelWrapper({
294-
countUnread: jest.fn().mockReturnValue(10),
295-
muteStatus: jest.fn().mockReturnValue({ muted: true }),
296-
on: channelOnMock,
297-
});
298+
const c = generateChannelResponse();
299+
await useInitializeChannel(c);
298300

299-
channel = c as unknown as Channel;
301+
channel.muteStatus = jest.fn().mockReturnValue({ muted: true });
300302

301303
const { getByTestId } = render(<TestComponent />);
302304

303305
await waitFor(() => getByTestId('channel-id'));
304306

307+
for (let i = 0; i < 10; i++) {
308+
const message = generateMessage({
309+
user: someOtherUser,
310+
});
311+
act(() => {
312+
dispatchMessageNewEvent(chatClient, message, channel || {});
313+
});
314+
}
315+
await waitFor(() => getByTestId('channel-id'));
316+
305317
await waitFor(() => {
306318
expect(getByTestId('unread-count')).toHaveTextContent('0');
307319
});
@@ -319,7 +331,7 @@ describe('ChannelPreview', () => {
319331
});
320332

321333
await waitFor(() => {
322-
expect(getByTestId('unread-count')).toHaveTextContent('0');
334+
expect(getByTestId('unread-count')).toHaveTextContent('5');
323335
});
324336
});
325337

package/src/components/MessageList/NetworkDownIndicator.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
33

44
import { useChannelContext } from '../../contexts/channelContext/ChannelContext';
@@ -33,16 +33,14 @@ export const NetworkDownIndicator = () => {
3333
} = useTheme();
3434
const { t } = useTranslationContext();
3535

36-
const getText = () => {
36+
const indicatorText = useMemo(() => {
3737
if (!isOnline) {
3838
return t('Reconnecting...');
3939
} else if (error) {
4040
return t('Error loading messages for this channel...');
4141
}
4242
return '';
43-
};
44-
45-
const indicatorText = getText();
43+
}, [error, isOnline, t]);
4644

4745
if (!indicatorText) {
4846
return null;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import { Chat } from '../../Chat/Chat';
2323
import { MessageList } from '../MessageList';
2424

2525
describe('MessageList', () => {
26-
afterEach(cleanup);
26+
afterEach(() => {
27+
cleanup();
28+
jest.clearAllMocks();
29+
});
2730

2831
it('should add new message at bottom of the list', async () => {
2932
const user1 = generateUser();
@@ -185,6 +188,10 @@ describe('MessageList', () => {
185188
);
186189

187190
await waitFor(() => {
191+
const all = queryAllByTestId('error-notification');
192+
if (all.length > 0) {
193+
console.log('FIBER2 NODE: ', all[0]._fiber.stateNode.children);
194+
}
188195
expect(queryAllByTestId('error-notification')).toHaveLength(0);
189196
expect(getByTestId('message-deleted')).toBeTruthy();
190197
expect(queryByTestId('only-visible-to-you')).toBeNull();

package/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@
16811681
resolved "https://registry.yarnpkg.com/@react-native-community/eslint-plugin/-/eslint-plugin-1.3.0.tgz#9e558170c106bbafaa1ef502bd8e6d4651012bf9"
16821682
integrity sha512-+zDZ20NUnSWghj7Ku5aFphMzuM9JulqCW+aPXT6IfIXFbb8tzYTTOSeRFOtuekJ99ibW2fUCSsjuKNlwDIbHFg==
16831683

1684-
"@react-native-community/netinfo@^11.3.2":
1684+
"@react-native-community/netinfo@^11.4.1":
16851685
version "11.4.1"
16861686
resolved "https://registry.yarnpkg.com/@react-native-community/netinfo/-/netinfo-11.4.1.tgz#a3c247aceab35f75dd0aa4bfa85d2be5a4508688"
16871687
integrity sha512-B0BYAkghz3Q2V09BF88RA601XursIEA111tnc2JOaN7axJWmNefmfjZqw/KdSxKZp7CZUuPpjBmz/WCR9uaHYg==

0 commit comments

Comments
 (0)