Skip to content

Commit

Permalink
VKT(Frontend): Rename publicHomePage -> publicExcellentLevelPage in C…
Browse files Browse the repository at this point in the history
…ypress tests
  • Loading branch information
pkoivisto committed Jan 3, 2025
1 parent d6904c9 commit 6004b68
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 169 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ExamLanguage } from 'enums/app';
import { onPublicExcellentLevelPage } from 'tests/cypress/support/page-objects/publicExcellentLevelPage';
import { publicExamEvents11 } from 'tests/msw/fixtures/publicExamEvents11';

describe('PublicExcellentLevelPage (mobile)', () => {
beforeEach(() => {
cy.viewport('iphone-x');
cy.openPublicExcellentLevelPage();
});

it('should allow filtering exam events based on exam language', () => {
onPublicExcellentLevelPage.expectFilteredExamEventsCount(
publicExamEvents11.length,
);

onPublicExcellentLevelPage.filterByLanguage(ExamLanguage.FI);
onPublicExcellentLevelPage.expectFilteredExamEventsCount(6);

onPublicExcellentLevelPage.filterByLanguage(ExamLanguage.SV);
onPublicExcellentLevelPage.expectFilteredExamEventsCount(5);

onPublicExcellentLevelPage.filterByLanguage(ExamLanguage.ALL);
onPublicExcellentLevelPage.expectFilteredExamEventsCount(
publicExamEvents11.length,
);
});

it('should display enroll button correctly based on enrollment status', () => {
onPublicExcellentLevelPage.expectEnrollButtonDisabled(1);
onPublicExcellentLevelPage.expectEnrollButtonText(
1,
'Ilmoittaudu myöhemmin',
);
onPublicExcellentLevelPage.expectEnrollButtonEnabled(2);
onPublicExcellentLevelPage.expectEnrollButtonText(2, 'Ilmoittaudu');
onPublicExcellentLevelPage.expectEnrollButtonEnabled(5);
onPublicExcellentLevelPage.expectEnrollButtonText(5, 'Ilmoittaudu jonoon');
});
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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 { onPublicExcellentLevelPage } from 'tests/cypress/support/page-objects/publicExcellentLevelPage';
import { onToast } from 'tests/cypress/support/page-objects/toast';
import { fixedDateForTests } from 'tests/cypress/support/utils/date';

Expand All @@ -14,11 +14,11 @@ beforeEach(() => {
describe('Public enrollment', () => {
describe('to exam event with room', () => {
it('reservation should have timer', () => {
onPublicHomePage.expectReservationTimeLeft('30', '00');
onPublicExcellentLevelPage.expectReservationTimeLeft('30', '00');
cy.tick(3000);
onPublicHomePage.expectReservationTimeLeft('29', '57');
onPublicExcellentLevelPage.expectReservationTimeLeft('29', '57');
cy.tick(30 * 60 * 1000);
onPublicHomePage.expectReservationTimeLeft('00', '00');
onPublicExcellentLevelPage.expectReservationTimeLeft('00', '00');
});

it('reservation should allow renewal', () => {
Expand All @@ -35,17 +35,17 @@ describe('Public enrollment', () => {
body: response,
}).as('renewReservation');

onPublicHomePage.expectReservationTimeLeft('30', '00');
onPublicExcellentLevelPage.expectReservationTimeLeft('30', '00');
cy.tick(29 * 60 * 1000);
onPublicHomePage.clickReservationRenewButton();
onPublicExcellentLevelPage.clickReservationRenewButton();
cy.wait('@renewReservation');
cy.tick(30 * 1000);
onPublicHomePage.expectReservationTimeLeft('29', '30');
onPublicExcellentLevelPage.expectReservationTimeLeft('29', '30');
});

it('reservation expired should display info modal', () => {
cy.tick(31 * 60 * 1000);
onPublicHomePage.expectReservationExpiredOkButtonEnabled();
onPublicExcellentLevelPage.expectReservationExpiredOkButtonEnabled();
});

it('should show session expired modal', () => {
Expand All @@ -54,7 +54,7 @@ describe('Public enrollment', () => {
cy.setCookie('noAuth', 'true');
cy.wait(10);
cy.tick(6 * 1000);
onPublicHomePage.expectSessionExpiredModal();
onPublicExcellentLevelPage.expectSessionExpiredModal();
});

it('should be able to fill out enrollment info', () => {
Expand Down Expand Up @@ -233,13 +233,13 @@ describe('Public enrollment', () => {
// TODO: Enable again once auth flow is complete.
describe('errors when enroll button is clicked on the home page', () => {
it.skip('exam event received congestion after the home page was opened', () => {
onPublicHomePage.clickEnrollButton(10);
onPublicExcellentLevelPage.clickEnrollButton(10);

onToast.expectText('Tutkintotilaisuus on ruuhkautunut');
});

it.skip('registration to exam event closed after the home page was opened', () => {
onPublicHomePage.clickEnrollButton(11);
onPublicExcellentLevelPage.clickEnrollButton(11);

onToast.expectText(
'Tutkintotilaisuuteen ilmoittautuminen on sulkeutunut',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ExamLanguage } from 'enums/app';
import { onCookieBanner } from 'tests/cypress/support/page-objects/cookieBanner';
import { onPublicExcellentLevelPage } from 'tests/cypress/support/page-objects/publicExcellentLevelPage';
import { publicExamEvents11 } from 'tests/msw/fixtures/publicExamEvents11';

describe('PublicExcellentLevelPage', () => {
beforeEach(() => {
cy.openPublicExcellentLevelPage();
});

it('should close cookie banner', () => {
onCookieBanner.closeBanner();

onCookieBanner.getBanner().should('not.exist');
});

it('should allow filtering exam events based on exam language', () => {
onPublicExcellentLevelPage.expectFilteredExamEventsCount(
publicExamEvents11.length,
);

onPublicExcellentLevelPage.filterByLanguage(ExamLanguage.FI);
onPublicExcellentLevelPage.expectFilteredExamEventsCount(6);

onPublicExcellentLevelPage.filterByLanguage(ExamLanguage.SV);
onPublicExcellentLevelPage.expectFilteredExamEventsCount(5);

onPublicExcellentLevelPage.filterByLanguage(ExamLanguage.ALL);
onPublicExcellentLevelPage.expectFilteredExamEventsCount(
publicExamEvents11.length,
);
});

it('should display enroll button correctly based on enrollment status', () => {
onPublicExcellentLevelPage.expectEnrollButtonDisabled(1);
onPublicExcellentLevelPage.expectEnrollButtonText(
1,
'Ilmoittaudu myöhemmin',
);
onPublicExcellentLevelPage.expectEnrollButtonEnabled(2);
onPublicExcellentLevelPage.expectEnrollButtonText(2, 'Ilmoittaudu');
onPublicExcellentLevelPage.expectEnrollButtonEnabled(5);
onPublicExcellentLevelPage.expectEnrollButtonText(5, 'Ilmoittaudu jonoon');
});
});

This file was deleted.

7 changes: 7 additions & 0 deletions frontend/packages/vkt/src/tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { AppRoutes } from 'enums/app';
import { RouteUtils } from 'utils/routes';

Cypress.Commands.add('openPublicHomePage', () => {
cy.window().then((win) => {
win.sessionStorage.setItem('persist:root', '{}');
});
cy.visit(AppRoutes.PublicHomePage);
});

Cypress.Commands.add('openPublicExcellentLevelPage', () => {
cy.window().then((win) => {
win.sessionStorage.setItem('persist:root', '{}');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { ExamLanguage } from 'enums/app';

const row = (id: number) => `public-exam-events__id-${id}-row`;

class PublicExcellentLevelPage {
elements = {
enrollButton: (examEventId: number) =>
cy.findByTestId(`public-exam-events-${examEventId}__enroll-btn`),
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'),
languageFilter: () => cy.findByTestId('language-filter'),
reservationTimerText: () =>
cy.findByTestId('public-enrollment__reservation-timer-text'),
reservationRenewButton: () =>
cy.findByTestId('public-enrollment__renew-reservation-modal-button'),
reservationExpiredOkButton: () =>
cy.findByTestId('public-enrollment__reservation-expired-ok-button'),
enrollAuthenticateButton: () =>
cy.findByTestId('public-enrollment__authenticate-button'),
sessionExpiredModal: () => cy.findByTestId('session-expired-modal'),
};

clickExamEventRow(id: number) {
this.elements.examEventRow(id).should('be.visible').click();
}

filterByLanguage(language: ExamLanguage) {
this.elements
.languageFilter()
.should('be.visible')
.get('[type="radio"]')
.check(language);
}

expectFilteredExamEventsCount(count: number) {
this.elements.examEventRows().should('have.length', count);
}

expectEnrollButtonText(examEventId: number, text: string) {
this.elements.enrollButton(examEventId).should('have.text', text);
}

expectEnrollButtonDisabled(examEventId: number) {
this.elements.enrollButton(examEventId).should('be.disabled');
}

expectEnrollButtonEnabled(examEventId: number) {
this.elements.enrollButton(examEventId).should('be.enabled');
}

expectCheckboxChecked(id: number) {
this.elements.examEventRowCheckbox(id).should('be.checked');
}

expectCheckboxNotChecked(id: number) {
this.elements.examEventRowCheckbox(id).should('not.be.checked');
}

clickEnrollButton(examEventId) {
this.elements.enrollButton(examEventId).should('be.visible').click();
}

expectReservationExpiredOkButtonEnabled() {
this.elements.reservationExpiredOkButton().should('be.visible.enabled');
}

expectSessionExpiredModal() {
this.elements.sessionExpiredModal().should('be.visible');
}

clickEnrollAuthenticateButton() {
this.elements.enrollAuthenticateButton().should('be.visible').click();
}

clickReservationRenewButton() {
this.elements.reservationRenewButton().should('be.visible').click();
}

expectReservationTimeLeft(minutes: string, seconds: string) {
this.elements
.reservationTimerText()
.should('be.visible')
.should('contain.text', `${minutes}:${seconds}`);
}
}

export const onPublicExcellentLevelPage = new PublicExcellentLevelPage();
Loading

0 comments on commit 6004b68

Please sign in to comment.