import { fireEvent, render, screen } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import { ImageLightbox } from './ImageLightbox' describe('ImageLightbox', () => { it('renders the selected image in a dialog', () => { render( {}} />, ) expect(screen.getByTestId('image-lightbox')).toBeInTheDocument() expect(screen.getByRole('img', { name: 'A lake' })).toHaveAttribute('src', 'https://example.com/photo.png') expect(screen.getByText('Image preview')).toHaveClass('sr-only') }) it('falls back to localized alt text when the image has no alt', () => { render( {}} />, ) expect(screen.getByRole('img', { name: '图像预览' })).toBeInTheDocument() }) it('calls onClose when the dialog closes', () => { const onClose = vi.fn() render( , ) fireEvent.keyDown(screen.getByTestId('image-lightbox'), { key: 'Escape' }) expect(onClose).toHaveBeenCalledTimes(1) }) })