Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(patients): set max date in date of birth date picker (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer authored Apr 21, 2020
1 parent a0f709a commit f292926
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
REACT_APP_HOSPITALRUN_API=http://0.0.0.0:3001
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ describe('date picker with label form group', () => {

it('should render and date time picker', () => {
const expectedName = 'test'
const expectedDate = new Date()
const wrapper = shallow(
<DatePickerWithLabelFormGroup
name={expectedName}
label="test"
value={new Date()}
isEditable
onChange={jest.fn()}
maxDate={expectedDate}
/>,
)

const input = wrapper.find(DateTimePicker)
expect(input).toHaveLength(1)
expect(input.prop('maxDate')).toEqual(expectedDate)
})

it('should render disabled is isDisable disabled is true', () => {
Expand Down
14 changes: 6 additions & 8 deletions src/__tests__/patients/GeneralInformation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe('General Information, without isEditable', () => {
let history = createMemoryHistory()

beforeEach(() => {
Date.now = jest.fn().mockReturnValue(new Date().valueOf())
jest.restoreAllMocks()
history = createMemoryHistory()
wrapper = mount(
<Router history={history}>
Expand All @@ -59,10 +61,6 @@ describe('General Information, without isEditable', () => {
)
})

beforeEach(() => {
jest.restoreAllMocks()
})

it('should render the prefix', () => {
const prefixInput = wrapper.findWhere((w: any) => w.prop('name') === 'prefix')
expect(prefixInput.prop('value')).toEqual(patient.prefix)
Expand Down Expand Up @@ -123,6 +121,7 @@ describe('General Information, without isEditable', () => {
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'dateOfBirth')
expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))
expect(dateOfBirthInput.prop('label')).toEqual('patient.dateOfBirth')
expect(dateOfBirthInput.prop('maxDate')).toEqual(new Date(Date.now()))
expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()
})

Expand Down Expand Up @@ -208,6 +207,8 @@ describe('General Information, isEditable', () => {
const onFieldChange = jest.fn()

beforeEach(() => {
jest.restoreAllMocks()
Date.now = jest.fn().mockReturnValue(new Date().valueOf())
history = createMemoryHistory()
wrapper = mount(
<Router history={history}>
Expand All @@ -216,10 +217,6 @@ describe('General Information, isEditable', () => {
)
})

beforeEach(() => {
jest.restoreAllMocks()
})

const expectedPrefix = 'expectedPrefix'
const expectedGivenName = 'expectedGivenName'
const expectedFamilyName = 'expectedFamilyName'
Expand Down Expand Up @@ -348,6 +345,7 @@ describe('General Information, isEditable', () => {
expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))
expect(dateOfBirthInput.prop('label')).toEqual('patient.dateOfBirth')
expect(dateOfBirthInput.prop('isEditable')).toBeTruthy()
expect(dateOfBirthInput.prop('maxDate')).toEqual(new Date(Date.now()))

act(() => {
dateOfBirthInput.prop('onChange')(new Date(expectedDateOfBirth))
Expand Down
14 changes: 13 additions & 1 deletion src/components/input/DatePickerWithLabelFormGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ interface Props {
isRequired?: boolean
feedback?: string
isInvalid?: boolean
maxDate?: Date
}

const DatePickerWithLabelFormGroup = (props: Props) => {
const { onChange, label, name, isEditable, value, isRequired, feedback, isInvalid } = props
const {
onChange,
label,
name,
isEditable,
value,
isRequired,
feedback,
isInvalid,
maxDate,
} = props
const id = `${name}DatePicker`
return (
<div className="form-group">
Expand All @@ -22,6 +33,7 @@ const DatePickerWithLabelFormGroup = (props: Props) => {
dateFormat="MM/dd/yyyy"
dateFormatCalendar="LLLL yyyy"
dropdownMode="scroll"
maxDate={maxDate}
selected={value}
timeIntervals={30}
withPortal={false}
Expand Down
1 change: 1 addition & 0 deletions src/patients/GeneralInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const GeneralInformation = (props: Props) => {
: undefined
}
isInvalid={invalidFields?.dateOfBirth}
maxDate={new Date(Date.now().valueOf())}
feedback={feedbackFields?.dateOfBirth}
onChange={(date: Date) => {
onDateOfBirthChange(date)
Expand Down

1 comment on commit f292926

@vercel
Copy link

@vercel vercel bot commented on f292926 Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.