Skip to content

Commit

Permalink
Fix state fields to be required, clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zakpatterson committed Jan 2, 2022
1 parent 8e1fa8d commit 7ed8b06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/components/income/W2JobInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const toIncomeW2 = (formData: IncomeW2UserInput): IncomeW2 => ({
ssWithholding: parseFormNumberOrThrow(formData.ssWithholding),
medicareWithholding: parseFormNumberOrThrow(formData.medicareWithholding),
state: formData.state,
stateWages: parseFormNumber(formData.stateWages),
stateWithholding: parseFormNumber(formData.stateWithholding)
stateWages: parseFormNumberOrThrow(formData.stateWages),
stateWithholding: parseFormNumberOrThrow(formData.stateWithholding)
})

const toIncomeW2UserInput = (data: IncomeW2): IncomeW2UserInput => ({
Expand Down Expand Up @@ -199,14 +199,14 @@ export default function W2JobInfo(): ReactElement {
name="stateWages"
label={boxLabel('16', 'State wages, tips, etc')}
patternConfig={Patterns.currency}
required={false}
required={true}
sizes={{ xs: 12, lg: 6 }}
/>
<LabeledInput
name="stateWithholding"
label={boxLabel('17', 'State income tax')}
patternConfig={Patterns.currency}
required={false}
required={true}
sizes={{ xs: 12, lg: 6 }}
/>
<GenericLabeledDropdown
Expand Down
40 changes: 23 additions & 17 deletions src/tests/components/income/W2JobInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ const testInfo: Information = {
stateResidencies: [{ state: 'AL' }]
}

const errors = {
inputRequired: () => screen.queryAllByText('Input is required'),
selectionRequired: () => screen.queryAllByText('Make a selection'),
inputWordFormat: () =>
screen.queryAllByText('Input should only include letters and spaces'),
einFormat: () =>
screen.queryAllByText('Input should be filled with 9 digits'),
all: () => {
// just a moment
}
}
errors.all = () => [
...errors.inputRequired(),
...errors.selectionRequired(),
...errors.inputWordFormat(),
...errors.einFormat()
]

describe('W2JobInfo', () => {
afterEach(async () => {
await waitFor(() => localStorage.clear())
Expand Down Expand Up @@ -142,8 +160,8 @@ describe('W2JobInfo', () => {
clickButton('Save')

await waitFor(() => {
expect(screen.getAllByText('Input is required')).toHaveLength(8)
expect(screen.getAllByText('Make a selection')).toHaveLength(2)
expect(errors.inputRequired()).toHaveLength(10)
expect(errors.selectionRequired()).toHaveLength(2)
})
})

Expand All @@ -154,11 +172,7 @@ describe('W2JobInfo', () => {
changeByLabelText('Employer name', '123')
clickButton('Save')

await waitFor(() =>
expect(
screen.getByText('Input should only include letters and spaces')
).toBeInTheDocument()
)
await waitFor(() => expect(errors.inputWordFormat()).toHaveLength(1))
})

it('Employers Identification Number', async () => {
Expand All @@ -168,11 +182,7 @@ describe('W2JobInfo', () => {
changeByLabelText(/Employer's Identification Number/, '123')
clickButton('Save')

await waitFor(() =>
expect(
screen.getByText('Input should be filled with 9 digits')
).toBeInTheDocument()
)
await waitFor(() => expect(errors.einFormat()).toHaveLength(1))
})

it('Occupation', async () => {
Expand All @@ -182,11 +192,7 @@ describe('W2JobInfo', () => {
changeByLabelText('Occupation', '123')
clickButton('Save')

await waitFor(() =>
expect(
screen.getByText('Input should only include letters and spaces')
).toBeInTheDocument()
)
await waitFor(() => expect(errors.inputWordFormat()).toHaveLength(1))
})
})

Expand Down

0 comments on commit 7ed8b06

Please sign in to comment.