Skip to content
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

front: update e2e study date check #9913

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading