import { describe, it, expect, vi } from 'vitest' import { render, screen } from '@testing-library/react' import HeroSection from '@/components/home/HeroSection' import type { Article } from '@/lib/types' vi.mock('next/image', () => ({ default: (props: Record) => { const { fill, priority, ...rest } = props return }, })) const mockArticle: Article = { id: '1', title: 'Frieren Season 2 Officially Announced', slug: 'frieren-s2', status: 'published', content: null, excerpt: 'The beloved series returns with a new season.', featured_image: 'uuid-image-123', published_at: '2026-05-28T00:00:00Z', date_created: '2026-05-28T00:00:00Z', is_featured: true, seo_title: null, seo_description: null, category: { id: '1', name: 'Anime', slug: 'anime', description: null }, tags: [], } describe('HeroSection', () => { it('renders the article title', () => { render() expect(screen.getByText('Frieren Season 2 Officially Announced')).toBeInTheDocument() }) it('renders the category name', () => { render() expect(screen.getByText('Anime')).toBeInTheDocument() }) it('renders the Featured badge', () => { render() expect(screen.getByText('Featured')).toBeInTheDocument() }) it('renders the excerpt when provided', () => { render() expect(screen.getByText('The beloved series returns with a new season.')).toBeInTheDocument() }) it('links to the article page', () => { render() const link = screen.getByRole('link', { name: /read article/i }) expect(link).toHaveAttribute('href', '/anime/frieren-s2') }) it('renders an image when featured_image is set', () => { render() const img = screen.getByRole('img') expect(img).toBeInTheDocument() expect(img).toHaveAttribute('alt', 'Frieren Season 2 Officially Announced') }) it('renders placeholder when featured_image is null', () => { const articleNoImg = { ...mockArticle, featured_image: null } const { container } = render() expect(container.querySelector('.bg-bg-elevated')).toBeInTheDocument() expect(screen.queryByRole('img')).not.toBeInTheDocument() }) it('does not render excerpt section when excerpt is null', () => { const articleNoExcerpt = { ...mockArticle, excerpt: null } render() expect(screen.queryByText('The beloved series returns with a new season.')).not.toBeInTheDocument() }) })