Skip to content
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

Fix migration test failure #1285

Open
wants to merge 2 commits into
base: feat/state-mgmt-migration-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const mockState = {
},
isOnline: true,
},
};const mockActions = { connect: jest.fn(), disconnect: jest.fn() };
}; const mockActions = { connect: jest.fn(), disconnect: jest.fn() };

jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({
__esModule: true,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/GroupChannel/context/GroupChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ const GroupChannelManager :React.FC<React.PropsWithChildren<GroupChannelProvider
return children;
};

const GroupChannelProvider: React.FC<React.PropsWithChildren<GroupChannelProviderProps>> = (props) => {
const GroupChannelProvider: React.FC<GroupChannelProviderProps> = (props) => {
return (
<InternalGroupChannelProvider>
<GroupChannelManager {...props}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, { act } from 'react';
import { render, screen } from '@testing-library/react';
import type { GroupChannelProviderProps } from '../types'
import type { GroupChannelProviderProps } from '../types';
import { GroupChannelProvider, useGroupChannelContext } from '../GroupChannelProvider';
import { ThreadReplySelectType } from '../const';
import { match } from 'ts-pattern';
Expand Down Expand Up @@ -57,8 +57,7 @@ const mockProps: GroupChannelProviderProps = {
scrollBehavior: 'smooth',
forceLeftToRightMessageLayout: false,

startingPoint: 0,

startingPoint: undefined,
// Message Focusing
animatedMessageId: null,
onMessageAnimated: jest.fn(),
Expand Down Expand Up @@ -93,23 +92,23 @@ const mockProps: GroupChannelProviderProps = {
describe('GroupChannel Migration Compatibility Tests', () => {
// 1. Provider Props Interface test
describe('GroupChannelProvider Props Compatibility', () => {
it('should accept all legacy props without type errors', () => {
const { rerender } = render(
it('should accept all legacy props without type errors', async () => {
const { rerender } = await act(async () => render(
<GroupChannelProvider {...mockProps}>
{mockProps.children}
</GroupChannelProvider>,
);
));

// Props change scenario test
rerender(
await act(async () => rerender(
<GroupChannelProvider
{...mockProps}
isReactionEnabled={false}
onBackClick={() => {}}
>
{mockProps.children}
</GroupChannelProvider>,
);
));
});
});

Expand Down
10 changes: 8 additions & 2 deletions src/modules/GroupChannel/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ReplyType } from '../../../types';
import { useMessageActions } from './hooks/useMessageActions';
import { useGroupChannelMessages } from '@sendbird/uikit-tools';
import { ThreadReplySelectType } from './const';
import { PropsWithChildren } from 'react';

// Message data source types
type MessageDataSource = ReturnType<typeof useGroupChannelMessages>;
Expand Down Expand Up @@ -66,8 +67,13 @@ interface InternalGroupChannelState extends MessageDataSource {
scrollPubSub: PubSubTypes<ScrollTopics, ScrollTopicUnion>;
}

export interface GroupChannelProviderProps extends
Pick<UserProfileProviderProps, 'renderUserProfile' | 'disableUserProfile'> {
export interface GroupChannelProviderProps extends PropsWithChildren<
Pick<UserProfileProviderProps,
'renderUserProfile' |
'disableUserProfile' |
'onUserProfileMessage'|
'onStartDirectMessage'
>> {
// Required
channelUrl: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ export const GroupChannelListManager: React.FC<GroupChannelListProviderProps> =
typingChannelUrls,
refreshing,
initialized,
refresh,
loadMore,
scrollRef,
]);
useDeepCompareEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({

jest.mock('@sendbird/uikit-tools', () => ({
...jest.requireActual('@sendbird/uikit-tools'),
useGroupChannelList: () => ({
useGroupChannelList: jest.fn(() => ({
refreshing: false,
initialized: true,
groupChannels: [],
groupChannels: [{ url: 'test-groupchannel-url-1', serialize: () => JSON.stringify(this) }],
refresh: jest.fn(),
loadMore: jest.fn(),
}),
})),
}));

const mockProps: GroupChannelListProviderProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ describe('MessageSearch Migration Compatibility Tests', () => {
'children',
'requestString',
'retryCount',
'setRetryCount',
'selectedMessageId',
'setSelectedMessageId',
'messageSearchDispatcher',
'scrollRef',
'allMessages',
'loading',
'isInvalid',
Comment on lines -62 to -69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check these why they're not in the return value of new useMessageSearchContext

'currentChannel',
'currentMessageSearchQuery',
'hasMoreResult',
Expand Down
4 changes: 2 additions & 2 deletions src/modules/MessageSearch/context/hooks/useMessageSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { MessageSearchQuery } from '@sendbird/chat/message';

import { useSyncExternalStore } from 'use-sync-external-store/shim';
import { ClientSentMessages } from '../../../../types';
import { MessageSearchContext } from '../MessageSearchProvider';
import { MessageSearchContext, type MessageSearchState } from '../MessageSearchProvider';

const useMessageSearch = () => {
const store = useContext(MessageSearchContext);
if (!store) throw new Error('useMessageSearch must be used within a MessageSearchProvider');

const state = useSyncExternalStore(store.subscribe, store.getState);
const state: MessageSearchState = useSyncExternalStore(store.subscribe, store.getState);
const actions = useMemo(() => ({
setCurrentChannel: (channel: GroupChannel) => store.setState(state => ({
...state,
Expand Down
13 changes: 1 addition & 12 deletions src/modules/Thread/context/ThreadProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,7 @@ export interface ThreadProviderProps extends
filterEmojiCategoryIds?: (message: SendableMessageType) => EmojiCategory['id'][];
}

export interface ThreadState {
channelUrl: string;
message: SendableMessageType | null;
onHeaderActionClick?: () => void;
onMoveToParentMessage?: (props: { message: SendableMessageType, channel: GroupChannel }) => void;
onBeforeSendUserMessage?: (message: string, quotedMessage?: SendableMessageType) => UserMessageCreateParams;
onBeforeSendFileMessage?: (file: File, quotedMessage?: SendableMessageType) => FileMessageCreateParams;
onBeforeSendVoiceMessage?: (file: File, quotedMessage?: SendableMessageType) => FileMessageCreateParams;
onBeforeSendMultipleFilesMessage?: (files: Array<File>, quotedMessage?: SendableMessageType) => MultipleFilesMessageCreateParams;
onBeforeDownloadFileMessage?: OnBeforeDownloadFileMessageType;
isMultipleFilesMessageEnabled?: boolean;
filterEmojiCategoryIds?: (message: SendableMessageType) => EmojiCategory['id'][];
export interface ThreadState extends ThreadProviderProps {
currentChannel: GroupChannel;
allThreadMessages: Array<CoreMessageType>;
localThreadMessages: Array<CoreMessageType>;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/Thread/context/__test__/Thread.migration.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jest.mock('../../../../lib/Sendbird/context/hooks/useSendbird', () => ({

jest.mock('../hooks/useThreadFetchers', () => ({
useThreadFetchers: jest.fn().mockReturnValue({
initialize: jest.fn(),
loadPrevious: jest.fn(),
loadNext: jest.fn(),
initializeThreadFetcher: jest.fn(),
fetchPrevThreads: jest.fn(),
fetchNextThreads: jest.fn(),
}),
}));

Expand Down