From f292926c46941159ba807bef3986f21a1ca34762 Mon Sep 17 00:00:00 2001 From: Jack Meyer Date: Tue, 21 Apr 2020 18:00:54 -0500 Subject: [PATCH] feat(patients): set max date in date of birth date picker (#2002) --- .env.example | 1 - .../input/DatePickerWithLabelFormGroup.test.tsx | 3 +++ src/__tests__/patients/GeneralInformation.test.tsx | 14 ++++++-------- .../input/DatePickerWithLabelFormGroup.tsx | 14 +++++++++++++- src/patients/GeneralInformation.tsx | 1 + 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 8e0036ab76..e69de29bb2 100644 --- a/.env.example +++ b/.env.example @@ -1 +0,0 @@ -REACT_APP_HOSPITALRUN_API=http://0.0.0.0:3001 \ No newline at end of file diff --git a/src/__tests__/components/input/DatePickerWithLabelFormGroup.test.tsx b/src/__tests__/components/input/DatePickerWithLabelFormGroup.test.tsx index 27a35b9524..0bb2fec902 100644 --- a/src/__tests__/components/input/DatePickerWithLabelFormGroup.test.tsx +++ b/src/__tests__/components/input/DatePickerWithLabelFormGroup.test.tsx @@ -26,6 +26,7 @@ describe('date picker with label form group', () => { it('should render and date time picker', () => { const expectedName = 'test' + const expectedDate = new Date() const wrapper = shallow( { 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', () => { diff --git a/src/__tests__/patients/GeneralInformation.test.tsx b/src/__tests__/patients/GeneralInformation.test.tsx index 7351e4cbb0..e748507206 100644 --- a/src/__tests__/patients/GeneralInformation.test.tsx +++ b/src/__tests__/patients/GeneralInformation.test.tsx @@ -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( @@ -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) @@ -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() }) @@ -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( @@ -216,10 +217,6 @@ describe('General Information, isEditable', () => { ) }) - beforeEach(() => { - jest.restoreAllMocks() - }) - const expectedPrefix = 'expectedPrefix' const expectedGivenName = 'expectedGivenName' const expectedFamilyName = 'expectedFamilyName' @@ -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)) diff --git a/src/components/input/DatePickerWithLabelFormGroup.tsx b/src/components/input/DatePickerWithLabelFormGroup.tsx index e1f137b0e8..777b69326e 100644 --- a/src/components/input/DatePickerWithLabelFormGroup.tsx +++ b/src/components/input/DatePickerWithLabelFormGroup.tsx @@ -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 (
@@ -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} diff --git a/src/patients/GeneralInformation.tsx b/src/patients/GeneralInformation.tsx index 93efcb6ce4..2b46abbd1c 100644 --- a/src/patients/GeneralInformation.tsx +++ b/src/patients/GeneralInformation.tsx @@ -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)