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 10, 2024
1 parent 45b2718 commit 6f1739d
Show file tree
Hide file tree
Showing 8 changed files with 712 additions and 108 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
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 './assets/scenario-utlis';
import PlaywrightScenarioPage from './pages/scenario-page-model';

let scenarioName: string;
Expand Down
99 changes: 99 additions & 0 deletions front/tests/009-rollingstock-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ import {
generateUniqueName,
verifyAndCheckInputById,
fillAndCheckInputById,
addRollingStock,
} from './assets/utils';
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 @@ -32,13 +41,15 @@ test.describe('Rollingstock editor page', () => {
await findAndDeleteRollingStock(uniqueRollingStockName);
await findAndDeleteRollingStock(uniqueUpdatedRollingStockName);
await findAndDeleteRollingStock(uniqueDeletedRollingStockName);
await findAndDeleteRollingStock(thermalElectricRollingStockName);
});

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

test('should correctly create a new rolling stock', async ({ page }) => {
Expand Down Expand Up @@ -189,4 +200,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 6f1739d

Please sign in to comment.