Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPDX-8335 Task Due This Week #1112

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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,6 +4,7 @@ import userEvent from '@testing-library/user-event';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { render } from '__tests__/util/testingLibraryReactMock';
import { LoadConstantsQuery } from 'src/components/Constants/LoadConstants.generated';
import { loadConstantsMockData } from 'src/components/Constants/LoadConstantsMock';
import { TaskModalEnum } from 'src/components/Task/Modal/TaskModal';
import { ActivityTypeEnum } from 'src/graphql/types.generated';
import useTaskModal from '../../../../hooks/useTaskModal';
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('TasksDueThisWeek', () => {
nodes: [
{
id: 'task_1',
subject: 'the quick brown fox jumps over the lazy dog',
subject: '1 the quick brown fox jumps over the lazy dog',
activityType: ActivityTypeEnum.PartnerCarePrayerRequest,
contacts: {
nodes: [{ hidden: true, name: 'Smith, Roger', id: '1' }],
Expand All @@ -89,7 +90,7 @@ describe('TasksDueThisWeek', () => {
},
{
id: 'task_2',
subject: 'the quick brown fox jumps over the lazy dog',
subject: '2 the quick brown fox jumps over the lazy dog',
activityType: ActivityTypeEnum.AppointmentInPerson,
contacts: {
nodes: [{ hidden: true, name: 'Smith, Sarah', id: '2' }],
Expand All @@ -101,17 +102,10 @@ describe('TasksDueThisWeek', () => {
],
totalCount: 1234,
};
const { getByTestId, queryByTestId, getByText } = render(
const { getByTestId, queryByTestId, getByText, findByText } = render(
<ThemeProvider theme={theme}>
<GqlMockedProvider<{ LoadConstants: LoadConstantsQuery }>
mocks={{
constant: {
activities: [
{ id: 'Prayer Request', value: 'Prayer Request' },
{ id: 'Appointment', value: 'Appointment' },
],
},
}}
mocks={{ LoadConstants: loadConstantsMockData }}
>
<TasksDueThisWeek dueTasks={dueTasks} accountListId="abc" />
</GqlMockedProvider>
Expand All @@ -132,17 +126,23 @@ describe('TasksDueThisWeek', () => {
);
expect(viewAllElement.textContent).toEqual('View All (1,234)');
const task1Element = getByTestId('TasksDueThisWeekListItem-task_1');
expect(task1Element.textContent).toEqual(
'Smith, Roger — the quick brown fox jumps over the lazy dog',
);
expect(getByText('Smith, Roger')).toBeInTheDocument();
expect(
await findByText('Partner Care - Prayer Request'),
).toBeInTheDocument();
expect(
getByText('1 the quick brown fox jumps over the lazy dog'),
).toBeInTheDocument();
userEvent.click(task1Element);
expect(openTaskModal).toHaveBeenCalledWith({
view: TaskModalEnum.Edit,
taskId: 'task_1',
});
expect(
getByTestId('TasksDueThisWeekListItem-task_2').textContent,
).toEqual('Smith, Sarah — the quick brown fox jumps over the lazy dog');
).toEqual(
'Smith, SarahAppointment - In Person2 the quick brown fox jumps over the lazy dog',
);
});

it('multiple contacts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import { DateTime } from 'luxon';
import { useTranslation } from 'react-i18next';
import { makeStyles } from 'tss-react/mui';
import AnimatedCard from 'src/components/AnimatedCard';
import { useLoadConstantsQuery } from 'src/components/Constants/LoadConstants.generated';
import { TaskModalEnum } from 'src/components/Task/Modal/TaskModal';
import TaskStatus from 'src/components/Task/Status';
import { ActivityTypeEnum } from 'src/graphql/types.generated';
import { useLocale } from 'src/hooks/useLocale';
import { usePhaseData } from 'src/hooks/usePhaseData';
import useTaskModal from 'src/hooks/useTaskModal';
import illustration8 from 'src/images/drawkit/grape/drawkit-grape-pack-illustration-8.svg';
import { numberFormat } from 'src/lib/intlFormat';
import { getLocalizedTaskType } from 'src/utils/functions/getLocalizedTaskType';
import { GetThisWeekQuery } from '../GetThisWeek.generated';

const useStyles = makeStyles()((theme: Theme) => ({
Expand Down Expand Up @@ -79,20 +77,8 @@ const TasksDueThisWeek = ({
const { t } = useTranslation();
const locale = useLocale();
const { openTaskModal, preloadTaskModal } = useTaskModal();
const { data } = useLoadConstantsQuery();
const [activityTypes, setActivityTypes] = React.useState(
data?.constant.activities,
);
React.useEffect(() => {
setActivityTypes(data?.constant.activities);
}, [data?.constant.activities]);

const translatedActivityType = (type: ActivityTypeEnum): string => {
return (
activityTypes?.find(({ id }) => id === getLocalizedTaskType(t, type))
?.value ?? ''
);
};
const { activityTypes } = usePhaseData();

const handleClick = ({
id: taskId,
Expand Down Expand Up @@ -182,17 +168,18 @@ const TasksDueThisWeek = ({
component="span"
variant="body2"
color="textPrimary"
marginRight="5px"
>
{task.activityType
? translatedActivityType(task.activityType)
: ''}
</Typography>{' '}
{!!task.activityType &&
(activityTypes.get(task.activityType)?.title ||
'')}
</Typography>
<Typography
component="span"
variant="body2"
color="textSecondary"
>
{task.activityType && '—'} {task.subject}
{task.subject}
</Typography>
</Box>
</Box>
Expand Down
Loading