Skip to content
Closed
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 @@ -104,7 +104,7 @@ const MessageSearchProvider: React.FC<MessageSearchProviderProps> = (props: Mess
{ sdk, logger, messageSearchDispatcher },
);

const requestString = useSearchStringEffect({ searchString: searchString ?? '' }, { messageSearchDispatcher });
const requestString = useSearchStringEffect({ searchString: searchString ?? messageSearchQuery.keyword }, { messageSearchDispatcher });

useGetSearchMessages(
{ currentChannel, channelUrl, requestString, messageSearchQuery, onResultLoaded, retryCount },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MessageSearchProvider, useMessageSearchContext } from '../MessageSearchProvider';
import { match } from 'ts-pattern';

jest.mock('../../../../hooks/useSendbirdStateContext', () => ({
__esModule: true,
default: () => ({}),
}));

const mockProps = {
channelUrl: 'channel-1',
searchString: '',
messageSearchQuery: {
keyword: 'test',
},
onResultLoaded: jest.fn(),
onResultClick: jest.fn(),
children: <div>Child Component</div>,
};

describe('MessageSearch Migration Compatibility Tests', () => {
// 1. Provider Props Interface test
describe('MessageSearchProvider Props Compatibility', () => {
it('should accept all legacy props without type errors', () => {
const { rerender } = render(<MessageSearchProvider {...mockProps}>{mockProps.children}</MessageSearchProvider>);

// Props change scenario test
rerender(
<MessageSearchProvider {...mockProps} searchString="updated" onResultLoaded={() => {}}>
{mockProps.children}
</MessageSearchProvider>
);
});
});

// 2. Context Hook return value test
describe('useMessageSearchContext Hook Return Values', () => {
type ContextType = ReturnType<typeof useMessageSearchContext>;
const expectedProps: Array<keyof ContextType> = [
'channelUrl',
'searchString',
'messageSearchQuery',
'onResultLoaded',
'onResultClick',
'children',
'requestString',
'retryCount',
'setRetryCount',
'selectedMessageId',
'setSelectedMessageId',
'messageSearchDispatcher',
'scrollRef',
'allMessages',
'loading',
'isInvalid',
'currentChannel',
'currentMessageSearchQuery',
'hasMoreResult',
'onScroll',
'handleRetryToConnect',
'handleOnScroll',
];

const TestComponent = () => {
const context = useMessageSearchContext();
return (
<div>
{expectedProps.map((prop) => (
<div key={prop} data-testid={`prop-${prop}`}>
{/* text can be function, object, string, or unknown */}
{match(context[prop])
.with('function', () => 'function')
.with('object', () => JSON.stringify(context[prop]))
.with('string', () => String(context[prop]))
.otherwise(() => 'unknown')}
</div>
))}
</div>
);
};

it('should provide all legacy context values', () => {
render(
<MessageSearchProvider {...mockProps}>
<TestComponent />
</MessageSearchProvider>
);

expectedProps.forEach((prop) => {
const element = screen.getByTestId(`prop-${prop}`);
expect(element).toBeInTheDocument();
});
});
});
});