import { fireEvent, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import PostList from '@/components/PostList'
import { buildPost } from '@/test/factories'
import { renderWithProviders } from '@/test/render'
describe ('PostList', () => {
it ('renders post thumbnails as links to post details', () => {
renderWithProviders (
,
)
expect (screen.getByRole ('link', { name: 'First' })).toHaveAttribute (
'href',
'/posts/1',
)
expect (
screen.getByRole ('link', { name: 'https://example.com/second' }),
).toHaveAttribute ('href', '/posts/2')
})
it ('calls the optional click handler', () => {
const onClick = vi.fn ()
renderWithProviders ()
fireEvent.click (screen.getByRole ('link', { name: 'テスト投稿' }))
expect (onClick).toHaveBeenCalledTimes (1)
})
})