Skip to content

Commit

Permalink
MPDX-8383 - Complete Task Modal - preselect result (#1148)
Browse files Browse the repository at this point in the history
* Preselects result when one result option is available.
  • Loading branch information
wjames111 authored Oct 25, 2024
1 parent ada0000 commit 9f1e8f2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Components availableResults={[ResultEnum.Completed]} />);

expect(handleResultChange).toHaveBeenCalledWith({
result: ResultEnum.Completed,
setFieldValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react';
import { Autocomplete, Grid, TextField } from '@mui/material';
import { useTranslation } from 'react-i18next';
import {
Expand Down Expand Up @@ -32,6 +33,18 @@ export const ResultAutocomplete: React.FC<ResultAutocompleteProps> = ({
}) => {
const { t } = useTranslation();

useEffect(() => {
if (availableResults.length === 1 && completedAction) {
handleResultChange({
result: availableResults[0],
setFieldValue,
setResultSelected,
phaseData,
completedAction,
});
}
}, [completedAction]);

return !!availableResults.length ? (
<Grid item>
<Autocomplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
27 changes: 21 additions & 6 deletions src/components/Task/Modal/Form/TaskModalTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -261,15 +276,15 @@ export const taskModalTests = (Components: Components) => {
ActivityTypeEnum.PartnerCareEmail,
);
expect(results).toEqual([]);
expect(nextActions).toEqual([]);
expect(nextActions).toEqual(options);
});

it('as correct options for PartnerCarePhysicalNewsletter', async () => {
const { results, nextActions } = await getOptions(
ActivityTypeEnum.PartnerCarePhysicalNewsletter,
);
expect(results).toEqual([]);
expect(nextActions).toEqual([]);
expect(nextActions).toEqual(options);
});

it('has correct options for NONE', async () => {
Expand All @@ -283,15 +298,15 @@ export const taskModalTests = (Components: Components) => {
ActivityTypeEnum.PartnerCarePrayerRequest,
);
expect(results).toEqual([]);
expect(nextActions).toEqual([]);
expect(nextActions).toEqual(options);
});

it('has correct options for PartnerCarePhoneCall', async () => {
const { results, nextActions } = await getOptions(
ActivityTypeEnum.PartnerCarePhoneCall,
);
expect(results).toEqual([]);
expect(nextActions).toEqual([]);
expect(nextActions).toEqual(options);
});

it('has correct options for InitiationLetter', async () => {
Expand All @@ -307,15 +322,15 @@ export const taskModalTests = (Components: Components) => {
ActivityTypeEnum.PartnerCareThank,
);
expect(results).toEqual([]);
expect(nextActions).toEqual([]);
expect(nextActions).toEqual(options);
});

it('has correct options for PartnerCareToDo', async () => {
const { results, nextActions } = await getOptions(
ActivityTypeEnum.PartnerCareToDo,
);
expect(results).toEqual([]);
expect(nextActions).toEqual([]);
expect(nextActions).toEqual(options);
});
});
};

0 comments on commit 9f1e8f2

Please sign in to comment.