Skip to content

Commit

Permalink
VKT(Frontend): Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoivisto committed Aug 23, 2024
1 parent 972038e commit f4ead59
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('Public enrollment', () => {
it('should be able to fill out enrollment info', () => {
cy.tick(3000);

onPublicEnrollmentPage.expectStepHeading('Täytä yhteystietosi');
onPublicEnrollmentPage.expectEnrollmentPersonDetails(
'Sukunimi:TestiläEtunimet:Tessa',
);
Expand All @@ -72,11 +73,7 @@ describe('Public enrollment', () => {
'[email protected]',
);
onPublicEnrollmentPage.fillOutContactDetails('phoneNumber', '040112233');
onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledCheckbox(
'previously-enrolled-no',
);
onPublicEnrollmentPage.enrollmentFullExamCheckbox();

onPublicEnrollmentPage.fillOutCertificateShippingDetails(
'street',
'Katu',
Expand All @@ -94,6 +91,20 @@ describe('Public enrollment', () => {
'Suomi',
);
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectStepHeading('Koulutustiedot');
onPublicEnrollmentPage.selectRadioButton(
'Ei perustetta maksuttomalle kielitutkinnolle',
);
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledRadio(
'previously-enrolled-no',
);
onPublicEnrollmentPage.enrollmentFullExamRadio();

onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectEnrollmentDetails(
'Tutkinto: Ruotsi, erinomainen taitoTutkintopäivä: 22.3.2022Ilmoittautuminen sulkeutuu: 15.3.2022Paikkoja vapaana: 6',
);
Expand Down Expand Up @@ -148,13 +159,6 @@ describe('Public enrollment', () => {
);
onPublicEnrollmentPage.fillOutContactDetails('phoneNumber', '040112233');
onPublicEnrollmentPage.expectContactDetailsErrorNotExist('phoneNumber');
onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.expectPreviuoslyEnrolledError();
onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledCheckbox(
'previously-enrolled-no',
);
onPublicEnrollmentPage.expectPreviouslyEnrolledErrorNotExist();

onPublicEnrollmentPage.expectCertificateShippingDetailsError('street');
onPublicEnrollmentPage.fillOutCertificateShippingDetails(
Expand Down Expand Up @@ -192,6 +196,30 @@ describe('Public enrollment', () => {
);
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectStepHeading('Koulutustiedot');
onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.expectEducationDetailsError();
onPublicEnrollmentPage.selectRadioButton(
'Ei perustetta maksuttomalle kielitutkinnolle',
);
onPublicEnrollmentPage.expectEducationDetailsErrorNotExist();
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectStepHeading('Valitse tutkinto');
onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.expectFullExamError();
onPublicEnrollmentPage.enrollmentFullExamRadio();
onPublicEnrollmentPage.expectFullExamErrorNotExist();

onPublicEnrollmentPage.expectPreviouslyEnrolledError();
onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledRadio(
'previously-enrolled-no',
);
onPublicEnrollmentPage.expectPreviouslyEnrolledErrorNotExist();

onPublicEnrollmentPage.clickNext();
onPublicEnrollmentPage.expectStepHeading('Esikatsele');

// TODO: test when consent error handling is added
// onPublicEnrollmentPage.clickSubmit();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@ import { examEventIdWithKoskiEducationDetailsFound } from 'tests/msw/fixtures/pu
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.expectStepHeading('Täytä yhteystietosi');
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',
Expand All @@ -35,6 +26,21 @@ describe('Public enrollment without payment', () => {
);
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectStepHeading('Koulutustiedot');
onPublicEnrollmentPage.expectTextContents(
'Tietojemme mukaan olet suorittanut tai suorittamassa seuraavan tutkinnon:',
);
onPublicEnrollmentPage.expectTextContents('Ylioppilastutkinto');
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectStepHeading('Valitse tutkinto');
onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledRadio(
'previously-enrolled-no',
);
onPublicEnrollmentPage.enrollmentFullExamRadio();
onPublicEnrollmentPage.clickNext();

onPublicEnrollmentPage.expectStepHeading('Esikatsele');
onPublicEnrollmentPage.expectPaymentSum('Maksuton');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ class PublicEnrollmentPage {
cy.findByTestId('public-enrollment__controlButtons__back'),
submitButton: () =>
cy.findByTestId('public-enrollment__controlButtons__submit'),
enrollmentPreviouslyEnrolledCheckbox: (checkboxName: string) =>
cy.findByTestId(`enrollment-checkbox-${checkboxName}`).find('span>input'),
enrollmentPreviouslyEnrolledRadio: (radioLabel: string) =>
cy.findByTestId(`enrollment-checkbox-${radioLabel}`).find('span>input'),
enrollmentPreviouslyEnrolledError: () =>
cy.get(`#has-previous-enrollment-error`),
enrollmentFullExamCheckbox: () =>
enrollmentFullExamRadio: () =>
cy.findByTestId('enrollment-checkbox-full-exam').find('input'),
fullExamError: () => cy.get('#full-exam-error'),
educationDetailsError: () => cy.get('#has-select-education-error'),
formTextContents: () =>
cy.get('div.public-enrollment__grid__form-container'),
paymentSumHeading: () => cy.findByTestId('public-enrollment__payment-sum'),
stepHeading: (heading: string) =>
cy.findByRole('heading', { name: heading }),
radioButton: (label: string) => cy.findByRole('radio', { name: label }),
};

expectEnrollmentDetails(details: string) {
Expand Down Expand Up @@ -64,7 +69,7 @@ class PublicEnrollmentPage {
expectContactDetailsErrorNotExist(field: string) {
this.elements.enrollmentContactDetailsFieldError(field).should('not.exist');
}
expectPreviuoslyEnrolledError() {
expectPreviouslyEnrolledError() {
this.elements
.enrollmentPreviouslyEnrolledError()
.should('be.visible')
Expand All @@ -84,6 +89,24 @@ class PublicEnrollmentPage {
.enrollmentCertificateShippingDetailsError(field)
.should('not.exist');
}
expectEducationDetailsError() {
this.elements
.educationDetailsError()
.should('be.visible')
.should('have.text', 'Tieto on pakollinen');
}
expectEducationDetailsErrorNotExist() {
this.elements.educationDetailsError().should('not.exist');
}
expectFullExamError() {
this.elements
.fullExamError()
.should('be.visible')
.should('have.text', 'Tieto on pakollinen');
}
expectFullExamErrorNotExist() {
this.elements.fullExamError().should('not.exist');
}
fillOutContactDetails(field: string, details: string) {
this.elements
.enrollmentContactDetailsField(field)
Expand All @@ -104,21 +127,27 @@ class PublicEnrollmentPage {
clickSubmit() {
this.elements.submitButton().should('be.visible').click();
}
checkEnrollmentPreviouslyEnrolledCheckbox(checkboxName: string) {
checkEnrollmentPreviouslyEnrolledRadio(radioName: string) {
this.elements
.enrollmentPreviouslyEnrolledCheckbox(checkboxName)
.enrollmentPreviouslyEnrolledRadio(radioName)
.should('be.exist')
.check();
}
enrollmentFullExamCheckbox() {
this.elements.enrollmentFullExamCheckbox().should('be.exist').check();
enrollmentFullExamRadio() {
this.elements.enrollmentFullExamRadio().should('be.exist').check();
}
expectTextContents(contents: string) {
this.elements.formTextContents().should('contain.text', contents);
}
expectPaymentSum(sum: string) {
this.elements.paymentSumHeading().should('contain.text', sum);
}
expectStepHeading(heading: string) {
this.elements.stepHeading(heading).should('be.visible');
}
selectRadioButton(label: string) {
this.elements.radioButton(label).click();
}
}

export const onPublicEnrollmentPage = new PublicEnrollmentPage();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class PublicHomePage {
examEventRow: (id: number) => cy.findByTestId(row(id)),
examEventRowCheckbox: (id: number) =>
cy.findByTestId(row(id)).find('input[type=checkbox]'),
examEventRows: () => cy.get('.public-homepage__grid-container__result-box').find('table > tbody > tr'),
examEventRows: () =>
cy
.get('.public-homepage__grid-container__result-box')
.find('table > tbody > tr'),
languageFilter: () => cy.findByTestId('exam-events__language-filter'),
reservationTimerText: () =>
cy.findByTestId('public-enrollment__reservation-timer-text'),
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/vkt/src/tests/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const handlers = [
http.get(APIEndpoints.PublicEducation, ({ request }) => {
if (
request.referrer.endsWith(
`/vkt/ilmoittaudu/${examEventIdWithKoskiEducationDetailsFound}/tiedot`,
`/vkt/ilmoittaudu/${examEventIdWithKoskiEducationDetailsFound}/koulutus`,
)
) {
return new Response(
Expand Down

0 comments on commit f4ead59

Please sign in to comment.