Skip to content

Commit

Permalink
VKT(Frontend): First frontend tests targeting the free enrollment flo…
Browse files Browse the repository at this point in the history
…w [deploy]
  • Loading branch information
pkoivisto committed Aug 6, 2024
1 parent 8df4ca6 commit 16a8ae4
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export const PublicEnrollmentPaymentSum = ({

return (
<div className="columns flex-end">
<H1 className="margin-top-lg">{content}</H1>
<H1
data-testid="public-enrollment__payment-sum"
className="margin-top-lg"
>
{content}
</H1>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HTTPStatusCode } from 'shared/enums';

import { APIEndpoints } from 'enums/api';
import { PublicReservationResponse } from 'interfaces/publicEnrollment';
import { onPublicEnrollmentPage } from 'tests/cypress/support/page-objects/publicEnrollmentPage';
import { onPublicHomePage } from 'tests/cypress/support/page-objects/publicHomePage';
import { onToast } from 'tests/cypress/support/page-objects/toast';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { onPublicEnrollmentPage } from 'tests/cypress/support/page-objects/publicEnrollmentPage';
import { examEventIdWithKoskiEducationDetailsFound } from 'tests/msw/fixtures/publicEnrollmentInitialisation';

describe('Public enrollment without payment', () => {
it('is possible when suitable education credentials are returned from KOSKI', () => {
cy.openPublicEnrollmentPage(examEventIdWithKoskiEducationDetailsFound);
onPublicEnrollmentPage.expectTextContents(
'Tietojemme mukaan olet suorittanut tai suorittamassa seuraavan tutkinnon:',
);
onPublicEnrollmentPage.expectTextContents('Ylioppilastutkinto');

onPublicEnrollmentPage.fillOutContactDetails('email', '[email protected]');
onPublicEnrollmentPage.fillOutContactDetails(
'emailConfirmation',
'[email protected]',
);
onPublicEnrollmentPage.fillOutContactDetails('phoneNumber', '040112233');
onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledCheckbox(
'previously-enrolled-no',
);
onPublicEnrollmentPage.enrollmentFullExamCheckbox();
onPublicEnrollmentPage.fillOutCertificateShippingDetails('street', 'Katu');
onPublicEnrollmentPage.fillOutCertificateShippingDetails(
'postalCode',
'99800',
);
onPublicEnrollmentPage.fillOutCertificateShippingDetails(
'town',
'Kaupunki',
);
onPublicEnrollmentPage.fillOutCertificateShippingDetails(
'country',
'Suomi',
);
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectPaymentSum('Maksuton');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class PublicEnrollmentPage {
cy.get(`#has-previous-enrollment-error`),
enrollmentFullExamCheckbox: () =>
cy.findByTestId('enrollment-checkbox-full-exam').find('input'),
formTextContents: () =>
cy.get('div.public-enrollment__grid__form-container'),
paymentSumHeading: () => cy.findByTestId('public-enrollment__payment-sum'),
};

expectEnrollmentDetails(details: string) {
Expand Down Expand Up @@ -110,6 +113,12 @@ class PublicEnrollmentPage {
enrollmentFullExamCheckbox() {
this.elements.enrollmentFullExamCheckbox().should('be.exist').check();
}
expectTextContents(contents: string) {
this.elements.formTextContents().should('contain.text', contents);
}
expectPaymentSum(sum: string) {
this.elements.paymentSumHeading().should('contain.text', sum);
}
}

export const onPublicEnrollmentPage = new PublicEnrollmentPage();
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ export const publicEnrollmentInitialisation = {
isRenewable: true,
},
};

export const examEventIdWithKoskiEducationDetailsFound = 234;

export const publicEnrollmentInitialisationWithFreeEnrollments = {
...publicEnrollmentInitialisation,
examEvent: {
...publicEnrollmentInitialisation.examEvent,
id: examEventIdWithKoskiEducationDetailsFound,
},
freeEnrollmentDetails: {
freeOralSkillLeft: 3,
freeTextualSkillLeft: 3,
},
};
36 changes: 33 additions & 3 deletions frontend/packages/vkt/src/tests/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { clerkExamEvent } from 'tests/msw/fixtures/clerkExamEvent';
import { clerkExamEvents9 } from 'tests/msw/fixtures/clerkExamEvents9';
import { clerkPaymentRefunded } from 'tests/msw/fixtures/clerkPaymentRefunded';
import { person } from 'tests/msw/fixtures/person';
import { publicEnrollmentInitialisation } from 'tests/msw/fixtures/publicEnrollmentInitialisation';
import {
examEventIdWithKoskiEducationDetailsFound,
publicEnrollmentInitialisation,
publicEnrollmentInitialisationWithFreeEnrollments,
} from 'tests/msw/fixtures/publicEnrollmentInitialisation';
import { publicExamEvents11 } from 'tests/msw/fixtures/publicExamEvents11';

export const handlers = [
Expand All @@ -30,8 +34,18 @@ export const handlers = [

return new Response(cookies.noAuth ? 'null' : JSON.stringify(person));
}),
http.get(APIEndpoints.PublicEducation, () => {
return new Response(JSON.stringify([]));
http.get(APIEndpoints.PublicEducation, ({ request }) => {
if (
request.referrer.endsWith(
`/vkt/ilmoittaudu/${examEventIdWithKoskiEducationDetailsFound}/tiedot`,
)
) {
return new Response(
JSON.stringify([{ educationType: 'ylioppilas', isActive: true }]),
);
} else {
return new Response(JSON.stringify([]));
}
}),
http.get(APIEndpoints.PublicExamEvent, () => {
return new Response(JSON.stringify(publicExamEvents11));
Expand Down Expand Up @@ -108,7 +122,23 @@ export const handlers = [
status: 200,
});
}),
http.get(
`${APIEndpoints.PublicExamEvent}/${examEventIdWithKoskiEducationDetailsFound}/enrollment`,
() => {
return new Response(
JSON.stringify(publicEnrollmentInitialisationWithFreeEnrollments),
{
status: 200,
},
);
},
),
http.put(`${APIEndpoints.ClerkPayment}/1/refunded`, () => {
return new Response(JSON.stringify(clerkPaymentRefunded), { status: 200 });
}),
http.get(APIEndpoints.FeatureFlags, () => {
return new Response(JSON.stringify({ freeEnrollmentAllowed: true }), {
status: 200,
});
}),
];

0 comments on commit 16a8ae4

Please sign in to comment.