Files
opencode-manager/frontend/src/components/ui/inline-image.test.tsx
T
Chris Scott f488b8762d fix(markdown): address inline image review feedback
Keep the leading slash when resolving relative paths against an absolute
markdown file, retry an inline image when its source changes after a load
failure, and render linked markdown images without a nested expand button.
2026-10-13 01:46:51 +00:00

55 lines
2.1 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { InlineImage } from './inline-image'
describe('InlineImage', () => {
it('opens a full-size dialog when the thumbnail is clicked', () => {
render(<InlineImage src="data:image/png;base64,aGVsbG8=" alt="shot.png" />)
const thumbnail = screen.getByAltText('shot.png')
expect(thumbnail).toHaveAttribute('src', 'data:image/png;base64,aGVsbG8=')
fireEvent.click(screen.getByRole('button', { name: 'Expand image: shot.png' }))
expect(screen.getAllByAltText('shot.png')).toHaveLength(2)
})
it('falls back to the alt text when the image fails to load', () => {
render(<InlineImage src="broken" alt="shot.png" />)
fireEvent.error(screen.getByAltText('shot.png'))
expect(screen.queryByRole('button')).not.toBeInTheDocument()
expect(screen.getByText('shot.png')).toBeInTheDocument()
})
it('retries a new source after an image failure', () => {
const { rerender } = render(<InlineImage src="broken" alt="shot.png" />)
fireEvent.error(screen.getByAltText('shot.png'))
expect(screen.queryByRole('button')).not.toBeInTheDocument()
expect(screen.getByText('shot.png')).toBeInTheDocument()
rerender(<InlineImage src="data:image/png;base64,aGVsbG8=" alt="shot.png" />)
expect(screen.getByAltText('shot.png')).toHaveAttribute('src', 'data:image/png;base64,aGVsbG8=')
expect(screen.getByRole('button', { name: 'Expand image: shot.png' })).toBeInTheDocument()
})
it('renders only the image without an expand button when not expandable', () => {
render(<InlineImage src="data:image/png;base64,aGVsbG8=" alt="shot.png" expandable={false} />)
expect(screen.getByAltText('shot.png')).toHaveAttribute('src', 'data:image/png;base64,aGVsbG8=')
expect(screen.queryByRole('button')).not.toBeInTheDocument()
})
it('falls back to the alt text for a non-expandable image that fails to load', () => {
render(<InlineImage src="broken" alt="shot.png" expandable={false} />)
fireEvent.error(screen.getByAltText('shot.png'))
expect(screen.getByText('shot.png')).toBeInTheDocument()
})
})