このコミットが含まれているのは:
@@ -0,0 +1,63 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import PostEmbed from '@/components/PostEmbed'
|
||||
import { buildPost } from '@/test/factories'
|
||||
|
||||
const dialogue = vi.hoisted (() => ({
|
||||
confirm: vi.fn (),
|
||||
}))
|
||||
|
||||
vi.mock ('@/components/dialogues/DialogueProvider', () => ({
|
||||
useDialogue: () => dialogue,
|
||||
}))
|
||||
|
||||
vi.mock ('@/components/NicoViewer', () => ({
|
||||
default: ({ id }: { id: string }) => <div>Nico:{id}</div>,
|
||||
}))
|
||||
|
||||
vi.mock ('react-youtube', () => ({
|
||||
default: ({ videoId }: { videoId: string }) => <div>YouTube:{videoId}</div>,
|
||||
}))
|
||||
|
||||
describe ('PostEmbed', () => {
|
||||
beforeEach (() => {
|
||||
vi.clearAllMocks ()
|
||||
})
|
||||
|
||||
it ('embeds nicovideo watch URLs', () => {
|
||||
render (<PostEmbed post={buildPost ({ url: 'https://www.nicovideo.jp/watch/sm12345' })}/>)
|
||||
|
||||
expect (screen.getByText ('Nico:sm12345')).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('embeds x/twitter status URLs', () => {
|
||||
render (<PostEmbed post={buildPost ({ url: 'https://x.com/someone/status/12345' })}/>)
|
||||
|
||||
expect (screen.getByRole ('link', { name: '@someone' })).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('embeds youtube watch URLs', () => {
|
||||
render (<PostEmbed post={buildPost ({ url: 'https://www.youtube.com/watch?v=abc123' })}/>)
|
||||
|
||||
expect (screen.getByText ('YouTube:abc123')).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('asks before framing unknown external pages', async () => {
|
||||
dialogue.confirm.mockResolvedValueOnce (true)
|
||||
render (
|
||||
<PostEmbed
|
||||
post={buildPost ({ url: 'https://example.com/page', title: 'external' })}/>,
|
||||
)
|
||||
|
||||
fireEvent.click (screen.getByRole ('link', { name: '外部ページを表示' }))
|
||||
|
||||
await waitFor (() => {
|
||||
expect (dialogue.confirm).toHaveBeenCalled ()
|
||||
})
|
||||
expect (await screen.findByTitle ('external')).toHaveAttribute (
|
||||
'src',
|
||||
'https://example.com/page',
|
||||
)
|
||||
})
|
||||
})
|
||||
新しい課題から参照
ユーザをブロックする