From 6aec64147f63e6764572d921cf12361f09b790ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Fri, 15 Nov 2024 09:25:05 -0300 Subject: [PATCH] test: improve other tests --- public/locales/en/shared.json | 3 +- src/files/domain/models/FilePreview.ts | 2 +- src/index.tsx | 18 +++---- .../PublishCollectionModal.tsx | 4 +- .../usePublishCollection.tsx | 5 +- .../file-info/file-info-cell/FileInfoCell.tsx | 4 -- .../collection-form/CollectionForm.tsx | 2 +- .../PublishCollectionModal.spec.tsx | 24 +++++++++ .../DatasetUploadFilesButton.spec.tsx | 6 ++- .../sections/route-enum/Route.spec.ts | 22 +++++++++ .../EditCreateCollectionForm.spec.tsx | 49 +++++++++++++++++++ 11 files changed, 117 insertions(+), 22 deletions(-) create mode 100644 tests/component/sections/route-enum/Route.spec.ts diff --git a/public/locales/en/shared.json b/public/locales/en/shared.json index 0380b9915..9d69de802 100644 --- a/public/locales/en/shared.json +++ b/public/locales/en/shared.json @@ -139,7 +139,8 @@ "cancel": "Cancel" }, "submitStatus": { - "success": "Collection created successfully." + "createSuccess": "Collection created successfully.", + "editSuccess": "Collection updated successfully." }, "saveButton": { "createMode": "Create Collection", diff --git a/src/files/domain/models/FilePreview.ts b/src/files/domain/models/FilePreview.ts index 19e8426d9..40d89d45b 100644 --- a/src/files/domain/models/FilePreview.ts +++ b/src/files/domain/models/FilePreview.ts @@ -15,7 +15,7 @@ export interface FilePreview { ingest: FileIngest metadata: FileMetadata permissions: FilePermissions - datasetVersionNumber?: DatasetVersionNumber + datasetVersionNumber: DatasetVersionNumber releaseOrCreateDate?: Date someDatasetVersionHasBeenReleased?: boolean datasetPersistentId?: string diff --git a/src/index.tsx b/src/index.tsx index c8cc67b83..a50dc685e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,13 +8,13 @@ import { AppLoader } from './sections/shared/layout/app-loader/AppLoader' const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement) root.render( - // - }> - - - - - - - // + + }> + + + + + + + ) diff --git a/src/sections/collection/publish-collection/PublishCollectionModal.tsx b/src/sections/collection/publish-collection/PublishCollectionModal.tsx index 260ea6b22..dfbff87d2 100644 --- a/src/sections/collection/publish-collection/PublishCollectionModal.tsx +++ b/src/sections/collection/publish-collection/PublishCollectionModal.tsx @@ -47,9 +47,7 @@ export function PublishCollectionModal({

{tCollection('publish.question')}

{submissionStatus === SubmissionStatus.Errored && ( -

- `${tCollection('publish.error')} ${publishError ? publishError : ''}` -

+

{`${tCollection('publish.error')} ${publishError}`}

)}
diff --git a/src/sections/collection/publish-collection/usePublishCollection.tsx b/src/sections/collection/publish-collection/usePublishCollection.tsx index 2a58b7a39..a514e9983 100644 --- a/src/sections/collection/publish-collection/usePublishCollection.tsx +++ b/src/sections/collection/publish-collection/usePublishCollection.tsx @@ -40,7 +40,10 @@ export function usePublishCollection( return }) .catch((err) => { - const errorMessage = err instanceof Error && err.message ? err.message : 'Unknown Error' // TODO: i18n + const errorMessage = + err instanceof Error && err.message + ? err.message + : 'Something went wrong while trying to publish the collection. Please try again later.' setPublishError(errorMessage) setSubmissionStatus(SubmissionStatus.Errored) diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx index 29ec191ca..494f4c1c6 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx @@ -13,10 +13,6 @@ import { FileDescription } from './file-info-data/FileDescription' import { FileLabels } from '../../../../../file/file-labels/FileLabels' export function FileInfoCell({ file }: { file: FilePreview }) { - if (!file.datasetVersionNumber) { - console.log('FileInfoCell error: FilePreview object must contain datasetVersionNumber') - return null - } return (
diff --git a/src/sections/shared/form/EditCreateCollectionForm/collection-form/CollectionForm.tsx b/src/sections/shared/form/EditCreateCollectionForm/collection-form/CollectionForm.tsx index 44cac4223..04d6a409d 100644 --- a/src/sections/shared/form/EditCreateCollectionForm/collection-form/CollectionForm.tsx +++ b/src/sections/shared/form/EditCreateCollectionForm/collection-form/CollectionForm.tsx @@ -86,7 +86,7 @@ export const CollectionForm = ({ )} {submissionStatus === SubmissionStatus.SubmitComplete && ( - {t('submitStatus.success')} + {onCreateMode ? t('submitStatus.createSuccess') : t('submitStatus.editSuccess')} )} diff --git a/tests/component/sections/collection/collection-publish/PublishCollectionModal.spec.tsx b/tests/component/sections/collection/collection-publish/PublishCollectionModal.spec.tsx index f6051500b..1a68515ba 100644 --- a/tests/component/sections/collection/collection-publish/PublishCollectionModal.spec.tsx +++ b/tests/component/sections/collection/collection-publish/PublishCollectionModal.spec.tsx @@ -23,6 +23,30 @@ describe('PublishCollectionModal', () => { // Check if the error message is displayed cy.contains(errorMessage).should('exist') }) + + it('displays the fallback error message when publishCollection fails without an error message', () => { + const handleClose = cy.stub() + const repository = {} as CollectionRepository // Mock the repository as needed + repository.publish = cy.stub().as('repositoryPublish').rejects('Unknown error') + + cy.mountAuthenticated( + + ) + + // Trigger the Publish action + cy.findByRole('button', { name: 'Continue' }).click() + + // Check if the error message is displayed + cy.contains( + 'Something went wrong while trying to publish the collection. Please try again later.' + ).should('exist') + }) + it('renders the PublishDatasetModal and triggers submitPublish on button click', () => { const handleClose = cy.stub() const repository = {} as CollectionRepository // Mock the repository as needed diff --git a/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx b/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx index 24c3ff587..c5198a9e5 100644 --- a/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx @@ -56,7 +56,9 @@ describe('DatasetUploadFilesButton', () => { cy.findByRole('button', { name: 'Upload Files' }).should('exist').should('be.disabled') }) - it.skip('calls upload files use case when button is clicked', () => { - // TODO - Implement upload files + it('test click', () => { + cy.mountAuthenticated(withDataset(, datasetWithUpdatePermissions)) + + cy.findByRole('button', { name: 'Upload Files' }).click() }) }) diff --git a/tests/component/sections/route-enum/Route.spec.ts b/tests/component/sections/route-enum/Route.spec.ts new file mode 100644 index 000000000..5c1b69ed5 --- /dev/null +++ b/tests/component/sections/route-enum/Route.spec.ts @@ -0,0 +1,22 @@ +import { Route, RouteWithParams } from '@/sections/Route.enum' + +describe('Route.enum.ts', () => { + describe('RouteWithParams', () => { + it('should return the correct route for COLLECTIONS', () => { + expect(RouteWithParams.COLLECTIONS()).to.be.equal(Route.COLLECTIONS_BASE) + expect(RouteWithParams.COLLECTIONS('123')).to.be.equal(`${Route.COLLECTIONS_BASE}/123`) + }) + + it('should return the correct route for CREATE_COLLECTION', () => { + expect(RouteWithParams.CREATE_COLLECTION('123')).to.be.equal(`/collections/123/create`) + }) + + it('should return the correct route for EDIT_COLLECTION', () => { + expect(RouteWithParams.EDIT_COLLECTION('123')).to.be.equal(`/collections/123/edit`) + }) + + it('should return the correct route for CREATE_DATASET', () => { + expect(RouteWithParams.CREATE_DATASET('123')).to.be.equal(`/datasets/123/create`) + }) + }) +}) 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 faaeab883..91da4bc5d 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 @@ -83,6 +83,7 @@ const allFacetableMetadataFields = MetadataBlockInfoMother.getAllFacetableMetada describe('EditCreateCollectionForm', () => { beforeEach(() => { collectionRepository.create = cy.stub().resolves(1) + collectionRepository.edit = cy.stub().resolves({}) collectionRepository.getFacets = cy.stub().resolves(collectionFacets) userRepository.getAuthenticated = cy.stub().resolves(testUser) metadataBlockInfoRepository.getByCollectionId = cy.stub().resolves(colllectionMetadataBlocks) @@ -1062,6 +1063,54 @@ describe('EditCreateCollectionForm', () => { cy.findByTestId('collection-form').should('exist') }) + it('submits a valid form and succeed', () => { + cy.customMount( + + ) + // 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.findByText('Error').should('not.exist') + cy.findByText('Success!').should('exist') + }) + + it('submits a valid form and fails', () => { + collectionRepository.edit = cy.stub().rejects(new Error('Error editing collection')) + + cy.customMount( + + ) + + // 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.findByText('Error').should('exist') + cy.findByText(/Error editing collection/).should('exist') + cy.findByText('Success!').should('not.exist') + }) + it('should not show the Host Collection field when editing the root collection', () => { cy.mountAuthenticated(