Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/doi form #455

Merged
merged 23 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
85de98d
Add DOI form in a popup modal
hannyle Sep 20, 2021
7dc7ceb
Create custom styles for form
hannyle Sep 20, 2021
17effa4
Fix for wrong flow return type
hannyle Sep 21, 2021
f79e42d
Get dataCite schema from back-end and fix for doi form
hannyle Oct 11, 2021
fcef839
Fix for FormAutocompleteField for less re-rendering
hannyle Oct 18, 2021
e75bcc7
Add dependent field value if autocomplete field is set
hannyle Oct 22, 2021
0fe5ee8
Fix for rendering form when removing field
hannyle Oct 25, 2021
055ed0c
Small fix for integration test
hannyle Oct 26, 2021
921f511
Fix for rendering nested fields of FormArray and FormOneOfField
hannyle Oct 28, 2021
d1feee0
Render DOI's formats pre-filled fields from submitted fileTypes
hannyle Oct 29, 2021
b9ffded
Fix for merging errors
hannyle Oct 29, 2021
6bcd7f8
Add e2e test for DOI form and bug fixing
hannyle Nov 2, 2021
75709ec
Save DoiForm info in redux
hannyle Nov 2, 2021
48e22af
Add nameType as hidden field for DOI form before patching
hannyle Nov 3, 2021
a92b96e
Fix for changing affiliations' name affecting on other fields
hannyle Nov 3, 2021
be40ade
Fix for the inconsistency of rendering Affiliations' fields
hannyle Nov 3, 2021
15635ef
Update e2e test for Affiliations' fields when deleting its name field
hannyle Nov 3, 2021
afd0ec0
Update e2e test for saving DOI form sucessfully
hannyle Nov 3, 2021
b645cb7
Fix for clear button position
hannyle Nov 3, 2021
52ef232
Add description for FormArray
hannyle Nov 3, 2021
a8c815e
Change errorPrefix to helperText for error messages
hannyle Nov 4, 2021
82e3c61
subject scheme should be fixed
blankdots Nov 4, 2021
a352da6
Merge pull request #522 from CSCfi/feature/fixed-subject-scheme
hannyle Nov 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions cypress/integration/doiForm.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
describe("DOI form", function () {
beforeEach(() => {
cy.login()

cy.get("button", { timeout: 10000 }).contains("Create Submission").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 render DOI form correctly with formats' prefilled values and affiliation's autocomplete field", () => {
// Fill in Run form
cy.clickFillForm("Run")

const testRunData = {
title: "Test Run",
experimentRefLabel: "Test Experiment reference label",
}

cy.get("input[data-testid='title']").type(testRunData.title)
cy.get("h2[data-testid='experimentRef']").parents().children("button").click()
cy.get("[data-testid='experimentRef.0.label']").type(testRunData.experimentRefLabel)

const testRunFile = {
fileName: "Run file name",
fileType: "bam",
checksumMethod: "MD5",
checksum: "Run file check sum",
}
cy.get("h2[data-testid='files']").parents().children("button").click()
cy.get("input[name='files.0.filename']").type(testRunFile.fileName)
cy.get("select[name='files.0.filetype']").select(testRunFile.fileType)
cy.get("select[name='files.0.checksumMethod']").select(testRunFile.checksumMethod)
cy.get("input[name='files.0.checksum']").type(testRunFile.checksum)

// Submit form
cy.get("button[type=submit]").contains("Submit").click()

// Submitted objects list should have newly added item from Run form
cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 1)

// Fill in Analysis form
cy.clickFillForm("Analysis")

const testAnalysisData = {
title1: "Test Analysis",
title2: "Test Analysis 2",
analysisType: "Reference Alignment",
refAlignmentAssembly: "Standard",
refAlignmentAssemblyId: "Standard Accession Id",
}

cy.get("input[name='title']").type(testAnalysisData.title1)
cy.get("select[name='analysisType']").select("Reference Alignment")
cy.get("select[name='analysisType.referenceAlignment.assembly']").select("Standard")
cy.get("input[name='analysisType.referenceAlignment.assembly.accessionId']").type("Standard Accession Id")

const testAnalysisFile = {
fileName: "Analysis file name",
fileType1: "cram",
fileType2: "bam",
checksumMethod: "SHA-256",
checksum: "Analysis file check sum",
}
// Select fileType
cy.get("h2[data-testid='files']").parents().children("button").click()
cy.get("input[name='files.0.filename']").type(testAnalysisFile.fileName)
cy.get("select[name='files.0.filetype']").select(testAnalysisFile.fileType1)
cy.get("select[name='files.0.checksumMethod']").select(testAnalysisFile.checksumMethod)
cy.get("input[name='files.0.checksum']").type(testAnalysisFile.checksum)

// Submit form
cy.get("button[type=submit]").contains("Submit").click()

// Submitted objects list should have newly added item from Run form
cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 1)

// Fill another Analysis form with the same fileType as Run form: "bam"
cy.get("button").contains("New form").click()
cy.get("input[name='title']").type(testAnalysisData.title2)
cy.get("select[name='analysisType']").select("Reference Alignment")
cy.get("select[name='analysisType.referenceAlignment.assembly']").select("Standard")
cy.get("input[name='analysisType.referenceAlignment.assembly.accessionId']").type("Standard Accession Id")
// Select fileType
cy.get("input[name='files.0.filename']").type(testAnalysisFile.fileName)
cy.get("select[name='files.0.filetype']").select(testAnalysisFile.fileType2)
cy.get("select[name='files.0.checksumMethod']").select(testAnalysisFile.checksumMethod)
cy.get("input[name='files.0.checksum']").type(testAnalysisFile.checksum)

// Submit form
cy.get("button[type=submit]").contains("Submit").click()

// Submitted objects list should have newly added item from Run form
cy.get(".MuiListItem-container", { timeout: 10000 }).should("have.length", 2)

// Go to DOI form
cy.get("button[type=button]").contains("Next").click()
cy.get("button").contains("Add DOI information (optional)", { timeout: 10000 }).click()
cy.get("div[role='dialog']").should("be.visible")

// Check file types from submitted Run form and Analysis form are Uniquely pre-filled in DOI form
cy.get("input[data-testid='formats.0']", { timeout: 10000 }).should("have.value", "bam")
cy.get("input[data-testid='formats.1']", { timeout: 10000 }).should("have.value", "cram")

// Go to Creators section and Add new item
cy.get("h2[data-testid='creators']").parents().children("button").click()
cy.get("h3[data-testid='creators.0.affiliation']", { timeout: 10000 }).parent().children("button").click()
// Type search words in autocomplete field
cy.get("input[name='creators.0.affiliation.0.name']").type("csc")
// Select the first result
cy.get(".MuiAutocomplete-option")
.should("be.visible")
.then($el => $el.first().click())
// Check the rest 3 fields are auto-filled and disabled
cy.get("input[data-testid='creators.0.affiliation.0.schemeUri']").should("have.value", "https://ror.org")
cy.get("input[data-testid='creators.0.affiliation.0.schemeUri']").should("be.disabled")

cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifier").should(
"have.value",
"https://ror.org/04m8m1253"
)
cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifier").should("be.disabled")

cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifierScheme']").should("have.value", "ROR")
cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifierScheme']").should("be.disabled")

// Remove Creators > Affiliations field and add a new field again
cy.get("div[data-testid='creators.0.affiliation']").children("button").click()
cy.get("h3[data-testid='creators.0.affiliation']").parent().children("button").click()

// Repeat search words in autocomplete field
cy.get("input[name='creators.0.affiliation.0.name']").type("csc")
// Select the first result
cy.get(".MuiAutocomplete-option")
.should("be.visible")
.then($el => $el.first().click())

// Check the rest 3 fields are auto-filled and disabled as they should be
cy.get("input[data-testid='creators.0.affiliation.0.schemeUri']").should("have.value", "https://ror.org")
cy.get("input[data-testid='creators.0.affiliation.0.schemeUri']").should("be.disabled")

cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifier").should(
"have.value",
"https://ror.org/04m8m1253"
)
cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifier").should("be.disabled")

cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifierScheme']").should("have.value", "ROR")
cy.get("input[data-testid='creators.0.affiliation.0.affiliationIdentifierScheme']").should("be.disabled")

// Go to Contributors and Add new item
cy.get("h2[data-testid='contributors']").parents().children("button").click()
cy.get("h3[data-testid='contributors.0.affiliation']", { timeout: 10000 }).parent().children("button").click()
// Type search words in autocomplete field
cy.get("input[name='contributors.0.affiliation.0.name']").type("demos")
// Select the first result
cy.get(".MuiAutocomplete-option")
.should("be.visible")
.then($el => $el.first().click())
// Check the rest 3 fields are auto-filled and disabled
cy.get("input[data-testid='contributors.0.affiliation.0.schemeUri").should("have.value", "https://ror.org")
cy.get("input[data-testid='contributors.0.affiliation.0.schemeUri").should("be.disabled")

cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifier").should(
"have.value",
"https://ror.org/032bmj362"
)
cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifier").should("be.disabled")

cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifierScheme']").should("have.value", "ROR")
cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifierScheme']").should("be.disabled")

// Delete the autocompleteField value and check the field <affiliationIdentifier> also removed
cy.get("input[name='contributors.0.affiliation.0.name']")
.parent()
.children("div[class='MuiAutocomplete-endAdornment']")
.click()
cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifier']").should("have.value", "")

