From f4ead59a1924e28ea2c247255861b8b5ac9e9835 Mon Sep 17 00:00:00 2001 From: Pyry Koivisto Date: Fri, 23 Aug 2024 14:39:49 +0300 Subject: [PATCH] VKT(Frontend): Fix tests --- .../integration/public_enrollment.spec.ts | 52 ++++++++++++++----- .../public_free_enrollment.spec.ts | 26 ++++++---- .../page-objects/publicEnrollmentPage.ts | 45 +++++++++++++--- .../support/page-objects/publicHomePage.ts | 5 +- .../packages/vkt/src/tests/msw/handlers.ts | 2 +- 5 files changed, 98 insertions(+), 32 deletions(-) diff --git a/frontend/packages/vkt/src/tests/cypress/integration/public_enrollment.spec.ts b/frontend/packages/vkt/src/tests/cypress/integration/public_enrollment.spec.ts index 7d4f4c207..88ed678cd 100644 --- a/frontend/packages/vkt/src/tests/cypress/integration/public_enrollment.spec.ts +++ b/frontend/packages/vkt/src/tests/cypress/integration/public_enrollment.spec.ts @@ -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', ); @@ -72,11 +73,7 @@ describe('Public enrollment', () => { 'test@test.invalid', ); onPublicEnrollmentPage.fillOutContactDetails('phoneNumber', '040112233'); - onPublicEnrollmentPage.clickNext(); - onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledCheckbox( - 'previously-enrolled-no', - ); - onPublicEnrollmentPage.enrollmentFullExamCheckbox(); + onPublicEnrollmentPage.fillOutCertificateShippingDetails( 'street', 'Katu', @@ -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', ); @@ -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( @@ -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(); }); diff --git a/frontend/packages/vkt/src/tests/cypress/integration/public_free_enrollment.spec.ts b/frontend/packages/vkt/src/tests/cypress/integration/public_free_enrollment.spec.ts index 15059459f..7d1b337c5 100644 --- a/frontend/packages/vkt/src/tests/cypress/integration/public_free_enrollment.spec.ts +++ b/frontend/packages/vkt/src/tests/cypress/integration/public_free_enrollment.spec.ts @@ -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', 'test@test.invalid'); onPublicEnrollmentPage.fillOutContactDetails( 'emailConfirmation', 'test@test.invalid', ); onPublicEnrollmentPage.fillOutContactDetails('phoneNumber', '040112233'); - onPublicEnrollmentPage.clickNext(); - onPublicEnrollmentPage.checkEnrollmentPreviouslyEnrolledCheckbox( - 'previously-enrolled-no', - ); - onPublicEnrollmentPage.enrollmentFullExamCheckbox(); onPublicEnrollmentPage.fillOutCertificateShippingDetails('street', 'Katu'); onPublicEnrollmentPage.fillOutCertificateShippingDetails( 'postalCode', @@ -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'); }); }); diff --git a/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicEnrollmentPage.ts b/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicEnrollmentPage.ts index c8442ba9a..836b73dc2 100644 --- a/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicEnrollmentPage.ts +++ b/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicEnrollmentPage.ts @@ -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) { @@ -64,7 +69,7 @@ class PublicEnrollmentPage { expectContactDetailsErrorNotExist(field: string) { this.elements.enrollmentContactDetailsFieldError(field).should('not.exist'); } - expectPreviuoslyEnrolledError() { + expectPreviouslyEnrolledError() { this.elements .enrollmentPreviouslyEnrolledError() .should('be.visible') @@ -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) @@ -104,14 +127,14 @@ 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); @@ -119,6 +142,12 @@ class PublicEnrollmentPage { 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(); diff --git a/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicHomePage.ts b/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicHomePage.ts index e0017f351..41f1fa9c9 100644 --- a/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicHomePage.ts +++ b/frontend/packages/vkt/src/tests/cypress/support/page-objects/publicHomePage.ts @@ -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'), diff --git a/frontend/packages/vkt/src/tests/msw/handlers.ts b/frontend/packages/vkt/src/tests/msw/handlers.ts index 9dcf9bdd2..a04a7d71c 100644 --- a/frontend/packages/vkt/src/tests/msw/handlers.ts +++ b/frontend/packages/vkt/src/tests/msw/handlers.ts @@ -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(