Skip to content

Commit 5890933

Browse files
committed
used useSendbird for mocking instead of useSendbirdStateContext
1 parent 21a625d commit 5890933

File tree

6 files changed

+37
-45
lines changed

6 files changed

+37
-45
lines changed

src/modules/ChannelSettings/__test__/ChannelSettings.migration.spec.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import { render, renderHook, screen } from '@testing-library/react';
33

4-
import { ChannelSettingsContextProps, ChannelSettingsProvider, useChannelSettingsContext } from '../context/ChannelSettingsProvider';
4+
import type { ChannelSettingsContextProps } from '../context/types';
5+
import { ChannelSettingsProvider, useChannelSettingsContext } from '../context/ChannelSettingsProvider';
56
import { match } from 'ts-pattern';
67

78
const mockState = {
@@ -18,14 +19,11 @@ const mockState = {
1819
},
1920
},
2021
};
21-
22-
jest.mock('../../../hooks/useSendbirdStateContext', () => ({
23-
__esModule: true,
24-
default: jest.fn(() => mockState),
25-
}));
26-
jest.mock('../../../lib/Sendbird', () => ({
22+
const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
23+
jest.mock('../../../lib/Sendbird/context/hooks/useSendbird', () => ({
2724
__esModule: true,
28-
useSendbirdStateContext: jest.fn(() => mockState),
25+
default: jest.fn(() => ({ state: mockState, actions: mockActions })),
26+
useSendbird: jest.fn(() => ({ state: mockState, actions: mockActions })),
2927
}));
3028

3129
const mockProps: ChannelSettingsContextProps = {

src/modules/CreateChannel/context/__tests__/CreateChannel.migration.spec.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
useCreateChannelContext,
88
} from '../CreateChannelProvider';
99

10-
const mockSendbirdStateContext = {
10+
const mockState = {
1111
stores: {
1212
userStore: {
1313
user: {
@@ -34,16 +34,12 @@ const mockSendbirdStateContext = {
3434
},
3535
isOnline: true,
3636
},
37-
};
38-
39-
jest.mock('../../../../hooks/useSendbirdStateContext', () => ({
40-
__esModule: true,
41-
default: () => mockSendbirdStateContext,
42-
}));
37+
};const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
4338

44-
jest.mock('../../../../lib/Sendbird', () => ({
39+
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
4540
__esModule: true,
46-
useSendbirdStateContext: () => mockSendbirdStateContext,
41+
default: jest.fn(() => ({ state: mockState, actions: mockActions })),
42+
useSendbird: jest.fn(() => ({ state: mockState, actions: mockActions })),
4743
}));
4844

4945
const mockProps: CreateChannelProviderProps = {

src/modules/GroupChannel/context/__tests__/GroupChannel.migration.spec.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import { render, screen } from '@testing-library/react';
3-
import { GroupChannelProvider, GroupChannelProviderProps, useGroupChannelContext } from '../GroupChannelProvider';
3+
import type { GroupChannelProviderProps } from '../types'
4+
import { GroupChannelProvider, useGroupChannelContext } from '../GroupChannelProvider';
45
import { ThreadReplySelectType } from '../const';
56
import { match } from 'ts-pattern';
67

7-
const mockSendbirdStateContext = {
8+
const mockState = {
89
config: {
910
pubSub: { subscribe: () => ({ remove: () => {} }) },
1011
isOnline: true,
@@ -31,14 +32,11 @@ const mockSendbirdStateContext = {
3132
},
3233
},
3334
};
34-
35-
jest.mock('../../../../lib/Sendbird', () => ({
36-
__esModule: true,
37-
useSendbirdStateContext: () => mockSendbirdStateContext,
38-
}));
39-
jest.mock('../../../../hooks/useSendbirdStateContext', () => ({
35+
const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
36+
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
4037
__esModule: true,
41-
default: () => mockSendbirdStateContext,
38+
default: jest.fn(() => ({ state: mockState, actions: mockActions })),
39+
useSendbird: jest.fn(() => ({ state: mockState, actions: mockActions })),
4240
}));
4341

4442
const mockProps: GroupChannelProviderProps = {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
useGroupChannelListContext,
88
} from '../GroupChannelListProvider';
99

10-
const mockSendbirdStateContext = {
10+
const mockState = {
1111
stores: {
1212
userStore: {
1313
user: {
@@ -35,15 +35,11 @@ const mockSendbirdStateContext = {
3535
isOnline: true,
3636
},
3737
};
38-
39-
jest.mock('../../../../hooks/useSendbirdStateContext', () => ({
40-
__esModule: true,
41-
default: () => mockSendbirdStateContext,
42-
}));
43-
44-
jest.mock('../../../../lib/Sendbird', () => ({
38+
const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
39+
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
4540
__esModule: true,
46-
useSendbirdStateContext: () => mockSendbirdStateContext,
41+
default: jest.fn(() => ({ state: mockState, actions: mockActions })),
42+
useSendbird: jest.fn(() => ({ state: mockState, actions: mockActions })),
4743
}));
4844

4945
jest.mock('@sendbird/uikit-tools', () => ({

src/modules/MessageSearch/context/__tests__/MessageSearch.migration.spec.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ import { render, screen } from '@testing-library/react';
33
import { MessageSearchProvider, useMessageSearchContext } from '../MessageSearchProvider';
44
import { match } from 'ts-pattern';
55

6-
jest.mock('../../../../hooks/useSendbirdStateContext', () => ({
6+
const mockState = {
7+
stores: { sdkStore: {} },
8+
config: { logger: console, groupChannel: {} },
9+
};
10+
const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
11+
12+
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
713
__esModule: true,
8-
default: () => ({}),
14+
default: jest.fn(() => ({ state: mockState, actions: mockActions })),
15+
useSendbird: jest.fn(() => ({ state: mockState, actions: mockActions })),
916
}));
1017

1118
const mockProps = {

src/modules/Thread/context/__test__/Thread.migration.spec.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55
import { ThreadProvider, ThreadProviderProps, useThreadContext } from '../ThreadProvider';
66
import { SendableMessageType } from '../../../../utils';
77

8-
const mockSendbirdStateContext = {
8+
const mockState = {
99
stores: {
1010
userStore: {
1111
},
@@ -30,15 +30,12 @@ const mockSendbirdStateContext = {
3030
isOnline: true,
3131
},
3232
};
33+
const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
3334

34-
jest.mock('../../../../hooks/useSendbirdStateContext', () => ({
35+
jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
3536
__esModule: true,
36-
default: () => mockSendbirdStateContext,
37-
}));
38-
39-
jest.mock('../../../../lib/Sendbird', () => ({
40-
__esModule: true,
41-
useSendbirdStateContext: () => mockSendbirdStateContext,
37+
default: jest.fn(() => ({ state: mockState, actions: mockActions })),
38+
useSendbird: jest.fn(() => ({ state: mockState, actions: mockActions })),
4239
}));
4340

4441
jest.mock('../hooks/useThreadFetchers', () => ({

0 commit comments

Comments
 (0)