Skip to content
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
36 changes: 35 additions & 1 deletion src/modules/search/components/result/list/ApartmentRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,41 @@

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(<ApartmentRow apartment={apt} projectOwnershipIsHaso={ownership_type === 'haso'} />);

Check warning on line 64 in src/modules/search/components/result/list/ApartmentRow.test.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless assignment to variable "container".

See more on https://sonarcloud.io/project/issues?id=City-of-Helsinki_asuntomyynti-react&issues=AZrd74SIYqGoADY7ixA5&open=AZrd74SIYqGoADY7ixA5&pullRequest=134

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,
Expand Down
6 changes: 4 additions & 2 deletions src/modules/search/components/result/list/ApartmentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@
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();

Check warning on line 74 in src/modules/search/components/result/list/ApartmentRow.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `Date.now()` over `Date#getTime()`.

See more on https://sonarcloud.io/project/issues?id=City-of-Helsinki_asuntomyynti-react&issues=AZrd74U2YqGoADY7ixA6&open=AZrd74U2YqGoADY7ixA6&pullRequest=134
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}`

// 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 = (
Expand Down