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() 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() 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() fireEvent.error(screen.getByAltText('shot.png')) expect(screen.queryByRole('button')).not.toBeInTheDocument() expect(screen.getByText('shot.png')).toBeInTheDocument() rerender() 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() 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() fireEvent.error(screen.getByAltText('shot.png')) expect(screen.getByText('shot.png')).toBeInTheDocument() }) })