From 86709987cbc8d1c27380493e0484aead682249a6 Mon Sep 17 00:00:00 2001 From: leevi-identio Date: Tue, 2 Dec 2025 08:31:41 +0200 Subject: [PATCH] Clean up code - add test for after-application buttons rendering --- .../result/list/ApartmentRow.test.tsx | 36 ++++++++++++++++++- .../components/result/list/ApartmentRow.tsx | 6 ++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/modules/search/components/result/list/ApartmentRow.test.tsx b/src/modules/search/components/result/list/ApartmentRow.test.tsx index dda4ccd..09f55f7 100644 --- a/src/modules/search/components/result/list/ApartmentRow.test.tsx +++ b/src/modules/search/components/result/list/ApartmentRow.test.tsx @@ -37,7 +37,41 @@ test.each(['haso', 'hitas'])( expect(applicationLink).toBeInTheDocument(); }); - + + + test.each<[string, string,boolean, string, boolean]>([ + ['haso', 'OPEN_FOR_APPLICATIONS',true, 'SEARCH:after-apply', true], + ['haso', 'OPEN_FOR_APPLICATIONS',false, 'SEARCH:apply', true], + ['haso', 'FREE_FOR_RESERVATIONS',false, 'SEARCH:apply', false], + ['hitas','OPEN_FOR_APPLICATIONS', false, 'SEARCH:apply', true], + ] + )( + 'renders after-application links correctly', + ( + ownership_type, + apartment_state_of_sale, + project_can_apply_afterwards, + expected_text, + expected_to_have_apply_link + ) => { + const apt = { + ...mockApartment, + apartment_state_of_sale: apartment_state_of_sale, + application_url: '', + project_application_end_time: '2025-08-31T12:00:00+03:00', + project_can_apply_afterwards: project_can_apply_afterwards, + } + let { container } = render(); + + if (expected_to_have_apply_link) { + expect(screen.queryByText(expected_text)).not.toBeNull(); + } + else { + expect(screen.queryByText(expected_text)).toBeNull(); + } + }); + + test('renders "contact us" links correctly for apartments', () => { const apt = { ...mockApartment, diff --git a/src/modules/search/components/result/list/ApartmentRow.tsx b/src/modules/search/components/result/list/ApartmentRow.tsx index 8431a49..dd8aa6b 100644 --- a/src/modules/search/components/result/list/ApartmentRow.tsx +++ b/src/modules/search/components/result/list/ApartmentRow.tsx @@ -71,7 +71,8 @@ const ApartmentRow = ({ const isApartmentFree = apartment_state_of_sale === ApartmentStateOfSale.FREE_FOR_RESERVATIONS.valueOf(); const isApartmentOpenForApplications = apartment_state_of_sale === ApartmentStateOfSale.OPEN_FOR_APPLICATIONS.valueOf(); - const canApplyAfterwards = apartment.project_can_apply_afterwards && projectOwnershipIsHaso; + const applicationEndTimeHasPassed = new Date().getTime() > new Date(apartment.project_application_end_time).getTime(); + const canApplyAfterwards = apartment.project_can_apply_afterwards && applicationEndTimeHasPassed && projectOwnershipIsHaso; const ownershipType = projectOwnershipIsHaso ? OwnershipType.haso : OwnershipType.hitas; const contactUrl = `${window.location.origin}/contact/apply_for_free_apartment?apartment=${apartment.apartment_number}&project=${apartment.project_id}` @@ -79,7 +80,8 @@ const ApartmentRow = ({ // dont depend on the application_url set in Drupal, but allow using it in case an override is needed const applicationUrl = apartment.application_url || `${window.location.origin}/application/add/${ownershipType}/${apartment.project_id}` - + // apartment status is OPEN_FOR_APPLICATIONS or apartment fulfills criteria for after-application + // user has no applications, reservations or hasn't been sold an apartment in the project const canCreateApplication = (isApartmentOpenForApplications || canApplyAfterwards) && !userHasApplicationForProject && !userHasReservedOrSoldApartmentInProject; const apartmentRowBaseDetails = (