refactor(tender-details): enhance translation page tests and layout

- Updated Cypress tests for the tender translation page to improve visibility checks and streamline assertions.
- Refactored test structure to utilize a dedicated function for fetching the visible title heading.
- Adjusted test cases to ensure accurate language switching and URL handling for tender details.
- Improved layout consistency in the translation page by refining element visibility checks and ensuring proper section rendering.
This commit is contained in:
AmirReza Jamali
2026-05-11 16:11:09 +03:30
parent 283aa9385e
commit f397158a29
36 changed files with 1325 additions and 854 deletions
@@ -2,6 +2,9 @@
const tenderId = "507f1f77bcf86cd799439055";
/** Visible title only — layout probe duplicates `<h1>` off-screen for measurement */
const tenderTitleHeading = () => cy.get("main h1").filter(":visible");
const makeTenderDetailsResponse = (
overrides: Partial<Record<string, any>> = {},
) => ({
@@ -54,12 +57,18 @@ describe("tender details - translation and summary", () => {
cy.visit(`/tenders/${tenderId}?lang=en`);
cy.wait("@getTenderDetailsEn");
cy.contains("h1", "Translated title EN").should("be.visible");
cy.contains("Resolved language").should("be.visible");
cy.contains("en").should("be.visible");
cy.contains("AI summary").should("be.visible");
cy.contains("Summary not ready yet").should("be.visible");
cy.contains("Translated description EN").should("be.visible");
tenderTitleHeading().should("contain.text", "Translated title EN");
cy.get("#tender-section-translation")
.should("be.visible")
.and("contain.text", "Resolved language")
.and("contain.text", "en");
cy.get("#tender-section-ai-summary")
.should("be.visible")
.and("contain.text", "AI summary")
.and("contain.text", "Summary not ready yet");
cy.get("#tender-section-description")
.should("be.visible")
.and("contain.text", "Translated description EN");
});
it("switches language from selector and reloads details with new lang query", () => {
@@ -83,7 +92,7 @@ describe("tender details - translation and summary", () => {
cy.get('select[name="lang"]').select("fr");
cy.location("search").should("include", "lang=fr");
cy.wait("@getTenderDetailsFr");
cy.contains("h1", "Titre FR").should("be.visible");
tenderTitleHeading().should("contain.text", "Titre FR");
cy.contains("Resume FR").should("be.visible");
});
@@ -124,22 +133,19 @@ describe("tender details - translation and summary", () => {
cy.wait("@translateTender");
});
it("redirects legacy /translation URL to tender details with lang preserved", () => {
it("loads tender details with lang query on the canonical URL", () => {
cy.intercept("GET", `**/api/proxy/tenders/${tenderId}**`, {
statusCode: 200,
body: makeTenderDetailsResponse({
title: "Redirect check",
title: "Lang query check",
language: "fa",
}),
}).as("getTenderAfterRedirect");
}).as("getTenderWithLang");
cy.visit(`/tenders/${tenderId}/translation?lang=fa`);
cy.location("pathname", { timeout: 15000 }).should(
"eq",
`/tenders/${tenderId}`,
);
cy.visit(`/tenders/${tenderId}?lang=fa`);
cy.location("pathname").should("eq", `/tenders/${tenderId}`);
cy.location("search").should("include", "lang=fa");
cy.wait("@getTenderAfterRedirect");
cy.contains("h1", "Redirect check").should("be.visible");
cy.wait("@getTenderWithLang");
tenderTitleHeading().should("contain.text", "Lang query check");
});
});