From 4abe296b684f7dfd9a976ede0369e17a446947f5 Mon Sep 17 00:00:00 2001 From: wjames111 Date: Tue, 22 Oct 2024 16:31:30 -0400 Subject: [PATCH 1/5] Preselects result when only one ersult option available. --- .../Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx | 7 +++++++ .../Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) 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..40bdaaabb 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx @@ -90,4 +90,11 @@ describe('ResultSelect', () => { completedAction: ActivityTypeEnum.FollowUpTextMessage, }); }); + it('Preselects result when only one result available', () => { + const { getByRole } = render( + , + ); + expect(getByRole('combobox', { name: 'Result' })).toBeInTheDocument(); + expect(getByRole('combobox', { name: 'Result' })).toHaveValue('Attempted'); + }); }); diff --git a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx index f8f99309a..53b57be6f 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx @@ -38,7 +38,7 @@ export const ResultAutocomplete: React.FC = ({ openOnFocus autoHighlight autoSelect - value={result} + value={availableResults.length === 1 ? availableResults[0] : result} options={availableResults} getOptionLabel={(result) => getLocalizedResultString(t, result)} renderInput={(params) => } From a1891b186b509720a178db708d5778c07852a604 Mon Sep 17 00:00:00 2001 From: Will James Date: Wed, 23 Oct 2024 10:29:19 -0400 Subject: [PATCH 2/5] Update src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx Co-authored-by: Bizz (Daniel Bisgrove) <56281168+dr-bizz@users.noreply.github.com> --- .../Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 40bdaaabb..0511726a8 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx @@ -90,7 +90,7 @@ describe('ResultSelect', () => { completedAction: ActivityTypeEnum.FollowUpTextMessage, }); }); - it('Preselects result when only one result available', () => { + it('preselects a result when only one result is available', () => { const { getByRole } = render( , ); From 0cc5ffc6ca5576eae499edf4d9cb5ffdbc2d4ed2 Mon Sep 17 00:00:00 2001 From: wjames111 Date: Wed, 23 Oct 2024 15:16:19 -0400 Subject: [PATCH 3/5] Fix for displayResult showing undefined. --- .../ResultAutocomplete/ResultAutocomplete.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx index 53b57be6f..c294f776a 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,13 +33,24 @@ export const ResultAutocomplete: React.FC = ({ }) => { const { t } = useTranslation(); + useEffect(() => { + if (availableResults.length === 1) { + handleResultChange({ + result: availableResults[0], + setFieldValue, + setResultSelected, + phaseData, + }); + } + }, [availableResults]); + return !!availableResults.length ? ( getLocalizedResultString(t, result)} renderInput={(params) => } From 3dff50e1bb879096d7e825876c046af3f024f4ec Mon Sep 17 00:00:00 2001 From: wjames111 Date: Thu, 24 Oct 2024 15:55:13 -0400 Subject: [PATCH 4/5] Fixes broken tests. --- .../ResultAutocomplete.test.tsx | 16 ++++++----- .../ResultAutocomplete/ResultAutocomplete.tsx | 1 + .../Form/LogForm/TaskModalLogForm.test.tsx | 1 - .../Task/Modal/Form/TaskModalTests.tsx | 27 ++++++++++++++----- 4 files changed, 32 insertions(+), 13 deletions(-) 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 0511726a8..566acef82 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.test.tsx @@ -90,11 +90,15 @@ describe('ResultSelect', () => { completedAction: ActivityTypeEnum.FollowUpTextMessage, }); }); - it('preselects a result when only one result is available', () => { - const { getByRole } = render( - , - ); - expect(getByRole('combobox', { name: 'Result' })).toBeInTheDocument(); - expect(getByRole('combobox', { name: 'Result' })).toHaveValue('Attempted'); + it('preselects a result when only one result is available', async () => { + render(); + + expect(handleResultChange).toHaveBeenCalledWith({ + result: ResultEnum.Completed, + setFieldValue, + setResultSelected, + phaseData, + completedAction: ActivityTypeEnum.FollowUpTextMessage, + }); }); }); diff --git a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx index c294f776a..a653700a3 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx @@ -40,6 +40,7 @@ export const ResultAutocomplete: React.FC = ({ setFieldValue, setResultSelected, phaseData, + completedAction, }); } }, [availableResults]); diff --git a/src/components/Task/Modal/Form/LogForm/TaskModalLogForm.test.tsx b/src/components/Task/Modal/Form/LogForm/TaskModalLogForm.test.tsx index 2803b3e07..f0a5e5aa2 100644 --- a/src/components/Task/Modal/Form/LogForm/TaskModalLogForm.test.tsx +++ b/src/components/Task/Modal/Form/LogForm/TaskModalLogForm.test.tsx @@ -177,7 +177,6 @@ describe('TaskModalLogForm', () => { 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); }); }); }; From 2078e82eab713aa1433bc546ec4b94bc7d892ea7 Mon Sep 17 00:00:00 2001 From: wjames111 Date: Thu, 24 Oct 2024 17:04:17 -0400 Subject: [PATCH 5/5] Fills Result Autocomplete once activityType is selected. --- .../Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx index a653700a3..384713263 100644 --- a/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx +++ b/src/components/Task/Modal/Form/Inputs/ResultAutocomplete/ResultAutocomplete.tsx @@ -34,7 +34,7 @@ export const ResultAutocomplete: React.FC = ({ const { t } = useTranslation(); useEffect(() => { - if (availableResults.length === 1) { + if (availableResults.length === 1 && completedAction) { handleResultChange({ result: availableResults[0], setFieldValue, @@ -43,7 +43,7 @@ export const ResultAutocomplete: React.FC = ({ completedAction, }); } - }, [availableResults]); + }, [completedAction]); return !!availableResults.length ? (