Skip to content

Commit

Permalink
test: improve other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 15, 2024
1 parent c3146c0 commit 6aec641
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 22 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
"cancel": "Cancel"
},
"submitStatus": {
"success": "Collection created successfully."
"createSuccess": "Collection created successfully.",
"editSuccess": "Collection updated successfully."
},
"saveButton": {
"createMode": "Create Collection",
Expand Down
2 changes: 1 addition & 1 deletion src/files/domain/models/FilePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface FilePreview {
ingest: FileIngest
metadata: FileMetadata
permissions: FilePermissions
datasetVersionNumber?: DatasetVersionNumber
datasetVersionNumber: DatasetVersionNumber
releaseOrCreateDate?: Date
someDatasetVersionHasBeenReleased?: boolean
datasetPersistentId?: string
Expand Down
18 changes: 9 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { AppLoader } from './sections/shared/layout/app-loader/AppLoader'

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(
// <React.StrictMode>
<React.Suspense fallback={<AppLoader fullViewport />}>
<LoadingProvider>
<ThemeProvider>
<App />
</ThemeProvider>
</LoadingProvider>
</React.Suspense>
// </React.StrictMode>
<React.StrictMode>
<React.Suspense fallback={<AppLoader fullViewport />}>
<LoadingProvider>
<ThemeProvider>
<App />
</ThemeProvider>
</LoadingProvider>
</React.Suspense>
</React.StrictMode>
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export function PublishCollectionModal({
<Stack direction="vertical">
<p className={styles.warningText}>{tCollection('publish.question')}</p>
{submissionStatus === SubmissionStatus.Errored && (
<p className={styles.errorText}>
`${tCollection('publish.error')} ${publishError ? publishError : ''}`
</p>
<p className={styles.errorText}>{`${tCollection('publish.error')} ${publishError}`}</p>
)}
</Stack>
</Modal.Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className={styles.container}>
<div className={styles['thumbnail-container']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const CollectionForm = ({
)}
{submissionStatus === SubmissionStatus.SubmitComplete && (
<Alert variant="success" dismissible={false}>
{t('submitStatus.success')}
{onCreateMode ? t('submitStatus.createSuccess') : t('submitStatus.editSuccess')}
</Alert>
)}
<FormProvider {...form}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<PublishCollectionModal
show={true}
repository={repository}
collectionId="testCollectionId"
handleClose={handleClose}
/>
)

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<DatasetUploadFilesButton />, datasetWithUpdatePermissions))

cy.findByRole('button', { name: 'Upload Files' }).click()
})
})
22 changes: 22 additions & 0 deletions tests/component/sections/route-enum/Route.spec.ts
Original file line number Diff line number Diff line change
@@ -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`)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1062,6 +1063,54 @@ describe('EditCreateCollectionForm', () => {
cy.findByTestId('collection-form').should('exist')
})

it('submits a valid form and succeed', () => {
cy.customMount(
<EditCreateCollectionForm
mode="edit"
user={testUser}
collection={collectionBeingEdited}
parentCollection={{ id: PARENT_COLLECTION_ID, name: PARENT_COLLECTION_NAME }}
collectionRepository={collectionRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
/>
)
// 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(
<EditCreateCollectionForm
mode="edit"
user={testUser}
collection={collectionBeingEdited}
parentCollection={{ id: PARENT_COLLECTION_ID, name: PARENT_COLLECTION_NAME }}
collectionRepository={collectionRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
/>
)

// 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(
<EditCreateCollectionForm
Expand Down

0 comments on commit 6aec641

Please sign in to comment.