Skip to content

Commit a689dd3

Browse files
git-babelAhyoungRyu
authored andcommitted
[CLNP-5914] Fix unit tests and UI error (#1267)
* Changelog * Fixed the broken unit tests of `GroupChannelListProvider` * Fixed the UI error when click `open in channel` in the other channel * Use `useDeepCompareEffect` in `ThreadProvider` and `GroupChannelListProvider`
1 parent bfd8141 commit a689dd3

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

src/modules/GroupChannelList/context/__tests__/GroupChannelListProvider.spec.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ describe('GroupChannelListProvider', () => {
4242
className: '',
4343
selectedChannelUrl: '',
4444
disableAutoSelect: false,
45-
allowProfileEdit: undefined,
46-
isTypingIndicatorEnabled: undefined,
47-
isMessageReceiptStatusEnabled: undefined,
45+
allowProfileEdit: true,
46+
isTypingIndicatorEnabled: false,
47+
isMessageReceiptStatusEnabled: false,
4848
onChannelSelect: expect.any(Function),
4949
onChannelCreated: expect.any(Function),
5050
onThemeChange: undefined,
@@ -87,11 +87,12 @@ describe('GroupChannelListProvider', () => {
8787
await act(async () => {
8888
result.current.updateState({ className: 'new-classname' });
8989
result.current.updateState({ disableAutoSelect: true });
90-
await waitFor(() => {
91-
const newState = result.current.state;
92-
expect(newState.className).toEqual('new-classname');
93-
expect(newState.disableAutoSelect).toEqual(true);
94-
});
90+
});
91+
92+
await waitFor(() => {
93+
const newState = result.current.state;
94+
expect(newState.className).toEqual('new-classname');
95+
expect(newState.disableAutoSelect).toEqual(true);
9596
});
9697
});
9798

src/modules/GroupChannelList/context/__tests__/useGroupChannelList.spec.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GroupChannelListProvider, useGroupChannelListContext } from '../GroupChannelListProvider';
1+
import { GroupChannelListProvider } from '../GroupChannelListProvider';
22
import { renderHook } from '@testing-library/react';
33
import React from 'react';
44
import { useGroupChannelList } from '../useGroupChannelList';
@@ -14,7 +14,12 @@ const mockState = {
1414
initialized: true,
1515
},
1616
},
17-
config: { logger: console },
17+
config: {
18+
logger: console,
19+
groupChannelList: {
20+
enableTypingIndicator: true,
21+
},
22+
},
1823
};
1924
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
2025
__esModule: true,
@@ -33,17 +38,12 @@ jest.mock('@sendbird/uikit-tools', () => ({
3338
useGroupChannelHandler: jest.fn(() => {}),
3439
}));
3540

36-
jest.mock('../GroupChannelListProvider', () => ({
37-
...jest.requireActual('../GroupChannelListProvider'),
38-
useGroupChannelListContext: jest.fn(),
39-
}));
40-
4141
const initialState = {
4242
className: '',
4343
selectedChannelUrl: '',
4444
disableAutoSelect: false,
45-
allowProfileEdit: false,
46-
isTypingIndicatorEnabled: false,
45+
allowProfileEdit: true,
46+
isTypingIndicatorEnabled: true,
4747
isMessageReceiptStatusEnabled: false,
4848
onChannelSelect: undefined,
4949
onChannelCreated: undefined,
@@ -59,14 +59,8 @@ const initialState = {
5959
loadMore: null,
6060
};
6161

62-
const mockStore = {
63-
getState: jest.fn(() => initialState),
64-
setState: jest.fn(),
65-
subscribe: jest.fn(() => jest.fn()),
66-
};
67-
6862
const wrapper = ({ children }) => (
69-
<GroupChannelListProvider onChannelSelect={jest.fn()} onChannelCreated={jest.fn()}>
63+
<GroupChannelListProvider>
7064
{children}
7165
</GroupChannelListProvider>
7266
);
@@ -78,15 +72,12 @@ describe('GroupChannelListProvider', () => {
7872
});
7973

8074
it('throws an error if used outside of GroupChannelListProvider', () => {
81-
(useGroupChannelListContext as jest.Mock).mockReturnValue(null);
82-
8375
expect(() => {
84-
renderHook(() => useGroupChannelList(), { wrapper });
76+
renderHook(() => useGroupChannelList());
8577
}).toThrow(new Error('useGroupChannelList must be used within a GroupChannelListProvider'));
8678
});
8779

8880
it('provide the correct initial state', () => {
89-
(useGroupChannelListContext as jest.Mock).mockReturnValue(mockStore);
9081
const { result } = renderHook(() => useGroupChannelList(), { wrapper });
9182

9283
expect(result.current.state).toEqual(expect.objectContaining(initialState));

src/modules/Thread/context/ThreadProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useStore } from '../../../hooks/useStore';
2323
import useSetCurrentUserId from './hooks/useSetCurrentUserId';
2424
import useThread from './useThread';
2525
import useSendbird from '../../../lib/Sendbird/context/hooks/useSendbird';
26+
import useDeepCompareEffect from '../../../hooks/useDeepCompareEffect';
2627

2728
export interface ThreadProviderProps extends
2829
Pick<UserProfileProviderProps, 'disableUserProfile' | 'renderUserProfile'> {
@@ -184,7 +185,7 @@ export const ThreadManager: React.FC<React.PropsWithChildren<ThreadProviderProps
184185
: new Map()
185186
), [currentChannel?.members]);
186187

187-
useEffect(() => {
188+
useDeepCompareEffect(() => {
188189
updateState({
189190
channelUrl,
190191
message,

0 commit comments

Comments
 (0)