-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLNP-5045] CreateChannelProvider Migration #1243
base: feat/state-mgmt-migration-1
Are you sure you want to change the base?
Changes from all commits
06171da
0b35de8
8f5833c
96cd60a
b860a4f
fd5d010
9aa4f4d
7f38509
370df39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React from 'react'; | ||
import * as useCreateChannelModule from '../../../context/useCreateChannel'; | ||
import { CHANNEL_TYPE } from '../../../types'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { LocalizationContext } from '../../../../../lib/LocalizationContext'; | ||
import CreateChannelUI from '../index'; | ||
|
||
jest.mock('../../../../../hooks/useSendbirdStateContext', () => ({ | ||
__esModule: true, | ||
default: jest.fn(() => ({ | ||
stores: { | ||
userStore: { | ||
user: { | ||
userId: ' test-user-id', | ||
}, | ||
}, | ||
sdkStore: { | ||
sdk: { | ||
currentUser: { | ||
userId: 'test-user-id', | ||
}, | ||
createApplicationUserListQuery: () => ({ | ||
next: () => Promise.resolve([{ userId: 'test-user-id' }]), | ||
isLoading: false, | ||
}), | ||
}, | ||
initialized: true, | ||
}, | ||
}, | ||
config: { | ||
logger: console, | ||
userId: 'test-user-id', | ||
groupChannel: { | ||
enableMention: true, | ||
}, | ||
isOnline: true, | ||
}, | ||
})), | ||
})); | ||
jest.mock('../../../context/useCreateChannel'); | ||
|
||
const mockStringSet = { | ||
MODAL__CREATE_CHANNEL__TITLE: 'CREATE_CHANNEL', | ||
MODAL__INVITE_MEMBER__SELECTED: 'USERS_SELECTED', | ||
}; | ||
|
||
const mockLocalizationContext = { | ||
stringSet: mockStringSet, | ||
}; | ||
|
||
const defaultMockState = { | ||
sdk: undefined, | ||
createChannel: undefined, | ||
userListQuery: undefined, | ||
onCreateChannelClick: undefined, | ||
onChannelCreated: undefined, | ||
onBeforeCreateChannel: undefined, | ||
step: 0, | ||
type: CHANNEL_TYPE.GROUP, | ||
onCreateChannel: undefined, | ||
overrideInviteUser: undefined, | ||
}; | ||
|
||
const defaultMockActions = { | ||
setStep: jest.fn(), | ||
setType: jest.fn(), | ||
}; | ||
|
||
describe('CreateChannelUI Integration Tests', () => { | ||
const mockUseCreateChannel = useCreateChannelModule.default as jest.Mock; | ||
|
||
const renderComponent = (mockState = {}, mockActions = {}) => { | ||
mockUseCreateChannel.mockReturnValue({ | ||
state: { ...defaultMockState, ...mockState }, | ||
actions: { ...defaultMockActions, ...mockActions }, | ||
}); | ||
|
||
return render( | ||
<LocalizationContext.Provider value={mockLocalizationContext as any}> | ||
<CreateChannelUI /> | ||
</LocalizationContext.Provider>, | ||
); | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
document.body.innerHTML = ` | ||
<div id='sendbird-modal-root' /> | ||
`; | ||
}); | ||
|
||
it('display initial state correctly', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByText('CREATE_CHANNEL')).toBeInTheDocument(); | ||
}); | ||
|
||
it('display SelectChannelType when step is 0', () => { | ||
renderComponent({ step: 0 }); | ||
|
||
expect(screen.getByText('CREATE_CHANNEL')).toBeInTheDocument(); | ||
}); | ||
|
||
it('display InviteUsers when step is 1', async () => { | ||
await act(async () => { | ||
renderComponent({ step: 1 }); | ||
}); | ||
|
||
expect(screen.getByText('0 USERS_SELECTED')).toBeInTheDocument(); | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ import './create-channel-ui.scss'; | |
|
||
import React from 'react'; | ||
|
||
import { useCreateChannelContext } from '../../context/CreateChannelProvider'; | ||
import InviteUsers from '../InviteUsers'; | ||
|
||
import SelectChannelType from '../SelectChannelType'; | ||
import useCreateChannel from '../../context/useCreateChannel'; | ||
|
||
export interface CreateChannelUIProps { | ||
onCancel?(): void; | ||
|
@@ -16,10 +16,14 @@ const CreateChannel: React.FC<CreateChannelUIProps> = (props: CreateChannelUIPro | |
const { onCancel, renderStepOne } = props; | ||
|
||
const { | ||
step, | ||
setStep, | ||
userListQuery, | ||
} = useCreateChannelContext(); | ||
state: { | ||
step, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순 궁금증인데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
userListQuery, | ||
}, | ||
actions: { | ||
setStep, | ||
}, | ||
} = useCreateChannel(); | ||
|
||
return ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import type { GroupChannelCreateParams } from '@sendbird/chat/groupChannel'; | |
|
||
import './invite-users.scss'; | ||
import { LocalizationContext } from '../../../../lib/LocalizationContext'; | ||
import { useCreateChannelContext } from '../../context/CreateChannelProvider'; | ||
import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext'; | ||
import { useMediaQueryContext } from '../../../../lib/MediaQueryContext'; | ||
import Modal from '../../../../ui/Modal'; | ||
|
@@ -15,6 +14,7 @@ import UserListItem from '../../../../ui/UserListItem'; | |
import { createDefaultUserListQuery, filterUser, setChannelType } from './utils'; | ||
import { noop } from '../../../../utils/utils'; | ||
import { UserListQuery } from '../../../../types'; | ||
import useCreateChannel from '../../context/useCreateChannel'; | ||
|
||
export interface InviteUsersProps { | ||
onCancel?: () => void; | ||
|
@@ -28,14 +28,16 @@ const InviteUsers: React.FC<InviteUsersProps> = ({ | |
userListQuery, | ||
}: InviteUsersProps) => { | ||
const { | ||
onCreateChannelClick, | ||
onBeforeCreateChannel, | ||
onChannelCreated, | ||
createChannel, | ||
onCreateChannel, | ||
overrideInviteUser, | ||
type, | ||
} = useCreateChannelContext(); | ||
state: { | ||
onCreateChannelClick, | ||
onBeforeCreateChannel, | ||
onChannelCreated, | ||
createChannel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 당장 꺼내서 써야할 때 state vs action 둘중 어디에있을까 추측해야하는 상황이라면 저는 action 에 있을거라 예상하게 될거같아요. 그래서 좀 더 나은 사용성 측면으로는 action 에 들어있는게 자연스러울거같긴합니다! |
||
onCreateChannel, | ||
overrideInviteUser, | ||
type, | ||
}, | ||
} = useCreateChannel(); | ||
|
||
const globalStore = useSendbirdStateContext(); | ||
const userId = globalStore?.config?.userId; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need async here since there's no usage of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
async
oract
is deleted, the error occurs.The test still pass even when the
act
is deleted; but I addedact
andasync
to prevent the error.