Skip to content

Commit

Permalink
front: verify rolling stock details table in e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Khoudli <[email protected]>
  • Loading branch information
Synar committed Feb 26, 2025
1 parent 3b34d23 commit bf9ae66
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions front/tests/009-rollingstock-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ test.describe('Rollingstock editor page tests', () => {

// Verify rolling stock details
await rollingStockEditorPage.searchRollingStock(uniqueRollingStockName);
await rollingStockEditorPage.verifyRollingStockDetailsTable(rollingstockDetails.expectedValues);
await rollingStockEditorPage.editRollingStock(uniqueRollingStockName);
for (const input of rollingstockDetails.inputs) {
const value = input.id === 'name' ? uniqueRollingStockName : input.value;
Expand Down Expand Up @@ -145,6 +146,9 @@ test.describe('Rollingstock editor page tests', () => {
// Submit and verify modification
await rollingStockEditorPage.submitRollingStock();
await rollingStockEditorPage.searchRollingStock(uniqueUpdatedRollingStockName);
await rollingStockEditorPage.verifyRollingStockDetailsTable(
rollingstockDetails.updatedExpectedValues
);
await rollingStockEditorPage.editRollingStock(uniqueUpdatedRollingStockName);
await deleteRollingStocks([uniqueUpdatedRollingStockName]);
});
Expand Down
32 changes: 31 additions & 1 deletion front/tests/assets/rollingStock/rollingstockDetails.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,35 @@
"additionalDetails": {
"electricalPowerStartupTime": 1,
"raisePantographTime": 20
}
},
"expectedValues": [
{ "id": "startupTime", "value": "5s" },
{ "id": "startupAcceleration", "value": "0.1m/s²" },
{ "id": "comfortAcceleration", "value": "1m/s²" },
{ "id": "inertiaCoefficient", "value": "1" },
{ "id": "constGamma", "value": "1m/s²" },
{ "id": "basePowerClass", "value": "7" },
{ "id": "rollingResistanceA", "value": "15kN" },
{ "id": "rollingResistanceB", "value": "0.3kN/(km/h)" },
{ "id": "rollingResistanceC", "value": "0.005kN/(km/h)²" },
{ "id": "loadingGauge", "value": "GA" },
{ "id": "rollingResistance", "value": "R(v) = a + bv + cv²" },
{ "id": "primaryCategory", "value": "NIGHT_TRAIN", "isTranslated": true },
{ "id": "otherCategories", "value": ["FREIGHT_TRAIN", "WORK_TRAIN"], "isTranslated": true }
],
"updatedExpectedValues": [
{ "id": "startupTime", "value": "4s" },
{ "id": "startupAcceleration", "value": "0.11m/s²" },
{ "id": "comfortAcceleration", "value": "0.99m/s²" },
{ "id": "inertiaCoefficient", "value": "1.3000000000000005" },
{ "id": "constGamma", "value": "1.1m/s²" },
{ "id": "basePowerClass", "value": "6" },
{ "id": "rollingResistanceA", "value": "13kN" },
{ "id": "rollingResistanceB", "value": "0.23kN/(km/h)" },
{ "id": "rollingResistanceC", "value": "0.002kN/(km/h)²" },
{ "id": "loadingGauge", "value": "G1" },
{ "id": "rollingResistance", "value": "R(v) = a + bv + cv²" },
{ "id": "primaryCategory", "value": "WORK_TRAIN", "isTranslated": true },
{ "id": "otherCategories", "value": ["HIGH_SPEED_TRAIN"], "isTranslated": true }
]
}
31 changes: 31 additions & 0 deletions front/tests/pages/rollingstock-editor-page-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,36 @@ class RollingstockEditorPage extends CommonPage {
await this.deleteRollingStockButton.click();
await this.confirmModalButtonYes.click();
}

// Verify rolling stock details table
async verifyRollingStockDetailsTable(
expectedValues: { id: string; value: string | string[]; isTranslated?: boolean }[]
) {
for (const { id, value, isTranslated } of expectedValues) {
let expectedValue = value;
// Convert translated fields
if (isTranslated) {
if (Array.isArray(value)) {
expectedValue = value.map(
(v) => this.translations.categoriesOptions[v] || this.translations[v]
);
} else {
expectedValue = this.translations.categoriesOptions[value] || this.translations[value];
}
}

// Locate and verify values
const row = this.page.getByRole('row', { name: this.translations[id] }).first();
await expect(row).toBeVisible();

const valueCell = row.getByRole('cell').nth(1);
await expect(valueCell).toBeVisible();

const actualValue = await valueCell.textContent();
expect(actualValue?.trim()).toBe(
Array.isArray(expectedValue) ? expectedValue.join(', ') : expectedValue.toString()
);
}
}
}
export default RollingstockEditorPage;
2 changes: 2 additions & 0 deletions front/tests/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ export type RollingStockDetails = {
speedEffortDataC1: { velocity: string; effort: string }[];
speedEffortDataUpdated: { velocity: string; effort: string }[];
additionalDetails: { electricalPowerStartupTime: number; raisePantographTime: number };
expectedValues: { id: string; value: string | string[]; isTranslated?: boolean }[];
updatedExpectedValues: { id: string; value: string | string[]; isTranslated?: boolean }[];
};

export type ProjectData = {
Expand Down

0 comments on commit bf9ae66

Please sign in to comment.