import { render } from '@testing-library/react-native' import React from 'react' import type { ConversationPreviewData, ConversationResource } from '../../../types' import { formatDatePreview } from '../../../utils/date' import { ConversationPreview } from '../conversation_preview' jest.mock('../conversation_actions', () => ({ ConversationActions: ({ children, accessibilityLabel, }: { children: React.ReactNode accessibilityLabel?: string }) => { const { View: MockView } = jest.requireActual('react-native') return {children} }, })) const createdAt = '2026-03-04T15:30:00Z' const conversation = ( conversationPreview: ConversationPreviewData, overrides: Partial = {} ): ConversationResource => ({ type: 'Conversation', id: 7, title: 'Worship Team', conversationPreview, createdAt, lastMessageCreatedAt: createdAt, muted: false, repliesDisabled: false, unreadCount: 0, unreadReaction: false, updatedAt: createdAt, ...overrides, }) const messagePreview: ConversationPreviewData = { kind: 'message', authorName: 'Ada Lovelace', value: null, text: 'See you Sunday', createdAt, } const renderPreview = ( preview: ConversationPreviewData, overrides: Partial = {} ) => render( ) describe('ConversationPreview', () => { it('prefixes message previews with the author', () => { const view = renderPreview({ kind: 'message', authorName: 'Ada Lovelace', value: null, text: 'See you Sunday', createdAt, }) expect(view.getByText('Ada Lovelace: See you Sunday')).toBeTruthy() }) it('shows system previews as their text alone', () => { const text = 'This conversation was unarchived by Ada Lovelace' const view = renderPreview({ kind: 'system', authorName: 'System', value: null, text, createdAt, }) expect(view.getByText(text)).toBeTruthy() expect(view.queryByText('System', { exact: false })).toBeNull() expect( view.getByLabelText( `Select Worship Team, Latest activity: ${text} at ${formatDatePreview(createdAt)}` ) ).toBeTruthy() }) it('marks an archived conversation with an archive icon instead of the disabled label', () => { const view = renderPreview(messagePreview, { disabled: true, disabledReason: 'archived' }) expect( view.getByTestId('conversation-archived-icon', { includeHiddenElements: true }) ).toBeTruthy() expect(view.getByLabelText(/^Select Worship Team, Archived,/)).toBeTruthy() }) it('keeps the disabled label for a conversation disabled for another reason', () => { const view = renderPreview(messagePreview, { disabled: true, disabledReason: 'safety_check' }) expect( view.queryByTestId('conversation-archived-icon', { includeHiddenElements: true }) ).toBeNull() expect(view.getByLabelText(/^Select Worship Team, Disabled,/)).toBeTruthy() }) })