From 3c0969a2f2314c6b565683468f4da06b90556df2 Mon Sep 17 00:00:00 2001 From: Sauli Purhonen Date: Fri, 28 May 2021 13:31:19 +0300 Subject: [PATCH] Dedicated test for form edit --- cypress/integration/app.spec.js | 14 --- cypress/integration/draft.spec.js | 37 ------- cypress/integration/editForm.spec.js | 158 +++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 51 deletions(-) create mode 100644 cypress/integration/editForm.spec.js diff --git a/cypress/integration/app.spec.js b/cypress/integration/app.spec.js index 6f4318f79..274ef4b22 100644 --- a/cypress/integration/app.spec.js +++ b/cypress/integration/app.spec.js @@ -36,20 +36,6 @@ describe("Basic e2e", function () { cy.get("button[type=submit]").contains("Submit").click() cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 1) - // Clear form - cy.get("button[type=button]").contains("Clear").click() - - // Edit saved submission - cy.get("button[type=button]").contains("Edit").click() - cy.get("input[name='descriptor.studyTitle']").should("have.value", "New title") - cy.get("input[name='descriptor.studyTitle']", { timeout: 10000 }).focus().type(" edited").blur() - cy.get("input[name='descriptor.studyTitle']").should("have.value", "New title edited") - cy.get("button[type=button]").contains("Update").click() - cy.get("div[role=alert]").contains("Object updated") - cy.get("button[type=button]").contains("New form").click() - cy.get("button[type=button]").contains("Edit").click() - cy.get("input[name='descriptor.studyTitle']").should("have.value", "New title edited") - // Upload a Study xml file. cy.get("div[role=button]").contains("Upload XML File").click() cy.fixture("study_test.xml").then(fileContent => { diff --git a/cypress/integration/draft.spec.js b/cypress/integration/draft.spec.js index 81d2dd8f0..a5a69b6dc 100644 --- a/cypress/integration/draft.spec.js +++ b/cypress/integration/draft.spec.js @@ -88,41 +88,4 @@ describe("Draft operations", function () { cy.get("div[role=button]").contains("Choose from drafts").click() cy.get("div").contains("No study drafts.") }) - - it("should render Experiment form correctly when editing", () => { - // Fill an Experiment form - cy.get("div[role=button]").contains("Experiment").click() - cy.wait(500) - cy.get("div[aria-expanded='true']") - .siblings() - .within(() => - cy - .get("div[role=button]") - .contains("Fill Form", { timeout: 10000 }) - .should("be.visible") - .then($btn => $btn.click()) - ) - cy.get("input[data-testid='title']").type("Test experiment") - cy.get("textarea[data-testid='description']").type("Test experiment description") - cy.get("textarea[name='design.designDescription']").type("Test design description") - - // Save Experiment form - cy.get("button[type='button']").contains("Save as Draft").click() - cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with") - - // Select the Experiment draft - cy.get("div[aria-expanded='true']") - .siblings() - .within(() => - cy - .get("div[role=button]") - .contains("Choose from drafts", { timeout: 10000 }) - .should("be.visible") - .then($btn => $btn.click()) - ) - cy.get("button[aria-label='Continue draft']").first().click() - cy.get("input[data-testid='title']").should("have.value", "Test experiment") - cy.get("textarea[data-testid='description']").should("have.value", "Test experiment description") - cy.get("textarea[name='design.designDescription']").should("have.value", "Test design description") - }) }) diff --git a/cypress/integration/editForm.spec.js b/cypress/integration/editForm.spec.js new file mode 100644 index 000000000..9b5536fde --- /dev/null +++ b/cypress/integration/editForm.spec.js @@ -0,0 +1,158 @@ +describe("Form edit functions", function () { + const baseUrl = "http://localhost:" + Cypress.env("port") + "/" + + beforeEach(() => { + cy.visit(baseUrl) + cy.get('[alt="CSC Login"]').click() + cy.wait(1000) + cy.get("button", { timeout: 10000 }).contains("Create Submission").click() + // Navigate to folder creation + cy.get("button[type=button]", { timeout: 10000 }).contains("New folder").click() + + // Add folder name & description, navigate to submissions + cy.get("input[name='name']").type("Test name") + cy.get("textarea[name='description']").type("Test description") + cy.get("button[type=button]").contains("Next").click() + }) + + it("should submit Sample form and display all form values when editing the form", () => { + // Fill a Sample form and submit object + cy.get("div[role=button]").contains("Sample").click() + cy.wait(500) + cy.get("div[aria-expanded='true']") + .siblings() + .within(() => + cy + .get("div[role=button]") + .contains("Fill Form", { timeout: 10000 }) + .should("be.visible") + .then($btn => $btn.click()) + ) + + const title = "Sample test title" + const taxonId = "123456" + const sampleData = "Human Sample" + const gender = "unknown" + + cy.get("input[name='title']").type(title) + cy.get("input[name='sampleName.taxonId']").type(taxonId) + cy.get("select[name='sampleData']").select(sampleData) + cy.get("select[name='sampleData.gender']").select(gender) + + // Submit form + cy.get("button[type=submit]").contains("Submit").click() + cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 1) + + // Clear form + cy.get("button[type=button]").contains("Clear").click() + + // Edit saved submission + cy.get("button[type=button]").contains("Edit").click() + cy.get("input[name='title']").should("have.value", title) + cy.get("input[name='title']", { timeout: 10000 }).focus().type(" edited").blur() + cy.get("input[name='title']").should("have.value", `${title} edited`) + cy.get("input[name='sampleName.taxonId']").should("have.value", taxonId) + cy.get("select[name='sampleData']").should("have.value", sampleData) + cy.get("select[name='sampleData.gender']").should("have.value", gender) + cy.get("button[type=button]").contains("Update").click() + cy.get("div[role=alert]").contains("Object updated") + + // Clear object in state + cy.get("button[type=button]").contains("New form").click() + + // Test updated title + cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 1) + cy.get("button[type=button]").contains("Edit").click() + cy.get("input[name='title']").should("have.value", `${title} edited`) + }) + + it("should render Experiment form correctly when editing", () => { + // Fill an Experiment form + cy.get("div[role=button]").contains("Experiment").click() + cy.wait(500) + cy.get("div[aria-expanded='true']") + .siblings() + .within(() => + cy + .get("div[role=button]") + .contains("Fill Form", { timeout: 10000 }) + .should("be.visible") + .then($btn => $btn.click()) + ) + + const title = "Test experiment" + const description = "Test experiment description" + const designDescription = "Test design description" + const sampleReference = "Individual Sample" + const individualSampleLabel = "Individual Sample test label" + + cy.get("input[data-testid='title']").type(title) + cy.get("textarea[data-testid='description']").type(description) + cy.get("textarea[name='design.designDescription']").type(designDescription) + cy.get("select[name='design.sampleDescriptor']").select(sampleReference) + cy.get("input[data-testid='design.sampleDescriptor.label']").type(individualSampleLabel) + + // Save Experiment form + cy.get("button[type='button']").contains("Save as Draft").click() + cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with") + + // Select the Experiment draft + cy.get("div[aria-expanded='true']") + .siblings() + .within(() => + cy + .get("div[role=button]") + .contains("Choose from drafts", { timeout: 10000 }) + .should("be.visible") + .then($btn => $btn.click()) + ) + cy.get("button[aria-label='Continue draft']").first().click() + cy.get("input[data-testid='title']").should("have.value", title) + cy.get("textarea[data-testid='description']").should("have.value", description) + cy.get("textarea[name='design.designDescription']").should("have.value", designDescription) + cy.get("select[name='design.sampleDescriptor']").should("have.value", sampleReference) + cy.get("input[data-testid='design.sampleDescriptor.label']").should("have.value", individualSampleLabel) + }) + + it("should render form with checkboxes correctly", () => { + // Fill an Dataset form + cy.get("div[role=button]").contains("Dataset").click() + cy.wait(500) + cy.get("div[aria-expanded='true']") + .siblings() + .within(() => + cy + .get("div[role=button]") + .contains("Fill Form", { timeout: 10000 }) + .should("be.visible") + .then($btn => $btn.click()) + ) + + const title = "Test Dataset" + + cy.get("input[data-testid='title']").type(title) + cy.get("[type='checkbox']").first().check() + + // Save draft + cy.get("button[type='button']").contains("Save as Draft").click() + cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with") + + // Select newly saved draft + cy.get("div[aria-expanded='true']") + .siblings() + .within(() => + cy + .get("div[role=button]") + .contains("Choose from drafts", { timeout: 10000 }) + .should("be.visible") + .then($btn => $btn.click()) + ) + + cy.get("button[aria-label='Continue draft']").first().click() + cy.get("[type='checkbox']").first().should("be.checked") + + // Test that checkbox clears with form clear -button + cy.get("button[type=button]", { timeout: 10000 }).contains("Clear form").click() + cy.get("[type='checkbox']").first().should("not.be.checked") + }) +})