Skip to content

Commit

Permalink
feat: update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Nov 15, 2023
1 parent e112c2a commit 36baaf6
Showing 1 changed file with 86 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AccessDatasetMenu } from '../../../../../../src/sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu'
import {
DatasetFileDownloadSizeMother,
DatasetPermissionsMother,
DatasetVersionMother
} from '../../../../dataset/domain/models/DatasetMother'
Expand All @@ -8,8 +9,18 @@ describe('AccessDatasetMenu', () => {
it('renders the AccessDatasetMenu if the user has download files permissions and the dataset is not deaccessioned', () => {
const version = DatasetVersionMother.createReleased()
const permissions = DatasetPermissionsMother.createWithFilesDownloadAllowed()

cy.customMount(<AccessDatasetMenu version={version} permissions={permissions} />)
const fileDownloadSizes = [
DatasetFileDownloadSizeMother.createOriginal(),
DatasetFileDownloadSizeMother.createArchival()
]
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={true}
version={version}
permissions={permissions}
/>
)

cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
})
Expand All @@ -20,27 +31,91 @@ describe('AccessDatasetMenu', () => {
canUpdateDataset: true,
canDownloadFiles: true
})

cy.customMount(<AccessDatasetMenu version={version} permissions={permissions} />)

const fileDownloadSizes = [
DatasetFileDownloadSizeMother.createOriginal(),
DatasetFileDownloadSizeMother.createArchival()
]
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={true}
version={version}
permissions={permissions}
/>
)
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
})

it('does not render the AccessDatasetMenu if the user do not have download files permissions', () => {
const version = DatasetVersionMother.create()
const permissions = DatasetPermissionsMother.createWithFilesDownloadNotAllowed()

cy.customMount(<AccessDatasetMenu version={version} permissions={permissions} />)

const fileDownloadSizes = [
DatasetFileDownloadSizeMother.createOriginal(),
DatasetFileDownloadSizeMother.createArchival()
]
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={true}
version={version}
permissions={permissions}
/>
)
cy.findByRole('button', { name: 'Access Dataset' }).should('not.exist')
})

it('does not render the AccessDatasetMenu if the dataset is deaccessioned and the user does not have update dataset permissions', () => {
const version = DatasetVersionMother.createDeaccessioned()
const permissions = DatasetPermissionsMother.createWithUpdateDatasetNotAllowed()

cy.customMount(<AccessDatasetMenu version={version} permissions={permissions} />)

const fileDownloadSizes = [
DatasetFileDownloadSizeMother.createOriginal(),
DatasetFileDownloadSizeMother.createArchival()
]
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={true}
version={version}
permissions={permissions}
/>
)
cy.findByRole('button', { name: 'Access Dataset' }).should('not.exist')
})
it('displays one dropdown option if there are no tabular files', () => {
const version = DatasetVersionMother.createReleased()
const permissions = DatasetPermissionsMother.createWithFilesDownloadAllowed()
const fileDownloadSizes = [DatasetFileDownloadSizeMother.createOriginal()]
// const menuItemName = 'Download ZIP' + ' (' + formatFileSize(fileDownloadSizes[0].size) + ')'
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={false}
version={version}
permissions={permissions}
/>
)
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
cy.findByRole('button', { name: 'Access Dataset' }).click()
cy.findByText(/Download ZIP \(\d+(\.\d+)? KB\)/).should('exist')
})
it('displays two dropdown options if there is at least one', () => {
const version = DatasetVersionMother.createReleased()
const permissions = DatasetPermissionsMother.createWithFilesDownloadAllowed()
const fileDownloadSizes = [
DatasetFileDownloadSizeMother.createOriginal(),
DatasetFileDownloadSizeMother.createArchival()
]
cy.customMount(
<AccessDatasetMenu
fileDownloadSizes={fileDownloadSizes}
hasOneTabularFileAtLeast={true}
version={version}
permissions={permissions}
/>
)
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
cy.findByRole('button', { name: 'Access Dataset' }).click()
cy.findByText(/Original Format ZIP \(\d+(\.\d+)? KB\)/).should('exist')
cy.findByText(/Archive Format \(\.tab\) ZIP \(\d+(\.\d+)? KB\)/).should('exist')
})
})

0 comments on commit 36baaf6

Please sign in to comment.