Skip to content

Commit 70292ce

Browse files
authored
Merge pull request #1814 from CruGlobal/MPDX-9650
MPDX-9650 - Improve validation in Savings Fund Transfer
2 parents 8544dce + 8f4210e commit 70292ce

2 files changed

Lines changed: 82 additions & 5 deletions

File tree

src/components/HrTools/SavingsFundTransfer/TransferModal/TransferModal.test.tsx

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,71 @@ describe('TransferModal', () => {
189189
userEvent.tab();
190190

191191
expect(
192-
await findByText('End date must be after transfer date'),
192+
await findByText(
193+
'End date must be at least one day after the transfer date',
194+
),
195+
).toBeInTheDocument();
196+
});
197+
198+
it('should reject an end date equal to the transfer date for recurring transfers', async () => {
199+
const { getByRole, findByLabelText, getByLabelText, findByText } = render(
200+
<Components />,
201+
);
202+
203+
userEvent.click(getByRole('radio', { name: /monthly/i }));
204+
expect(getByRole('radio', { name: /monthly/i })).toBeChecked();
205+
206+
const transferDate = await findByLabelText(/transfer date/i);
207+
const endDate = getByLabelText(/end date/i);
208+
209+
userEvent.clear(transferDate);
210+
userEvent.type(transferDate, '12/01/2024');
211+
userEvent.tab();
212+
213+
userEvent.clear(endDate);
214+
userEvent.type(endDate, '12/01/2024');
215+
216+
userEvent.tab();
217+
218+
expect(
219+
await findByText(
220+
'End date must be at least one day after the transfer date',
221+
),
193222
).toBeInTheDocument();
194223
});
195224

225+
it('should accept an end date one day after the transfer date for recurring transfers', async () => {
226+
const { getByRole, findByLabelText, getByLabelText, queryByText } =
227+
render(<Components />);
228+
229+
userEvent.click(getByRole('radio', { name: /monthly/i }));
230+
expect(getByRole('radio', { name: /monthly/i })).toBeChecked();
231+
232+
expect(await findByLabelText(/end date/i)).toBeInTheDocument();
233+
234+
const transferDate = getByLabelText(/transfer date/i);
235+
const endDate = getByLabelText(/end date/i);
236+
237+
userEvent.clear(transferDate);
238+
userEvent.type(transferDate, '12/01/2024');
239+
expect(transferDate).toHaveValue('12/01/2024');
240+
userEvent.tab();
241+
242+
userEvent.clear(endDate);
243+
userEvent.type(endDate, '12/02/2024');
244+
expect(endDate).toHaveValue('12/02/2024');
245+
246+
userEvent.tab();
247+
248+
await waitFor(() =>
249+
expect(
250+
queryByText(
251+
'End date must be at least one day after the transfer date',
252+
),
253+
).not.toBeInTheDocument(),
254+
);
255+
});
256+
196257
it('should submit form with valid data', async () => {
197258
const { getByRole } = render(<Components />);
198259

@@ -306,6 +367,18 @@ describe('TransferModal', () => {
306367
);
307368
});
308369

370+
it('should show descriptive helper text for the end date field', async () => {
371+
const { getByRole, findByText } = render(<Components />);
372+
373+
userEvent.click(getByRole('radio', { name: /monthly/i }));
374+
375+
expect(
376+
await findByText(
377+
'The transfer will no longer recur after this date. If left blank, the transfer will recur indefinitely until manually stopped.',
378+
),
379+
).toBeInTheDocument();
380+
});
381+
309382
it('should show error message when monthly schedule is selected', async () => {
310383
const { getByRole, getByLabelText, findByText } = render(<Components />);
311384

src/components/HrTools/SavingsFundTransfer/TransferModal/TransferModal.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ const transferSchema = (locale: string) =>
116116
is: (schedule: ScheduleEnum) => schedule !== ScheduleEnum.OneTime,
117117
then: (schema) =>
118118
schema.test(
119-
'end>=start',
120-
i18n.t('End date must be after transfer date'),
119+
'end>start',
120+
i18n.t('End date must be at least one day after the transfer date'),
121121
function (end) {
122122
const start = this.parent.transferDate as DateTime | null;
123123
if (!end || !start) {
124124
return true;
125125
}
126-
return end.toMillis() >= start.toMillis();
126+
return end.startOf('day') > start.startOf('day');
127127
},
128128
),
129129
otherwise: (schema) => schema.notRequired(),
@@ -468,7 +468,11 @@ export const TransferModal: React.FC<TransferModalProps> = ({
468468
}}
469469
error={touched.endDate && Boolean(errors.endDate)}
470470
helperText={
471-
touched.endDate && (errors.endDate as string)
471+
touched.endDate && errors.endDate
472+
? errors.endDate
473+
: t(
474+
'The transfer will no longer recur after this date. If left blank, the transfer will recur indefinitely until manually stopped.',
475+
)
472476
}
473477
/>
474478
</Grid>

0 commit comments

Comments
 (0)