Skip to content

Commit

Permalink
Merge pull request #475 from CSCfi/feature/using-draft-templates
Browse files Browse the repository at this point in the history
Feature/using draft templates
  • Loading branch information
blankdots authored Oct 7, 2021
2 parents a9bb251 + 106e5bd commit 3460cfe
Show file tree
Hide file tree
Showing 38 changed files with 594 additions and 382 deletions.
4 changes: 1 addition & 3 deletions cypress/integration/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ describe("Basic e2e", function () {

cy.get("button", { timeout: 10000 }).contains("Create Submission").click()

// Navigate to folder creation
cy.get("button[type=button]").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()

cy.wait(500)
// Skip-link
cy.get("div[role=button]").contains("Study").click()
cy.get("div[role=button]").contains("Fill Form").type("{enter}")
Expand Down
3 changes: 1 addition & 2 deletions cypress/integration/draft.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ describe("Draft operations", function () {
cy.login()

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()
cy.wait(500)
})

it("should create new folder, save, delete and continue draft", () => {
Expand Down
152 changes: 90 additions & 62 deletions cypress/integration/draftTemplates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ describe("draft selections and templates", function () {
cy.login()

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 show the list of drafts before folder is published, and show saved drafts in Home page", () => {
// Fill a Study form
cy.wait(500)
cy.get("div[role=button]", { timeout: 10000 }).contains("Study").click()
cy.get("div[role=button]").contains("Fill Form").click()
cy.get("input[name='descriptor.studyTitle']").type("Study test title")
Expand Down Expand Up @@ -47,7 +44,7 @@ describe("draft selections and templates", function () {
.then($btn => $btn.click())
)

cy.get("input[name='title']").type("Sample draft title ")
cy.get("input[name='title']").type("Sample draft title")
cy.get("input[name='sampleName.taxonId']").type(123)
cy.get("button[type=button]").contains("Save as Draft").click()
cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with")
Expand All @@ -62,7 +59,8 @@ describe("draft selections and templates", function () {
"have.text",
"Objects in this folder will be published. Please choose the drafts you would like to save, unsaved drafts will be removed from this folder."
)

})
it("should show the list of drafts before folder is published, and show saved drafts in Home page", () => {
// Select drafts inside the dialog
cy.get("form").within(() => {
cy.get("input[type='checkbox']").first().check()
Expand All @@ -78,68 +76,98 @@ describe("draft selections and templates", function () {
// Check if the drafts have been saved as user's templates in Home page
cy.contains("Your Draft Templates", { timeout: 10000 }).should("be.visible")
// Check saved Study draft
cy.get("h6").contains("Draft-study").as("studyObject")
cy.get("h6").contains("Template-study").as("studyObject")
cy.get("@studyObject")
.should("be.visible")
.then($el => $el.click())
cy.get("div[data-schema='draft-study']").contains("Study draft title").should("be.visible")
cy.get("div[data-schema='template-study']").contains("Study draft title").should("be.visible")
// Check saved Sample draft
cy.get("h6").contains("Draft-sample").as("sampleObject")
cy.get("h6").contains("Template-sample").as("sampleObject")
cy.get("@sampleObject")
.should("be.visible")
.then($el => $el.click())
cy.get("div[data-schema='draft-sample']").contains("Sample draft title").should("be.visible")
})

it("should open the correct draft when clicking View button", () => {
// Fill a Study form
cy.get("div[role=button]").contains("Study").click()
cy.get("div[role=button]").contains("Fill Form").click()
cy.get("input[name='descriptor.studyTitle']").type("Study test title")
cy.get("input[name='descriptor.studyTitle']").should("have.value", "Study test title")
cy.get("select[name='descriptor.studyType']").select("Metagenomics")

// Submit Study form
cy.get("button[type=submit]").contains("Submit").click()
cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 1)

// Create another Study draft form
cy.get("button").contains("New form").click()
cy.get("input[name='descriptor.studyTitle']").type("Study draft title")

// Save a draft
cy.get("button[type=button]").contains("Save as Draft").click()
cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with")

// Create and Save another draft - Sample draft
cy.get("div[role=button]", { timeout: 10000 }).contains("Sample").click({ force: true })
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[name='title']").type("Sample draft title")
cy.get("input[name='sampleName.taxonId']").type(123)
cy.get("button[type=button]").contains("Save as Draft").click()
cy.get("div[role=alert]", { timeout: 10000 }).contains("Draft saved with")

// Navigate to summary
cy.get("button[type=button]").contains("Next").click()

// Navigate to publish button at the bottom
cy.get("button[type=button]").contains("Publish").click()

// Select drafts inside the dialog
cy.get("form").within(() => {
cy.get("button[aria-label='View draft']").last().click()
cy.get("div[data-schema='template-sample']").contains("Sample draft title").should("be.visible")
}),
it("should open the correct draft when clicking View button", () => {
// Select drafts inside the dialog
cy.get("form").within(() => {
cy.get("button[aria-label='View draft']").last().click()
})
cy.get("h1", { timeout: 10000 }).contains("Sample").should("be.visible")
cy.get("[data-testid='title']").should("have.value", "Sample draft title")
}),
it("should be able to select draft templates and reuse them when creating a new folder", () => {
// Select drafts inside the dialog
cy.get("form").within(() => {
cy.get("input[type='checkbox']").first().check()
cy.get("input[type='checkbox']").last().check()

// Publish folder
cy.get('button[aria-label="Publish folder contents and move to frontpage"]').contains("Publish").click()
})
// Navigate back to home page
cy.get("div", { timeout: 10000 }).contains("Logged in as:")
// Check if the drafts have been saved as user's templates in Home page
cy.contains("Your Draft Templates", { timeout: 10000 }).should("be.visible")

// Select some drafts to reuse
cy.get("[data-testid='form-template-study']").within(() => {
cy.get("input").first().check()
})

cy.get("[data-testid='form-template-sample']").within(() => {
cy.get("input").first().click()
})

// Check that selected drafts exist
cy.get("button", { timeout: 10000 }).contains("Create Submission").click()
cy.get("[data-testid='toggle-user-drafts']", { timeout: 10000 }).click()
cy.get("[data-testid='form-template-study']").within(() => {
cy.get("input").first().should("be.checked")
})
cy.get("[data-testid='form-template-sample']").within(() => {
cy.get("input").first().should("be.checked")
})

// Create a new submission with selected drafts
cy.get("input[name='name']").type("Test name")
cy.get("textarea[name='description']").type("Test description")
cy.get("button[type=button]").contains("Next").click()

cy.wait(500)

// Check that selected templates exist in the folder
cy.clickFillForm("Study")
cy.get("[data-testid='Draft-objects']").children().should("have.length", 1)

cy.clickFillForm("Sample")
cy.get("[data-testid='Draft-objects']").children().should("have.length", 1)

// Check if the draft can be used
cy.get("[aria-label='Edit submission']").click()
cy.get("[data-testid='title']").should("have.value", "Sample draft title")
cy.get("[data-testid='title']").type(" edited")
cy.get("button[type=button]").contains("Update draft").click()

// Check that the draft works normlly as its title should be updated
cy.get("[aria-label='Edit submission']").click()
cy.get("[data-testid='title']").should("have.value", "Sample draft title edited")

// Check that editing a draft folder with adding a new template also works
// Navigate to home & find folder
cy.findDraftFolder("Test name")
cy.get('button[aria-label="Edit current folder"]').contains("Edit").click()

// Select a new Study template
cy.get("[data-testid='toggle-user-drafts']", { timeout: 10000 }).click()
cy.get("[data-testid='form-template-study']").within(() => {
cy.get("input").first().check()
})
cy.get("button[type=button]").contains("Next").click()

cy.wait(500)
// Check that the new template is added as a draft
cy.clickFillForm("Study")
cy.get("[data-testid='Draft-objects']").children().should("have.length", 2)
})
cy.get("h1", { timeout: 10000 }).contains("Sample").should("be.visible")
cy.get("input[name='title']").should("have.value", "Sample draft title")
})
})
3 changes: 1 addition & 2 deletions cypress/integration/editForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ describe("Populate form and render form elements by object data", function () {
cy.login()

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()
cy.wait(500)
})

it("should submit Sample form and display all form values when editing the form", () => {
Expand Down
4 changes: 1 addition & 3 deletions cypress/integration/emptyForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ describe("empty form should not be alerted or saved", function () {

cy.get("button", { timeout: 10000 }).contains("Create Submission").click()

// Navigate to folder creation
cy.get("button[type=button]").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()
cy.wait(500)
})

it("should have New form button and Clear form button emptied the form", () => {
Expand Down
12 changes: 4 additions & 8 deletions cypress/integration/home.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ describe("Home e2e", function () {
// Create a new Unpublished folder
cy.get("button").contains("Create Submission").click()

// Navigate to folder creation
cy.get("button[type=button]").contains("New folder").click()

// Add folder name & description, navigate to editing folder
cy.get("input[name='name']").type("Test unpublished folder")
cy.get("textarea[name='description']").type("Test description")
cy.get("button[type=button]").contains("Next").click()

// Fill a Study form
cy.wait(500)
cy.get("div[role=button]", { timeout: 10000 }).contains("Study").click()
cy.get("div[role=button]").contains("Fill Form").click()
cy.get("input[name='descriptor.studyTitle']").type("Test title")
Expand Down Expand Up @@ -57,6 +55,7 @@ describe("Home e2e", function () {
cy.get('button[aria-label="Edit current folder"]').contains("Edit").click()
cy.get("input[name='name']").clear().type("Edited unpublished folder")
cy.get("button[type=button]").contains("Next").click()
cy.wait(500)

// Navigate to home and delete object
cy.findDraftFolder("Edited unpublished folder")
Expand Down Expand Up @@ -118,14 +117,11 @@ describe("Home e2e", function () {
// Create a new Published folder
cy.get("button").contains("Create Submission").click()

// Navigate to folder creation
cy.get("button[type=button]").contains("New folder").click()

// Add folder name & description, navigate to editing folder
cy.get("input[name='name']").type("Test published folder")
cy.get("textarea[name='description']").type("Test description")
cy.get("button[type=button]").contains("Next").click()

cy.wait(500)
// Fill a Study form
cy.get("div[role=button]").contains("Study").click()
cy.get("div[role=button]").contains("Fill Form").click()
Expand All @@ -138,7 +134,7 @@ describe("Home e2e", function () {

// Navigate to summary
cy.get("button[type=button]").contains("Next").click()

cy.wait(500)
// Check the amount of submitted objects in Study
cy.get("h6").contains("Study").parent("div").children().eq(1).should("have.text", 1)

Expand Down
5 changes: 1 addition & 4 deletions cypress/integration/linkingAccessionIds.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ describe("Linking Accession Ids", function () {
cy.wait(1000)
cy.get("button", { timeout: 10000 }).contains("Create Submission").click()

// Navigate to folder creation
cy.get("button[type=button]").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()

cy.wait(500)
// Upload a Study xml file.
cy.get("div[role=button]").contains("Study").click()
cy.get("div[role=button]").contains("Upload XML File").click()
Expand Down
11 changes: 3 additions & 8 deletions cypress/integration/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ describe("Login e2e", function () {
cy.setMockUser("frontend.test", "FrontendTest", "E2EUser")
})

const baseUrl = "http://localhost:" + Cypress.env("port") + "/"

it("should contain session cookie", () => {
cy.visit(baseUrl)
cy.get('[alt="CSC Login"]').click()
cy.login()
cy.getCookie("MTD_SESSION").should("exist")
})

it("should contain the test user name", () => {
cy.visit(baseUrl)
cy.get('[alt="CSC Login"]').click()
cy.login()
cy.get("div").contains("Logged in as: E2EUser FrontendTest")
})

it("should go to main page on logout", () => {
cy.visit(baseUrl)
cy.get('[alt="CSC Login"]').click()
cy.login()
cy.contains("Log out").click()
cy.location().should(loc => {
expect(loc.pathname).to.eq("/")
Expand Down
3 changes: 1 addition & 2 deletions cypress/integration/objectLinksAttributes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ describe("render objects' links and attributes ", function () {

cy.get("button", { timeout: 10000 }).contains("Create Submission").click()

// Navigate to folder creation
cy.get("button[type=button]").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()
cy.wait(500)
// Focus on the Study title input in the Study form (not type anything)
cy.get("div[role=button]").contains("Study").click()
cy.get("div[role=button]").contains("Fill Form").click()
Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/objectTitles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ describe("draft and submitted objects' titles", function () {
beforeEach(() => {
cy.login()
cy.get("button", { timeout: 10000 }).contains("Create Submission").click()
// Navigate to folder creation
cy.get("button[type=button]").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()
cy.wait(500)
})

it("should show correct Submitted object's displayTitle", () => {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe("draft and submitted objects' titles", function () {

// Navigate to summary
cy.get("button[type=button]").contains("Next").click()

cy.wait(500)
// Check the submitted object has correct displayTitle
cy.get("h6").contains("Study").parent("div").children().eq(1).should("have.text", 1)
cy.get("div[data-schema='study']", { timeout: 10000 }).should("contain.text", "Test title 2")
Expand Down
Loading

0 comments on commit 3460cfe

Please sign in to comment.