-
Notifications
You must be signed in to change notification settings - Fork 143
[CLNP-5045] CreateChannelProvider Migration #1243
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
Changes from 9 commits
06171da
0b35de8
8f5833c
96cd60a
b860a4f
fd5d010
9aa4f4d
7f38509
370df39
7ec8a6f
c6e6c8d
09b20b9
24f23cb
d44026c
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, | ||
|
||
| userListQuery, | ||
| }, | ||
| actions: { | ||
| setStep, | ||
| }, | ||
| } = useCreateChannel(); | ||
|
|
||
| return ( | ||
| <> | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.