このコミットが含まれているのは:
@@ -46,20 +46,37 @@ describe ('PostOriginalCreatedTimeField', () => {
|
||||
.toBe (60_000)
|
||||
})
|
||||
|
||||
it ('normalises second-bearing values to minute precision', () => {
|
||||
it ('does not rewrite mounted values that only differ by offset notation', () => {
|
||||
const setFrom = vi.fn ()
|
||||
const setBefore = vi.fn ()
|
||||
|
||||
render (
|
||||
<PostOriginalCreatedTimeField
|
||||
originalCreatedFrom="2026-01-01T00:00:05Z"
|
||||
originalCreatedFrom="2024-01-01T12:34+09:00"
|
||||
setOriginalCreatedFrom={setFrom}
|
||||
originalCreatedBefore="2026-01-02T00:00:00.123Z"
|
||||
originalCreatedBefore="2024-01-01T12:35+09:00"
|
||||
setOriginalCreatedBefore={setBefore}/>,
|
||||
)
|
||||
|
||||
expect (setFrom).toHaveBeenCalledWith ('2026-01-01T00:00Z')
|
||||
expect (setBefore).toHaveBeenCalledWith ('2026-01-02T00:00Z')
|
||||
expect (setFrom).not.toHaveBeenCalled ()
|
||||
expect (setBefore).not.toHaveBeenCalled ()
|
||||
})
|
||||
|
||||
it ('emits minute-precision UTC values only when the user edits the input', () => {
|
||||
const setFrom = vi.fn ()
|
||||
|
||||
render (
|
||||
<PostOriginalCreatedTimeField
|
||||
originalCreatedFrom="2024-01-01T12:34+09:00"
|
||||
setOriginalCreatedFrom={setFrom}
|
||||
originalCreatedBefore={null}
|
||||
setOriginalCreatedBefore={vi.fn ()}/>,
|
||||
)
|
||||
|
||||
const input = screen.getDisplayValue ('2024-01-01T12:34')
|
||||
fireEvent.change (input, { target: { value: '2024-01-01T12:35' } })
|
||||
|
||||
expect (setFrom).toHaveBeenCalledWith ('2024-01-01T03:35Z')
|
||||
})
|
||||
|
||||
it ('resets both values', () => {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
import DateTimeField, { toMinutePrecisionIsoUtc } from '@/components/common/DateTimeField'
|
||||
import FormField from '@/components/common/FormField'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -22,24 +20,6 @@ const PostOriginalCreatedTimeField: FC<Props> = (
|
||||
originalCreatedBefore,
|
||||
setOriginalCreatedBefore,
|
||||
errors }: Props) => {
|
||||
useEffect (() => {
|
||||
if (originalCreatedFrom == null)
|
||||
return
|
||||
|
||||
const normalised = toMinutePrecisionIsoUtc (originalCreatedFrom)
|
||||
if (normalised !== originalCreatedFrom)
|
||||
setOriginalCreatedFrom (normalised)
|
||||
}, [originalCreatedFrom, setOriginalCreatedFrom])
|
||||
|
||||
useEffect (() => {
|
||||
if (originalCreatedBefore == null)
|
||||
return
|
||||
|
||||
const normalised = toMinutePrecisionIsoUtc (originalCreatedBefore)
|
||||
if (normalised !== originalCreatedBefore)
|
||||
setOriginalCreatedBefore (normalised)
|
||||
}, [originalCreatedBefore, setOriginalCreatedBefore])
|
||||
|
||||
return (
|
||||
<FormField label="オリジナルの作成日時" messages={errors}>
|
||||
{({ describedBy, invalid }) => (
|
||||
|
||||
@@ -88,4 +88,36 @@ describe ('PostImportRowForm', () => {
|
||||
expect (screen.getAllByRole ('textbox').filter (
|
||||
_1 => _1.getAttribute ('aria-invalid') === 'true')).toHaveLength (3)
|
||||
})
|
||||
|
||||
it ('keeps untouched original created values unchanged in the save payload', async () => {
|
||||
let actions: DialogueFormAction[] = []
|
||||
const row = buildPostImportRow ({
|
||||
attributes: {
|
||||
originalCreatedFrom: '2024-01-01T12:34+09:00',
|
||||
originalCreatedBefore: '2024-01-01T12:35+09:00' } })
|
||||
const controls: DialogueFormControls = {
|
||||
close: vi.fn (),
|
||||
confirm: vi.fn (),
|
||||
setActions: next => {
|
||||
actions = next
|
||||
} }
|
||||
const onSave = vi.fn ().mockResolvedValue ({ saved: true, row: null })
|
||||
|
||||
render (
|
||||
<PostImportRowForm
|
||||
row={row}
|
||||
controls={controls}
|
||||
onSave={onSave}/>)
|
||||
await waitFor (() => expect (actions.length).toBe (2))
|
||||
|
||||
await act (async () => {
|
||||
await actions.find (_1 => _1.label === '編輯内容を保存')?.onSelect ()
|
||||
})
|
||||
|
||||
expect (onSave).toHaveBeenCalledWith ({
|
||||
draft: expect.objectContaining ({
|
||||
originalCreatedFrom: '2024-01-01T12:34+09:00',
|
||||
originalCreatedBefore: '2024-01-01T12:35+09:00' }),
|
||||
resetRequested: false })
|
||||
})
|
||||
})
|
||||
|
||||
新しい課題から参照
ユーザをブロックする