Skip to content

Commit

Permalink
fixup! tests: add feedback mail test
Browse files Browse the repository at this point in the history
  • Loading branch information
Caracol3 committed Mar 5, 2025
1 parent 6594571 commit 519cc42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
53 changes: 26 additions & 27 deletions front/tests/015-stdcm-feedback-mail.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
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', () => {
test.slow(); // Mark test as slow due to multiple steps
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 = {
Expand All @@ -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);
});
});
18 changes: 18 additions & 0 deletions front/tests/assets/constants/mail-feedback-const.ts
Original file line number Diff line number Diff line change
@@ -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.
`;
2 changes: 2 additions & 0 deletions front/tests/pages/stdcm/simulation-results-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 519cc42

Please sign in to comment.