From 519cc42c7b7684a4ba584c5650d1e7e81f60fe9d Mon Sep 17 00:00:00 2001 From: Mathieu Date: Wed, 5 Mar 2025 10:25:30 +0100 Subject: [PATCH] fixup! tests: add feedback mail test --- front/tests/015-stdcm-feedback-mail.spec.ts | 53 +++++++++---------- .../assets/constants/mail-feedback-const.ts | 18 +++++++ .../pages/stdcm/simulation-results-page.ts | 2 + 3 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 front/tests/assets/constants/mail-feedback-const.ts diff --git a/front/tests/015-stdcm-feedback-mail.spec.ts b/front/tests/015-stdcm-feedback-mail.spec.ts index 34a6ba48e1c..9b3c55c8b9a 100644 --- a/front/tests/015-stdcm-feedback-mail.spec.ts +++ b/front/tests/015-stdcm-feedback-mail.spec.ts @@ -1,8 +1,15 @@ import { test } from '@playwright/test'; -import STDCMPage from './pages/stdcm-page-model'; + +import type { Infra } from 'common/api/osrdEditoastApi'; + +import { expectedBody, expectedSubject } from './assets/constants/mail-feedback-const'; +import ConsistSection from './pages/stdcm/consist-section'; +import DestinationSection from './pages/stdcm/destination-section'; +import OriginSection from './pages/stdcm/origin-section'; +import SimulationResultPage from './pages/stdcm/simulation-results-page'; +import STDCMPage from './pages/stdcm/stdcm-page'; import { waitForInfraStateToBeCached } from './utils'; import { getInfra } from './utils/api-utils'; -import type { Infra } from 'common/api/osrdEditoastApi'; import type { ConsistFields } from './utils/types'; test.describe('FeedbackCard Tests', () => { @@ -10,6 +17,10 @@ test.describe('FeedbackCard Tests', () => { test.use({ viewport: { width: 1920, height: 1080 } }); let stdcmPage: STDCMPage; + let consistSection: ConsistSection; + let originSection: OriginSection; + let destinationSection: DestinationSection; + let simulationResultPage: SimulationResultPage; let infra: Infra; const consistDetails: ConsistFields = { @@ -25,41 +36,29 @@ test.describe('FeedbackCard Tests', () => { }); test.beforeEach('Navigate to the STDCM page', async ({ page }) => { - stdcmPage = new STDCMPage(page); + [stdcmPage, consistSection, originSection, destinationSection, simulationResultPage] = [ + new STDCMPage(page), + new ConsistSection(page), + new OriginSection(page), + new DestinationSection(page), + new SimulationResultPage(page), + ]; await page.goto('/stdcm'); await page.waitForLoadState('networkidle'); await stdcmPage.removeViteOverlay(); - // Wait for infra to be in 'CACHED' state before proceeding await waitForInfraStateToBeCached(infra.id); }); test('Verify FeedbackCard visibility', async () => { - await stdcmPage.fillAndVerifyConsistDetails(consistDetails, '180', '40'); - await stdcmPage.fillAndVerifyOriginDetails(); - await stdcmPage.fillAndVerifyDestinationDetails(); + await consistSection.fillAndVerifyConsistDetails(consistDetails, '180', '40'); + await originSection.fillAndVerifyOriginDetails(); + await destinationSection.fillAndVerifyDestinationDetails(); await stdcmPage.launchSimulation(); - await stdcmPage.verifyFeedbackCardVisibility(); - await stdcmPage.clickFeedbackButton(); - const expectedSubject = 'Feedback on the STDCM simulator'; - const expectedBody = ` -******** -Simulation details: - -Traction Engine: electricRollingStockName -Composition Code: HLP -Tonnage: 180 t -Length: 40 m -Max Speed: 100 km/h - -Origin: Perrigny BV -Destination: Miramas BV -Departure Time: 14:30 - -Please share your feedback here. -`; + await simulationResultPage.verifyFeedbackCardVisibility(); + await simulationResultPage.clickFeedbackButton(); - await stdcmPage.verifyMailRedirection(expectedSubject, expectedBody); + await simulationResultPage.verifyMailRedirection(expectedSubject, expectedBody); }); }); diff --git a/front/tests/assets/constants/mail-feedback-const.ts b/front/tests/assets/constants/mail-feedback-const.ts new file mode 100644 index 00000000000..d5b65395dce --- /dev/null +++ b/front/tests/assets/constants/mail-feedback-const.ts @@ -0,0 +1,18 @@ +export const expectedSubject = 'Feedback on the STDCM simulator'; + +export const expectedBody = ` +******** +Simulation details: + +Traction Engine: electricRollingStockName +Composition Code: HLP +Tonnage: 180 t +Length: 40 m +Max Speed: 100 km/h + +Origin: Perrigny BV +Destination: Miramas BV +Departure Time: 14:30 + +Please share your feedback here. +`; diff --git a/front/tests/pages/stdcm/simulation-results-page.ts b/front/tests/pages/stdcm/simulation-results-page.ts index bf25ecb70a7..29a5821d692 100644 --- a/front/tests/pages/stdcm/simulation-results-page.ts +++ b/front/tests/pages/stdcm/simulation-results-page.ts @@ -216,10 +216,12 @@ class SimulationResultPage extends STDCMPage { await expect(this.feedbackDescription).toBeVisible(); await expect(this.feedbackButton).toBeVisible(); } + async clickFeedbackButton() { await expect(this.feedbackButton).toBeEnabled(); await this.feedbackButton.click(); } + async verifyMailRedirection(expectedSubject: string, expectedBody: string) { await this.clickFeedbackButton(); const mailtoUrl = await this.page.evaluate(() => window.location.href);