diff --git a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx index 606a4af9d..566acef82 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx @@ -82,6 +82,17 @@ describe('ResultSelect', () => { expect(getByRole('option', { name: 'Completed' })).toBeInTheDocument(); userEvent.click(getByRole('option', { name: 'Completed' })); + expect(handleResultChange).toHaveBeenCalledWith({ + result: ResultEnum.Completed, + setFieldValue, + setResultSelected, + phaseData, + completedAction: ActivityTypeEnum.FollowUpTextMessage, + }); + }); + it('preselects a result when only one result is available', async () => { + render(); + expect(handleResultChange).toHaveBeenCalledWith({ result: ResultEnum.Completed, setFieldValue, diff --git a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx index f8f99309a..384713263 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx @@ -1,3 +1,4 @@ +import { useEffect } from 'react'; import { Autocomplete, Grid, TextField } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { @@ -32,6 +33,18 @@ export const ResultAutocomplete: React.FC = ({ }) => { const { t } = useTranslation(); + useEffect(() => { + if (availableResults.length === 1 && completedAction) { + handleResultChange({ + result: availableResults[0], + setFieldValue, + setResultSelected, + phaseData, + completedAction, + }); + } + }, [completedAction]); + return !!availableResults.length ? ( { expect(queryByLabelText('Comment')).not.toBeInTheDocument(); expect(queryByLabelText('Tags')).not.toBeInTheDocument(); expect(queryByLabelText('Assignee')).not.toBeInTheDocument(); - expect(queryByLabelText('Next Action')).not.toBeInTheDocument(); userEvent.click(getByLabelText('Show More')); expect(getByLabelText('Comment')).toBeInTheDocument(); userEvent.type(getByLabelText('Comment'), 'test comment'); diff --git a/src/components/Task/Modal/Form/TaskModalTests.tsx b/src/components/Task/Modal/Form/TaskModalTests.tsx index 2d971485e..fdf22e49e 100644 --- a/src/components/Task/Modal/Form/TaskModalTests.tsx +++ b/src/components/Task/Modal/Form/TaskModalTests.tsx @@ -16,6 +16,21 @@ type Components = ({ props, }: ComponentsProps) => JSX.Element; +const options = [ + 'None', + 'Phone Call', + 'Email', + 'Text Message', + 'Social Media', + 'In Person', + 'Thank You Note', + 'Digital Newsletter', + 'Physical Newsletter', + 'Prayer Request', + 'Update Information', + 'To Do', +]; + // eslint-disable-next-line jest/no-export export const taskModalTests = (Components: Components) => { describe('Task Modal Results +Next Action', () => { @@ -261,7 +276,7 @@ export const taskModalTests = (Components: Components) => { ActivityTypeEnum.PartnerCareEmail, ); expect(results).toEqual([]); - expect(nextActions).toEqual([]); + expect(nextActions).toEqual(options); }); it('as correct options for PartnerCarePhysicalNewsletter', async () => { @@ -269,7 +284,7 @@ export const taskModalTests = (Components: Components) => { ActivityTypeEnum.PartnerCarePhysicalNewsletter, ); expect(results).toEqual([]); - expect(nextActions).toEqual([]); + expect(nextActions).toEqual(options); }); it('has correct options for NONE', async () => { @@ -283,7 +298,7 @@ export const taskModalTests = (Components: Components) => { ActivityTypeEnum.PartnerCarePrayerRequest, ); expect(results).toEqual([]); - expect(nextActions).toEqual([]); + expect(nextActions).toEqual(options); }); it('has correct options for PartnerCarePhoneCall', async () => { @@ -291,7 +306,7 @@ export const taskModalTests = (Components: Components) => { ActivityTypeEnum.PartnerCarePhoneCall, ); expect(results).toEqual([]); - expect(nextActions).toEqual([]); + expect(nextActions).toEqual(options); }); it('has correct options for InitiationLetter', async () => { @@ -307,7 +322,7 @@ export const taskModalTests = (Components: Components) => { ActivityTypeEnum.PartnerCareThank, ); expect(results).toEqual([]); - expect(nextActions).toEqual([]); + expect(nextActions).toEqual(options); }); it('has correct options for PartnerCareToDo', async () => { @@ -315,7 +330,7 @@ export const taskModalTests = (Components: Components) => { ActivityTypeEnum.PartnerCareToDo, ); expect(results).toEqual([]); - expect(nextActions).toEqual([]); + expect(nextActions).toEqual(options); }); }); };