From 66c40019326a8f66aa687d69cbb1f83617c8d939 Mon Sep 17 00:00:00 2001 From: Chandrasekhar Ramakrishnan Date: Wed, 25 Oct 2023 11:27:57 +0200 Subject: [PATCH] tests: add tests for slow and error responses from user and statuspage (#2283) (#2858) --- tests/cypress/e2e/home.spec.ts | 35 ++++++++----------- tests/cypress/e2e/maintenance.spec.ts | 1 - .../support/renkulab-fixtures/global.ts | 12 +++++-- .../cypress/support/renkulab-fixtures/user.ts | 6 +++- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/cypress/e2e/home.spec.ts b/tests/cypress/e2e/home.spec.ts index 6467f94b0..186cb9b19 100644 --- a/tests/cypress/e2e/home.spec.ts +++ b/tests/cypress/e2e/home.spec.ts @@ -46,32 +46,25 @@ describe("404 page", () => { }); }); -describe("display the maintenance page", () => { +describe("display the home page even when APIs return strange responses", () => { beforeEach(() => { - new Fixtures(cy).config().versions(); - }); - - it("displays an error when trying to get status page information", () => { - // ! we plan to change this behavior and ignore statuspage info when unavailable #2283 - new Fixtures(cy).renkuDown(); + new Fixtures(cy) + .config() + .versions() + .statuspageDown() + .userNone(undefined, 1000); cy.visit("/"); - cy.get("h1").should("have.length", 1); - cy.get("h1").contains("RenkuLab Down").should("be.visible"); - cy.get(".alert-content") - .contains("Could not retrieve status information") - .should("be.visible"); }); - it("displays status page information", () => { - // if the call to get the user fails (e.g., no .userNone() fixture) - // then show the status page - new Fixtures(cy).getStatuspageInfo(); - cy.visit("/"); - cy.wait("@getStatuspageInfo"); + it("displays the home page intro text", () => { + cy.wait("@getUser"); cy.get("h1").should("have.length", 1); - cy.get("h1").contains("RenkuLab Down").should("be.visible"); - cy.get("h3").contains("RenkuLab Status").should("be.visible"); - cy.get("h4").contains("Scheduled Maintenance Details").should("be.visible"); + cy.get("h1") + .first() + .should( + "have.text", + "An open-source knowledge infrastructure for collaborative and reproducible data science" + ); }); }); diff --git a/tests/cypress/e2e/maintenance.spec.ts b/tests/cypress/e2e/maintenance.spec.ts index 4ffaa30a5..d5487561b 100644 --- a/tests/cypress/e2e/maintenance.spec.ts +++ b/tests/cypress/e2e/maintenance.spec.ts @@ -51,7 +51,6 @@ describe("display the maintenance page when there is no user response", () => { }); it("displays an error when trying to get status page information", () => { - // ! we plan to change this behavior and ignore statuspage info when unavailable #2283 new Fixtures(cy).renkuDown().statuspageDown(); cy.visit("/"); cy.get("h1").should("have.length", 1); diff --git a/tests/cypress/support/renkulab-fixtures/global.ts b/tests/cypress/support/renkulab-fixtures/global.ts index 847d1b8e8..2c80c98c6 100644 --- a/tests/cypress/support/renkulab-fixtures/global.ts +++ b/tests/cypress/support/renkulab-fixtures/global.ts @@ -25,12 +25,12 @@ import { FixturesConstructor } from "./fixtures"; function Global(Parent: T) { return class NewSessionFixtures extends Parent { getStatuspageInfo({ - name = "getStatuspageInfo", fixture = "statuspage-operational.json", + name = "getStatuspageInfo", overrides, }: { - name?: string; fixture?: string; + name?: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any overrides?: any; } = {}) { @@ -51,6 +51,14 @@ function Global(Parent: T) { return this; } + statuspageDown(name = "getStatuspageInfo") { + cy.intercept("https://*.statuspage.io/api/v2/summary.jsonr", { + statusCode: 500, + body: {}, + }).as(name); + return this; + } + config(params?: { name?: string; fixture?: string; diff --git a/tests/cypress/support/renkulab-fixtures/user.ts b/tests/cypress/support/renkulab-fixtures/user.ts index 24773d67a..5b3af8b6d 100644 --- a/tests/cypress/support/renkulab-fixtures/user.ts +++ b/tests/cypress/support/renkulab-fixtures/user.ts @@ -40,8 +40,12 @@ function User(Parent: T) { return this; } - userNone(names = { user: "getUser", keycloakUser: "getKeycloakUser" }) { + userNone( + names = { user: "getUser", keycloakUser: "getKeycloakUser" }, + delay = undefined + ) { cy.intercept("/ui-server/api/user", { + delay: delay, statusCode: 401, body: {}, }).as(names.user);