このコミットが含まれているのは:
@@ -0,0 +1,34 @@
|
||||
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 (
|
||||
<PostList posts={[
|
||||
buildPost ({ id: 1, title: 'First', thumbnail: 'first.jpg' }),
|
||||
buildPost ({ id: 2, title: null, url: 'https://example.com/second' }),
|
||||
]}/>,
|
||||
)
|
||||
|
||||
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 (<PostList posts={[buildPost ()]} onClick={onClick}/>)
|
||||
|
||||
fireEvent.click (screen.getByRole ('link', { name: 'テスト投稿' }))
|
||||
|
||||
expect (onClick).toHaveBeenCalledTimes (1)
|
||||
})
|
||||
})
|
||||
新しい課題から参照
ユーザをブロックする