Reviewed-on: #359 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #359 でマージされました.
このコミットが含まれているのは:
@@ -1,4 +1,4 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { act, fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
@@ -31,15 +31,31 @@ const dialogue = vi.hoisted (() => ({
|
||||
confirm: vi.fn (),
|
||||
}))
|
||||
|
||||
const postEmbed = vi.hoisted (() => ({
|
||||
props: vi.fn (),
|
||||
play: vi.fn (),
|
||||
seek: vi.fn (),
|
||||
}))
|
||||
|
||||
vi.mock ('@/lib/api', () => api)
|
||||
vi.mock ('@/lib/posts', () => postsApi)
|
||||
vi.mock ('@/components/dialogues/DialogueProvider', () => ({
|
||||
useDialogue: () => dialogue,
|
||||
}))
|
||||
vi.mock ('@/components/PostEmbed', () => ({
|
||||
default: ({ post }: {
|
||||
default: (props: {
|
||||
ref?: { current: unknown }
|
||||
post: { title: string | null; url: string }
|
||||
}) => <div>Embed:{post.title || post.url}</div>,
|
||||
}) => {
|
||||
postEmbed.props (props)
|
||||
if (props.ref)
|
||||
props.ref.current = {
|
||||
play: postEmbed.play,
|
||||
seek: postEmbed.seek,
|
||||
}
|
||||
|
||||
return <div>Embed:{props.post.title || props.post.url}</div>
|
||||
},
|
||||
}))
|
||||
vi.mock ('@/components/PostEditForm', () => ({
|
||||
default: () => <div>Post edit form</div>,
|
||||
@@ -153,6 +169,7 @@ const mockDefaultApi = () => {
|
||||
|
||||
describe ('TheatreDetailPage', () => {
|
||||
beforeEach (() => {
|
||||
vi.useRealTimers ()
|
||||
vi.clearAllMocks ()
|
||||
mockDefaultApi ()
|
||||
})
|
||||
@@ -188,6 +205,83 @@ describe ('TheatreDetailPage', () => {
|
||||
.toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it ('does not seek to zero while applying video length from the player', async () => {
|
||||
api.apiPut.mockImplementation ((path: string) => {
|
||||
switch (path)
|
||||
{
|
||||
case '/theatres/7/watching':
|
||||
return Promise.resolve (buildTheatreInfo ({
|
||||
hostFlg: true,
|
||||
postId: currentPost.id,
|
||||
postStartedAt: '2026-01-02T03:04:05.000Z',
|
||||
postElapsedMs: 7_000,
|
||||
watchingUsers: [{ id: 1, name: 'tester' }],
|
||||
skipVote: {
|
||||
votesCount: 0,
|
||||
requiredCount: 2,
|
||||
watchingUsersCount: 1,
|
||||
voted: false,
|
||||
},
|
||||
}))
|
||||
|
||||
default:
|
||||
return Promise.reject (new Error (`Unexpected PUT ${ path }`))
|
||||
}
|
||||
})
|
||||
|
||||
renderPage ()
|
||||
await screen.findByText ('Embed:上映中の投稿')
|
||||
|
||||
const props = postEmbed.props.mock.calls.at (-1)![0]
|
||||
|
||||
act (() => {
|
||||
props.onVideoReady (120_000)
|
||||
props.onPlaybackChange (0)
|
||||
})
|
||||
|
||||
const seekMs = postEmbed.seek.mock.calls[0][0]
|
||||
expect (seekMs).toBeGreaterThanOrEqual (7_000)
|
||||
expect (seekMs).toBeLessThan (10_000)
|
||||
expect (postEmbed.seek).not.toHaveBeenCalledWith (0)
|
||||
})
|
||||
|
||||
it ('does not advance host post while video length is unknown', async () => {
|
||||
api.apiPut.mockImplementation ((path: string) => {
|
||||
switch (path)
|
||||
{
|
||||
case '/theatres/7/watching':
|
||||
return Promise.resolve (buildTheatreInfo ({
|
||||
hostFlg: true,
|
||||
postId: currentPost.id,
|
||||
postStartedAt: '2026-01-02T03:04:05.000Z',
|
||||
postElapsedMs: 4_000,
|
||||
watchingUsers: [{ id: 1, name: 'tester' }],
|
||||
skipVote: {
|
||||
votesCount: 0,
|
||||
requiredCount: 2,
|
||||
watchingUsersCount: 1,
|
||||
voted: false,
|
||||
},
|
||||
}))
|
||||
|
||||
default:
|
||||
return Promise.reject (new Error (`Unexpected PUT ${ path }`))
|
||||
}
|
||||
})
|
||||
|
||||
renderPage ()
|
||||
|
||||
await screen.findByText ('Embed:上映中の投稿')
|
||||
await waitFor (() => {
|
||||
expect (api.apiPut).toHaveBeenCalledWith ('/theatres/7/watching')
|
||||
})
|
||||
|
||||
await waitFor (() => {
|
||||
expect (api.apiPut).toHaveBeenCalledTimes (2)
|
||||
}, { timeout: 2_500 })
|
||||
expect (api.apiPatch).not.toHaveBeenCalledWith ('/theatres/7/next_post')
|
||||
})
|
||||
|
||||
it ('deletes an owned comment after confirmation', async () => {
|
||||
renderPage ()
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする