forked from HHS/Head-Start-TTADP
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from adhocteam/js-129-change-datepicker-lib
Switch react-datepicker for react-dates
- Loading branch information
Showing
10 changed files
with
392 additions
and
157 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
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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
.usa-date-picker__button { | ||
margin-top: 0.5rem | ||
} | ||
.smart-hub--date-picker-input { | ||
/* | ||
We want the open button on the right of the date input and | ||
want the next focusable item after the button to be the calendar. | ||
row-reverse to deal with tab ordering in the case where | ||
the open button is clicked and then the user changes focus | ||
with the tab key. Since the open button has tabindex of -1 | ||
we won't run into an issue of focus moving "backwards" | ||
*/ | ||
flex-direction: row-reverse; | ||
width: fit-content; | ||
} |
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 |
---|---|---|
@@ -1,59 +1,66 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { | ||
render, screen, fireEvent, waitFor, | ||
render, screen, fireEvent, waitFor, act, | ||
} from '@testing-library/react'; | ||
|
||
import { useForm } from 'react-hook-form'; | ||
import DatePicker from '../DatePicker'; | ||
|
||
// react-dates when opening the calendar in these tests. For details see | ||
// https://github.com/airbnb/react-dates/issues/1426#issuecomment-593420014 | ||
Object.defineProperty(window, 'getComputedStyle', { | ||
value: () => ({ | ||
paddingLeft: 0, | ||
paddingRight: 0, | ||
paddingTop: 0, | ||
paddingBottom: 0, | ||
marginLeft: 0, | ||
marginRight: 0, | ||
marginTop: 0, | ||
marginBottom: 0, | ||
borderBottomWidth: 0, | ||
borderTopWidth: 0, | ||
borderRightWidth: 0, | ||
borderLeftWidth: 0, | ||
}), | ||
}); | ||
|
||
describe('DatePicker', () => { | ||
// eslint-disable-next-line react/prop-types | ||
const RenderDatePicker = ({ minDate, maxDate, disabled }) => { | ||
const RenderDatePicker = ({ disabled }) => { | ||
const { control } = useForm(); | ||
return ( | ||
<form> | ||
<DatePicker | ||
control={control} | ||
label="label" | ||
name="picker" | ||
minDate={minDate} | ||
maxDate={maxDate} | ||
disabled={disabled} | ||
/> | ||
</form> | ||
); | ||
}; | ||
|
||
it('disabled flag disables text input', () => { | ||
render(<RenderDatePicker disabled />); | ||
it('disabled flag disables text input', async () => { | ||
await act(async () => render(<RenderDatePicker disabled />)); | ||
expect(screen.getByRole('textbox')).toBeDisabled(); | ||
}); | ||
|
||
it('accepts text input', async () => { | ||
render(<RenderDatePicker />); | ||
const textbox = screen.getByRole('textbox'); | ||
fireEvent.change(textbox, { target: { value: '01/01/2000' } }); | ||
waitFor(() => expect(screen.getByRole('textbox')).toHaveTextContent('01/01/2000')); | ||
}); | ||
|
||
describe('maxDate', () => { | ||
it('causes input after minDate to be discarded', async () => { | ||
const date = new Date(2000, 1, 2); | ||
render(<RenderDatePicker maxDate={date} />); | ||
const textbox = screen.getByRole('textbox'); | ||
fireEvent.change(textbox, { target: { value: '01/03/1000' } }); | ||
waitFor(() => expect(screen.getByRole('textbox')).toHaveTextContent('')); | ||
}); | ||
await waitFor(() => expect(screen.getByRole('textbox')).toHaveValue('01/01/2000')); | ||
}); | ||
|
||
describe('minDate', () => { | ||
it('causes input before minDate to be discarded', async () => { | ||
const date = new Date(2000, 1, 2); | ||
render(<RenderDatePicker minDate={date} />); | ||
const textbox = screen.getByRole('textbox'); | ||
fireEvent.change(textbox, { target: { value: '01/01/1000' } }); | ||
waitFor(() => expect(screen.getByRole('textbox')).toHaveTextContent('')); | ||
it('clicking the open button will open the calendar', async () => { | ||
await act(async () => { | ||
render(<RenderDatePicker />); | ||
const openCalendar = screen.getByRole('button'); | ||
fireEvent.click(openCalendar); | ||
}); | ||
const button = await waitFor(() => screen.getByLabelText('Move backward to switch to the previous month.')); | ||
await waitFor(() => expect(button).toBeVisible()); | ||
}); | ||
}); |
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
Oops, something went wrong.