-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add feedback email adress after simulation in stdcm #11031
Open
Caracol3
wants to merge
3
commits into
dev
Choose a base branch
from
mcy/front-stdcm-add-email-adress-after-simulation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+247
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
front/src/applications/stdcm/components/StdcmResults/StdcmFeedback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Button } from '@osrd-project/ui-core'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Comment } from '@osrd-project/ui-icons'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import dayjs from 'dayjs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useTranslation } from 'react-i18next'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useSelector } from 'react-redux'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import type { StdcmResultsOutput } from 'applications/stdcm/types'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { getSelectedSimulation } from 'reducers/osrdconf/stdcmConf/selectors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { dateTimeFormatting } from 'utils/date'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const FeedbackCard = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to keep the same name used for the file
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { t } = useTranslation('stdcm'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const selectedSimulation = useSelector(getSelectedSimulation); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const resultsOutput = selectedSimulation.outputs as StdcmResultsOutput; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { rollingStock } = resultsOutput.results; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const trainName = rollingStock.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const consistCode = rollingStock?.metadata?.series; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const consistLength = `${rollingStock.length} m`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const consistMass = `${rollingStock.mass / 1000} t`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const maxSpeed = `${Math.round(rollingStock.max_speed * 3.6)} km/h`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const origin = resultsOutput.results.simulationPathSteps[0]?.location?.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const destination = resultsOutput.results.simulationPathSteps.at(-1)?.location?.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const departureTime = dateTimeFormatting( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dayjs.utc(resultsOutput.results.departure_time).toDate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const handleEmailClick = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const subject = encodeURIComponent(t('mailFeedback.subject')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const trainInfo = encodeURIComponent(` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
******** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('mailFeedback.simulationDetails')}: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('consist.tractionEngine')}: ${trainName} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('consist.compositionCode')}: ${consistCode} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('consist.tonnage')}: ${consistMass} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('consist.length')}: ${consistLength} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('consist.maxSpeed')}: ${maxSpeed} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('trainPath.origin')}: ${origin} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('trainPath.destination')}: ${destination} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${t('departureTime')}: ${departureTime} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const body = `${trainInfo}${t('mailFeedback.body')}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
window.location.href = `mailto:[email protected]?subject=${subject}&body=${body}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+28
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The email content formatting could be simplified:
Suggested change
This:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div className="feedback-card"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div className="feedback-separator" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div className="feedback-card-header"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<h3 data-testid="feedback-title"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{t('mailFeedback.title')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Comment className="feedback-card-header-icon" size="sm" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</h3> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<p className="feedback-card-text">{t('mailFeedback.description')}</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data-testid="feedback-button" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label={t('mailFeedback.writeButton')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
variant="Cancel" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
size="medium" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onClick={handleEmailClick} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default FeedbackCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { test } from '@playwright/test'; | ||
|
||
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 { 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 = { | ||
tractionEngine: 'electricRollingStockName', | ||
towedRollingStock: 'HLP', | ||
tonnage: '180', | ||
length: '40', | ||
speedLimitTag: 'MA100', | ||
}; | ||
|
||
test.beforeAll('Fetch infrastructure', async () => { | ||
infra = await getInfra(); | ||
}); | ||
|
||
test.beforeEach('Navigate to the STDCM page', async ({ 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 consistSection.fillAndVerifyConsistDetails(consistDetails, '180', '40'); | ||
await originSection.fillAndVerifyOriginDetails(); | ||
await destinationSection.fillAndVerifyDestinationDetails(); | ||
await stdcmPage.launchSimulation(); | ||
|
||
await simulationResultPage.verifyFeedbackCardVisibility(); | ||
await simulationResultPage.clickFeedbackButton(); | ||
|
||
await simulationResultPage.verifyMailRedirection(expectedSubject, expectedBody); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,14 @@ class SimulationResultPage extends STDCMPage { | |
|
||
private readonly startNewQueryWithDataButton: Locator; | ||
|
||
private readonly feedbackCardContainer: Locator; | ||
|
||
private readonly feedbackTitle: Locator; | ||
|
||
private readonly feedbackDescription: Locator; | ||
|
||
private readonly feedbackButton: Locator; | ||
|
||
constructor(page: Page) { | ||
super(page); | ||
this.mapResultContainer = page.locator('#stdcm-map-result'); | ||
|
@@ -55,6 +63,10 @@ class SimulationResultPage extends STDCMPage { | |
this.startNewQueryButton = page.getByTestId('start-new-query-button'); | ||
this.startNewQueryWithDataButton = page.getByTestId('start-new-query-with-data-button'); | ||
this.simulationList = page.locator('.stdcm-results .simulation-list'); | ||
this.feedbackCardContainer = page.locator('.feedback-card'); | ||
this.feedbackTitle = page.getByTestId('feedback-title'); | ||
this.feedbackDescription = this.feedbackCardContainer.locator('.feedback-card-text'); | ||
this.feedbackButton = page.getByTestId('feedback-button'); | ||
} | ||
|
||
private getSimulationLengthAndDurationLocator(simulationNumber: number): Locator { | ||
|
@@ -195,5 +207,26 @@ class SimulationResultPage extends STDCMPage { | |
// Validate length and duration | ||
expect(actualLengthAndDuration).toEqual(expectedLengthAndDuration); | ||
} | ||
|
||
async verifyFeedbackCardVisibility() { | ||
await this.launchSimulation(); | ||
await expect(this.simulationResultTable).toBeVisible(); | ||
await expect(this.feedbackCardContainer).toBeVisible(); | ||
await expect(this.feedbackTitle).toBeVisible(); | ||
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); | ||
const expectedMailto = `mailto:[email protected]?subject=${encodeURIComponent(expectedSubject)}&body=${encodeURIComponent(expectedBody)}`; | ||
expect(mailtoUrl).toContain(expectedMailto); | ||
} | ||
} | ||
export default SimulationResultPage; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translation key contains formatting that should be handled in the component:
This way: