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
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: React CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
env:
TZ: Europe/Helsinki
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install Dependencies
run: yarn install

- name: Run tests
run: yarn test
2 changes: 1 addition & 1 deletion src/modules/search/components/result/ProjectInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ProjectInfo', () => {
});

it('has user applications', () => {
render(<ProjectInfo project={mockProject} userHasApplications />);
render(<ProjectInfo applicationUrl={'https://foo.bar'} project={mockProject} userHasApplications />);
expect(screen.getByText('SEARCH:user-application-project')).toBeDefined();
});

Expand Down
28 changes: 28 additions & 0 deletions src/modules/search/components/result/list/ApartmentRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ test('renders apartment details', () => {
expect(screen.queryByText('A15')).not.toBeNull(); // apartment_number
expect(screen.queryByText('1h+k+s')).not.toBeNull(); // apartment_structure
});

test.each<string>(['haso', 'hitas'])(
'renders application links correctly for %s apartments',
(ownership_type) => {
const apt = {
...mockApartment,
apartment_state_of_sale: 'OPEN_FOR_APPLICATIONS',
application_url: '',
}
let { container } = render(<ApartmentRow apartment={apt} projectOwnershipIsHaso={ownership_type === 'haso'} />);
const expectedApplicationLink = `${window.location.origin}/application/add/${ownership_type}/${mockApartment.project_id}`;

const applicationLink = container.querySelector(`a[href="${expectedApplicationLink}"]`);

expect(applicationLink).toBeInTheDocument();
});

test('renders "contact us" links correctly for apartments', () => {
const apt = {
...mockApartment,
apartment_state_of_sale: 'FREE_FOR_RESERVATIONS'
}
let { container } = render(<ApartmentRow apartment={apt} />);
const expectedContactUsLink = `${window.location.origin}/contact/apply_for_free_apartment?apartment=${mockApartment.apartment_number}&project=${mockApartment.project_id}`

const contactUsLink = container.querySelector(`a[href="${expectedContactUsLink}"]`);
expect(contactUsLink).toBeInTheDocument();
});
10 changes: 7 additions & 3 deletions src/modules/search/components/result/list/ApartmentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cx from 'classnames';
import { useTranslation } from 'react-i18next';
import { IconAngleDown, IconAngleUp, IconPenLine } from 'hds-react';

import { Apartment, ApartmentStateOfSale } from '../../../../../types/common';
import { Apartment, ApartmentStateOfSale, OwnershipType } from '../../../../../types/common';
import { fullURL } from '../../../utils/fullURL';
import { getApartmentPrice } from '../../../utils/getApartmentPrice';
import { userHasApplicationForApartment, userHasReservedOrSoldApartment } from '../../../utils/userApplications';
Expand Down Expand Up @@ -39,7 +39,6 @@ const ApartmentRow = ({
apartment_number,
apartment_state_of_sale,
apartment_structure,
application_url,
floor,
floor_max,
nid,
Expand Down Expand Up @@ -74,8 +73,13 @@ const ApartmentRow = ({
apartment_state_of_sale === ApartmentStateOfSale.OPEN_FOR_APPLICATIONS.valueOf();
const canApplyAfterwards = apartment.project_can_apply_afterwards && 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}`


const canCreateApplication = (isApartmentOpenForApplications || canApplyAfterwards) && !userHasApplicationForProject && !userHasReservedOrSoldApartmentInProject;

const apartmentRowBaseDetails = (
Expand Down Expand Up @@ -170,7 +174,7 @@ const ApartmentRow = ({
{
canCreateApplication && (
<CreateApplicationButton
href={fullURL(application_url)}
href={fullURL(applicationUrl)}
apartment={apartment}
/>
)
Expand Down
6 changes: 6 additions & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ export type FilterItem = {
helperText?: string;
};

export enum OwnershipType {
haso='haso',
hitas='hitas',
puolihitas='puolihitas'
}

export enum FilterType {
MultiSelect,
Input,
Expand Down