Skip to content

Commit 1ac1df6

Browse files
committed
front: fix e2e date check for study
Signed-off-by: maymanaf <med.aymen.naf@gmail.com>
1 parent c98d385 commit 1ac1df6

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

front/tests/003-study-management.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test.describe('Validate the Study creation workflow', () => {
3737
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
3838
const studyName = `${studyData.name} ${uuidv4()}`; // Unique study name
3939
const todayDateISO = new Date().toISOString().split('T')[0]; // Get today's date in ISO format
40-
const expectedDate = formatDateToDayMonthYear(todayDateISO);
40+
const expectedDate = formatDateToDayMonthYear(todayDateISO, OSRDLanguage);
4141
// Create a new study using the study page model
4242
await studyPage.createStudy({
4343
name: studyName,
@@ -79,7 +79,7 @@ test.describe('Validate the Study creation workflow', () => {
7979
await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
8080
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
8181
const tomorrowDateISO = new Date(Date.now() + 86400000).toISOString().split('T')[0]; // Get tomorrow's date in ISO format
82-
const expectedDate = formatDateToDayMonthYear(tomorrowDateISO);
82+
const expectedDate = formatDateToDayMonthYear(tomorrowDateISO, OSRDLanguage);
8383
// Update the study with new values
8484
await studyPage.updateStudy({
8585
name: `${study.name} (updated)`,

front/tests/utils/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,18 @@ export async function clickWithDelay(element: Locator, delay = 500): Promise<voi
9292
/**
9393
* Convert a date string from YYYY-MM-DD format to "DD mmm YYYY" format.
9494
* @param dateString - The input date string in YYYY-MM-DD format.
95+
* @param OSRDLanguage - The current language of the application
9596
* @returns The formatted date string in "DD mmm YYYY" format.
9697
*/
97-
export function formatDateToDayMonthYear(dateString: string): string {
98+
export function formatDateToDayMonthYear(dateString: string, OSRDLanguage: string): string {
99+
const locale = OSRDLanguage === 'English' ? 'en-GB' : 'fr-FR';
98100
const date = new Date(dateString);
99-
100-
// Format the date to "15 Oct 2024" using toLocaleDateString
101-
const formattedDate = date.toLocaleDateString('en-GB', {
101+
const formattedDate = date.toLocaleDateString(locale, {
102102
day: 'numeric',
103103
month: 'short',
104104
year: 'numeric',
105105
});
106-
107-
// Convert the short month (first letter capitalized) to lowercase
108-
return formattedDate.replace(/([A-Z])/g, (match) => match.toLowerCase());
106+
return formattedDate.replace('.', '');
109107
}
110108
/**
111109
* Waits until the infrastructure state becomes 'CACHED' before proceeding to the next step.

0 commit comments

Comments
 (0)