From 224c8e55a4febbeef449508e5e592a4ca057c98d Mon Sep 17 00:00:00 2001 From: Sebastian Tilsch Date: Tue, 3 Sep 2024 15:15:56 +0200 Subject: [PATCH] add cytoscape test for person and extend cypress commands --- .../cypress/e2e/personList.cy.js | 95 +++++++++++++++++++ .../cypress/support/commands.ts | 2 + apps/exhibition-live/package.json | 1 + 3 files changed, 98 insertions(+) create mode 100644 apps/exhibition-live/cypress/e2e/personList.cy.js diff --git a/apps/exhibition-live/cypress/e2e/personList.cy.js b/apps/exhibition-live/cypress/e2e/personList.cy.js new file mode 100644 index 00000000..f2b64894 --- /dev/null +++ b/apps/exhibition-live/cypress/e2e/personList.cy.js @@ -0,0 +1,95 @@ +describe("Person List Error Check", () => { + it("should be able to create a new person", () => { + cy.visit("http://localhost:5173/de/list/Person"); + //bigger window size + cy.viewport(1920, 1080); + + cy.get("div:nth-child(3)>div:nth-child(1)>button:nth-child(1)").click({ + force: true, + }); + cy.findByLabelText("Name", { selector: "input", trim: true }).click({ + force: true, + }); + cy.findByLabelText("Name", { selector: "input", trim: true }).type( + "Adam Ries", + { delay: 1 }, + ); + cy.get("div:nth-child(1)>div:nth-child(2)>button:nth-child(1)").click({ + force: true, + }); + cy.get("textarea").eq(0).click({ force: true }); + cy.get("textarea") + .eq(0) + .type("Ein Mathematiker aus Annaberg", { delay: 0 }); + cy.findByLabelText("Geografischer Ort", { + selector: "input", + trim: true, + }).click({ force: true }); + cy.findByLabelText("Geografischer Ort", { + selector: "input", + trim: true, + }).type("Annaberg-Buch"); + cy.get('div[aria-label$="Annaberg-Buchholz"]') + .closest("li") + .find('svg[data-testid="CheckIcon"]') + .eq(0) + .click({ force: true }); + + cy.contains("h4", "Arbeitsorte") + .closest("div.MuiGrid-item") + .within(() => { + cy.get("input").eq(0).click(); + cy.get("input").eq(0).type("09"); + cy.get("input").eq(0).trigger("keydown", { keyCode: 9, which: 9 }); + cy.get("input").eq(1).type("02"); + cy.get("input").eq(1).trigger("keydown", { keyCode: 9, which: 9 }); + cy.get("input").eq(2).type("1878"); + cy.get("input").eq(2).trigger("keydown", { keyCode: 9, which: 9 }); + cy.get("input").eq(3).type("07"); + cy.get("input").eq(3).trigger("keydown", { keyCode: 9, which: 9 }); + cy.get("input").eq(4).type("02"); + cy.get("input").eq(4).trigger("keydown", { keyCode: 9, which: 9 }); + cy.get("input").eq(5).type("1879"); + + cy.get('svg[data-testid="CheckIcon"]').eq(0).click({ force: true }); + cy.contains("span", "Annaberg-Buchholz (9.2.1878 - 7.2.1879)").should( + "exist", + ); + }); + + //cy.screenshot(`createPerson-${(new Date()).getTime()}-${Cypress.env("COMMIT_SHA")}`); + + cy.get('button[aria-label="save"]').click({ force: true }); + cy.get("div#notistack-snackbar").should( + "have.text", + "erfolgreich gespeichert", + ); + cy.wait(1000); + //cy.get("div:nth-child(1)>div:nth-child(1)>div:nth-child(1)>div:nth-child(1)>button:nth-child(1)").click({ force: true}) + //cy.get("div.MuiTypography-h1")//.should('have.text',"Adam Ries") + + cy.screenshot( + `showPerson-${new Date().getTime()}-${Cypress.env("COMMIT_SHA")}`, + ); + }); + + it('should check for "Cannot read properties of null error', () => { + cy.visit("http://localhost:5173/de/list/Person"); + + cy.screenshot( + `useContext-${new Date().getTime()}-${Cypress.env("COMMIT_SHA")}`, + ); + + cy.on("uncaught:exception", () => { + // Listen for JavaScript errors + return false; + }); + + try { + cy.contains("h3", "Cannot read properties of null").should("not.exist"); + } catch (error) { + // This block will execute if the element is not found + cy.log("Error message not found, as expected."); + } + }); +}); diff --git a/apps/exhibition-live/cypress/support/commands.ts b/apps/exhibition-live/cypress/support/commands.ts index b5939753..9f51754d 100644 --- a/apps/exhibition-live/cypress/support/commands.ts +++ b/apps/exhibition-live/cypress/support/commands.ts @@ -1,4 +1,6 @@ /// + +import "@testing-library/cypress/add-commands"; // *********************************************** // This example commands.ts shows you how to // create various custom commands and overwrite diff --git a/apps/exhibition-live/package.json b/apps/exhibition-live/package.json index 8a78d214..81b01c5c 100644 --- a/apps/exhibition-live/package.json +++ b/apps/exhibition-live/package.json @@ -165,6 +165,7 @@ "@storybook/react": "^8.1.5", "@storybook/storybook-deployer": "^2.8.16", "@storybook/testing-react": "^2.0.1", + "@testing-library/cypress": "^10.0.2", "@types/dot": "^1.1.6", "@types/gapi": "^0.0.47", "@types/json-schema": "^7.0.14",