// Type new search words
cy.get("input[name='contributors.0.affiliation.0.name']").type("test")
// Select the first result and check the <affiliationIdentifier> field is filled and disabled
cy.get(".MuiAutocomplete-option")
.should("be.visible")
.then($el => $el.first().click())
cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifier").should(
"have.value",
"https://ror.org/03fknzz27"
)
cy.get("input[data-testid='contributors.0.affiliation.0.affiliationIdentifier").should("be.disabled")
}),
it("should fill the required fields and save DOI form successfully", () => {
// Go to DOI form
cy.get("button[type=button]").contains("Next").click()
cy.get("button").contains("Add DOI information (optional)", { timeout: 10000 }).click()
cy.get("div[role='dialog']").should("be.visible")

// Fill in required Creators field
cy.get("h2[data-testid='creators']").parent().children("button").click()
cy.get("input[data-testid='creators.0.givenName']").type("John Smith")

// Fill in required Subjects field
cy.get("h2[data-testid='subjects']").parent().children("button").click()
cy.get("select[name='subjects.0.subject']").select("FOS: Mathematics")

cy.get("button[type='submit']").click()
cy.contains(".MuiAlert-message", "DOI form has been saved successfully")

// Open the DOI form again and check the fields render correctly
cy.get("button").contains("Add DOI information (optional)", { timeout: 10000 }).click()
cy.get("input[data-testid='creators.0.givenName']").should("have.value", "John Smith")
cy.get("select[name='subjects.0.subject']").should("have.value", "FOS: Mathematics")
})
})
7 changes: 7 additions & 0 deletions cypress/integration/objectLinksAttributes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ describe("render objects' links and attributes ", function () {

cy.get("input[name='studyAttributes.0.tag']").should("have.value", "Test Attributes Tag")
cy.get("textarea[name='studyAttributes.0.value']").should("have.value", "Test Attributes Value")

// Remove URL Link and check that the rest of the Study Links render correctly
cy.get("div[data-testid='studyLinks[1]']").children("button").click()
cy.get("div[class='arrayRow']", { timeout: 10000 }).should("have.length", 2)

cy.get("select[name='studyLinks.0']").should("have.value", "XRef Link")
cy.get("select[name='studyLinks.1']").should("have.value", "Entrez Link")
})
})
5 changes: 4 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const App = (): React$Element<typeof React.Fragment> => {
if (isMounted) {
if (response.ok) {
const schemas = response.data
.filter(schema => schema.title !== "Project" && schema.title !== "Submission")
.filter(
schema =>
schema.title !== "Project" && schema.title !== "Submission" && schema.title !== "Datacite DOI schema"
)
.map(schema => schema.title.toLowerCase())
dispatch(setObjectTypesArray(schemas))
} else {
Expand Down
9 changes: 5 additions & 4 deletions src/__tests__/FormAutocompleteField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react"

import "@testing-library/jest-dom/extend-expect"
import { ThemeProvider } from "@material-ui/core/styles"
import { render, screen, waitFor, within } from "@testing-library/react"
import { render, screen, waitFor, within, act } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { rest } from "msw"
import { setupServer } from "msw/node"
Expand Down Expand Up @@ -81,11 +81,12 @@ describe("Test autocomplete on organisation field", () => {

const autocomplete = await waitFor(() => screen.getByTestId("organisation"))
const input = await waitFor(() => within(autocomplete).getByRole("textbox"))

autocomplete.focus()

// Assign value to input field
userEvent.type(input, "test")
act(() => {
// Assign value to input field
userEvent.type(input, "test")
})

// Find loading indicator
await waitFor(() => screen.getByRole("progressbar"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import WizardAlert from "./WizardAlert"

import saveDraftsAsTemplates from "components/NewDraftWizard/WizardHooks/WizardSaveTemplatesHook"
import { ResponseStatus } from "constants/responseStatus"
import { resetFileTypes } from "features/fileTypesSlice"
import { updateStatus } from "features/statusMessageSlice"
import { resetObjectType } from "features/wizardObjectTypeSlice"
import { publishFolderContent, deleteFolderAndContent, resetFolder } from "features/wizardSubmissionFolderSlice"
Expand Down Expand Up @@ -98,6 +99,7 @@ const WizardFooter = (): React$Element<any> => {
})
)
})
dispatch(resetFileTypes())
} else {
setDialogOpen(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { useDispatch, useSelector } from "react-redux"
import { useHistory } from "react-router-dom"

import { ResponseStatus } from "constants/responseStatus"
import { ObjectSubmissionTypes, ObjectStatus } from "constants/wizardObject"
import { ObjectSubmissionTypes, ObjectStatus, ObjectTypes } from "constants/wizardObject"
import { deleteFileType } from "features/fileTypesSlice"
import { updateStatus } from "features/statusMessageSlice"
import { setCurrentObject, resetCurrentObject } from "features/wizardCurrentObjectSlice"
import { setObjectType } from "features/wizardObjectTypeSlice"
Expand Down Expand Up @@ -40,6 +41,7 @@ const WizardSavedObjectActions = (props: WizardSavedObjectActionsProps): React$E
const classes = useStyles()
const dispatch = useDispatch()
const currentObject = useSelector(state => state.currentObject)

const history = useHistory()

const handleObjectEdit = async () => {
Expand Down Expand Up @@ -114,6 +116,11 @@ const WizardSavedObjectActions = (props: WizardSavedObjectActionsProps): React$E
}

if (currentObject.accessionId === props.objectId) dispatch(resetCurrentObject())

// Delete fileType that is equivalent to deleted object
if (props.objectType === ObjectTypes.analysis || props.objectType === ObjectTypes.run) {
dispatch(deleteFileType(props.objectId))
}
}

const renderEditLabel = submissionType => {
Expand Down
Loading