Skip to content
Open
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
12 changes: 9 additions & 3 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,17 @@
"(Quarter)": "(Quarter)",
"(Sent by {{firstName}} {{lastName}})": "(Sent by {{firstName}} {{lastName}})",
"(Year)": "(Year)",
"Before You Start": "Before You Start",
"Complete this form by": "Complete this form by",
"Dismiss": "Dismiss",
"Email the MPD Team.": "Email the MPD Team.",
"Questions or need a change?": "Questions or need a change?",
"Review your goal, see how to present it to partners, and read your next steps. We also emailed you the full worksheet as a PDF.": "Review your goal, see how to present it to partners, and read your next steps. We also emailed you the full worksheet as a PDF.",
"Starting on {{date}}": "Starting on {{date}}",
"View my MPD goal": "View my MPD goal",
"What is {{spouseName}}'s current annual requested MHA?": "What is {{spouseName}}'s current annual requested MHA?",
"You'll receive your support goal at {{trainingName}} that begins on {{date}}.": "You'll receive your support goal at {{trainingName}} that begins on {{date}}.",
"You'll receive your support goal at {{trainingName}}.": "You'll receive your support goal at {{trainingName}}.",
"Your goal changed since you last looked. Review the updated worksheet, which was also emailed to you as a PDF.": "Your goal changed since you last looked. Review the updated worksheet, which was also emailed to you as a PDF.",
"Your MPD goal is ready": "Your MPD goal is ready",
"Your MPD goal was already sent, so this questionnaire can't change.": "Your MPD goal was already sent, so this questionnaire can't change.",
Expand Down Expand Up @@ -1234,7 +1242,6 @@
"Drag here to create columns": "Drag here to create columns",
"Drag here to create rows": "Drag here to create rows",
"Drag here to create values": "Drag here to create values",
"Due {{date}}. After that you can't change or submit it.": "Due {{date}}. After that you can't change or submit it.",
"Due Date": "Due Date",
"Due Time": "Due Time",
"e.g., Home visits, Conference travel": "e.g., Home visits, Conference travel",
Expand Down Expand Up @@ -3191,7 +3198,7 @@
"Spouse's Last Name": "Spouse's Last Name",
"Spouse's Personal Information": "Spouse's Personal Information",
"Spouse's requested annual salary": "Spouse's requested annual salary",
"Spouse's requested MHA": "Spouse's requested MHA",
"Spouse's annual requested MHA": "Spouse's annual requested MHA",
"Sri Lanka": "Sri Lanka",
"Staff": "Staff",
"Staff - non-RMO Spouse": "Staff - non-RMO Spouse",
Expand Down Expand Up @@ -3844,7 +3851,6 @@
"What expenses can I claim on my MHA?": "What expenses can I claim on my MHA?",
"What is {{spouseName}}'s 403(b) contribution percentage?": "What is {{spouseName}}'s 403(b) contribution percentage?",
"What is {{spouseName}}'s current requested annual salary?": "What is {{spouseName}}'s current requested annual salary?",
"What is {{spouseName}}'s current requested MHA?": "What is {{spouseName}}'s current requested MHA?",
"What is HCM?": "What is HCM?",
"What is your monthly payment for all of your {{debtType}}?": "What is your monthly payment for all of your {{debtType}}?",
"What ministry are you expecting to serve with?": "What ministry are you expecting to serve with?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('VariantQuestions', () => {
).toBeInTheDocument();
expect(
getByRole('spinbutton', {
name: "What is Jane's current requested MHA?",
name: "What is Jane's current annual requested MHA?",
}),
).toBeInTheDocument();
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export const VariantQuestions: React.FC = () => {
<NumberQuestion
fieldName="spouseMhaAmount"
schema={schema}
question={t("What is {{spouseName}}'s current requested MHA?", {
spouseName,
})}
question={t(
"What is {{spouseName}}'s current annual requested MHA?",
{
spouseName,
},
)}
helperText={t('Please enter zero if you have not requested MHA.')}
startAdornment={<CurrencyAdornment />}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const newStaffQuestionnaireMock: DeepPartial<
completedAt: null,
deadline: null,
locked: false,
trainingName: null,
trainingStartDate: null,
viewerIsStaffMember: null,
personNumber: '000123456',
firstName: 'John',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import React from 'react';
import { ThemeProvider } from '@mui/material/styles';
import { render } from '@testing-library/react';
import theme from 'src/theme';
import { render } from '__tests__/util/testingLibraryReactMock';
import { NsoMpdQuestionnaireTestWrapper } from '../NsoMpdQuestionnaireTestWrapper';
import { Settings } from './Settings';

const TestComponent: React.FC = () => (
<ThemeProvider theme={theme}>
<NsoMpdQuestionnaireTestWrapper
newStaffQuestionnaire={{ deadline: '2027-01-20T22:00:00Z' }}
>
<Settings />
</ThemeProvider>
</NsoMpdQuestionnaireTestWrapper>
);

describe('Settings', () => {
it('opens with Before You Start and the due date', async () => {
const { findByText, getByRole } = render(<TestComponent />);

expect(
getByRole('heading', { name: 'Before You Start' }),
).toBeInTheDocument();
expect(await findByText('Complete this form by')).toBeInTheDocument();
});

it('renders the informational title and description', () => {
const { getByText } = render(<TestComponent />);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React from 'react';
import { Alert, AlertTitle, Stack, Typography } from '@mui/material';
import { Trans, useTranslation } from 'react-i18next';
import { TrainingDates } from './TrainingDates';

/**
* Informational subsection of the Personal Information step. Display-only guidance for the user
* before they answer — not a sidebar sub-step.
* Informational subsection of the Personal Information step: the training and due dates, then
* display-only guidance for the user before they answer — not a sidebar sub-step.
*/
export const Settings: React.FC = () => {
const { t } = useTranslation();

return (
<Stack spacing={2}>
<Typography variant="h6">{t('Settings')}</Typography>
<Typography variant="h6">{t('Before You Start')}</Typography>
<TrainingDates />
<Alert severity="info">
<AlertTitle>
{t('Please read all information before answering.')}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { render } from '__tests__/util/testingLibraryReactMock';
import { NsoMpdQuestionnaireTestWrapper } from '../NsoMpdQuestionnaireTestWrapper';
import { useNsoMpdQuestionnaire } from '../Shared/NsoMpdQuestionnaireContext';
import { TrainingDates } from './TrainingDates';

/** Shows once the questionnaire query has answered. */
const LoadedProbe: React.FC = () => {
const { questionnaire } = useNsoMpdQuestionnaire();
return questionnaire ? <span>loaded</span> : null;
};

const deadline = '2027-01-20T22:00:00Z';

const renderDates = (
questionnaire: Partial<{
trainingName: string | null;
trainingStartDate: string | null;
deadline: string | null;
locked: boolean;
completed: boolean;
}>,
) =>
render(
<NsoMpdQuestionnaireTestWrapper newStaffQuestionnaire={questionnaire}>
<TrainingDates />
<LoadedProbe />
</NsoMpdQuestionnaireTestWrapper>,
);

describe('TrainingDates', () => {
it('shows the training and when it starts', async () => {
const { findByText, getByText } = renderDates({
trainingName: 'Winter NSO 2027',
trainingStartDate: '2027-01-05',
});

expect(await findByText('Winter NSO 2027')).toBeInTheDocument();
expect(getByText('Starting on Jan 5, 2027')).toBeInTheDocument();
});

it('leaves out the start date when there is no training name', async () => {
const { findByText, queryByText } = renderDates({
trainingName: null,
trainingStartDate: '2027-01-05',
});
await findByText('loaded');

expect(queryByText(/Starting on/)).not.toBeInTheDocument();
});

it('leaves out the training when it has no start date', async () => {
const { findByText, queryByText } = renderDates({
trainingName: 'Winter NSO 2027',
trainingStartDate: null,
});
await findByText('loaded');

expect(queryByText('Winter NSO 2027')).not.toBeInTheDocument();
expect(queryByText(/Starting on/)).not.toBeInTheDocument();
});

it('shows when the form is due, in Eastern time', async () => {
const { findByText, getByText } = renderDates({ deadline });

expect(await findByText('Complete this form by')).toBeInTheDocument();
expect(getByText('Jan 20, 2027, 5:00 PM EST')).toBeInTheDocument();
});

it.each([
['there is no deadline', { deadline: null }],
['it is locked', { deadline, locked: true }],
['it was submitted', { deadline, completed: true }],
])('leaves out the due date when %s', async (_, questionnaire) => {
const { findByText, queryByText } = renderDates(questionnaire);
await findByText('loaded');

expect(queryByText('Complete this form by')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import AccessTime from '@mui/icons-material/AccessTime';
import CalendarTodayOutlined from '@mui/icons-material/CalendarTodayOutlined';
import { Box, Stack, Typography } from '@mui/material';
import { DateTime } from 'luxon';
import { useTranslation } from 'react-i18next';
import { useLocale } from 'src/hooks/useLocale';
import { dateFormat } from 'src/lib/intlFormat';
import { deadlineFormat } from '../../Shared/questionnaireDeadline';
import { useNsoMpdQuestionnaire } from '../Shared/NsoMpdQuestionnaireContext';

const DateBox: React.FC<{
icon: React.ReactNode;
label: string;
value: string;
}> = ({ icon, label, value }) => (
<Stack
direction="row"
spacing={1.5}
p={2}
borderRadius={1}
bgcolor="grey.100"
>
{icon}
<Box component="dl" m={0}>
<Typography component="dt" variant="body2">
{label}
</Typography>
<Typography component="dd" fontWeight="bold" m={0}>
{value}
</Typography>
</Box>
</Stack>
);

/** The household's training start and the form's due date, shown once at the top of Step 1. */
export const TrainingDates: React.FC = () => {
const { t } = useTranslation();
const locale = useLocale();
const { questionnaire } = useNsoMpdQuestionnaire();

if (!questionnaire) {
return null;
}

const { trainingName, trainingStartDate, deadline, locked, completed } =
questionnaire;
const showTraining = !!trainingName && !!trainingStartDate;
// A locked form explains itself on every step (DeadlineNotice); a submitted one has no due date
const showDue = !!deadline && !locked && !completed;
if (!showTraining && !showDue) {
return null;
}

return (
<Box
display="grid"
gridTemplateColumns="repeat(auto-fit, minmax(min(240px, 100%), 1fr))"
gap={1.5}
>
{showTraining && (
<DateBox
icon={<CalendarTodayOutlined color="primary" />}
label={trainingName}
value={t('Starting on {{date}}', {
date: dateFormat(DateTime.fromISO(trainingStartDate), locale),
})}
/>
)}
{showDue && (
<DateBox
icon={<AccessTime color="primary" />}
label={t('Complete this form by')}
value={deadlineFormat(deadline, locale)}
/>
)}
</Box>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ const renderNotice = (
);

describe('DeadlineNotice', () => {
it('shows when the questionnaire is due, in Eastern time', async () => {
const { findByText } = renderNotice({ deadline });
it('leaves an open deadline to Step 1', async () => {
const { findByText, queryByText } = renderNotice({ deadline });
await findByText('loaded');

expect(
await findByText(
"Due Jan 20, 2027, 5:00 PM EST. After that you can't change or submit it.",
),
).toBeInTheDocument();
expect(queryByText(/deadline|Due/)).not.toBeInTheDocument();
});

it('says the deadline passed and who can reopen it', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ import { useLocale } from 'src/hooks/useLocale';
import { deadlineFormat } from '../../Shared/questionnaireDeadline';
import { useNsoMpdQuestionnaire } from './NsoMpdQuestionnaireContext';

/** The household's deadline on every step: when it is due, or that it passed and who can reopen it. */
/**
* Why the questionnaire is locked, on every step: its goal was sent, or the deadline passed and who
* can reopen it. An open deadline shows once, on Step 1 (TrainingDates).
*/
export const DeadlineNotice: React.FC = () => {
const { t } = useTranslation();
const locale = useLocale();
const { questionnaire } = useNsoMpdQuestionnaire();

if (!questionnaire || questionnaire.completed) {
if (!questionnaire?.locked) {
return null;
}
if (questionnaire.completed) {
return null;
}

const { deadline, locked } = questionnaire;
const { deadline } = questionnaire;
const date = deadline ? deadlineFormat(deadline, locale) : '';
const pastDeadline =
!!deadline && DateTime.fromISO(deadline) < DateTime.now();

// The API also locks a household whose goal was already sent, deadline or not
if (locked && !pastDeadline) {
if (!pastDeadline) {
return (
<Alert severity="info" sx={{ mx: 4 }}>
{t(
Expand All @@ -31,24 +37,12 @@ export const DeadlineNotice: React.FC = () => {
</Alert>
);
}
if (locked) {
return (
<Alert severity="warning" sx={{ mx: 4 }}>
{t(
'The deadline for this questionnaire passed on {{date}}. To change or submit it, ask the MPD team at mpdhelp@cru.org to reopen it.',
{ date },
)}
</Alert>
);
}
if (!deadline) {
return null;
}
return (
<Alert severity="info" sx={{ mx: 4 }}>
{t("Due {{date}}. After that you can't change or submit it.", {
date,
})}
<Alert severity="warning" sx={{ mx: 4 }}>
{t(
'The deadline for this questionnaire passed on {{date}}. To change or submit it, ask the MPD team at mpdhelp@cru.org to reopen it.',
{ date },
)}
</Alert>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ fragment NewStaffQuestionnaireFields on NewStaffQuestionnaire {
completedAt
deadline
locked
trainingName
trainingStartDate
viewerIsStaffMember
accountTransfers
assignmentType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ describe('NsoMpdQuestionnaireLayout', () => {
expect(getByText('Main panel content')).toBeInTheDocument();
});

it('keeps the form about 600px wide (MUI sm) inside its margins', () => {
const { getByTestId } = render(<TestComponent />);

expect(getByTestId('NsoMpdQuestionnaireContent')).toHaveStyle({
maxWidth: 'calc(600px + 64px)',
});
});

it('enables every step icon in the rail', () => {
const { getByRole } = render(<TestComponent />);

Expand Down
Loading
Loading