From b8913590e4a139eca5df6c1af3ba9e36dc936327 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Tue, 15 Oct 2024 23:46:44 +0100 Subject: [PATCH 1/3] Begin adding tests for edit page and file upload --- webapp/cypress/e2e/editPage.cy.js | 29 ++++++++++++++++++++++++++++ webapp/cypress/fixtures/example_data | 1 + webapp/cypress/support/commands.js | 24 +++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 120000 webapp/cypress/fixtures/example_data diff --git a/webapp/cypress/e2e/editPage.cy.js b/webapp/cypress/e2e/editPage.cy.js index 2b08f3f1f..c4f67ae90 100644 --- a/webapp/cypress/e2e/editPage.cy.js +++ b/webapp/cypress/e2e/editPage.cy.js @@ -246,4 +246,33 @@ describe("Edit Page", () => { cy.get('[data-testid="search-input"]').type("editable_sample"); cy.get("[data-testid=sample-table] tr:nth-of-type(1) > td:nth-of-type(9)").contains(2); // 2 blocks are present }); + + it("Clicks the upload buttons and checks that the modals are shown", () => { + cy.get('[data-testid="search-input"]').type("editable_sample"); + cy.findByText("editable_sample").click(); + cy.findByLabelText("Name").should("have.value", "This is a sample name"); + + cy.findByText("Upload files...").click(); + cy.findByText("Drop files here, browse files or import from:").should("exist"); + cy.findByLabelText("Close Modal").click(); + + cy.findByText("Add files from server...").click(); + cy.findByText("Select files to add").should("exist"); + cy.findByLabelText("Close").click(); + }); + + it("Uploads an XRD file, makes an XRD block and checks that the plot works", () => { + cy.uploadFileViaAPI("editable_sample", "XRD/example_bmb.xye"); + + cy.get('[data-testid="search-input"]').type("editable_sample"); + cy.findByText("editable_sample").click(); + cy.findByLabelText("Name").should("have.value", "This is a sample name"); + + cy.findByText("Add a block").click(); + cy.get(".dropdown-menu").findByText("Powder XRD").click(); + + cy.findByLabelText("Select a file:").click(); + cy.get(".file-select-dropdown").findByText("example_bmb.xye").click(); + cy.findByText("X axis").exists(); + }); }); diff --git a/webapp/cypress/fixtures/example_data b/webapp/cypress/fixtures/example_data new file mode 120000 index 000000000..50c5159be --- /dev/null +++ b/webapp/cypress/fixtures/example_data @@ -0,0 +1 @@ +../../../pydatalab/example_data \ No newline at end of file diff --git a/webapp/cypress/support/commands.js b/webapp/cypress/support/commands.js index 2d5a62887..6b3fea41e 100644 --- a/webapp/cypress/support/commands.js +++ b/webapp/cypress/support/commands.js @@ -116,6 +116,30 @@ Cypress.Commands.add("deleteSampleViaAPI", (item_id) => { }); }); +Cypress.Commands.add("uploadFileViaAPI", (itemId, path) => { + cy.log("Upload a test file via the API: " + path); + cy.fixture(path, "binary") + .then(Cypress.Blob.binaryStringToBlob) + .then((blob) => { + const formData = new FormData(); + formData.append("relativePath", "null"); + formData.append("name", path); + formData.append("type", "application/octet-stream"); + formData.append("size", blob.size.toString()); + formData.append("item_id", itemId); + formData.append("replace_file", "null"); + formData.append("files[]", blob, path); + + return cy.request({ + method: "POST", + url: API_URL + "/upload-file/", + body: formData, + headers: { "Content-Type": "multipart/form-data" }, + form: true, + }); + }); +}); + Cypress.Commands.add("searchAndSelectItem", (search_text, selector, clickPlus = false) => { // searches in the dropdown for the first real item with the given name, looking for a badge // if clickPlus, then also click the add row button before looking for the search bar From 08a98087e3b03622311ab84dd9decfeba222c8d0 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Wed, 16 Oct 2024 00:55:40 +0100 Subject: [PATCH 2/3] Skip name check --- webapp/cypress/e2e/editPage.cy.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/webapp/cypress/e2e/editPage.cy.js b/webapp/cypress/e2e/editPage.cy.js index c4f67ae90..0e4b3a941 100644 --- a/webapp/cypress/e2e/editPage.cy.js +++ b/webapp/cypress/e2e/editPage.cy.js @@ -203,7 +203,6 @@ describe("Edit Page", () => { it("Add some blocks to the sample and checks unsaved warning behavior", () => { cy.get('[data-testid="search-input"]').type("editable_sample"); cy.findByText("editable_sample").click(); - cy.findByLabelText("Name").should("have.value", "This is a sample name"); cy.findByText("Add a block").click(); cy.get(".dropdown-menu").findByText("Comment").click(); @@ -266,7 +265,6 @@ describe("Edit Page", () => { cy.get('[data-testid="search-input"]').type("editable_sample"); cy.findByText("editable_sample").click(); - cy.findByLabelText("Name").should("have.value", "This is a sample name"); cy.findByText("Add a block").click(); cy.get(".dropdown-menu").findByText("Powder XRD").click(); From beeec1e6a796e833181be8251c2bb840da5ca1f6 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Wed, 16 Oct 2024 01:38:53 +0100 Subject: [PATCH 3/3] Fix test typo --- webapp/cypress/e2e/editPage.cy.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webapp/cypress/e2e/editPage.cy.js b/webapp/cypress/e2e/editPage.cy.js index 0e4b3a941..e473934d7 100644 --- a/webapp/cypress/e2e/editPage.cy.js +++ b/webapp/cypress/e2e/editPage.cy.js @@ -249,7 +249,6 @@ describe("Edit Page", () => { it("Clicks the upload buttons and checks that the modals are shown", () => { cy.get('[data-testid="search-input"]').type("editable_sample"); cy.findByText("editable_sample").click(); - cy.findByLabelText("Name").should("have.value", "This is a sample name"); cy.findByText("Upload files...").click(); cy.findByText("Drop files here, browse files or import from:").should("exist"); @@ -271,6 +270,6 @@ describe("Edit Page", () => { cy.findByLabelText("Select a file:").click(); cy.get(".file-select-dropdown").findByText("example_bmb.xye").click(); - cy.findByText("X axis").exists(); + cy.findByText("X axis").should("exist"); }); });