diff --git a/src/sections/shared/form/EditCreateCollectionForm/CollectionFormHelper.ts b/src/sections/shared/form/EditCreateCollectionForm/CollectionFormHelper.ts
index 87db5967c..9338487f5 100644
--- a/src/sections/shared/form/EditCreateCollectionForm/CollectionFormHelper.ts
+++ b/src/sections/shared/form/EditCreateCollectionForm/CollectionFormHelper.ts
@@ -222,6 +222,10 @@ export class CollectionFormHelper {
public static formatCollectionContactsToFormContacts(
collectionContacts: CollectionContact[]
): CollectionFormContactValue[] {
+ if (collectionContacts.length === 0) {
+ return [{ value: '' }]
+ }
+
return collectionContacts.map((contact) => ({
value: contact.email
}))
diff --git a/src/sections/shared/form/EditCreateCollectionForm/EditCreateCollectionForm.tsx b/src/sections/shared/form/EditCreateCollectionForm/EditCreateCollectionForm.tsx
index 0967273fb..45ab3b2b5 100644
--- a/src/sections/shared/form/EditCreateCollectionForm/EditCreateCollectionForm.tsx
+++ b/src/sections/shared/form/EditCreateCollectionForm/EditCreateCollectionForm.tsx
@@ -32,7 +32,7 @@ type EditCreateCollectionFormProps =
| {
mode: 'create'
user: User
- collection?: never
+ collection?: never // In create mode, collection is undefined, we only have parentCollection
parentCollection: Collection
collectionRepository: CollectionRepository
metadataBlockInfoRepository: MetadataBlockInfoRepository
@@ -41,7 +41,7 @@ type EditCreateCollectionFormProps =
mode: 'edit'
user: User
collection: Collection
- parentCollection?: ParentCollectionDataInEdition
+ parentCollection?: ParentCollectionDataInEdition // In edit mode, parentCollection could be undefined in case of root collection
collectionRepository: CollectionRepository
metadataBlockInfoRepository: MetadataBlockInfoRepository
}
@@ -104,7 +104,7 @@ export const EditCreateCollectionForm = ({
}, [allMetadataBlocksInfo])
const collectionInputLevelsToFormat =
- mode === 'edit' ? collection?.inputLevels : parentCollection?.inputLevels
+ mode === 'edit' ? collection.inputLevels : parentCollection.inputLevels
const formattedCollectionInputLevels: FormattedCollectionInputLevelsWithoutParentBlockName =
useDeepCompareMemo(() => {
diff --git a/tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts b/tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts
index e0100a41e..ef100ddf0 100644
--- a/tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts
+++ b/tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts
@@ -579,6 +579,14 @@ describe('CollectionFormHelper', () => {
expect(result).to.deep.equal(expected)
})
+ it('formats empty collection contacts to empty form contacts values ', () => {
+ const collectionContacts: CollectionContact[] = []
+
+ const result = CollectionFormHelper.formatCollectionContactsToFormContacts(collectionContacts)
+
+ expect(result).to.deep.equal([{ value: '' }])
+ })
+
describe('defineShouldCheckUseFromParent', () => {
it('returns false if is on edit mode and is editing the root collection', () => {
const result = CollectionFormHelper.defineShouldCheckUseFromParent(true, true, true)
diff --git a/tests/component/sections/shared/edit-create-collection-form/EditCreateCollectionForm.spec.tsx b/tests/component/sections/shared/edit-create-collection-form/EditCreateCollectionForm.spec.tsx
index a9bc524fa..d0369fd56 100644
--- a/tests/component/sections/shared/edit-create-collection-form/EditCreateCollectionForm.spec.tsx
+++ b/tests/component/sections/shared/edit-create-collection-form/EditCreateCollectionForm.spec.tsx
@@ -1,20 +1,9 @@
+import { CollectionType } from '@/collection/domain/models/CollectionType'
import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository'
-import { MetadataBlockName } from '@/metadata-block-info/domain/models/MetadataBlockInfo'
+import { CollectionDTO } from '@/collection/domain/useCases/DTOs/CollectionDTO'
import { MetadataBlockInfoRepository } from '@/metadata-block-info/domain/repositories/MetadataBlockInfoRepository'
-import { CollectionFormHelper } from '@/sections/shared/form/EditCreateCollectionForm/CollectionFormHelper'
-import {
- EditCreateCollectionForm,
- INPUT_LEVELS_GROUPER,
- METADATA_BLOCKS_NAMES_GROUPER,
- USE_FACETS_FROM_PARENT,
- USE_FIELDS_FROM_PARENT
-} from '@/sections/shared/form/EditCreateCollectionForm/EditCreateCollectionForm'
-import {
- CollectionFormData,
- CollectionFormFacet,
- FormattedCollectionInputLevels,
- FormattedCollectionInputLevelsWithoutParentBlockName
-} from '@/sections/shared/form/EditCreateCollectionForm/types'
+import { collectionNameToAlias } from '@/sections/shared/form/EditCreateCollectionForm/collection-form/top-fields-section/IdentifierField'
+import { EditCreateCollectionForm } from '@/sections/shared/form/EditCreateCollectionForm/EditCreateCollectionForm'
import { UserRepository } from '@/users/domain/repositories/UserRepository'
import { CollectionFacetMother } from '@tests/component/collection/domain/models/CollectionFacetMother'
import { CollectionMother } from '@tests/component/collection/domain/models/CollectionMother'
@@ -30,15 +19,23 @@ const testUser = UserMother.create()
const PARENT_COLLECTION_ID = 'root'
const PARENT_COLLECTION_NAME = 'Root'
+const PARENT_COLLECTION_CONTACT_EMAIL = 'root@test.com'
const COLLECTION_BEING_EDITED_ID = 'collection-being-edited-id'
const COLLECTION_BEING_EDITED_NAME = 'Collection In Edition'
+const COLLECTION_BEING_EDITED_AFFILIATION = 'Collection In Edition Affiliation'
+const COLLECTION_BEING_EDITED_DESCRIPTION = 'Collection In Edition Description'
+const COLLECTION_BEING_EDITED_CONTACT_EMAIL = 'collectionEdited@test.com'
const defaultCollectionNameInCreateMode = `${testUser.displayName} Collection`
const collectionBeingEdited = CollectionMother.create({
id: COLLECTION_BEING_EDITED_ID,
name: COLLECTION_BEING_EDITED_NAME,
+ description: COLLECTION_BEING_EDITED_DESCRIPTION,
+ affiliation: COLLECTION_BEING_EDITED_AFFILIATION,
+ type: CollectionType.JOURNALS,
+ contacts: [{ email: COLLECTION_BEING_EDITED_CONTACT_EMAIL, displayOrder: 0 }],
hierarchy: UpwardHierarchyNodeMother.createCollection({
id: COLLECTION_BEING_EDITED_ID,
name: COLLECTION_BEING_EDITED_NAME,
@@ -51,6 +48,18 @@ const collectionBeingEdited = CollectionMother.create({
isMetadataBlockRoot: false
})
+const rootCollection = CollectionMother.create({
+ id: PARENT_COLLECTION_ID,
+ name: PARENT_COLLECTION_NAME,
+ contacts: [{ email: PARENT_COLLECTION_CONTACT_EMAIL, displayOrder: 0 }],
+ hierarchy: UpwardHierarchyNodeMother.createCollection({
+ id: PARENT_COLLECTION_ID,
+ name: PARENT_COLLECTION_NAME
+ }),
+ isFacetRoot: true,
+ isMetadataBlockRoot: true
+})
+
const VIEW_AND_EDIT_FIELDS_LABEL = '[+] View fields + set as hidden, required, or optional'
const VIEW_FIELDS_LABEL = '[+] View fields'
@@ -65,60 +74,20 @@ const allMetadataBlocksMock = [
MetadataBlockInfoMother.getSocialScienceBlock()
]
-
-
-// const baseInputLevels: FormattedCollectionInputLevels =
-// CollectionFormHelper.defineBaseInputLevels(allMetadataBlocksMock)
-
-// const formattedCollectionInputLevels: FormattedCollectionInputLevelsWithoutParentBlockName =
-// CollectionFormHelper.formatCollectiontInputLevels(collection?.inputLevels)
-
-// const mergedInputLevels = CollectionFormHelper.mergeBaseAndDefaultInputLevels(
-// baseInputLevels,
-// formattedCollectionInputLevels
-// )
-
-// const defaultBlocksNames = {
-// [MetadataBlockName.CITATION]: true,
-// [MetadataBlockName.GEOSPATIAL]: false,
-// [MetadataBlockName.SOCIAL_SCIENCE]: false,
-// [MetadataBlockName.ASTROPHYSICS]: false,
-// [MetadataBlockName.BIOMEDICAL]: false,
-// [MetadataBlockName.JOURNAL]: false,
-// [MetadataBlockName.COMPUTATIONAL_WORKFLOW]: false,
-// [MetadataBlockName.CODE_META]: false
-// }
-
-// const defaultCollectionFacetsMock: CollectionFormFacet[] = CollectionFacetMother.createFacets().map(
-// (facet) => ({
-// id: facet.name,
-// value: facet.name,
-// label: facet.displayName
-// })
-// )
+const collectionFacets = CollectionFacetMother.createFacets()
const allFacetableMetadataFields = MetadataBlockInfoMother.getAllFacetableMetadataFields()
-// const formDefaultValues: CollectionFormData = {
-// hostCollection: collection.name,
-// name: defaultCollectionName,
-// alias: '',
-// type: '',
-// contacts: [{ value: testUser.email }],
-// affiliation: testUser.affiliation ?? '',
-// storage: 'S3',
-// description: '',
-// [USE_FIELDS_FROM_PARENT]: true,
-// [METADATA_BLOCKS_NAMES_GROUPER]: defaultBlocksNames,
-// [INPUT_LEVELS_GROUPER]: mergedInputLevels,
-// [USE_FACETS_FROM_PARENT]: true,
-// facetIds: defaultCollectionFacetsMock
-// }
+// TODO:ME - Test: EditCollection.spec - test the permissions error
+// TODO:ME - Test: CreateCollection.spec - test the permissions error
+// TODO:ME - Test: EditCollectionDropdown.spec - test the onClickEdit and the rendering or not the affiliation next to name
+// TODO:ME - Test: check the error message when not selecting any facet
+// TODO:ME - Test unchecking block name checkbox and checking it again setting input levels related to default
describe('EditCreateCollectionForm', () => {
beforeEach(() => {
collectionRepository.create = cy.stub().resolves(1)
- collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+ collectionRepository.getFacets = cy.stub().resolves(collectionFacets)
userRepository.getAuthenticated = cy.stub().resolves(testUser)
metadataBlockInfoRepository.getByCollectionId = cy.stub().resolves(colllectionMetadataBlocks)
metadataBlockInfoRepository.getAll = cy.stub().resolves(allMetadataBlocksMock)
@@ -133,7 +102,7 @@ describe('EditCreateCollectionForm', () => {
@@ -146,7 +115,7 @@ describe('EditCreateCollectionForm', () => {
@@ -160,7 +129,7 @@ describe('EditCreateCollectionForm', () => {
@@ -181,7 +150,7 @@ describe('EditCreateCollectionForm', () => {
@@ -195,7 +164,7 @@ describe('EditCreateCollectionForm', () => {
@@ -213,7 +182,7 @@ describe('EditCreateCollectionForm', () => {
@@ -235,7 +204,7 @@ describe('EditCreateCollectionForm', () => {
@@ -255,7 +224,7 @@ describe('EditCreateCollectionForm', () => {
@@ -273,7 +242,7 @@ describe('EditCreateCollectionForm', () => {
@@ -296,7 +265,7 @@ describe('EditCreateCollectionForm', () => {
@@ -319,7 +288,7 @@ describe('EditCreateCollectionForm', () => {
@@ -327,6 +296,713 @@ describe('EditCreateCollectionForm', () => {
cy.findByText('Cancel').click()
})
+
+ it('should display an alert error message for each error in loading the required data', () => {
+ collectionRepository.getFacets = cy
+ .stub()
+ .rejects(new Error('Error getting collection facets'))
+ metadataBlockInfoRepository.getByCollectionId = cy
+ .stub()
+ .rejects(new Error('Error getting metadata blocks info'))
+ metadataBlockInfoRepository.getAll = cy
+ .stub()
+ .rejects(new Error('Error getting all metadata blocks info'))
+ metadataBlockInfoRepository.getAllFacetableMetadataFields = cy
+ .stub()
+ .rejects(new Error('Error getting all facetable metadata fields'))
+
+ cy.mountAuthenticated(
+
+ )
+
+ cy.findByText(/Error getting collection facets/).should('exist')
+ cy.findByText(/Error getting metadata blocks info/).should('exist')
+ cy.findByText(/Error getting all metadata blocks info/).should('exist')
+ cy.findByText(/Error getting all facetable metadata fields/).should('exist')
+ })
+
+ describe('IdentifierField suggestion functionality', () => {
+ it('should show to apply an identifier suggestion', () => {
+ cy.customMount(
+
+ )
+
+ const aliasSuggestion = collectionNameToAlias(defaultCollectionNameInCreateMode)
+
+ cy.findByText(/Psst... try this/).should('exist')
+ cy.findByText(/Psst... try this/).should('include.text', aliasSuggestion)
+
+ cy.findByRole('button', { name: 'Apply suggestion' }).should('exist')
+ })
+
+ it('should apply suggestion when clicking the button and hide suggestion', () => {
+ cy.customMount(
+
+ )
+
+ const aliasSuggestion = collectionNameToAlias(defaultCollectionNameInCreateMode)
+
+ cy.findByRole('button', { name: 'Apply suggestion' }).click()
+
+ cy.findByLabelText(/^Identifier/i).should('have.value', aliasSuggestion)
+
+ cy.findByText(/Psst... try this/).should('not.exist')
+ })
+ })
+
+ describe('ContactsField functionality', () => {
+ it('should add a new contact field when clicking the add button', () => {
+ cy.customMount(
+
+ )
+
+ cy.findByLabelText('Add Email').click()
+
+ cy.findAllByLabelText('Add Email').should('exist').should('have.length', 2)
+ cy.findByLabelText('Remove Email').should('exist')
+ })
+
+ it('should add and then remove a contact field', () => {
+ cy.customMount(
+
+ )
+
+ cy.findByLabelText('Add Email').click()
+ cy.findAllByLabelText('Add Email').should('exist').should('have.length', 2)
+
+ cy.get('[id="contacts.1.value"]').type('test@test.com')
+
+ cy.findByLabelText('Remove Email').should('exist')
+
+ cy.findByLabelText('Remove Email').click()
+
+ cy.findByLabelText('Add Email').should('exist')
+ cy.findByLabelText('Remove Email').should('not.exist')
+
+ cy.get('[id="contacts.1.value"]').should('not.exist')
+ })
+ })
+
+ describe('MetadataFieldsSection functionality', () => {
+ beforeEach(() => {
+ cy.mountAuthenticated(
+
+ )
+
+ cy.get('[data-testid="use-fields-from-parent-checkbox"]').as('useFieldsFromParentCheckbox')
+ })
+
+ describe('Use fields from parent checkbox', () => {
+ it('should be checked by default', () => {
+ cy.get('@useFieldsFromParentCheckbox').should('be.checked')
+ })
+
+ it('should open the reset confirmation modal when unchecking and then checking the checkbox again', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ cy.get('@useFieldsFromParentCheckbox').check({ force: true })
+
+ cy.findByText(/Reset Modifications/).should('exist')
+ })
+
+ it('should close the reset confirmation modal if cancelling without finally checking the checkbox', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ cy.get('@useFieldsFromParentCheckbox').check({ force: true })
+
+ cy.findByText(/Reset Modifications/).should('exist')
+
+ cy.findByTestId('confirm-reset-modal-cancel').click()
+
+ cy.findByText(/Reset Modifications/).should('not.exist')
+
+ cy.get('@useFieldsFromParentCheckbox').should('not.be.checked')
+ })
+
+ it('should reset the metadata fields when confirming the reset', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck()
+
+ // Modify a field in citation block
+ cy.findByRole('button', {
+ name: VIEW_AND_EDIT_FIELDS_LABEL
+ })
+ .should('exist')
+ .click()
+
+ cy.findByLabelText('Subtitle').uncheck({ force: true })
+
+ cy.findByLabelText('Subtitle').should('not.be.checked')
+
+ cy.get('@useFieldsFromParentCheckbox').check({ force: true })
+
+ cy.findByText(/Reset Modifications/).should('exist')
+
+ cy.findByTestId('confirm-reset-modal-continue').click()
+
+ cy.findByText(/Reset Modifications/).should('not.exist')
+
+ cy.get('@useFieldsFromParentCheckbox').should('be.checked')
+
+ // Check if field is back to its original state
+ cy.findAllByRole('button', {
+ name: VIEW_FIELDS_LABEL
+ })
+ .first()
+ .click()
+
+ cy.findByLabelText('Subtitle').should('be.checked')
+ })
+
+ it('should send metadataBlockNames and inputLevels as undefined if use fields from parent is checked', () => {
+ const collectionRepository = {} as CollectionRepository
+ collectionRepository.create = cy.stub().as('createCollection').resolves()
+ collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+
+ cy.mountAuthenticated(
+
+ )
+
+ // Accept suggestion
+ cy.findByRole('button', { name: 'Apply suggestion' }).click()
+ // Select a Category option
+ cy.findByLabelText(/^Category/i).select(1)
+
+ cy.findByRole('button', { name: 'Create Collection' }).click()
+
+ cy.get('@createCollection').should((spy) => {
+ const createCollectionSpy = spy as unknown as Cypress.Agent
+ const collectionDTO = createCollectionSpy.getCall(0).args[0] as CollectionDTO
+
+ const inputLevels = collectionDTO.inputLevels
+ const metadataBlockNames = collectionDTO.metadataBlockNames
+
+ expect(inputLevels).to.be.undefined
+ expect(metadataBlockNames).to.be.undefined
+ })
+ })
+
+ it('should not send metadataBlockNames and inputLevels as undefined if use fields from parent is unchecked', () => {
+ const collectionRepository = {} as CollectionRepository
+ collectionRepository.create = cy.stub().as('createCollection').resolves()
+ collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+
+ cy.mountAuthenticated(
+
+ )
+
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ // Accept suggestion
+ cy.findByRole('button', { name: 'Apply suggestion' }).click()
+ // Select a Category option
+ cy.findByLabelText(/^Category/i).select(1)
+
+ cy.findByRole('button', { name: 'Create Collection' }).click()
+
+ cy.get('@createCollection').should((spy) => {
+ const createCollectionSpy = spy as unknown as Cypress.Agent
+ const collectionDTO = createCollectionSpy.getCall(0).args[0] as CollectionDTO
+
+ console.log({ collectionDTO })
+
+ const inputLevels = collectionDTO.inputLevels
+ const metadataBlockNames = collectionDTO.metadataBlockNames
+
+ expect(inputLevels).to.not.be.undefined
+ expect(metadataBlockNames).to.not.be.undefined
+ })
+ })
+ })
+
+ describe('InputLevelFieldRow', () => {
+ it('On not composed fields - should unclude and include the field when checking the checkbox', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ // Open citation input levels
+ cy.findByRole('button', {
+ name: VIEW_AND_EDIT_FIELDS_LABEL
+ })
+ .should('exist')
+ .click({ force: true })
+
+ // First unclude the subtitle field
+ cy.findByLabelText('Subtitle').uncheck({ force: true })
+
+ cy.findByLabelText('Subtitle').should('not.be.checked')
+
+ // Go to parent td of Subtitle field and find sibling td to check if Hidden checkbox is there
+ cy.findByLabelText('Subtitle')
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Hidden').should('exist').should('be.checked')
+ })
+
+ // Second include the subtitle field
+ cy.findByLabelText('Subtitle').check({ force: true })
+ cy.findByLabelText('Subtitle').should('be.checked')
+
+ // Go to parent td of Subtitle field and find sibling td to check if Hidden checkbox is not there anymore
+ cy.findByLabelText('Subtitle')
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Hidden').should('not.exist')
+ })
+ })
+
+ it('On composed fields - should unclude and include the child field when checking the checkbox', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ // Open citation input levels
+ cy.findByRole('button', {
+ name: VIEW_AND_EDIT_FIELDS_LABEL
+ })
+ .should('exist')
+ .click()
+
+ // First unclude the other identifier composed field
+ cy.findByLabelText('Other Identifier').uncheck({ force: true })
+
+ cy.findByLabelText('Other Identifier').should('not.be.checked')
+
+ // Go to child fields rows and check if Hidden checkbox is there
+ cy.findByText('Other Identifier Agency', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Hidden').should('exist').should('be.checked')
+ })
+
+ cy.findByText('Other Identifier Identifier', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Hidden').should('exist').should('be.checked')
+ })
+
+ // Second include the other identifier composed fields
+ cy.findByLabelText('Other Identifier').check({ force: true })
+ cy.findByLabelText('Other Identifier').should('be.checked')
+
+ // Go to child fields rows and check if Hidden checkbox is not there anymore and they optional checkbox is checked
+ cy.findByText('Other Identifier Agency', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Hidden').should('not.exist')
+ cy.findByLabelText('Optional').should('be.checked')
+ })
+
+ cy.findByText('Other Identifier Identifier', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Hidden').should('not.exist')
+ cy.findByLabelText('Optional').should('be.checked')
+ })
+ })
+
+ it('On not composed fields - should select correctly the Required or Optional radios', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ // Open citation input levels
+ cy.findByRole('button', {
+ name: VIEW_AND_EDIT_FIELDS_LABEL
+ })
+ .should('exist')
+ .click()
+
+ // Go to parent td of Subtitle field and find sibling td to select the Required radio
+ cy.findByLabelText('Subtitle')
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Required').should('exist').should('not.be.checked')
+ cy.findByLabelText('Optional').should('exist').should('be.checked')
+
+ cy.findByLabelText('Required').check({ force: true })
+ cy.findByLabelText('Required').should('be.checked')
+ cy.findByLabelText('Optional').should('not.be.checked')
+
+ cy.findByLabelText('Optional').check({ force: true })
+ cy.findByLabelText('Optional').should('be.checked')
+ cy.findByLabelText('Required').should('not.be.checked')
+ })
+
+ // Second set the subtitle field as optional
+ // cy.findByLabelText('Subtitle').uncheck({ force: true })
+
+ // // Go to parent td of Subtitle field and find sibling td to check if Optional radio is there
+ // cy.findByLabelText('Subtitle')
+ // .closest('td')
+ // .next()
+ // .next()
+ // .within(() => {
+ // cy.findByLabelText('Optional').should('exist').should('be.checked')
+ // })
+ })
+
+ it('On composed fields - should select correctly the Required or Optional radios of child fields', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ // Open citation input levels
+ cy.findByRole('button', {
+ name: VIEW_AND_EDIT_FIELDS_LABEL
+ })
+ .should('exist')
+ .click()
+
+ // Go to child fields row and check if Required radio is there and perform the check/uncheck
+ cy.findByText('Other Identifier Identifier', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Required').should('exist').should('not.be.checked')
+ cy.findByLabelText('Optional').should('exist').should('be.checked')
+
+ cy.findByLabelText('Required').check({ force: true })
+ cy.findByLabelText('Required').should('be.checked')
+ cy.findByLabelText('Optional').should('not.be.checked')
+ })
+
+ cy.findByText('Other Identifier Agency', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Required').should('exist').should('not.be.checked')
+ cy.findByLabelText('Optional').should('exist').should('be.checked')
+
+ cy.findByLabelText('Required').check({ force: true })
+ cy.findByLabelText('Required').should('be.checked')
+ cy.findByLabelText('Optional').should('not.be.checked')
+
+ cy.findByLabelText('Optional').check({ force: true })
+ cy.findByLabelText('Optional').should('be.checked')
+ cy.findByLabelText('Required').should('not.be.checked')
+ })
+
+ cy.findByText('Other Identifier Identifier', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Optional').check({ force: true })
+ })
+
+ cy.findByText('Other Identifier Agency', { exact: true })
+ .closest('td')
+ .next()
+ .within(() => {
+ cy.findByLabelText('Required').should('exist').should('not.be.checked')
+ cy.findByLabelText('Optional').should('exist').should('be.checked')
+
+ cy.findByLabelText('Required').check({ force: true })
+ cy.findByLabelText('Required').should('be.checked')
+ cy.findByLabelText('Optional').should('not.be.checked')
+
+ cy.findByLabelText('Optional').check({ force: true })
+ cy.findByLabelText('Optional').should('be.checked')
+ cy.findByLabelText('Required').should('not.be.checked')
+ })
+ })
+ })
+
+ describe('Opens input levels table correctly on different states', () => {
+ it('should open the Citation input levels on view mode', () => {
+ cy.findAllByRole('button', {
+ name: VIEW_FIELDS_LABEL
+ })
+ .first()
+ .should('exist')
+ .click()
+
+ cy.findByRole('table').should('exist').should('be.visible')
+
+ cy.findByRole('table').within(() => {
+ cy.findByText('Title').should('be.visible')
+ cy.findByLabelText('Subtitle').should('be.visible').should('be.disabled')
+ })
+
+ // Close the table
+ cy.findAllByLabelText('Hide input levels table').first().click()
+
+ cy.findByRole('table').should('not.exist')
+ })
+
+ it('should open the Citation input levels on edit mode', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ cy.findByRole('button', {
+ name: VIEW_AND_EDIT_FIELDS_LABEL
+ })
+ .should('exist')
+ .click()
+
+ cy.findByRole('table').should('exist').should('be.visible')
+
+ cy.findByRole('table').within(() => {
+ cy.findByText('Title').should('be.visible')
+ cy.findByLabelText('Subtitle').should('be.visible').should('not.be.disabled')
+ })
+
+ // Close the table
+ cy.findAllByLabelText('Hide input levels table').first().click()
+
+ cy.findByRole('table').should('not.exist')
+ })
+
+ it('should enable fields when opening an input levels table on view mode and checking the block name checkbox', () => {
+ cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
+
+ cy.findAllByRole('button', {
+ name: VIEW_FIELDS_LABEL
+ })
+ .first()
+ .should('exist')
+ .click()
+
+ cy.findByRole('table').should('exist').should('be.visible')
+
+ cy.findByRole('table').within(() => {
+ cy.findByLabelText('Geographic Unit').should('exist').should('be.disabled')
+ })
+
+ // Now check the Geospatial block name checkbox
+ cy.findByLabelText('Geospatial Metadata').check({ force: true })
+
+ cy.findByRole('table').should('exist').should('be.visible')
+
+ cy.findByRole('table').within(() => {
+ cy.findByLabelText('Geographic Unit').should('exist').should('not.be.disabled')
+ })
+ })
+ })
+ })
+
+ describe('BrowseSearchFacetsSection functionality', () => {
+ beforeEach(() => {
+ cy.mountAuthenticated(
+
+ )
+
+ cy.get('[data-testid="use-facets-from-parent-checkbox"]').as('useFacetsFromParentCheckbox')
+ cy.get('[data-testid="transfer-list-container"]').as('transferListContainer')
+ cy.findByTestId('left-list-group').as('leftList')
+ cy.findByTestId('actions-column').as('actionsColumn')
+ cy.findByTestId('right-list-group').as('rightList')
+ })
+
+ it('should populate the right list with the default facets', () => {
+ cy.get('@rightList').children().should('have.length', 4)
+
+ cy.get('@rightList').within(() => {
+ cy.findByLabelText('Author Name').should('exist')
+ cy.findByLabelText('Subject').should('exist')
+ cy.findByLabelText('Keyword Term').should('exist')
+ cy.findByLabelText('Deposit Date').should('exist')
+ })
+ })
+
+ it('should reset the newly selected facets when checking the checkbox', () => {
+ cy.get('@useFacetsFromParentCheckbox').should('be.checked')
+ cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
+ cy.get('@useFacetsFromParentCheckbox').should('not.be.checked')
+
+ cy.get('@rightList').should('exist')
+ cy.get('@rightList').children().should('have.length', 4)
+ cy.get('@rightList').within(() => {
+ cy.findByLabelText('Author Name').should('exist')
+ cy.findByLabelText('Subject').should('exist')
+ cy.findByLabelText('Keyword Term').should('exist')
+ cy.findByLabelText('Deposit Date').should('exist')
+ })
+
+ cy.get('@transferListContainer').within(() => {
+ cy.findByLabelText('Topic Classification Term').check({ force: true })
+
+ cy.findByLabelText('Topic Classification Term').should('be.checked')
+ })
+
+ cy.get('@actionsColumn').within(() => {
+ cy.findByLabelText('move selected to right').click()
+ })
+
+ cy.get('@leftList').within(() => {
+ cy.findByLabelText('Topic Classification Term').should('not.exist')
+ })
+
+ cy.get('@rightList').children().should('have.length', 5)
+
+ cy.get('@rightList').within(() => {
+ cy.findByLabelText('Author Name').should('exist')
+ cy.findByLabelText('Subject').should('exist')
+ cy.findByLabelText('Keyword Term').should('exist')
+ cy.findByLabelText('Deposit Date').should('exist')
+ cy.findByLabelText('Topic Classification Term').should('exist')
+ })
+
+ cy.get('@useFacetsFromParentCheckbox').check({ force: true })
+
+ cy.get('@rightList').children().should('have.length', 4)
+
+ cy.get('@rightList').within(() => {
+ cy.findByLabelText('Author Name').should('exist')
+ cy.findByLabelText('Subject').should('exist')
+ cy.findByLabelText('Keyword Term').should('exist')
+ cy.findByLabelText('Deposit Date').should('exist')
+ cy.findByLabelText('Topic Classification Term').should('not.exist')
+ })
+
+ cy.get('@leftList').within(() => {
+ cy.findByLabelText('Topic Classification Term').should('exist')
+ })
+ })
+
+ it('should populate the select to filter facets by blocks correctly', () => {
+ cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
+
+ cy.findByTestId('select-facets-by-block').within(() => {
+ cy.findByLabelText('Toggle options menu').click()
+
+ cy.findAllByText('All Metadata Fields').should('have.length', 2)
+
+ cy.findByText('Citation Metadata').should('have.length', 1)
+ cy.findByText('Geospatial Metadata').should('have.length', 1)
+ cy.findByText('Astronomy and Astrophysics Metadata').should('have.length', 1)
+ cy.findByText('Life Sciences Metadata').should('have.length', 1)
+ cy.findByText('Journal Metadata').should('have.length', 1)
+ cy.findByText('Social Science and Humanities Metadata').should('have.length', 1)
+ })
+ })
+
+ it('should filter the facets by blocks correctly', () => {
+ cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
+
+ cy.findByTestId('select-facets-by-block').within(() => {
+ cy.findByLabelText('Toggle options menu').click()
+
+ cy.findByText('Journal Metadata').click()
+ })
+
+ cy.get('@leftList').children().should('have.length', 4)
+
+ cy.get('@leftList').within(() => {
+ cy.findByLabelText('Journal Volume').should('exist')
+ cy.findByLabelText('Journal Issue').should('exist')
+ cy.findByLabelText('Journal Publication Date').should('exist')
+ cy.findByLabelText('Type of Article').should('exist')
+ })
+
+ cy.findByTestId('select-facets-by-block').within(() => {
+ cy.findByLabelText('Toggle options menu').click()
+
+ cy.findByText('Social Science and Humanities Metadata').click()
+ })
+
+ cy.get('@leftList').children().should('have.length', 5)
+
+ cy.get('@leftList').within(() => {
+ cy.findByLabelText('Unit of Analysis').should('exist')
+ cy.findByLabelText('Universe').should('exist')
+ cy.findByLabelText('Time Method').should('exist')
+ cy.findByLabelText('Frequency').should('exist')
+ cy.findByLabelText('Response Rate').should('exist')
+ })
+
+ cy.findByTestId('select-facets-by-block').within(() => {
+ cy.findByLabelText('Toggle options menu').click()
+
+ cy.findByText('All Metadata Fields').click()
+ })
+
+ cy.get('@leftList')
+ .children()
+ .should('have.length', allFacetableMetadataFields.length - collectionFacets.length)
+ })
+
+ it('should reset the select to filter by facets when checking the checkbox', () => {
+ cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
+
+ cy.findByTestId('select-facets-by-block').within(() => {
+ cy.findByLabelText('Toggle options menu').click()
+
+ cy.findByText('Journal Metadata').click()
+ })
+
+ cy.get('@leftList').children().should('have.length', 4)
+
+ cy.get('@leftList').within(() => {
+ cy.findByLabelText('Journal Volume').should('exist')
+ cy.findByLabelText('Journal Issue').should('exist')
+ cy.findByLabelText('Journal Publication Date').should('exist')
+ cy.findByLabelText('Type of Article').should('exist')
+ })
+
+ cy.get('@useFacetsFromParentCheckbox').check({ force: true })
+
+ cy.get('@leftList')
+ .children()
+ .should('have.length', allFacetableMetadataFields.length - collectionFacets.length)
+
+ cy.findByTestId('select-facets-by-block').within(() => {
+ cy.findByText('All Metadata Fields').should('exist')
+ })
+ })
+ })
})
describe('on edit mode', () => {
@@ -344,756 +1020,204 @@ describe('EditCreateCollectionForm', () => {
cy.findByTestId('collection-form').should('exist')
})
- // TODO:ME - Case for not showing host collection field when editing the root collection
- })
+ it('should not show the Host Collection field when editing the root collection', () => {
+ cy.mountAuthenticated(
+
+ )
- // describe('IdentifierField suggestion functionality', () => {
- // it('should show to apply an identifier suggestion', () => {
- // cy.customMount(
- //
- // )
-
- // const aliasSuggestion = collectionNameToAlias(defaultCollectionName)
-
- // cy.findByText(/Psst... try this/).should('exist')
- // cy.findByText(/Psst... try this/).should('include.text', aliasSuggestion)
-
- // cy.findByRole('button', { name: 'Apply suggestion' }).should('exist')
- // })
-
- // it('should apply suggestion when clicking the button and hide suggestion', () => {
- // cy.customMount(
- //
- // )
-
- // const aliasSuggestion = collectionNameToAlias(defaultCollectionName)
-
- // cy.findByRole('button', { name: 'Apply suggestion' }).click()
-
- // cy.findByLabelText(/^Identifier/i).should('have.value', aliasSuggestion)
-
- // cy.findByText(/Psst... try this/).should('not.exist')
- // })
-
- // it('should not show suggestion when identifier is already the suggestion', () => {
- // cy.customMount(
- //
- // )
-
- // cy.findByText(/Psst... try this/).should('not.exist')
- // })
-
- // it('should not show suggestion if Collection Name is empty', () => {
- // cy.customMount(
- //
- // )
-
- // cy.findByText(/Psst... try this/).should('not.exist')
- // })
- // })
-
- // describe('ContactsField functionality', () => {
- // it('should add a new contact field when clicking the add button', () => {
- // cy.customMount(
- //
- // )
-
- // cy.findByLabelText('Add Email').click()
-
- // cy.findAllByLabelText('Add Email').should('exist').should('have.length', 2)
- // cy.findByLabelText('Remove Email').should('exist')
- // })
-
- // it('should remove a contact field when clicking the remove button', () => {
- // cy.customMount(
- //
- // )
- // cy.findAllByLabelText('Add Email').should('exist').should('have.length', 2)
- // cy.findByLabelText('Remove Email').should('exist')
-
- // cy.findByLabelText('Remove Email').click()
-
- // cy.findByLabelText('Add Email').should('exist')
- // cy.findByLabelText('Remove Email').should('not.exist')
- // })
- // })
-
- // describe('MetadataFieldsSection functionality', () => {
- // beforeEach(() => {
- // cy.mountAuthenticated(
- //
- // )
-
- // cy.get('[data-testid="use-fields-from-parent-checkbox"]').as('useFieldsFromParentCheckbox')
- // })
-
- // describe('Use fields from parent checkbox', () => {
- // it('should be checked by default', () => {
- // cy.get('@useFieldsFromParentCheckbox').should('be.checked')
- // })
-
- // it('should open the reset confirmation modal when unchecking and then checking the checkbox again', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // cy.get('@useFieldsFromParentCheckbox').check({ force: true })
-
- // cy.findByText(/Reset Modifications/).should('exist')
- // })
-
- // it('should close the reset confirmation modal if cancelling without finally checking the checkbox', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // cy.get('@useFieldsFromParentCheckbox').check({ force: true })
-
- // cy.findByText(/Reset Modifications/).should('exist')
-
- // cy.findByTestId('confirm-reset-modal-cancel').click()
-
- // cy.findByText(/Reset Modifications/).should('not.exist')
-
- // cy.get('@useFieldsFromParentCheckbox').should('not.be.checked')
- // })
-
- // it('should reset the metadata fields when confirming the reset', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck()
-
- // // Modify a field in citation block
- // cy.findByRole('button', {
- // name: VIEW_AND_EDIT_FIELDS_LABEL
- // })
- // .should('exist')
- // .click()
-
- // cy.findByLabelText('Subtitle').uncheck({ force: true })
-
- // cy.findByLabelText('Subtitle').should('not.be.checked')
-
- // cy.get('@useFieldsFromParentCheckbox').check({ force: true })
-
- // cy.findByText(/Reset Modifications/).should('exist')
-
- // cy.findByTestId('confirm-reset-modal-continue').click()
-
- // cy.findByText(/Reset Modifications/).should('not.exist')
-
- // cy.get('@useFieldsFromParentCheckbox').should('be.checked')
-
- // // Check if field is back to its original state
- // cy.findAllByRole('button', {
- // name: VIEW_FIELDS_LABEL
- // })
- // .first()
- // .click()
-
- // cy.findByLabelText('Subtitle').should('be.checked')
- // })
-
- // it('should send metadataBlockNames and inputLevels as undefined if use fields from parent is checked', () => {
- // const collectionRepository = {} as CollectionRepository
- // collectionRepository.create = cy.stub().as('createCollection').resolves()
-
- // cy.customMount(
- //
- // )
- // // Accept suggestion
- // cy.findByRole('button', { name: 'Apply suggestion' }).click()
- // // Select a Category option
- // cy.findByLabelText(/^Category/i).select(1)
-
- // cy.findByRole('button', { name: 'Create Collection' }).click()
-
- // cy.get('@createCollection').should((spy) => {
- // const createCollectionSpy = spy as unknown as Cypress.Agent
- // const collectionDTO = createCollectionSpy.getCall(0).args[0] as CollectionDTO
-
- // const inputLevels = collectionDTO.inputLevels
- // const metadataBlockNames = collectionDTO.metadataBlockNames
-
- // expect(inputLevels).to.be.undefined
- // expect(metadataBlockNames).to.be.undefined
- // })
- // })
-
- // it('should not send metadataBlockNames and inputLevels as undefined if use fields from parent is unchecked', () => {
- // const collectionRepository = {} as CollectionRepository
- // collectionRepository.create = cy.stub().as('createCollection').resolves()
-
- // cy.customMount(
- //
- // )
-
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // // Accept suggestion
- // cy.findByRole('button', { name: 'Apply suggestion' }).click()
- // // Select a Category option
- // cy.findByLabelText(/^Category/i).select(1)
-
- // cy.findByRole('button', { name: 'Create Collection' }).click()
-
- // cy.get('@createCollection').should((spy) => {
- // const createCollectionSpy = spy as unknown as Cypress.Agent
- // const collectionDTO = createCollectionSpy.getCall(0).args[0] as CollectionDTO
-
- // const inputLevels = collectionDTO.inputLevels
- // const metadataBlockNames = collectionDTO.metadataBlockNames
-
- // expect(inputLevels).to.not.be.undefined
- // expect(metadataBlockNames).to.not.be.undefined
- // })
- // })
- // })
-
- // describe('InputLevelFieldRow', () => {
- // it('On not composed fields - should unclude and include the field when checking the checkbox', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // // Open citation input levels
- // cy.findByRole('button', {
- // name: VIEW_AND_EDIT_FIELDS_LABEL
- // })
- // .should('exist')
- // .click({ force: true })
-
- // // First unclude the subtitle field
- // cy.findByLabelText('Subtitle').uncheck({ force: true })
-
- // cy.findByLabelText('Subtitle').should('not.be.checked')
-
- // // Go to parent td of Subtitle field and find sibling td to check if Hidden checkbox is there
- // cy.findByLabelText('Subtitle')
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Hidden').should('exist').should('be.checked')
- // })
-
- // // Second include the subtitle field
- // cy.findByLabelText('Subtitle').check({ force: true })
- // cy.findByLabelText('Subtitle').should('be.checked')
-
- // // Go to parent td of Subtitle field and find sibling td to check if Hidden checkbox is not there anymore
- // cy.findByLabelText('Subtitle')
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Hidden').should('not.exist')
- // })
- // })
-
- // it('On composed fields - should unclude and include the child field when checking the checkbox', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // // Open citation input levels
- // cy.findByRole('button', {
- // name: VIEW_AND_EDIT_FIELDS_LABEL
- // })
- // .should('exist')
- // .click()
-
- // // First unclude the other identifier composed field
- // cy.findByLabelText('Other Identifier').uncheck({ force: true })
-
- // cy.findByLabelText('Other Identifier').should('not.be.checked')
-
- // // Go to child fields rows and check if Hidden checkbox is there
- // cy.findByText('Other Identifier Agency', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Hidden').should('exist').should('be.checked')
- // })
-
- // cy.findByText('Other Identifier Identifier', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Hidden').should('exist').should('be.checked')
- // })
-
- // // Second include the other identifier composed fields
- // cy.findByLabelText('Other Identifier').check({ force: true })
- // cy.findByLabelText('Other Identifier').should('be.checked')
-
- // // Go to child fields rows and check if Hidden checkbox is not there anymore and they optional checkbox is checked
- // cy.findByText('Other Identifier Agency', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Hidden').should('not.exist')
- // cy.findByLabelText('Optional').should('be.checked')
- // })
-
- // cy.findByText('Other Identifier Identifier', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Hidden').should('not.exist')
- // cy.findByLabelText('Optional').should('be.checked')
- // })
- // })
-
- // it('On not composed fields - should select correctly the Required or Optional radios', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // // Open citation input levels
- // cy.findByRole('button', {
- // name: VIEW_AND_EDIT_FIELDS_LABEL
- // })
- // .should('exist')
- // .click()
-
- // // Go to parent td of Subtitle field and find sibling td to select the Required radio
- // cy.findByLabelText('Subtitle')
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Required').should('exist').should('not.be.checked')
- // cy.findByLabelText('Optional').should('exist').should('be.checked')
-
- // cy.findByLabelText('Required').check({ force: true })
- // cy.findByLabelText('Required').should('be.checked')
- // cy.findByLabelText('Optional').should('not.be.checked')
-
- // cy.findByLabelText('Optional').check({ force: true })
- // cy.findByLabelText('Optional').should('be.checked')
- // cy.findByLabelText('Required').should('not.be.checked')
- // })
-
- // // Second set the subtitle field as optional
- // // cy.findByLabelText('Subtitle').uncheck({ force: true })
-
- // // // Go to parent td of Subtitle field and find sibling td to check if Optional radio is there
- // // cy.findByLabelText('Subtitle')
- // // .closest('td')
- // // .next()
- // // .next()
- // // .within(() => {
- // // cy.findByLabelText('Optional').should('exist').should('be.checked')
- // // })
- // })
-
- // it('On composed fields - should select correctly the Required or Optional radios of child fields', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // // Open citation input levels
- // cy.findByRole('button', {
- // name: VIEW_AND_EDIT_FIELDS_LABEL
- // })
- // .should('exist')
- // .click()
-
- // // Go to child fields row and check if Required radio is there and perform the check/uncheck
- // cy.findByText('Other Identifier Identifier', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Required').should('exist').should('not.be.checked')
- // cy.findByLabelText('Optional').should('exist').should('be.checked')
-
- // cy.findByLabelText('Required').check({ force: true })
- // cy.findByLabelText('Required').should('be.checked')
- // cy.findByLabelText('Optional').should('not.be.checked')
- // })
-
- // cy.findByText('Other Identifier Agency', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Required').should('exist').should('not.be.checked')
- // cy.findByLabelText('Optional').should('exist').should('be.checked')
-
- // cy.findByLabelText('Required').check({ force: true })
- // cy.findByLabelText('Required').should('be.checked')
- // cy.findByLabelText('Optional').should('not.be.checked')
-
- // cy.findByLabelText('Optional').check({ force: true })
- // cy.findByLabelText('Optional').should('be.checked')
- // cy.findByLabelText('Required').should('not.be.checked')
- // })
-
- // cy.findByText('Other Identifier Identifier', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Optional').check({ force: true })
- // })
-
- // cy.findByText('Other Identifier Agency', { exact: true })
- // .closest('td')
- // .next()
- // .within(() => {
- // cy.findByLabelText('Required').should('exist').should('not.be.checked')
- // cy.findByLabelText('Optional').should('exist').should('be.checked')
-
- // cy.findByLabelText('Required').check({ force: true })
- // cy.findByLabelText('Required').should('be.checked')
- // cy.findByLabelText('Optional').should('not.be.checked')
-
- // cy.findByLabelText('Optional').check({ force: true })
- // cy.findByLabelText('Optional').should('be.checked')
- // cy.findByLabelText('Required').should('not.be.checked')
- // })
- // })
- // })
-
- // describe('Opens input levels table correctly on different states', () => {
- // it('should open the Citation input levels on view mode', () => {
- // // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // cy.findAllByRole('button', {
- // name: VIEW_FIELDS_LABEL
- // })
- // .first()
- // .should('exist')
- // .click()
-
- // cy.findByRole('table').should('exist').should('be.visible')
-
- // cy.findByRole('table').within(() => {
- // cy.findByText('Title').should('be.visible')
- // cy.findByLabelText('Subtitle').should('be.visible').should('be.disabled')
- // })
-
- // // Close the table
- // cy.findAllByLabelText('Hide input levels table').first().click()
-
- // cy.findByRole('table').should('not.exist')
- // })
-
- // it('should open the Citation input levels on edit mode', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // cy.findByRole('button', {
- // name: VIEW_AND_EDIT_FIELDS_LABEL
- // })
- // .should('exist')
- // .click()
-
- // cy.findByRole('table').should('exist').should('be.visible')
-
- // cy.findByRole('table').within(() => {
- // cy.findByText('Title').should('be.visible')
- // cy.findByLabelText('Subtitle').should('be.visible').should('not.be.disabled')
- // })
-
- // // Close the table
- // cy.findAllByLabelText('Hide input levels table').first().click()
-
- // cy.findByRole('table').should('not.exist')
- // })
-
- // it('should enable fields when opening an input levels table on view mode and checking the block name checkbox', () => {
- // cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true })
-
- // cy.findAllByRole('button', {
- // name: VIEW_FIELDS_LABEL
- // })
- // .first()
- // .should('exist')
- // .click()
-
- // cy.findByRole('table').should('exist').should('be.visible')
-
- // cy.findByRole('table').within(() => {
- // cy.findByLabelText('Geographic Unit').should('exist').should('be.disabled')
- // })
-
- // // Now check the Geospatial block name checkbox
- // cy.findByLabelText('Geospatial Metadata').check({ force: true })
-
- // cy.findByRole('table').should('exist').should('be.visible')
-
- // cy.findByRole('table').within(() => {
- // cy.findByLabelText('Geographic Unit').should('exist').should('not.be.disabled')
- // })
- // })
- // })
- // })
-
- // describe('BrowseSearchFacetsSection functionality', () => {
- // beforeEach(() => {
- // cy.mountAuthenticated(
- //
- // )
-
- // cy.get('[data-testid="use-facets-from-parent-checkbox"]').as('useFacetsFromParentCheckbox')
- // cy.get('[data-testid="transfer-list-container"]').as('transferListContainer')
- // cy.findByTestId('left-list-group').as('leftList')
- // cy.findByTestId('actions-column').as('actionsColumn')
- // cy.findByTestId('right-list-group').as('rightList')
- // })
-
- // it('should populate the right list with the default facets', () => {
- // cy.get('@rightList').children().should('have.length', 4)
-
- // cy.get('@rightList').within(() => {
- // cy.findByLabelText('Author Name').should('exist')
- // cy.findByLabelText('Subject').should('exist')
- // cy.findByLabelText('Keyword Term').should('exist')
- // cy.findByLabelText('Deposit Date').should('exist')
- // })
- // })
-
- // it('should reset the newly selected facets when checking the checkbox', () => {
- // cy.get('@useFacetsFromParentCheckbox').should('be.checked')
- // cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
- // cy.get('@useFacetsFromParentCheckbox').should('not.be.checked')
-
- // cy.get('@rightList').should('exist')
- // cy.get('@rightList').children().should('have.length', 4)
- // cy.get('@rightList').within(() => {
- // cy.findByLabelText('Author Name').should('exist')
- // cy.findByLabelText('Subject').should('exist')
- // cy.findByLabelText('Keyword Term').should('exist')
- // cy.findByLabelText('Deposit Date').should('exist')
- // })
-
- // cy.get('@transferListContainer').within(() => {
- // cy.findByLabelText('Topic Classification Term').check({ force: true })
-
- // cy.findByLabelText('Topic Classification Term').should('be.checked')
- // })
-
- // cy.get('@actionsColumn').within(() => {
- // cy.findByLabelText('move selected to right').click()
- // })
-
- // cy.get('@leftList').within(() => {
- // cy.findByLabelText('Topic Classification Term').should('not.exist')
- // })
-
- // cy.get('@rightList').children().should('have.length', 5)
-
- // cy.get('@rightList').within(() => {
- // cy.findByLabelText('Author Name').should('exist')
- // cy.findByLabelText('Subject').should('exist')
- // cy.findByLabelText('Keyword Term').should('exist')
- // cy.findByLabelText('Deposit Date').should('exist')
- // cy.findByLabelText('Topic Classification Term').should('exist')
- // })
-
- // cy.get('@useFacetsFromParentCheckbox').check({ force: true })
-
- // cy.get('@rightList').children().should('have.length', 4)
-
- // cy.get('@rightList').within(() => {
- // cy.findByLabelText('Author Name').should('exist')
- // cy.findByLabelText('Subject').should('exist')
- // cy.findByLabelText('Keyword Term').should('exist')
- // cy.findByLabelText('Deposit Date').should('exist')
- // cy.findByLabelText('Topic Classification Term').should('not.exist')
- // })
-
- // cy.get('@leftList').within(() => {
- // cy.findByLabelText('Topic Classification Term').should('exist')
- // })
- // })
-
- // it('should populate the select to filter facets by blocks correctly', () => {
- // cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
-
- // cy.findByTestId('select-facets-by-block').within(() => {
- // cy.findByLabelText('Toggle options menu').click()
-
- // cy.findAllByText('All Metadata Fields').should('have.length', 2)
-
- // cy.findByText('Citation Metadata').should('have.length', 1)
- // cy.findByText('Geospatial Metadata').should('have.length', 1)
- // cy.findByText('Astronomy and Astrophysics Metadata').should('have.length', 1)
- // cy.findByText('Life Sciences Metadata').should('have.length', 1)
- // cy.findByText('Journal Metadata').should('have.length', 1)
- // cy.findByText('Social Science and Humanities Metadata').should('have.length', 1)
- // })
- // })
-
- // it('should filter the facets by blocks correctly', () => {
- // cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
-
- // cy.findByTestId('select-facets-by-block').within(() => {
- // cy.findByLabelText('Toggle options menu').click()
-
- // cy.findByText('Journal Metadata').click()
- // })
-
- // cy.get('@leftList').children().should('have.length', 4)
-
- // cy.get('@leftList').within(() => {
- // cy.findByLabelText('Journal Volume').should('exist')
- // cy.findByLabelText('Journal Issue').should('exist')
- // cy.findByLabelText('Journal Publication Date').should('exist')
- // cy.findByLabelText('Type of Article').should('exist')
- // })
-
- // cy.findByTestId('select-facets-by-block').within(() => {
- // cy.findByLabelText('Toggle options menu').click()
-
- // cy.findByText('Social Science and Humanities Metadata').click()
- // })
-
- // cy.get('@leftList').children().should('have.length', 5)
-
- // cy.get('@leftList').within(() => {
- // cy.findByLabelText('Unit of Analysis').should('exist')
- // cy.findByLabelText('Universe').should('exist')
- // cy.findByLabelText('Time Method').should('exist')
- // cy.findByLabelText('Frequency').should('exist')
- // cy.findByLabelText('Response Rate').should('exist')
- // })
-
- // cy.findByTestId('select-facets-by-block').within(() => {
- // cy.findByLabelText('Toggle options menu').click()
-
- // cy.findByText('All Metadata Fields').click()
- // })
-
- // cy.get('@leftList')
- // .children()
- // .should(
- // 'have.length',
- // allFacetableMetadataFields.length - defaultCollectionFacetsMock.length
- // )
- // })
-
- // it('should reset the select to filter by facets when checking the checkbox', () => {
- // cy.get('@useFacetsFromParentCheckbox').uncheck({ force: true })
-
- // cy.findByTestId('select-facets-by-block').within(() => {
- // cy.findByLabelText('Toggle options menu').click()
-
- // cy.findByText('Journal Metadata').click()
- // })
-
- // cy.get('@leftList').children().should('have.length', 4)
-
- // cy.get('@leftList').within(() => {
- // cy.findByLabelText('Journal Volume').should('exist')
- // cy.findByLabelText('Journal Issue').should('exist')
- // cy.findByLabelText('Journal Publication Date').should('exist')
- // cy.findByLabelText('Type of Article').should('exist')
- // })
-
- // cy.get('@useFacetsFromParentCheckbox').check({ force: true })
-
- // cy.get('@leftList')
- // .children()
- // .should(
- // 'have.length',
- // allFacetableMetadataFields.length - defaultCollectionFacetsMock.length
- // )
-
- // cy.findByTestId('select-facets-by-block').within(() => {
- // cy.findByText('All Metadata Fields').should('exist')
- // })
- // })
- // })
-
- // TODO:ME Move this to EditCreateCollectionForm.spec.tsx
- // it('should display an alert error message for each error in loading the required data', () => {
- // collectionRepository.getUserPermissions = cy
- // .stub()
- // .rejects(new Error('Error getting user permissions'))
- // collectionRepository.getFacets = cy.stub().rejects(new Error('Error getting collection facets'))
- // metadataBlockInfoRepository.getByCollectionId = cy
- // .stub()
- // .rejects(new Error('Error getting metadata blocks info'))
- // metadataBlockInfoRepository.getAll = cy
- // .stub()
- // .rejects(new Error('Error getting all metadata blocks info'))
- // metadataBlockInfoRepository.getAllFacetableMetadataFields = cy
- // .stub()
- // .rejects(new Error('Error getting all facetable metadata fields'))
-
- // cy.mountAuthenticated(
- //
- // )
-
- // cy.findByText(/Error getting user permissions/).should('exist')
- // cy.findByText(/Error getting collection facets/).should('exist')
- // cy.findByText(/Error getting metadata blocks info/).should('exist')
- // cy.findByText(/Error getting all metadata blocks info/).should('exist')
- // cy.findByText(/Error getting all facetable metadata fields/).should('exist')
- // })
-})
+ cy.findByLabelText(/^Host Collection/i).should('not.exist')
+ })
+ it('should not show Use metadata fields from [Parent] and Use browse/search facets from [Parent] when editing the root collection', () => {
+ cy.mountAuthenticated(
+
+ )
+
+ cy.findByTestId('use-fields-from-parent-checkbox').should('not.exist')
+ cy.findByTestId('use-facets-from-parent-checkbox').should('not.exist')
+ })
+
+ it('should prefill the top fields with the collection data', () => {
+ cy.mountAuthenticated(
+
+ )
+
+ cy.findByLabelText(/^Collection Name/i).should('have.value', collectionBeingEdited.name)
+ cy.findByLabelText(/^Affiliation/i).should('have.value', collectionBeingEdited.affiliation)
+ cy.findByLabelText(/^Identifier/i).should('have.value', collectionBeingEdited.id)
+ cy.findByLabelText(/^Category/i).should('have.value', collectionBeingEdited.type)
+ cy.findAllByLabelText(/^Description/i)
+ .first()
+ .should('have.value', collectionBeingEdited.description)
+
+ cy.findByLabelText(/^Email/i).should('have.value', collectionBeingEdited.contacts[0].email)
+ })
+
+ it('when editing the root collection, should not send metadataBlockNames and inputLevels as undefined if any of them have changed', () => {
+ const collectionRepository = {} as CollectionRepository
+ collectionRepository.edit = cy.stub().as('editCollection').resolves()
+ collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+ cy.mountAuthenticated(
+
+ )
+
+ // Check a new metadata block
+ cy.findByLabelText('Geospatial Metadata').check({ force: true })
+
+ cy.findByRole('button', { name: 'Save Changes' }).click()
+
+ cy.get('@editCollection').should((spy) => {
+ const editCollectionSpy = spy as unknown as Cypress.Agent
+ const collectionDTO = editCollectionSpy.getCall(0).args[1] as CollectionDTO
+
+ const inputLevels = collectionDTO.inputLevels
+ const metadataBlockNames = collectionDTO.metadataBlockNames
+
+ expect(inputLevels).not.to.be.undefined
+ expect(metadataBlockNames).not.to.be.undefined
+ })
+ })
+
+ it('when editing the root collection, should send metadataBlockNames and inputLevels as undefined if they didnt changed', () => {
+ const collectionRepository = {} as CollectionRepository
+ collectionRepository.edit = cy.stub().as('editCollection').resolves()
+ collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+
+ cy.mountAuthenticated(
+
+ )
+
+ // Change affiliation in order to be able to save
+ cy.findByLabelText(/^Affiliation/i)
+ .clear()
+ .type('New Affiliation')
+
+ cy.findByRole('button', { name: 'Save Changes' }).click()
+
+ cy.get('@editCollection').should((spy) => {
+ const editCollectionSpy = spy as unknown as Cypress.Agent
+ const collectionDTO = editCollectionSpy.getCall(0).args[1] as CollectionDTO
+
+ const inputLevels = collectionDTO.inputLevels
+ const metadataBlockNames = collectionDTO.metadataBlockNames
+
+ expect(inputLevels).to.be.undefined
+ expect(metadataBlockNames).to.be.undefined
+ })
+ })
+
+ it('when editing root collection, should not send facetIds as undefined if they have changed', () => {
+ const collectionRepository = {} as CollectionRepository
+ collectionRepository.edit = cy.stub().as('editCollection').resolves()
+ collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+
+ cy.mountAuthenticated(
+
+ )
+
+ cy.findByTestId('left-list-group').as('leftList')
+ cy.findByTestId('actions-column').as('actionsColumn')
+ cy.findByTestId('right-list-group').as('rightList')
+
+ // Change the default selected facets
+ cy.get('@leftList').within(() => {
+ cy.findByText('Topic Classification Term').click()
+ })
+
+ cy.get('@actionsColumn').within(() => {
+ cy.findByLabelText('move selected to right').click()
+ })
+
+ cy.get('@rightList').within(() => {
+ cy.findByLabelText('Topic Classification Term').should('exist')
+ })
+
+ cy.findByRole('button', { name: 'Save Changes' }).click()
+
+ cy.get('@editCollection').should((spy) => {
+ const editCollectionSpy = spy as unknown as Cypress.Agent
+ const collectionDTO = editCollectionSpy.getCall(0).args[1] as CollectionDTO
+
+ const facetIds = collectionDTO.facetIds
+
+ expect(facetIds).to.not.be.undefined
+ })
+ })
+
+ it('when editing root collection, should send facetIds as undefined if they didnt changed', () => {
+ const collectionRepository = {} as CollectionRepository
+ collectionRepository.edit = cy.stub().as('editCollection').resolves()
+ collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets())
+
+ cy.mountAuthenticated(
+
+ )
+
+ // Change affiliation in order to be able to save
+ cy.findByLabelText(/^Affiliation/i)
+ .clear()
+ .type('New Affiliation')
+
+ cy.findByRole('button', { name: 'Save Changes' }).click()
+
+ cy.get('@editCollection').should((spy) => {
+ const editCollectionSpy = spy as unknown as Cypress.Agent
+ const collectionDTO = editCollectionSpy.getCall(0).args[1] as CollectionDTO
+
+ const facetIds = collectionDTO.facetIds
+
+ expect(facetIds).to.be.undefined
+ })
+ })
+ })
+})