import { fireEvent, render } from '@testing-library/react-native'
import React from 'react'
import type { MessageSearchResultResource } from '../../../../types/resources/search_result'
import { formatDatePreview } from '../../../../utils/date'
import { defaultTheme } from '../../../../utils/theme'
import { MessageResultRow } from '../message_result_row'
const result: MessageSearchResultResource = {
id: '42',
type: 'message',
title: 'Worship Team',
url: '/conversations/7?message_id=42',
extra: {
conversationId: 7,
authorName: 'Ada Lovelace',
snippet: [
{ text: '…planning the ', match: false },
{ text: 'budget', match: true },
{ text: ' meeting for next week', match: false },
],
createdAt: '2026-03-04T15:30:00Z',
avatar: {
customAvatarType: null,
customAvatarKey: null,
customAvatarColor: null,
customAvatarImageUrl: null,
previewAvatarUrls: [],
},
},
}
const interactionColor = defaultTheme('light').colors.interaction
describe('MessageResultRow', () => {
it('renders the title, author, snippet, and date', () => {
const view = render()
expect(view.getByText('Worship Team')).toBeTruthy()
expect(view.getByText('Ada Lovelace:', { exact: false })).toBeTruthy()
expect(view.getByText('…planning the ')).toBeTruthy()
expect(view.getByText('budget')).toBeTruthy()
expect(view.getByText(' meeting for next week')).toBeTruthy()
expect(view.getByText(formatDatePreview(result.extra.createdAt))).toBeTruthy()
})
it('colors matched segments with the interaction color', () => {
const view = render()
expect(view.getByText('budget')).toHaveStyle({ color: interactionColor })
expect(view.getByText('…planning the ')).not.toHaveStyle({ color: interactionColor })
})
it('exposes the row as a button with a composed label and reports presses', () => {
const onPress = jest.fn()
const date = formatDatePreview(result.extra.createdAt)
const view = render()
const row = view.getByRole('button', {
name: `Worship Team, Ada Lovelace: …planning the budget meeting for next week, ${date}`,
})
fireEvent.press(row)
expect(onPress).toHaveBeenCalledWith(result)
})
})