-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimeLocalField.test.jsx
More file actions
56 lines (47 loc) · 1.34 KB
/
Copy pathDateTimeLocalField.test.jsx
File metadata and controls
56 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react'
import { render } from '@testing-library/react'
import { DateTimeLocalField, ValidationContext } from '.'
const buildPayload = () => {
return {
type: 'datetime-local',
defaultValue: '2004-06-15T01:02:03',
max: '2010-08-15',
min: '2000-06-15',
name: 'post[birth_date]',
id: 'post_birth_date',
}
}
describe('DateTimeLocalField', () => {
it('renders', () => {
const payload = buildPayload()
const { getByLabelText } = render(
<DateTimeLocalField
{...payload}
label={'Birth Date'}
errorKey={'birth_date'}
/>
)
const input = getByLabelText('Birth Date')
expect(input.value).toEqual('2004-06-15T01:02:03')
expect(input.max).toEqual('2010-08-15')
expect(input.min).toEqual('2000-06-15')
expect(input.type).toEqual('datetime-local')
})
it('renders with field errors', async () => {
const payload = buildPayload()
const validationErrors = {
birth_date: 'birth invalid',
}
const { getByText } = render(
<ValidationContext.Provider value={validationErrors}>
<DateTimeLocalField
{...payload}
label={'Birth Date'}
errorKey={'birth_date'}
/>
</ValidationContext.Provider>
)
const errorField = getByText('birth invalid')
expect(errorField).not.toBeNull()
})
})