-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update type for Address form. Fix MultiValueEntry component not setti…
…ng coded values on edit (#1827) Co-authored-by: Michael Peels <michaelpeels@Michael-Peels.local>
- Loading branch information
Showing
10 changed files
with
454 additions
and
68 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
32 changes: 14 additions & 18 deletions
32
apps/modernization-ui/src/apps/patient/add/extended/inputs/address/AddressMultiEntry.tsx
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
37 changes: 7 additions & 30 deletions
37
apps/modernization-ui/src/apps/patient/add/extended/inputs/address/AddressView.spec.tsx
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
20 changes: 7 additions & 13 deletions
20
apps/modernization-ui/src/apps/patient/add/extended/inputs/address/AddressView.tsx
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
149 changes: 149 additions & 0 deletions
149
apps/modernization-ui/src/apps/patient/data/address/AddressEntryFields.spec.tsx
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,149 @@ | ||
import { fireEvent, render, waitFor, screen } from '@testing-library/react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { AddressEntry } from '../entry'; | ||
import { AddressEntryFields } from './AddressEntryFields'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const mockPatientAddressCodedValues = { | ||
types: [{ name: 'House', value: 'H' }], | ||
uses: [{ name: 'Home', value: 'HM' }] | ||
}; | ||
|
||
jest.mock('apps/patient/profile/addresses/usePatientAddressCodedValues', () => ({ | ||
usePatientAddressCodedValues: () => mockPatientAddressCodedValues | ||
})); | ||
|
||
const mockLocationCodedValues = { | ||
states: { | ||
all: [{ name: 'StateName', value: '1' }] | ||
}, | ||
counties: { | ||
byState: (state: string) => [{ name: 'CountyName', value: '2' }] | ||
}, | ||
countries: [{ name: 'CountryName', value: '3' }] | ||
}; | ||
|
||
jest.mock('location/useLocationCodedValues', () => ({ | ||
useLocationCodedValues: () => mockLocationCodedValues | ||
})); | ||
|
||
const form = renderHook(() => | ||
useForm<AddressEntry>({ | ||
mode: 'onBlur', | ||
defaultValues: { | ||
asOf: undefined, | ||
type: undefined, | ||
use: undefined, | ||
address1: '', | ||
address2: '', | ||
city: '', | ||
state: undefined, | ||
zipcode: '', | ||
county: undefined, | ||
country: undefined, | ||
censusTract: '', | ||
comment: '' | ||
} | ||
}) | ||
).result.current; | ||
|
||
describe('PhoneEmailEntryFields', () => { | ||
it('should render the proper labels', () => { | ||
const { getByLabelText } = render( | ||
<FormProvider {...form}> | ||
<AddressEntryFields /> | ||
</FormProvider> | ||
); | ||
|
||
expect(getByLabelText('Address as of')).toBeInTheDocument(); | ||
expect(getByLabelText('Type')).toBeInTheDocument(); | ||
expect(getByLabelText('Use')).toBeInTheDocument(); | ||
expect(getByLabelText('Street address 1')).toBeInTheDocument(); | ||
expect(getByLabelText('Street address 2')).toBeInTheDocument(); | ||
expect(getByLabelText('City')).toBeInTheDocument(); | ||
expect(getByLabelText('State')).toBeInTheDocument(); | ||
expect(getByLabelText('Zip')).toBeInTheDocument(); | ||
expect(getByLabelText('County')).toBeInTheDocument(); | ||
expect(getByLabelText('Census tract')).toBeInTheDocument(); | ||
expect(getByLabelText('Country')).toBeInTheDocument(); | ||
expect(getByLabelText('Address comments')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should require type', async () => { | ||
const { getByLabelText, getByText } = render( | ||
<FormProvider {...form}> | ||
<AddressEntryFields /> | ||
</FormProvider> | ||
); | ||
|
||
const typeInput = getByLabelText('Type'); | ||
act(() => { | ||
fireEvent.blur(typeInput); | ||
}); | ||
await waitFor(() => { | ||
expect(getByText('Type is required.')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should require use', async () => { | ||
const { getByLabelText, getByText } = render( | ||
<FormProvider {...form}> | ||
<AddressEntryFields /> | ||
</FormProvider> | ||
); | ||
|
||
const useInput = getByLabelText('Use'); | ||
act(() => { | ||
fireEvent.blur(useInput); | ||
}); | ||
await waitFor(() => { | ||
expect(getByText('Use is required.')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should require as of', async () => { | ||
const { getByLabelText, getByText } = render( | ||
<FormProvider {...form}> | ||
<AddressEntryFields /> | ||
</FormProvider> | ||
); | ||
|
||
const asOf = getByLabelText('Address as of'); | ||
act(() => { | ||
fireEvent.blur(asOf); | ||
}); | ||
await waitFor(() => { | ||
expect(getByText('As of date is required.')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should be valid with as of, type, and use', async () => { | ||
const { getByLabelText } = render( | ||
<FormProvider {...form}> | ||
<AddressEntryFields /> | ||
</FormProvider> | ||
); | ||
|
||
const asOf = getByLabelText('Address as of'); | ||
const type = getByLabelText('Type'); | ||
const use = getByLabelText('Use'); | ||
await screen.findByText('Use'); | ||
|
||
act(() => { | ||
userEvent.paste(asOf, '01/20/2020'); | ||
fireEvent.blur(asOf); | ||
userEvent.selectOptions(use, 'HM'); | ||
fireEvent.blur(use); | ||
userEvent.selectOptions(type, 'H'); | ||
fireEvent.blur(type); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(form.getFieldState('asOf').invalid).toBeFalsy(); | ||
expect(form.getFieldState('type').invalid).toBeFalsy(); | ||
expect(form.getFieldState('use').invalid).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.