Skip to content

Commit

Permalink
test: add unrelated test cases to increase coverage branch
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Jan 16, 2025
1 parent 55e6a1f commit d0cf486
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,85 @@ describe('CollectionItemsPanel', () => {
})
})
})

describe('Sorting', () => {
// These cases about sorting are not possible to test the change in here as they react to the url change
// They are properly tested in the e2e tests and in another unit test.
// This will just click the different sort buttons to go through the code
it('clicks the sort by name A-Z button', () => {
cy.customMount(
<CollectionItemsPanel
collectionId={ROOT_COLLECTION_ALIAS}
collectionRepository={collectionRepository}
collectionQueryParams={{
pageQuery: 1,
searchQuery: undefined,
typesQuery: undefined,
filtersQuery: undefined
}}
addDataSlot={null}
/>
)

cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Name \(A-Z\)/ }).click()
})

it('clicks the sort by name Z-A button', () => {
cy.customMount(
<CollectionItemsPanel
collectionId={ROOT_COLLECTION_ALIAS}
collectionRepository={collectionRepository}
collectionQueryParams={{
pageQuery: 1,
searchQuery: undefined,
typesQuery: undefined,
filtersQuery: undefined
}}
addDataSlot={null}
/>
)

cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Name \(Z-A\)/ }).click()
})

it('clicks the sort by newest button', () => {
cy.customMount(
<CollectionItemsPanel
collectionId={ROOT_COLLECTION_ALIAS}
collectionRepository={collectionRepository}
collectionQueryParams={{
pageQuery: 1,
searchQuery: undefined,
typesQuery: undefined,
filtersQuery: undefined
}}
addDataSlot={null}
/>
)

cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Newest/ }).click()
})

it('clicks the sort by oldest button', () => {
cy.customMount(
<CollectionItemsPanel
collectionId={ROOT_COLLECTION_ALIAS}
collectionRepository={collectionRepository}
collectionQueryParams={{
pageQuery: 1,
searchQuery: undefined,
typesQuery: undefined,
filtersQuery: undefined
}}
addDataSlot={null}
/>
)

cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Oldest/ }).click()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,44 @@ describe('EditDatasetMenu', () => {
.should('have.class', 'disabled')
cy.findByRole('button', { name: 'Metadata' }).should('exist').should('have.class', 'disabled')
})

it('clicks on the Files (Upload) button', () => {
const dataset = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithAllAllowed(),
locks: [],
hasValidTermsOfAccess: true
})

cy.mountAuthenticated(<EditDatasetMenu dataset={dataset} />)

cy.findByRole('button', { name: 'Edit Dataset' }).click()
cy.findByRole('button', { name: 'Files (Upload)' }).click()
})

it('clicks on the Files (Upload) button and dataset version is DRAFT', () => {
const dataset = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithAllAllowed(),
locks: [],
hasValidTermsOfAccess: true,
version: DatasetVersionMother.createDraft()
})

cy.mountAuthenticated(<EditDatasetMenu dataset={dataset} />)

cy.findByRole('button', { name: 'Edit Dataset' }).click()
cy.findByRole('button', { name: 'Files (Upload)' }).click()
})

it('clicks on the Metadata button', () => {
const dataset = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithAllAllowed(),
locks: [],
hasValidTermsOfAccess: true
})

cy.mountAuthenticated(<EditDatasetMenu dataset={dataset} />)

cy.findByRole('button', { name: 'Edit Dataset' }).click()
cy.findByRole('button', { name: 'Metadata' }).click()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { DatasetProvider } from '../../../../../../src/sections/dataset/DatasetP
import {
DatasetLockMother,
DatasetMother,
DatasetPermissionsMother
DatasetPermissionsMother,
DatasetVersionMother
} from '../../../../dataset/domain/models/DatasetMother'
import { DatasetRepository } from '../../../../../../src/dataset/domain/repositories/DatasetRepository'
import { Dataset as DatasetModel } from '../../../../../../src/dataset/domain/models/Dataset'
Expand All @@ -13,6 +14,7 @@ const datasetRepository: DatasetRepository = {} as DatasetRepository
const datasetWithUpdatePermissions = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed()
})

describe('DatasetUploadFilesButton', () => {
const withDataset = (component: ReactNode, dataset: DatasetModel | undefined) => {
datasetRepository.getByPersistentId = cy.stub().resolves(dataset)
Expand Down Expand Up @@ -61,4 +63,14 @@ describe('DatasetUploadFilesButton', () => {

cy.findByRole('button', { name: 'Upload Files' }).click()
})

it('test click with a draft dataset version', () => {
const draftDatasetVersion = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(),
version: DatasetVersionMother.createDraft()
})
cy.mountAuthenticated(withDataset(<DatasetUploadFilesButton />, draftDatasetVersion))

cy.findByRole('button', { name: 'Upload Files' }).click()
})
})

0 comments on commit d0cf486

Please sign in to comment.