このコミットが含まれているのは:
@@ -1,8 +1,7 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { toMinutePrecisionIsoUtc } from '@/components/common/DateTimeField'
|
||||
import PostNewPage from '@/pages/posts/PostNewPage'
|
||||
import { buildUser } from '@/test/factories'
|
||||
import { renderWithProviders } from '@/test/render'
|
||||
@@ -108,15 +107,31 @@ describe ('PostNewPage', () => {
|
||||
expect (screen.getAllByRole ('textbox')[4]).toHaveAttribute ('aria-invalid', 'true')
|
||||
})
|
||||
|
||||
it ('shares the common post field components with the import form', () => {
|
||||
const newPage = readFileSync ('src/pages/posts/PostNewPage.tsx', 'utf8')
|
||||
const importForm = readFileSync ('src/components/posts/import/PostImportRowForm.tsx', 'utf8')
|
||||
it ('uses the shared duration, tags, and datetime value contract for post submission', async () => {
|
||||
api.apiPost.mockResolvedValueOnce ({})
|
||||
api.apiGet.mockResolvedValue ([])
|
||||
|
||||
expect (newPage).toContain ("@/components/posts/PostTextField")
|
||||
expect (newPage).toContain ("@/components/posts/PostDurationField")
|
||||
expect (newPage).toContain ("@/components/posts/PostTagsField")
|
||||
expect (importForm).toContain ("@/components/posts/PostTextField")
|
||||
expect (importForm).toContain ("@/components/posts/PostDurationField")
|
||||
expect (importForm).toContain ("@/components/posts/PostTagsField")
|
||||
const { container } = renderWithProviders (<PostNewPage user={buildUser ({ role: 'member' })}/>)
|
||||
|
||||
const textboxes = screen.getAllByRole ('textbox')
|
||||
fireEvent.change (textboxes[0], { target: { value: 'https://example.com/post' } })
|
||||
fireEvent.change (textboxes[1], { target: { value: '投稿タイトル' } })
|
||||
fireEvent.change (textboxes[4], { target: { value: '動画 tag1 tag2' } })
|
||||
fireEvent.change (
|
||||
screen.getByPlaceholderText ('例: 2 / 2.5 / 1:23'),
|
||||
{ target: { value: '2.5' } })
|
||||
const datetimeInputs = container.querySelectorAll ('input[type="datetime-local"]')
|
||||
fireEvent.change (datetimeInputs[0] as HTMLInputElement, {
|
||||
target: { value: '2024-01-01T12:34' } })
|
||||
fireEvent.click (screen.getByRole ('button', { name: '追加' }))
|
||||
|
||||
await waitFor (() => expect (api.apiPost).toHaveBeenCalled ())
|
||||
|
||||
const formData = api.apiPost.mock.calls[0]?.[1] as FormData
|
||||
expect (container.querySelector ('input[type="file"]')).not.toBeNull ()
|
||||
expect (formData.get ('duration')).toBe ('2.5')
|
||||
expect (formData.get ('tags')).toBe ('動画 tag1 tag2')
|
||||
expect (formData.get ('original_created_from')).toBe (
|
||||
toMinutePrecisionIsoUtc ('2024-01-01T12:34'))
|
||||
})
|
||||
})
|
||||
|
||||
新しい課題から参照
ユーザをブロックする