Skip to content

Commit

Permalink
Dedicated test for form edit
Browse files Browse the repository at this point in the history
  • Loading branch information
saulipurhonen committed May 28, 2021
1 parent 1432bce commit 3c0969a
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 51 deletions.
14 changes: 0 additions & 14 deletions cypress/integration/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
37 changes: 0 additions & 37 deletions cypress/integration/draft.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
158 changes: 158 additions & 0 deletions cypress/integration/editForm.spec.js
Original file line number Diff line number Diff line change
@@ -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")
})
})

0 comments on commit 3c0969a

Please sign in to comment.