-
Notifications
You must be signed in to change notification settings - Fork 143
[CLNP-5047] Migrate GroupChannelProvider to new state management pattern #1246
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
Merged
AhyoungRyu
merged 5 commits into
feat/state-mgmt-migration-1
from
feat/CLNP-5047/groupchannel-migration
Nov 19, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e175dd2
[Refactor] Migrate GroupChannelProvider to new state management pattern
AhyoungRyu bd41304
Make useXXXContext return all states & actions for backward compatibi…
AhyoungRyu 74702f6
Merge messageActions into groupchannel actions
AhyoungRyu 7f4737e
Add unit tests
AhyoungRyu ea6a79f
Add improvement notes for useToggleReactionCallback race condition
AhyoungRyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/modules/GroupChannel/__test__/GroupChannelUIView.integration.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom/extend-expect'; | ||
| import { GroupChannelUIView } from '../components/GroupChannelUI/GroupChannelUIView'; | ||
| import useSendbirdStateContext from '../../../hooks/useSendbirdStateContext'; | ||
|
|
||
| jest.mock('../../../hooks/useSendbirdStateContext'); | ||
|
|
||
| const mockUseSendbirdStateContext = useSendbirdStateContext as jest.Mock; | ||
|
|
||
| describe('GroupChannelUIView Integration Tests', () => { | ||
| const defaultProps = { | ||
| channelUrl: 'test-channel', | ||
| isInvalid: false, | ||
| renderChannelHeader: jest.fn(() => <div>Channel Header</div>), | ||
| renderMessageList: jest.fn(() => <div>Message List</div>), | ||
| renderMessageInput: jest.fn(() => <div>Message Input</div>), | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| mockUseSendbirdStateContext.mockImplementation(() => ({ | ||
| stores: { | ||
| sdkStore: { error: null }, | ||
| }, | ||
| config: { | ||
| logger: { info: jest.fn() }, | ||
| isOnline: true, | ||
| groupChannel: { | ||
| enableTypingIndicator: true, | ||
| typingIndicatorTypes: new Set(['text']), | ||
| }, | ||
| }, | ||
| })); | ||
| }); | ||
|
|
||
| it('renders basic channel components correctly', () => { | ||
| render(<GroupChannelUIView {...defaultProps} />); | ||
|
|
||
| expect(screen.getByText('Channel Header')).toBeInTheDocument(); | ||
| expect(screen.getByText('Message List')).toBeInTheDocument(); | ||
| expect(screen.getByText('Message Input')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders loading placeholder when isLoading is true', () => { | ||
| render(<GroupChannelUIView {...defaultProps} isLoading={true} />); | ||
| // Placeholder is a just loading spinner in this case | ||
| expect(screen.getByRole('button')).toHaveClass('sendbird-icon-spinner'); | ||
| }); | ||
|
|
||
| it('renders invalid placeholder when channelUrl is missing', () => { | ||
| render(<GroupChannelUIView {...defaultProps} channelUrl="" />); | ||
| expect(screen.getByText('No channels')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders error placeholder when isInvalid is true', () => { | ||
| render(<GroupChannelUIView {...defaultProps} isInvalid={true} />); | ||
| expect(screen.getByText('Something went wrong')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders SDK error placeholder when SDK has error', () => { | ||
| mockUseSendbirdStateContext.mockImplementation(() => ({ | ||
| stores: { | ||
| sdkStore: { error: new Error('SDK Error') }, | ||
| }, | ||
| config: { | ||
| logger: { info: jest.fn() }, | ||
| isOnline: true, | ||
| }, | ||
| })); | ||
|
|
||
| render(<GroupChannelUIView {...defaultProps} />); | ||
| expect(screen.getByText('Something went wrong')).toBeInTheDocument(); | ||
| expect(screen.getByText('Retry')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders custom placeholders when provided', () => { | ||
| const renderPlaceholderLoader = () => <div>Custom Loader</div>; | ||
| const renderPlaceholderInvalid = () => <div>Custom Invalid</div>; | ||
|
|
||
| const { rerender } = render( | ||
| <GroupChannelUIView | ||
| {...defaultProps} | ||
| isLoading={true} | ||
| renderPlaceholderLoader={renderPlaceholderLoader} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('Custom Loader')).toBeInTheDocument(); | ||
|
|
||
| rerender( | ||
| <GroupChannelUIView | ||
| {...defaultProps} | ||
| isInvalid={true} | ||
| renderPlaceholderInvalid={renderPlaceholderInvalid} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('Custom Invalid')).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/modules/GroupChannel/components/RemoveMessageModal/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.