-
Notifications
You must be signed in to change notification settings - Fork 7
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
c69f165
commit 90f7d02
Showing
2 changed files
with
38 additions
and
44 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
78 changes: 36 additions & 42 deletions
78
frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js
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 |
---|---|---|
@@ -1,55 +1,49 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import '@testing-library/jest-dom'; | ||
import { | ||
render, | ||
screen, | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TextInput } from '@trussworks/react-uswds'; | ||
import ObjectiveFormItem from '../ObjectiveFormItem'; | ||
|
||
const RenderObjectiveFormItem = ({ | ||
// eslint-disable-next-line react/prop-types | ||
isValid, formItemValue, onChange = () => { }, | ||
}) => { | ||
return ( | ||
<ObjectiveFormItem | ||
showErrors={!isValid} | ||
className="margin-top-0" | ||
message='objective form item required' | ||
label='Objective' | ||
value={formItemValue} | ||
> | ||
<TextInput | ||
name="text-input-name" | ||
aria-label='text-input-label' | ||
onChange={onChange} | ||
value={formItemValue} | ||
/> | ||
</ObjectiveFormItem> | ||
); | ||
}; | ||
// eslint-disable-next-line react/prop-types | ||
isValid, formItemValue, onChange = () => { }, | ||
}) => ( | ||
<ObjectiveFormItem | ||
showErrors={!isValid} | ||
className="margin-top-0" | ||
message="objective form item required" | ||
label="Objective" | ||
value={formItemValue} | ||
> | ||
<TextInput | ||
name="text-input-name" | ||
aria-label="text-input-label" | ||
onChange={onChange} | ||
value={formItemValue} | ||
/> | ||
</ObjectiveFormItem> | ||
); | ||
|
||
describe('ObjectiveFormItem', () => { | ||
it('renders correctly', async () => { | ||
const onChange = jest.fn(); | ||
render(<RenderObjectiveFormItem isValid formItemValue="some value" onChange={onChange} />); | ||
const save = await screen.findByText('Objective'); | ||
expect(save).toBeVisible(); | ||
const errorMessage = screen.queryByText('objective form item required'); | ||
expect(errorMessage).toBeNull(); | ||
}); | ||
|
||
it('renders correctly', async () => { | ||
const onChange = jest.fn(); | ||
render(<RenderObjectiveFormItem isValid={true} formItemValue={'some value'} onChange={onChange} />); | ||
const save = await screen.findByText('Objective'); | ||
expect(save).toBeVisible(); | ||
const errorMessage = screen.queryByText('objective form item required'); | ||
expect(errorMessage).toBeNull(); | ||
}); | ||
|
||
it('renders with required message', async () => { | ||
const onChange = jest.fn(); | ||
render(<RenderObjectiveFormItem isValid={false} formItemValue={''} onChange={onChange} />); | ||
const save = await screen.findByText('Objective'); | ||
expect(save).toBeVisible(); | ||
const errorMessage = await screen.findByText('objective form item required'); | ||
expect(errorMessage).toBeVisible(); | ||
}); | ||
it('renders with required message', async () => { | ||
const onChange = jest.fn(); | ||
render(<RenderObjectiveFormItem isValid={false} formItemValue="" onChange={onChange} />); | ||
const save = await screen.findByText('Objective'); | ||
expect(save).toBeVisible(); | ||
const errorMessage = await screen.findByText('objective form item required'); | ||
expect(errorMessage).toBeVisible(); | ||
}); | ||
}); | ||
|
||
|
||
|