-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DateTimeLocalField on vanilla
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters