Skip to content

Commit

Permalink
front: fix e2e date check for study
Browse files Browse the repository at this point in the history
Signed-off-by: maymanaf <med.aymen.naf@gmail.com>
  • Loading branch information
Maymanaf committed Dec 3, 2024
1 parent c98d385 commit 83934dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions front/tests/003-study-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test.describe('Validate the Study creation workflow', () => {
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
const studyName = `${studyData.name} ${uuidv4()}`; // Unique study name
const todayDateISO = new Date().toISOString().split('T')[0]; // Get today's date in ISO format
const expectedDate = formatDateToDayMonthYear(todayDateISO);
const expectedDate = formatDateToDayMonthYear(todayDateISO, OSRDLanguage);
// Create a new study using the study page model
await studyPage.createStudy({
name: studyName,
Expand Down Expand Up @@ -79,7 +79,7 @@ test.describe('Validate the Study creation workflow', () => {
await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
const tomorrowDateISO = new Date(Date.now() + 86400000).toISOString().split('T')[0]; // Get tomorrow's date in ISO format
const expectedDate = formatDateToDayMonthYear(tomorrowDateISO);
const expectedDate = formatDateToDayMonthYear(tomorrowDateISO, OSRDLanguage);
// Update the study with new values
await studyPage.updateStudy({
name: `${study.name} (updated)`,
Expand Down
12 changes: 5 additions & 7 deletions front/tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,18 @@ export async function clickWithDelay(element: Locator, delay = 500): Promise<voi
/**
* Convert a date string from YYYY-MM-DD format to "DD mmm YYYY" format.
* @param dateString - The input date string in YYYY-MM-DD format.
* @param OSRDLanguage - The current language of the application
* @returns The formatted date string in "DD mmm YYYY" format.
*/
export function formatDateToDayMonthYear(dateString: string): string {
export function formatDateToDayMonthYear(dateString: string, OSRDLanguage: string): string {
const locale = OSRDLanguage === 'English' ? 'en-GB' : 'fr-FR';
const date = new Date(dateString);

// Format the date to "15 Oct 2024" using toLocaleDateString
const formattedDate = date.toLocaleDateString('en-GB', {
const formattedDate = date.toLocaleDateString(locale, {
day: 'numeric',
month: 'short',
year: 'numeric',
});

// Convert the short month (first letter capitalized) to lowercase
return formattedDate.replace(/([A-Z])/g, (match) => match.toLowerCase());
return formattedDate.replace('.', '');
}
/**
* Waits until the infrastructure state becomes 'CACHED' before proceeding to the next step.
Expand Down

0 comments on commit 83934dc

Please sign in to comment.