import { OFFICIAL_CHANNEL_TYPE } from '@linktr.ee/messaging-taxonomy' import React from 'react' import type { Channel } from 'stream-chat' import { describe, expect, it, vi, beforeEach } from 'vitest' import { renderWithProviders, screen } from '../test/utils' import { ChannelView } from './ChannelView' let activeChannel: unknown let activeChannelProps: Record = {} let activeComponentOverrides: Record = {} vi.mock('stream-chat-react', () => ({ Channel: (props: { channel: unknown children: React.ReactNode [key: string]: unknown }) => { activeChannel = props.channel activeChannelProps = props return
{props.children}
}, Window: ({ children }: { children: React.ReactNode }) => (
{children}
), MessageList: ({ head }: { head?: React.ReactElement }) => (
{head}
), WithComponents: ({ children, overrides, }: { children: React.ReactNode overrides?: Record }) => { activeComponentOverrides = overrides ?? {} return <>{children} }, useMessageContext: () => ({ message: { id: 'message-1', text: 'hello' } }), useChannelStateContext: () => ({ channel: activeChannel }), useChatContext: () => ({ client: { userID: 'visitor-1', user: { id: 'visitor-1' } }, }), useTypingContext: () => ({ typing: {} }), useAIState: () => ({ aiState: 'AI_STATE_IDLE' }), AIStates: { Error: 'AI_STATE_ERROR', ExternalSources: 'AI_STATE_EXTERNAL_SOURCES', Generating: 'AI_STATE_GENERATING', Idle: 'AI_STATE_IDLE', Stop: 'AI_STATE_STOP', Thinking: 'AI_STATE_THINKING', }, })) vi.mock('../providers/MessagingProvider', () => ({ useMessagingContext: () => ({ service: null, debug: false }), })) const messageInputProps: Array> = [] vi.mock('./CustomMessageInput', () => ({ CustomMessageInput: (props: { renderActions?: () => React.ReactNode renderHeader?: () => React.ReactNode [key: string]: unknown }) => { messageInputProps.push({ ...props }) return (
{props.renderHeader?.()} {props.renderActions?.()}
) }, })) const customMessageMounts = vi.fn() const customMessageUnmounts = vi.fn() vi.mock('./CustomMessage', () => ({ CustomMessage: (props: { onOutboundClick?: (outbound: { id: string; name?: string }) => void }) => { React.useEffect(() => { customMessageMounts() return customMessageUnmounts }, []) return ( )) renderWithProviders( (
channel-banner
)} renderMessageInputActions={renderMessageInputActions} /> ) expect(screen.getByTestId('channel-banner')).toBeInTheDocument() expect(screen.getByTestId('message-input-action')).toHaveTextContent( 'channel-1' ) expect(renderMessageInputActions).toHaveBeenCalledWith(channel) }) it('passes sendButton to Channel as SendButton when provided', () => { const CustomSendButton = () => (