Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ 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();

jest.mock('libs/permission/usePermissions', () => ({
usePermissions: () => ({ permissions: [], allows: mockAllows })
}));

const Fixture = () => {
const Fixture = ({ mode }: { mode?: 'onChange' | 'onBlur' }) => {
const form = useForm<PatientCriteriaEntry>({
mode: 'onChange',
mode: mode ?? 'onChange',
defaultValues: { status: [{ name: 'Active', label: 'Active', value: 'ACTIVE' }] }
});

Expand Down Expand Up @@ -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(<Fixture mode="onBlur" />);

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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }) => (
<CheckboxGroup
name={name}
label={'Include records that are'}
Expand All @@ -127,7 +127,6 @@ export const BasicInformation = ({ sizing, orientation }: EntryFieldsProps) => {
options={statusOptions}
value={value}
onChange={onChange}
onBlur={onBlur}
error={error?.message}
/>
)}
Expand Down