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 Jun 28, 2024
1 parent 64ce2e6 commit 3fbdcc7
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const RollingStockEditorButtons = ({
})}
>
<button
data-testId="rollingstock-edit-button"
type="button"
className="btn btn-primary bg-orange px-1 py-0"
aria-label={t('translation:common.edit')}
Expand All @@ -122,6 +123,7 @@ const RollingStockEditorButtons = ({
<Pencil />
</button>
<button
data-testId="rollingstock-duplicate-button"
type="button"
className="btn btn-primary px-1 py-0"
aria-label={t('translation:common.duplicate')}
Expand All @@ -132,6 +134,7 @@ const RollingStockEditorButtons = ({
<Duplicate />
</button>
<button
data-testId="rollingstock-delete-button"
type="button"
className="btn btn-primary bg-red px-1 py-0"
aria-label={t('translation:common.delete')}
Expand Down
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
77 changes: 76 additions & 1 deletion front/tests/009-rollingstock-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
generateUniqueName,
verifyAndCheckInputById,
fillAndCheckInputById,
addRollingStock,
} from './assets/utils';
import PlaywrightRollingstockEditorPage from './pages/rollingstock-editor-page-model';

Expand All @@ -16,8 +17,13 @@ const rollingstockDetailsPath = path.resolve(
__dirname,
'../tests/assets/rollingStock/rollingstockDetails.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;
let uniqueUpdatedRollingStockName: string;
Expand All @@ -32,13 +38,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 +197,71 @@ test.describe('Rollingstock editor page', () => {
rollingStockEditorPage.page.getByTestId(uniqueDeletedRollingStockName)
).toBeHidden();
});

test('should correctly search and filter rolling stock', async ({ page }) => {
const rollingStockEditorPage = new PlaywrightRollingstockEditorPage(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 rollingStockEditorPage.getRollingStockSearchNumber();

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

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

// Perform a filtering action for thermal rolling stock
await rollingStockEditorPage.electricRollingStockFilter();
await rollingStockEditorPage.themalRollingStockFilter();

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

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

// Verify that filtering reduces the count and all the RS have thermal and electric icons
expect(await rollingStockEditorPage.getThermalElectricRollingStockIcons.count()).toEqual(
await rollingStockEditorPage.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(rollingStockEditorPage.getThermalRollingStockFirstIcon).toBeVisible();
await expect(rollingStockEditorPage.getElectricRollingStockFirstIcon).toBeVisible();

// Clear filters and search
await rollingStockEditorPage.electricRollingStockFilter();
await rollingStockEditorPage.themalRollingStockFilter();
await rollingStockEditorPage.clearSearchRollingStock();

// Verify that the count of rolling stock is back to the initial number
expect(await rollingStockEditorPage.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)
expect(await rollingStockEditorPage.getRollingStockSearchNumber()).toEqual(0);
});
});
Loading

0 comments on commit 3fbdcc7

Please sign in to comment.