-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: maymanaf <[email protected]> front: add op simulation settings e2e test Signed-off-by: maymanaf <[email protected]>
- Loading branch information
Showing
51 changed files
with
2,555 additions
and
2,616 deletions.
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
File renamed without changes.
File renamed without changes.
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
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
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 |
---|---|---|
@@ -1,63 +1,61 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
import HomePage from './pages/home-page-model'; | ||
import enTranslations from '../public/locales/en/home/home.json'; | ||
import frTranslations from '../public/locales/fr/home/home.json'; | ||
|
||
// Describe the test suite for the home page of OSRD | ||
test.describe('Home page OSRD', () => { | ||
let homePage: HomePage; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
// Create an instance of the HomePage class | ||
let OSRDLanguage: string; | ||
test.beforeEach('Navigate to the home page', async ({ page }) => { | ||
homePage = new HomePage(page); | ||
// Go to the home page of OSRD | ||
await homePage.goToHomePage(); | ||
OSRDLanguage = await homePage.getOSRDLanguage(); | ||
}); | ||
|
||
test.afterEach(async () => { | ||
// Navigate back to the home page of OSRD | ||
test.afterEach('Returns to the home page', async () => { | ||
await homePage.backToHomePage(); | ||
}); | ||
|
||
// Test that the home page of OSRD displays links to other pages | ||
test('should display links in the home page', async () => { | ||
await homePage.getDisplayLinks(); | ||
/** *************** Test 1 **************** */ | ||
test('Verify the links for different pages in Home Page', async () => { | ||
// Determine the correct translations based on the selected language | ||
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations; | ||
|
||
// List of expected links on the home page | ||
const expectedLinks = [ | ||
translations.operationalStudies, | ||
translations.stdcm, | ||
translations.editor, | ||
translations.rollingStockEditor, | ||
translations.map, | ||
]; | ||
|
||
// Verify that the displayed links match the expected ones | ||
await expect(homePage.linksTitle).toHaveText(expectedLinks); | ||
}); | ||
|
||
test('should be correctly redirected to the "Operational Studies" page after clicking on the link', async () => { | ||
// Navigate to the "Operational Studies" page | ||
/** *************** Test 2 **************** */ | ||
test('Verify redirection to to the Operational Studies page', async () => { | ||
await homePage.goToOperationalStudiesPage(); | ||
// Check that the URL of the page matches the expected pattern | ||
await expect(homePage.page).toHaveURL(/.*\/operational-studies/); | ||
await expect(homePage.page).toHaveURL(/.*\/operational-studies/); // Check the URL | ||
}); | ||
|
||
test('should be correctly redirected to the "Map" page after clicking on the link', async () => { | ||
// Navigate to the "Map" page | ||
/** *************** Test 3 **************** */ | ||
test('Verify redirection toto the Map page', async () => { | ||
await homePage.goToCartoPage(); | ||
|
||
// Check that the URL of the page matches the expected pattern | ||
await expect(homePage.page).toHaveURL(/.*\/map/); | ||
}); | ||
|
||
test('should be correctly redirected to the "Editor" page after clicking on the link', async () => { | ||
// Navigate to the "Editor" page | ||
/** *************** Test 4 **************** */ | ||
test('Verify redirection to to the Infrastructure editor page', async () => { | ||
await homePage.goToEditorPage(); | ||
|
||
// Check that the URL of the page matches the expected pattern | ||
await expect(homePage.page).toHaveURL(/.*\/editor\/*/); | ||
}); | ||
|
||
test('should be correctly redirected to the "STDCM" page after clicking on the link', async ({ | ||
context, | ||
}) => { | ||
// Start waiting for new page before clicking. Note no await. | ||
const pagePromise = context.waitForEvent('page'); | ||
|
||
// Navigate to the "STDCM" page | ||
await homePage.goToSTDCMPage(); | ||
|
||
const newPage = await pagePromise; | ||
|
||
// Check that the URL of the page matches the expected pattern | ||
await expect(newPage).toHaveURL(/.*\/stdcm/); | ||
/** *************** Test 5 **************** */ | ||
test('Verify redirection to to the STDCM page', async ({ context }) => { | ||
const stdcmPage = await homePage.goToSTDCMPage(context); | ||
await expect(stdcmPage).toHaveURL(/.*\/stdcm/); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,145 +1,100 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { test } from '@playwright/test'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import type { Project } from 'common/api/osrdEditoastApi'; | ||
|
||
import projectData from './assets/operationStudies/project.json'; | ||
import CommonPage from './pages/common-page-model'; | ||
import HomePage from './pages/home-page-model'; | ||
import ProjectPage from './pages/project-page-model'; | ||
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/api-setup'; | ||
import { generateUniqueName } from './utils'; | ||
import { createProject } from './utils/setup-utils'; | ||
import { deleteProject } from './utils/teardown-utils'; | ||
|
||
let project: Project; | ||
test.describe('Validate the Operational Study Project workflow', () => { | ||
let project: Project; | ||
|
||
test.beforeEach(async () => { | ||
project = await postApiRequest('/api/projects/', { | ||
...projectData, | ||
name: `${projectData.name} ${uuidv4()}`, | ||
budget: 1234567890, | ||
test.beforeEach('Navigate to the Operational Studies projects page', async ({ page }) => { | ||
await page.goto('/operational-studies/projects'); | ||
}); | ||
}); | ||
|
||
test.afterEach(async () => { | ||
await deleteApiRequest(`/api/projects/${project.id}/`); | ||
}); | ||
|
||
test.describe('Test if project workflow is working properly', () => { | ||
/** *************** Test 1 **************** */ | ||
test('Create a new project', async ({ page }) => { | ||
const homePage = new HomePage(page); | ||
const projectPage = new ProjectPage(page); | ||
const commonPage = new CommonPage(page); | ||
|
||
await homePage.goToHomePage(); | ||
await homePage.goToOperationalStudiesPage(); | ||
await expect(projectPage.getAddProjectBtn).toBeVisible(); | ||
await projectPage.openProjectModalCreation(); | ||
|
||
// Define a unique project name for the test | ||
const projectName = `${projectData.name} ${uuidv4()}`; | ||
await projectPage.setProjectName(projectName); | ||
|
||
await projectPage.setProjectDescription(projectData.description); | ||
|
||
await projectPage.setProjectObjectives(projectData.objectives); | ||
|
||
await projectPage.setProjectFunder(projectData.funders); | ||
|
||
await projectPage.setProjectBudget(projectData.budget); | ||
|
||
await commonPage.setTag(projectData.tags[0]); | ||
await commonPage.setTag(projectData.tags[1]); | ||
await commonPage.setTag(projectData.tags[2]); | ||
|
||
const createButton = homePage.page.getByTestId('createProject'); | ||
await createButton.click(); | ||
await homePage.page.waitForURL('**/projects/*'); | ||
expect(await projectPage.getProjectName.textContent()).toContain(projectName); | ||
expect(await projectPage.getProjectDescription.textContent()).toContain( | ||
projectData.description | ||
); | ||
const objectives = await projectPage.getProjectObjectives.textContent(); | ||
expect(objectives).not.toEqual(null); | ||
if (objectives !== null) | ||
expect(objectives.replace(/[^A-Za-z0-9]/g, '')).toContain( | ||
(project.objectives ?? '').replace(/[^A-Za-z0-9]/g, '') | ||
); | ||
expect(await projectPage.getProjectFinancialsInfos.textContent()).toContain( | ||
projectData.funders | ||
); | ||
const budget = await projectPage.getProjectFinancialsAmount.textContent(); | ||
expect(budget).not.toEqual(null); | ||
if (budget !== null) expect(budget.replace(/[^0-9]/g, '')).toContain(projectData.budget); | ||
const tags = await projectPage.getProjectTags.textContent(); | ||
expect(tags).toContain(projectData.tags.join('')); | ||
|
||
const projects = await getApiRequest('/api/projects/'); | ||
const actualTestProject = projects.results.find((p: Project) => p.name === projectName); | ||
|
||
const deleteProject = await deleteApiRequest(`/api/projects/${actualTestProject.id}/`); | ||
expect(deleteProject.status()).toEqual(204); | ||
|
||
// Create a new project using the project page model and json data | ||
await projectPage.createOrUpdateProject({ | ||
name: projectName, | ||
description: projectData.description, | ||
objectives: projectData.objectives, | ||
funders: projectData.funders, | ||
budget: projectData.budget, | ||
tags: projectData.tags, | ||
}); | ||
|
||
// Validate that the project was created with the correct data | ||
await projectPage.validateProjectData({ | ||
name: projectName, | ||
description: projectData.description, | ||
objectives: projectData.objectives, | ||
funders: projectData.funders, | ||
budget: projectData.budget, | ||
tags: projectData.tags, | ||
}); | ||
|
||
// Delete the created project | ||
await deleteProject(projectName); | ||
}); | ||
|
||
test(' update a project', async ({ page }) => { | ||
/** *************** Test 2 **************** */ | ||
test('Update an existing project', async ({ page }) => { | ||
// Create a project | ||
project = await createProject(generateUniqueName('project_test_e2e')); | ||
|
||
const homePage = new HomePage(page); | ||
const projectPage = new ProjectPage(page); | ||
const commonPage = new CommonPage(page); | ||
|
||
await page.goto('/operational-studies/projects'); | ||
|
||
// Open the created project by name using the project page model | ||
await projectPage.openProjectByTestId(project.name); | ||
|
||
await projectPage.openProjectModalUpdate(); | ||
|
||
await projectPage.setProjectName(`${project.name} (updated)`); | ||
|
||
await projectPage.setProjectDescription(`${project.description} (updated)`); | ||
|
||
await projectPage.setProjectObjectives(`updated`); | ||
|
||
await projectPage.setProjectFunder(`${project.funders} (updated)`); | ||
|
||
await projectPage.setProjectBudget('123456789'); | ||
|
||
await commonPage.setTag('update-tag'); | ||
|
||
await projectPage.clickProjectUpdateConfirmBtn(); | ||
|
||
// Update the project data and save it | ||
await projectPage.createOrUpdateProject({ | ||
name: `${project.name} (updated)`, | ||
description: `${project.description} (updated)`, | ||
objectives: `${projectData.objectives} (updated)`, | ||
funders: `${project.funders} (updated)`, | ||
budget: '123456789', | ||
tags: ['update-tag'], | ||
isUpdate: true, // Indicate that this is an update | ||
}); | ||
|
||
// Navigate back to the Operational Studies page via the home page | ||
await homePage.goToHomePage(); | ||
await homePage.goToOperationalStudiesPage(); | ||
|
||
// Reopen the updated project and validate the updated data | ||
await projectPage.openProjectByTestId(`${project.name} (updated)`); | ||
|
||
expect(await projectPage.getProjectName.innerText()).toContain(`${project.name} (updated)`); | ||
expect(await projectPage.getProjectDescription.textContent()).toContain( | ||
`${project.description} (updated)` | ||
); | ||
expect(await projectPage.getProjectObjectives.textContent()).toContain('updated'); | ||
expect(await projectPage.getProjectFinancialsInfos.textContent()).toContain( | ||
`${project.funders} (updated)` | ||
); | ||
const budget = await projectPage.getProjectFinancialsAmount.textContent(); | ||
expect(budget).not.toEqual(null); | ||
if (budget !== null) expect(budget.replace(/[^0-9]/g, '')).toContain('123456789'); | ||
expect(await projectPage.getProjectTags.textContent()).toContain( | ||
`${project.tags.join('')}update-tag` | ||
); | ||
|
||
const deleteProject = await deleteApiRequest(`/api/projects/${project.id}/`); | ||
expect(deleteProject.status()).toEqual(204); | ||
await projectPage.validateProjectData({ | ||
name: `${project.name} (updated)`, | ||
description: `${project.description} (updated)`, | ||
objectives: `${projectData.objectives} (updated)`, | ||
funders: `${project.funders} (updated)`, | ||
budget: '123456789', | ||
tags: ['update-tag'], | ||
}); | ||
// Delete the created project | ||
await deleteProject(`${project.name} (updated)`); | ||
}); | ||
|
||
/** *************** Test 3 **************** */ | ||
test('Delete a project', async ({ page }) => { | ||
const projectPage = new ProjectPage(page); | ||
|
||
await page.goto('/operational-studies/projects'); | ||
// Create a project | ||
project = await createProject(generateUniqueName('project_test_e2e')); | ||
|
||
const projectPage = new ProjectPage(page); | ||
// Find the project by name and delete it using the page model | ||
await projectPage.clickProjectByName(project.name); | ||
await projectPage.checkLabelProjectSelected(); | ||
await expect(projectPage.getProjectDeleteBtn).not.toBeEmpty(); | ||
await projectPage.clickProjectDeleteBtn(); | ||
await expect(projectPage.getProjectDeleteConfirmBtn).toBeVisible(); | ||
await projectPage.clickProjectDeleteConfirmBtn(); | ||
await expect(projectPage.getProjectDeleteConfirmBtn).not.toBeVisible(); | ||
await expect(projectPage.getProjectDeleteBtn).not.toBeVisible(); | ||
await expect(projectPage.getProjectByName(project.name)).not.toBeVisible(); | ||
await projectPage.deleteProject(project.name); | ||
}); | ||
}); |
Oops, something went wrong.