From 3ab4295c6686fdb5c9846d42741e723255d8388d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Mon, 11 Nov 2024 16:07:17 -0300 Subject: [PATCH] test: update tests in progress --- .../CollectionFormHelper.spec.ts | 37 +- .../EditCreateCollectionForm.spec.tsx | 1074 +++++++++++++++++ .../useGetAllFacetableMetadataFields.spec.tsx | 6 +- .../useGetAllMetadataBlocksInfo.spec.tsx | 8 +- .../hooks}/useGetCollectionFacets.spec.tsx | 6 +- ...seGetCollectionMetadataBlocksInfo.spec.tsx | 6 +- 6 files changed, 1119 insertions(+), 18 deletions(-) rename tests/component/sections/{create-collection => shared/edit-create-collection-form}/CollectionFormHelper.spec.ts (93%) create mode 100644 tests/component/sections/shared/edit-create-collection-form/EditCreateCollectionForm.spec.tsx rename tests/component/{sections/create-collection => shared/hooks}/useGetAllFacetableMetadataFields.spec.tsx (87%) rename tests/component/{sections/create-collection => shared/hooks}/useGetAllMetadataBlocksInfo.spec.tsx (84%) rename tests/component/{sections/create-collection => shared/hooks}/useGetCollectionFacets.spec.tsx (88%) rename tests/component/{sections/create-collection => shared/hooks}/useGetCollectionMetadataBlocksInfo.spec.tsx (87%) diff --git a/tests/component/sections/create-collection/CollectionFormHelper.spec.ts b/tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts similarity index 93% rename from tests/component/sections/create-collection/CollectionFormHelper.spec.ts rename to tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts index 6c60b85f6..d00ad3c67 100644 --- a/tests/component/sections/create-collection/CollectionFormHelper.spec.ts +++ b/tests/component/sections/shared/edit-create-collection-form/CollectionFormHelper.spec.ts @@ -1,16 +1,18 @@ -import { CollectionInputLevel } from '../../../../src/collection/domain/models/Collection' -import { CollectionInputLevelDTO } from '../../../../src/collection/domain/useCases/DTOs/CollectionDTO' +import { CollectionInputLevel } from '@/collection/domain/models/Collection' +import { CollectionContact } from '@/collection/domain/models/CollectionContact' +import { CollectionInputLevelDTO } from '@/collection/domain/useCases/DTOs/CollectionDTO' import { MetadataBlockInfo, MetadataBlockName, MetadataField -} from '../../../../src/metadata-block-info/domain/models/MetadataBlockInfo' +} from '@/metadata-block-info/domain/models/MetadataBlockInfo' +import { CollectionFormHelper } from '@/sections/shared/form/EditCreateCollectionForm/CollectionFormHelper' import { + CollectionFormContactValue, FormattedCollectionInputLevels, FormattedCollectionInputLevelsWithoutParentBlockName, MetadataFieldWithParentBlockInfo -} from '../../../../src/sections/create-collection/collection-form/CollectionForm' -import { CollectionFormHelper } from '../../../../src/sections/create-collection/collection-form/CollectionFormHelper' +} from '@/sections/shared/form/EditCreateCollectionForm/types' const allMetadataBlocksInfoMock: MetadataBlockInfo[] = [ { @@ -551,4 +553,29 @@ describe('CollectionFormHelper', () => { expect(result).to.equal('coverage.Spectral.MinimumWavelength') }) + + it('formats collection contacts to form contacts values', () => { + const collectionContacts: CollectionContact[] = [ + { + email: 'test1@mail.com', + displayOrder: 0 + }, + { + email: 'test2@mail.com', + displayOrder: 1 + } + ] + const expected: CollectionFormContactValue[] = [ + { + value: 'test1@mail.com' + }, + { + value: 'test2@mail.com' + } + ] + + const result = CollectionFormHelper.formatCollectionContactsToFormContacts(collectionContacts) + + expect(result).to.deep.equal(expected) + }) }) 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 new file mode 100644 index 000000000..69c4939e1 --- /dev/null +++ b/tests/component/sections/shared/edit-create-collection-form/EditCreateCollectionForm.spec.tsx @@ -0,0 +1,1074 @@ +import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' +import { MetadataBlockName } from '@/metadata-block-info/domain/models/MetadataBlockInfo' +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 { UserRepository } from '@/users/domain/repositories/UserRepository' +import { CollectionFacetMother } from '@tests/component/collection/domain/models/CollectionFacetMother' +import { CollectionMother } from '@tests/component/collection/domain/models/CollectionMother' +import { MetadataBlockInfoMother } from '@tests/component/metadata-block-info/domain/models/MetadataBlockInfoMother' +import { UserMother } from '@tests/component/users/domain/models/UserMother' + +const collectionRepository: CollectionRepository = {} as CollectionRepository + +const metadataBlockInfoRepository = {} as MetadataBlockInfoRepository + +const PARENT_COLLECTION_ID = 'root' + +const COLLECTION_NAME = 'Collection Name' +const collection = CollectionMother.create({ name: COLLECTION_NAME }) + +const VIEW_AND_EDIT_FIELDS_LABEL = '[+] View fields + set as hidden, required, or optional' +const VIEW_FIELDS_LABEL = '[+] View fields' + +const colllectionMetadataBlocks = [MetadataBlockInfoMother.getCitationBlock()] + +const allMetadataBlocksMock = [ + MetadataBlockInfoMother.getCitationBlock(), + MetadataBlockInfoMother.getGeospatialBlock(), + MetadataBlockInfoMother.getAstrophysicsBlock(), + MetadataBlockInfoMother.getBiomedicalBlock(), + MetadataBlockInfoMother.getJournalBlock(), + MetadataBlockInfoMother.getSocialScienceBlock() +] + +const testUser = UserMother.create() +const userRepository: UserRepository = {} as UserRepository + +const defaultCollectionName = `${testUser.displayName} Collection` + +// 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 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 +// } + +describe('EditCreateCollectionForm', () => { + beforeEach(() => { + collectionRepository.create = cy.stub().resolves(1) + collectionRepository.getById = cy.stub().resolves(collection) + collectionRepository.getFacets = cy.stub().resolves(CollectionFacetMother.createFacets()) + userRepository.getAuthenticated = cy.stub().resolves(testUser) + + metadataBlockInfoRepository.getByCollectionId = cy.stub().resolves(colllectionMetadataBlocks) + metadataBlockInfoRepository.getAll = cy.stub().resolves(allMetadataBlocksMock) + metadataBlockInfoRepository.getAllFacetableMetadataFields = cy + .stub() + .resolves(allFacetableMetadataFields) + }) + + /* + + + + +*/ + + describe('should render the form', () => { + it('on create mode', () => { + cy.mountAuthenticated( + + ) + + cy.findByTestId('collection-form').should('exist') + }) + + it('on edit mode', () => { + cy.mountAuthenticated( + + ) + + cy.findByTestId('collection-form').should('exist') + }) + }) + + // it('prefills the Host Collection field with current owner collection', () => { + // cy.mountAuthenticated( + // + // ) + + // cy.findByLabelText(/^Host Collection/i).should('have.value', COLLECTION_NAME) + // }) + + // it('pre-fills specific form fields with user data', () => { + // cy.mountAuthenticated( + // + // ) + + // cy.findByLabelText(/^Collection Name/i).should('have.value', defaultCollectionName) + + // cy.findByLabelText(/^Affiliation/i).should('have.value', testUser.affiliation) + + // cy.findByLabelText(/^Email/i).should('have.value', testUser.email) + // }) + + // it('submit button should be disabled when form has not been touched', () => { + // cy.customMount( + // + // ) + + // cy.findByRole('button', { name: 'Create Collection' }).should('be.disabled') + // }) + + // it('submit button should not be disabled when form has been touched', () => { + // cy.customMount( + // + // ) + + // cy.findByLabelText(/^Collection Name/i) + // .clear() + // .type('New Collection Name') + + // cy.findByRole('button', { name: 'Create Collection' }).should('not.be.disabled') + // }) + + // it('shows error message when form is submitted with empty required fields', () => { + // cy.customMount( + // + // ) + + // // Change collection name so submit button is no longer disabled + // cy.findByLabelText(/^Collection Name/i) + // .clear() + // .type('New Collection Name') + + // cy.findByRole('button', { name: 'Create Collection' }).click() + + // cy.findByText('Category is required').should('exist') + // cy.findByText('Identifier is required').should('exist') + // }) + + // it('shows error message when form is submitted with invalid email', () => { + // cy.customMount( + // + // ) + + // cy.findByLabelText(/^Email/i) + // .clear() + // .type('invalid-email') + + // cy.findByRole('button', { name: 'Create Collection' }).click() + + // cy.findByText('Email is not a valid email').should('exist') + // }) + // it('shows error message when form is submitted with invalid identifier', () => { + // cy.customMount( + // + // ) + + // cy.findByLabelText(/^Identifier/i).type('invalid identifier') + + // cy.findByRole('button', { name: 'Create Collection' }).click() + + // cy.findByText(/Identifier is not valid./).should('exist') + // }) + + // it('submits a valid form and succeed', () => { + // 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.findByText('Error').should('not.exist') + // cy.findByText('Success!').should('exist') + // }) + + // it('submits a valid form and fails', () => { + // collectionRepository.create = cy.stub().rejects(new Error('Error creating collection')) + + // 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.findByText('Error').should('exist') + // cy.findByText(/Error creating collection/).should('exist') + // cy.findByText('Success!').should('not.exist') + // }) + + // it('cancel button is clickable', () => { + // cy.customMount( + // + // ) + + // cy.findByText('Cancel').click() + // }) + + // 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') + // }) + // }) + // }) +}) diff --git a/tests/component/sections/create-collection/useGetAllFacetableMetadataFields.spec.tsx b/tests/component/shared/hooks/useGetAllFacetableMetadataFields.spec.tsx similarity index 87% rename from tests/component/sections/create-collection/useGetAllFacetableMetadataFields.spec.tsx rename to tests/component/shared/hooks/useGetAllFacetableMetadataFields.spec.tsx index ed47c7e8a..8c7b6164e 100644 --- a/tests/component/sections/create-collection/useGetAllFacetableMetadataFields.spec.tsx +++ b/tests/component/shared/hooks/useGetAllFacetableMetadataFields.spec.tsx @@ -1,7 +1,7 @@ import { act, renderHook } from '@testing-library/react' -import { MetadataBlockInfoRepository } from '../../../../src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' -import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models/MetadataBlockInfoMother' -import { useGetAllFacetableMetadataFields } from '../../../../src/sections/create-collection/useGetAllFacetableMetadataFields' +import { MetadataBlockInfoMother } from '@tests/component/metadata-block-info/domain/models/MetadataBlockInfoMother' +import { MetadataBlockInfoRepository } from '@/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' +import { useGetAllFacetableMetadataFields } from '@/shared/hooks/useGetAllFacetableMetadataFields' const metadataBlockInfoRepository: MetadataBlockInfoRepository = {} as MetadataBlockInfoRepository const allFacetableMetadataFieldsMock = MetadataBlockInfoMother.createFacetableMetadataFields() diff --git a/tests/component/sections/create-collection/useGetAllMetadataBlocksInfo.spec.tsx b/tests/component/shared/hooks/useGetAllMetadataBlocksInfo.spec.tsx similarity index 84% rename from tests/component/sections/create-collection/useGetAllMetadataBlocksInfo.spec.tsx rename to tests/component/shared/hooks/useGetAllMetadataBlocksInfo.spec.tsx index b61e51809..a2f05c3b2 100644 --- a/tests/component/sections/create-collection/useGetAllMetadataBlocksInfo.spec.tsx +++ b/tests/component/shared/hooks/useGetAllMetadataBlocksInfo.spec.tsx @@ -1,8 +1,8 @@ import { act, renderHook } from '@testing-library/react' -import { MetadataBlockInfoRepository } from '../../../../src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' -import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models/MetadataBlockInfoMother' -import { useGetAllMetadataBlocksInfo } from '../../../../src/sections/create-collection/useGetAllMetadataBlocksInfo' -import { MetadataFieldsHelper } from '../../../../src/sections/shared/form/DatasetMetadataForm/MetadataFieldsHelper' +import { MetadataBlockInfoMother } from '@tests/component/metadata-block-info/domain/models/MetadataBlockInfoMother' +import { MetadataBlockInfoRepository } from '@/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' +import { MetadataFieldsHelper } from '@/sections/shared/form/DatasetMetadataForm/MetadataFieldsHelper' +import { useGetAllMetadataBlocksInfo } from '@/shared/hooks/useGetAllMetadataBlocksInfo' const metadataBlockInfoRepository: MetadataBlockInfoRepository = {} as MetadataBlockInfoRepository const allMetadataBlocksInfoMock = MetadataBlockInfoMother.getAllBlocks() diff --git a/tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx b/tests/component/shared/hooks/useGetCollectionFacets.spec.tsx similarity index 88% rename from tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx rename to tests/component/shared/hooks/useGetCollectionFacets.spec.tsx index 797eef2e1..7e328147c 100644 --- a/tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx +++ b/tests/component/shared/hooks/useGetCollectionFacets.spec.tsx @@ -1,7 +1,7 @@ import { act, renderHook } from '@testing-library/react' -import { useGetCollectionFacets } from '../../../../src/sections/create-collection/useGetCollectionFacets' -import { CollectionRepository } from '../../../../src/collection/domain/repositories/CollectionRepository' -import { CollectionFacetMother } from '../../collection/domain/models/CollectionFacetMother' +import { CollectionFacetMother } from '@tests/component/collection/domain/models/CollectionFacetMother' +import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' +import { useGetCollectionFacets } from '@/shared/hooks/useGetCollectionFacets' const collectionRepository: CollectionRepository = {} as CollectionRepository const collectionFacetsMock = CollectionFacetMother.createFacets() diff --git a/tests/component/sections/create-collection/useGetCollectionMetadataBlocksInfo.spec.tsx b/tests/component/shared/hooks/useGetCollectionMetadataBlocksInfo.spec.tsx similarity index 87% rename from tests/component/sections/create-collection/useGetCollectionMetadataBlocksInfo.spec.tsx rename to tests/component/shared/hooks/useGetCollectionMetadataBlocksInfo.spec.tsx index 5be83bc26..3da86a2bc 100644 --- a/tests/component/sections/create-collection/useGetCollectionMetadataBlocksInfo.spec.tsx +++ b/tests/component/shared/hooks/useGetCollectionMetadataBlocksInfo.spec.tsx @@ -1,7 +1,7 @@ import { act, renderHook } from '@testing-library/react' -import { MetadataBlockInfoRepository } from '../../../../src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' -import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models/MetadataBlockInfoMother' -import { useGetCollectionMetadataBlocksInfo } from '../../../../src/sections/create-collection/useGetCollectionMetadataBlocksInfo' +import { MetadataBlockInfoMother } from '@tests/component/metadata-block-info/domain/models/MetadataBlockInfoMother' +import { MetadataBlockInfoRepository } from '@/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' +import { useGetCollectionMetadataBlocksInfo } from '@/shared/hooks/useGetCollectionMetadataBlocksInfo' const metadataBlockInfoRepository: MetadataBlockInfoRepository = {} as MetadataBlockInfoRepository const metadataBlocksInfoMock = MetadataBlockInfoMother.getAllBlocks()