diff --git a/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.spec.tsx b/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.spec.tsx index 5645601f86..f026ebebae 100644 --- a/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.spec.tsx +++ b/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.spec.tsx @@ -4,7 +4,6 @@ import { FormProvider, useForm } from 'react-hook-form'; import { BasicInformation } from './BasicInformation'; import { PatientCriteriaEntry } from '../criteria'; import { SkipLinkProvider } from 'SkipLink/SkipLinkContext'; -import { error } from 'console'; const mockAllows = jest.fn(); @@ -12,9 +11,9 @@ jest.mock('libs/permission/usePermissions', () => ({ usePermissions: () => ({ permissions: [], allows: mockAllows }) })); -const Fixture = () => { +const Fixture = ({ mode }: { mode?: 'onChange' | 'onBlur' }) => { const form = useForm({ - mode: 'onChange', + mode: mode ?? 'onChange', defaultValues: { status: [{ name: 'Active', label: 'Active', value: 'ACTIVE' }] } }); @@ -79,4 +78,20 @@ describe('when Basic information renders', () => { expect(errorMessage).toHaveTextContent('The Date of birth should have a month between'); expect(errorMessage).toHaveTextContent('The Date of birth should be at least'); }); + + it('should not show an error message when unchecking all status boxes then tabbing to next checkbox', async () => { + mockAllows.mockReturnValue(true); + const { getByRole, queryByRole } = render(); + + const user = userEvent.setup(); + + const statusCheckbox = getByRole('checkbox', { name: 'Active' }); + expect(statusCheckbox).toBeChecked(); + await user.click(statusCheckbox); + expect(statusCheckbox).not.toBeChecked(); + await user.tab(); + + const errorMessage = queryByRole('alert'); + expect(errorMessage).not.toBeInTheDocument(); + }); }); diff --git a/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.tsx b/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.tsx index cec5b67ea3..f9970d8bce 100644 --- a/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.tsx +++ b/apps/modernization-ui/src/apps/search/patient/PatientCriteria/BasicInformation.tsx @@ -117,7 +117,7 @@ export const BasicInformation = ({ sizing, orientation }: EntryFieldsProps) => { rules={{ required: { value: true, message: 'At least one status is required' } }} - render={({ field: { onChange, onBlur, value, name }, fieldState: { error } }) => ( + render={({ field: { onChange, value, name }, fieldState: { error } }) => ( { options={statusOptions} value={value} onChange={onChange} - onBlur={onBlur} error={error?.message} /> )}