-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb098d7
commit 6e4d31c
Showing
1 changed file
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import { render, waitFor, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Formik } from 'formik'; | ||
|
||
import OriginInfo from 'components/Office/OriginInfo/OriginInfo'; | ||
|
||
const defaultProps = { | ||
setFieldValue: jest.fn(), | ||
currentZip: '90210', | ||
isUseResidentialAddressZIPChecked: false, | ||
postalCodeValidator: jest.fn(), | ||
}; | ||
|
||
describe('OriginInfo component', () => { | ||
it('renders blank form on load', async () => { | ||
render( | ||
<Formik | ||
initialValues={{ | ||
plannedDepartureDate: '', | ||
originPostalCode: '', | ||
useResidentialAddressZIP: false, | ||
secondOriginPostalCode: '', | ||
}} | ||
> | ||
<OriginInfo {...defaultProps} /> | ||
</Formik>, | ||
); | ||
expect(await screen.getByRole('heading', { level: 2, name: 'Origin info' })).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Planned departure date')).toBeInstanceOf(HTMLInputElement); | ||
expect(screen.getByLabelText('Origin ZIP')).toBeInstanceOf(HTMLInputElement); | ||
expect(screen.getByLabelText('Second origin ZIP (optional)')).toBeInstanceOf(HTMLInputElement); | ||
}); | ||
|
||
it('fills in current ZIP when use current ZIP checkbox is checked', async () => { | ||
render( | ||
<Formik | ||
initialValues={{ | ||
plannedDepartureDate: '', | ||
originPostalCode: '', | ||
useResidentialAddressZIP: false, | ||
secondOriginPostalCode: '', | ||
}} | ||
> | ||
{({ setFieldValue }) => { | ||
return <OriginInfo {...defaultProps} setFieldValue={setFieldValue} />; | ||
}} | ||
</Formik>, | ||
); | ||
const useCurrentZip = screen.getByText('Use current ZIP'); | ||
const originZip = screen.getByLabelText('Origin ZIP'); | ||
expect(originZip.value).toBe(''); | ||
userEvent.click(useCurrentZip); | ||
await waitFor(() => { | ||
expect(originZip.value).toBe(defaultProps.currentZip); | ||
}); | ||
}); | ||
}); |