Skip to content

Commit

Permalink
front: add e2e tests search and filter rolling stock
Browse files Browse the repository at this point in the history
  • Loading branch information
Maymanaf committed Jul 15, 2024
1 parent e65899e commit 84491f5
Show file tree
Hide file tree
Showing 15 changed files with 860 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const SearchRollingStock = ({
</div>
</div>
<div className="col-md-2 mt-1 ml-auto">
<small>
<small data-testid="search-results-text">
{filteredRollingStockList.length > 0
? `${filteredRollingStockList.length} ${t('resultsFound')}`
: t('noResultFound')}
Expand Down
4 changes: 2 additions & 2 deletions front/tests/002-project-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
import type { Project } from 'common/api/osrdEditoastApi';

import projectData from './assets/operationStudies/project.json';
import { deleteApiRequest, getApiRequest, postApiRequest } from './assets/utils';
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/index';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import { ProjectPage } from './pages/project-page-model';
Expand Down Expand Up @@ -60,7 +60,7 @@ test.describe('Test if operationnal study : project workflow is working properly
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, '')
(project.objectives ?? '').replace(/[^A-Za-z0-9]/g, '')
);
expect(await projectPage.getProjectFinancialsInfos.textContent()).toContain(
projectData.funders
Expand Down
2 changes: 1 addition & 1 deletion front/tests/003-study-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
import type { Project, Study } from 'common/api/osrdEditoastApi';

import studyData from './assets/operationStudies/study.json';
import { getProject, postApiRequest } from './assets/utils';
import { getProject, postApiRequest } from './utils/index';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import { StudyPage } from './pages/study-page-model';
Expand Down
2 changes: 1 addition & 1 deletion front/tests/004-scenario-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
import type { Infra, Project, Scenario, Study } from 'common/api/osrdEditoastApi';

import scenarioData from './assets/operationStudies/scenario.json';
import { getInfra, getProject, getStudy, postApiRequest } from './assets/utils';
import { getInfra, getProject, getStudy, postApiRequest } from './utils/index';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import ScenarioPage from './pages/scenario-page-model';
Expand Down
2 changes: 1 addition & 1 deletion front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
import type { Infra, Project, RollingStock, Scenario, Study } from 'common/api/osrdEditoastApi';

import scenarioData from './assets/operationStudies/scenario.json';
import { getProject, getStudy, getRollingStock, postApiRequest, getInfra } from './assets/utils';
import { getProject, getStudy, getRollingStock, postApiRequest, getInfra } from './utils/index';
import { PlaywrightHomePage } from './pages/home-page-model';
import RollingStockSelectorPage from './pages/rolling-stock-selector-page';
import PlaywrightScenarioPage from './pages/scenario-page-model';
Expand Down
2 changes: 1 addition & 1 deletion front/tests/008-allowances.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '@playwright/test';
import { v4 as uuidv4 } from 'uuid';

import createCompleteScenario, { allowancesManagement } from './assets/utils';
import createCompleteScenario, { allowancesManagement } from './utils/scenario-utils';
import PlaywrightScenarioPage from './pages/scenario-page-model';

let scenarioName: string;
Expand Down
119 changes: 111 additions & 8 deletions front/tests/009-rollingstock-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ import path from 'path';
import { test, expect } from '@playwright/test';

import {
findAndDeleteRollingStock,
findAndDeleteRollingStocks,
generateUniqueName,
verifyAndCheckInputById,
fillAndCheckInputById,
} from './assets/utils';
addRollingStock,
} from './utils/index';
import RollingStockSelectorPage from './pages/rolling-stock-selector-page';
import PlaywrightRollingstockEditorPage from './pages/rollingstock-editor-page-model';

// Correct path to load rolling stock details from JSON
const rollingstockDetailsPath = path.resolve(
__dirname,
'../tests/assets/rollingStock/rollingstockDetails.json'
);
// Correct path to load electrical and themal rolling stock from JSON
const rollingstockPath = path.resolve(
__dirname,
'../tests/assets/rollingStock/thermal-electric_rolling_stock.json'
);
const rollingstockDetails = JSON.parse(fs.readFileSync(rollingstockDetailsPath, 'utf-8'));
const rollingStockJson = JSON.parse(fs.readFileSync(rollingstockPath, 'utf8'));
const thermalElectricRollingStockName = 'thermal-electric_rolling_stock';

test.describe('Rollingstock editor page', () => {
let uniqueRollingStockName: string;
Expand All @@ -29,16 +38,22 @@ test.describe('Rollingstock editor page', () => {
uniqueDeletedRollingStockName = await generateUniqueName('D_RSN');

// Check and delete the specified rolling stocks if they exist
await findAndDeleteRollingStock(uniqueRollingStockName);
await findAndDeleteRollingStock(uniqueUpdatedRollingStockName);
await findAndDeleteRollingStock(uniqueDeletedRollingStockName);
await findAndDeleteRollingStocks([
uniqueRollingStockName,
uniqueUpdatedRollingStockName,
uniqueDeletedRollingStockName,
thermalElectricRollingStockName,
]);
});

test.afterEach(async () => {
// Clean up by deleting the created or updated rolling stock
await findAndDeleteRollingStock(uniqueRollingStockName);
await findAndDeleteRollingStock(uniqueUpdatedRollingStockName);
await findAndDeleteRollingStock(uniqueDeletedRollingStockName);
await findAndDeleteRollingStocks([
uniqueRollingStockName,
uniqueUpdatedRollingStockName,
uniqueDeletedRollingStockName,
thermalElectricRollingStockName,
]);
});

test('should correctly create a new rolling stock', async ({ page }) => {
Expand Down Expand Up @@ -189,4 +204,92 @@ test.describe('Rollingstock editor page', () => {
rollingStockEditorPage.page.getByTestId(uniqueDeletedRollingStockName)
).toBeHidden();
});
test('should correctly filter a rolling stock', async ({ page }) => {
const rollingStockEditorPage = new PlaywrightRollingstockEditorPage(page);
const rollingStockSelectorPage = new RollingStockSelectorPage(page);
// Navigate to rolling stock editor page
await rollingStockEditorPage.navigateToPage();

// Extract and check the initial count of rolling stock
const initialRollingStockFoundNumber =
await rollingStockSelectorPage.getRollingStockSearchNumber();

// Perform a filtering action for electric rolling stock
await rollingStockSelectorPage.electricRollingStockFilter();

// Verify that filtering reduces the count and all the RS have electic icons
expect(await rollingStockSelectorPage.getElectricRollingStockIcons.count()).toEqual(
await rollingStockSelectorPage.getRollingStockSearchNumber()
);

// Clear electric filter
await rollingStockSelectorPage.electricRollingStockFilter();

// Perform a filtering action for thermal rolling stock
await rollingStockSelectorPage.thermalRollingStockFilter();

// Verify that filtering reduces the count and all the RS have thermal icons
expect(await rollingStockSelectorPage.getThermalRollingStockIcons.count()).toEqual(
await rollingStockSelectorPage.getRollingStockSearchNumber()
);

// Perform a filtering action for combined thermal-electric rolling stock
await rollingStockSelectorPage.electricRollingStockFilter();

// Verify that filtering reduces the count and all the RS have thermal and electric icons
expect(await rollingStockSelectorPage.getThermalElectricRollingStockIcons.count()).toEqual(
await rollingStockSelectorPage.getRollingStockSearchNumber()
);

// Clear filters
await rollingStockSelectorPage.electricRollingStockFilter();
await rollingStockSelectorPage.thermalRollingStockFilter();

// Verify that the count of rolling stock is back to the initial number
expect(await rollingStockSelectorPage.getRollingStockList.count()).toEqual(
initialRollingStockFoundNumber
);
});

test('should correctly search for a rolling stock', async ({ page }) => {
const rollingStockEditorPage = new PlaywrightRollingstockEditorPage(page);
const rollingStockSelectorPage = new RollingStockSelectorPage(page);
// Add a rolling stock via postAPI
await addRollingStock(thermalElectricRollingStockName, rollingStockJson);

// Navigate to rolling stock editor page
await rollingStockEditorPage.navigateToPage();

// Extract and check the initial count of rolling stock
const initialRollingStockFoundNumber =
await rollingStockSelectorPage.getRollingStockSearchNumber();

// Search for the specific rolling stock
await rollingStockEditorPage.searchRollingStock(thermalElectricRollingStockName);
expect(
rollingStockEditorPage.page.getByTestId(
`rollingstock-thermal-${thermalElectricRollingStockName}`
)
).toBeDefined();

// Verify that the first rolling stock has the thermal and electric icon
await expect(rollingStockSelectorPage.getThermalRollingStockFirstIcon).toBeVisible();
await expect(rollingStockSelectorPage.getElectricRollingStockFirstIcon).toBeVisible();

// Clear the search
await rollingStockEditorPage.clearSearchRollingStock();

// Verify that the count of rolling stock is back to the initial number
expect(await rollingStockSelectorPage.getRollingStockList.count()).toEqual(
initialRollingStockFoundNumber
);
// Search for a non existing rolling stock
await rollingStockEditorPage.searchRollingStock(
`${thermalElectricRollingStockName}-no-results`
);

// Verify that the count of rolling stock is 0 (No results Found)
await expect(rollingStockSelectorPage.getNoRollingStockResult).toBeVisible();
expect(await rollingStockSelectorPage.getRollingStockSearchNumber()).toEqual(0);
});
});
Loading

0 comments on commit 84491f5

Please sign in to comment.