|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { MessageSearchProvider, useMessageSearchContext } from '../MessageSearchProvider'; |
| 4 | + |
| 5 | +jest.mock('../../../../hooks/useSendbirdStateContext', () => ({ |
| 6 | + __esModule: true, |
| 7 | + default: () => ({}), |
| 8 | +})); |
| 9 | + |
| 10 | +describe('MessageSearch Migration Compatibility Tests', () => { |
| 11 | + // 1. Provider Props Interface test |
| 12 | + describe('MessageSearchProvider Props Compatibility', () => { |
| 13 | + const mockProps = { |
| 14 | + channelUrl: 'channel-1', |
| 15 | + searchString: 'test', |
| 16 | + messageSearchQuery: {}, |
| 17 | + onResultLoaded: jest.fn(), |
| 18 | + onResultClick: jest.fn(), |
| 19 | + }; |
| 20 | + |
| 21 | + it('should accept all legacy props without type errors', () => { |
| 22 | + const { rerender } = render( |
| 23 | + <MessageSearchProvider {...mockProps}> |
| 24 | + <div>Child Component</div> |
| 25 | + </MessageSearchProvider>, |
| 26 | + ); |
| 27 | + |
| 28 | + // Props change scenario test |
| 29 | + rerender( |
| 30 | + <MessageSearchProvider |
| 31 | + {...mockProps} |
| 32 | + searchString="updated" |
| 33 | + onResultLoaded={() => {}} |
| 34 | + > |
| 35 | + <div>Child Component</div> |
| 36 | + </MessageSearchProvider>, |
| 37 | + ); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + // 2. Context Hook return value test |
| 42 | + describe('useMessageSearchContext Hook Return Values', () => { |
| 43 | + const TestComponent = () => { |
| 44 | + const context = useMessageSearchContext(); |
| 45 | + |
| 46 | + // Check if all properties used by previous users exist |
| 47 | + const expectedProps: Array<keyof typeof context> = [ |
| 48 | + 'searchString', |
| 49 | + 'allMessages', |
| 50 | + 'loading', |
| 51 | + 'isInvalid', |
| 52 | + 'currentChannel', |
| 53 | + 'hasMoreResult', |
| 54 | + 'onScroll', |
| 55 | + 'onResultClick', |
| 56 | + 'selectedMessageId', |
| 57 | + ]; |
| 58 | + |
| 59 | + return ( |
| 60 | + <div> |
| 61 | + {expectedProps.map(prop => ( |
| 62 | + <div key={prop} data-testid={`prop-${prop}`}> |
| 63 | + {typeof context[prop]} |
| 64 | + </div> |
| 65 | + ))} |
| 66 | + </div> |
| 67 | + ); |
| 68 | + }; |
| 69 | + |
| 70 | + it('should provide all legacy context values', () => { |
| 71 | + render( |
| 72 | + <MessageSearchProvider channelUrl="channel-1"> |
| 73 | + <TestComponent /> |
| 74 | + </MessageSearchProvider>, |
| 75 | + ); |
| 76 | + |
| 77 | + // Check if all required properties exist |
| 78 | + const expectedProps = [ |
| 79 | + 'searchString', |
| 80 | + 'allMessages', |
| 81 | + 'loading', |
| 82 | + 'isInvalid', |
| 83 | + 'currentChannel', |
| 84 | + 'hasMoreResult', |
| 85 | + ]; |
| 86 | + |
| 87 | + expectedProps.forEach(prop => { |
| 88 | + expect(screen.getByTestId(`prop-${prop}`)).toBeInTheDocument(); |
| 89 | + }); |
| 90 | + }); |
| 91 | + }); |
| 92 | +}); |
0 commit comments