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

psp=8857 Do not use global lease to check periods - fix start date is… #4196

Merged
merged 4 commits into from
Jul 15, 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 @@ -48,6 +48,7 @@ const defaultLeaseWithPeriodsPayments: LeaseFormModel = {
{
...defaultFormLeasePeriod,
expiryDate: '2020-01-01',
startDate: '2020-01-01',
statusTypeCode: toTypeCodeNullable(LeasePeriodStatusTypes.EXERCISED),
payments: [{ ...defaultTestFormLeasePayment }],
},
Expand Down Expand Up @@ -144,17 +145,23 @@ describe('PeriodsPaymentsContainer component', () => {

describe('period logic tests', () => {
it('when adding a new initial period, the start date is set to the start date of the lease', async () => {
const {
component: { getAllByText, getByDisplayValue },
} = await setup({ claims: [Claims.LEASE_EDIT, Claims.LEASE_ADD] });
mockAxios.onPost().reply(200, { id: 1 });
const temp = mockGetLeasePeriods.response;
try {
mockGetLeasePeriods.response = [];
const {
component: { getAllByText, getByDisplayValue },
} = await setup({ claims: [Claims.LEASE_EDIT, Claims.LEASE_ADD] });
mockAxios.onPost().reply(200, { id: 1 });

const addButton = getAllByText('Add a Period')[0];
await act(async () => {
userEvent.click(addButton);
});
const addButton = getAllByText('Add a Period')[0];
await act(async () => {
userEvent.click(addButton);
});

expect(getByDisplayValue('Jan 01, 2020')).toBeVisible();
expect(getByDisplayValue('Jan 01, 2020')).toBeVisible();
} finally {
mockGetLeasePeriods.response = temp;
}
});

it(`doesn't make any request when cancelling the period modal`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export const PeriodPaymentsContainer: React.FunctionComponent<
setDeleteModalWarning,
setConfirmDeleteModalValues,
comfirmDeleteModalValues,
} = useDeletePeriodsPayments(deleteLeasePeriod, refreshLeasePeriods, onSuccess);
} = useDeletePeriodsPayments(
deleteLeasePeriod,
refreshLeasePeriods,
getLeasePeriods.response,
onSuccess,
);

/**
* Send the save request (either an update or an add). Use the response to update the parent lease.
Expand Down Expand Up @@ -123,7 +128,7 @@ export const PeriodPaymentsContainer: React.FunctionComponent<

const onEdit = useCallback(
(values: FormLeasePeriod) => {
if (lease?.periods?.length === 0) {
if (getLeasePeriods?.response?.length === 0) {
values = {
...values,
startDate: isValidIsoDateTime(lease?.startDate) ? lease.startDate : '',
Expand All @@ -144,7 +149,7 @@ export const PeriodPaymentsContainer: React.FunctionComponent<

setEditModalValues(values);
},
[lease],
[getLeasePeriods?.response?.length, lease?.paymentReceivableType?.id, lease.startDate],
);

const onEditPayment = useCallback((values: FormLeasePayment) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const useDeletePeriodsPayments = (
(period: ApiGen_Concepts_LeasePeriod) => Promise<AxiosResponse<boolean, any>>
>,
getLeasePeriods: (leaseId: number) => Promise<void>,
leasePeriods: ApiGen_Concepts_LeasePeriod[],
onSuccess: () => void,
) => {
const [comfirmDeleteModalValues, setConfirmDeleteModalValues] = useState<
Expand Down Expand Up @@ -55,16 +56,16 @@ export const useDeletePeriodsPayments = (
setDeleteModalWarning({ title: 'Delete Period', message: deleteWithPayments });
return false;
} else if (
lease?.periods?.length !== undefined &&
lease.periods.length > 1 &&
leasePeriod.id === lease?.periods[0].id
leasePeriods?.length !== undefined &&
leasePeriods.length > 1 &&
leasePeriod.id === leasePeriods[0].id
) {
setDeleteModalWarning({ title: 'Delete Period', message: deleteInitialWithRenewals });
return false;
}
return true;
},
[lease?.periods],
[leasePeriods],
);

/**
Expand Down
Loading