Skip to content

Commit

Permalink
Add unit tests for OriginInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
hannaliebl authored and jenniferlynparsons committed Jun 2, 2022
1 parent bb098d7 commit 6e4d31c
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/components/Office/OriginInfo/OriginInfo.test.jsx
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);
});
});
});

0 comments on commit 6e4d31c

Please sign in to comment.