import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { MessageView } from '../../src/components/MessageView.tsx'
const d = (name: string) => `network.sharedcomputer.chat.defs#${name}`
const blobUrl = (cid: string) => `/blob/${cid}`
describe('MessageView', () => {
it('shows text as plain text and keeps reasoning and tool details collapsed', () => {
const { container } = render(
,
)
expect(screen.getByText('**not markdown**')).toBeInTheDocument()
for (const details of container.querySelectorAll('details')) expect(details.open).toBe(false)
expect(screen.getByRole('link', { name: 'Example' })).toHaveAttribute(
'href',
'https://example.com',
)
})
it('shows streamed text for a pending reply', () => {
render(
,
)
expect(screen.getByText('Hel')).toBeInTheDocument()
})
it('shows an error and a stopped label', () => {
const { rerender } = render(
,
)
expect(screen.getByRole('alert')).toHaveTextContent('rate limited')
rerender(
,
)
expect(screen.getByText('Stopped.')).toBeInTheDocument()
})
it('shows images inline and files by name', () => {
render(
,
)
expect(screen.getByAltText('a cat')).toHaveAttribute('src', '/blob/img1')
expect(screen.getByRole('link', { name: 'report.pdf' })).toHaveAttribute('href', '/blob/pdf1')
})
it('switches between siblings', () => {
const onPick = vi.fn()
render(
,
)
expect(screen.getByText(/2 \/ 3/)).toBeInTheDocument()
screen.getByRole('button', { name: '›' }).click()
expect(onPick).toHaveBeenCalledWith(2)
})
it('says a message is encrypted', () => {
render(
,
)
expect(screen.getByText('This message is encrypted.')).toBeInTheDocument()
})
})