veza/apps/web/src/components/ui/optimized-image.test.tsx
senke 37981c2c17 chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 19:39:18 +01:00

63 lines
1.9 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { OptimizedImage } from './optimized-image';
vi.mock('@/hooks/useIntersectionObserver', () => ({
useIntersectionObserver: () => ({ isIntersecting: true }),
}));
vi.mock('@/components/ui/optimized-image/useImageFormatSupport', () => ({
useImageFormatSupport: () => ['jpeg'],
}));
describe('OptimizedImage Component', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('renders loading placeholder when src is provided', () => {
const { container } = render(<OptimizedImage src="test.jpg" alt="Test image" />);
const wrapper = container.querySelector('.relative');
expect(wrapper).toBeInTheDocument();
});
it('renders custom placeholder while loading', () => {
render(
<OptimizedImage
src="test.jpg"
alt="Test"
placeholder={<div>Loading...</div>}
/>,
);
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
it('accepts fallback prop and renders', () => {
render(
<OptimizedImage
src="test.jpg"
alt="Test"
fallback={<div data-testid="custom-fallback">Image not available</div>}
/>,
);
expect(document.querySelector('.relative')).toBeInTheDocument();
});
it('applies custom className to wrapper', () => {
const { container } = render(
<OptimizedImage src="test.jpg" alt="Test" className="custom-class" />,
);
const wrapper = container.querySelector('.custom-class');
expect(wrapper).toBeInTheDocument();
});
it('applies width and height to wrapper', () => {
const { container } = render(
<OptimizedImage src="test.jpg" alt="Test" width={200} height={200} />,
);
const wrapper = container.querySelector('.relative');
const style = wrapper?.getAttribute('style') ?? '';
expect(style).toContain('width: 200px');
expect(style).toContain('height: 200px');
});
});