Skip to content

Commit

Permalink
feat(DatasetActionButtons): add LinkDatasetButton component
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Sep 12, 2023
1 parent 17ef891 commit 6149156
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ export class Dataset {
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly isValid: boolean
public readonly isValid: boolean,
public readonly isReleased: boolean
) {}

public getTitle(): string {
Expand Down Expand Up @@ -299,7 +300,8 @@ export class Dataset {
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly isValid: boolean
public readonly isValid: boolean,
public readonly isReleased: boolean
) {
this.withLabels()
}
Expand Down Expand Up @@ -361,7 +363,8 @@ export class Dataset {
this.permissions,
this.locks,
this.hasValidTermsOfAccess,
this.isValid
this.isValid,
this.isReleased
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PublishDatasetMenu } from './publish-dataset-menu/PublishDatasetMenu'
import styles from './DatasetActionButtons.module.scss'
import { SubmitForReviewButton } from './submit-for-review-button/SubmitForReviewButton'
import { EditDatasetMenu } from './edit-dataset-menu/EditDatasetMenu'
import { LinkDatasetButton } from './link-dataset-button/LinkDatasetButton'

interface DatasetActionButtonsProps {
dataset: Dataset
Expand All @@ -17,6 +18,7 @@ export function DatasetActionButtons({ dataset }: DatasetActionButtonsProps) {
<PublishDatasetMenu dataset={dataset} />
<SubmitForReviewButton dataset={dataset} />
<EditDatasetMenu dataset={dataset} />
<LinkDatasetButton dataset={dataset} />
</ButtonGroup>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Button } from '@iqss/dataverse-design-system'
import { Dataset, DatasetStatus } from '../../../../dataset/domain/models/Dataset'

interface LinkDatasetButtonProps {
dataset: Dataset
}
export function LinkDatasetButton({ dataset }: LinkDatasetButtonProps) {
// TODO - get session context
if (!dataset.isReleased || dataset.version.status === DatasetStatus.DEACCESSIONED) {
return <></>
}
return <Button variant="secondary">Link Dataset</Button>
}
4 changes: 3 additions & 1 deletion tests/component/dataset/domain/models/DatasetMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class DatasetMother {
locks: [],
hasValidTermsOfAccess: faker.datatype.boolean(),
isValid: faker.datatype.boolean(),
isReleased: faker.datatype.boolean(),
...props
}

Expand All @@ -275,7 +276,8 @@ export class DatasetMother {
dataset.permissions,
dataset.locks,
dataset.hasValidTermsOfAccess,
dataset.isValid
dataset.isValid,
dataset.isReleased
).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
DatasetVersionMother
} from '../../../dataset/domain/models/DatasetMother'

const dataset = DatasetMother.create()
describe('DatasetActionButtons', () => {
it('renders the DatasetActionButtons with the Publish button', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersion(),
permissions: DatasetPermissionsMother.createWithAllAllowed()
permissions: DatasetPermissionsMother.createWithAllAllowed(),
isReleased: true
})

cy.customMount(<DatasetActionButtons dataset={dataset} />)
Expand All @@ -19,6 +19,7 @@ describe('DatasetActionButtons', () => {
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
cy.findByRole('button', { name: 'Publish Dataset' }).should('exist')
cy.findByRole('button', { name: 'Edit Dataset' }).should('exist')
cy.findByRole('button', { name: 'Link Dataset' }).should('exist')
})

it('renders the DatasetActionButtons with the Submit for Review button', () => {
Expand All @@ -28,7 +29,8 @@ describe('DatasetActionButtons', () => {
canDownloadFiles: true,
canUpdateDataset: true,
canPublishDataset: false
})
}),
isReleased: true
})

cy.customMount(<DatasetActionButtons dataset={dataset} />)
Expand All @@ -37,5 +39,6 @@ describe('DatasetActionButtons', () => {
cy.findByRole('button', { name: 'Access Dataset' }).should('exist')
cy.findByRole('button', { name: 'Submit for Review' }).should('exist')
cy.findByRole('button', { name: 'Edit Dataset' }).should('exist')
cy.findByRole('button', { name: 'Link Dataset' }).should('exist')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
DatasetMother,
DatasetVersionMother
} from '../../../../dataset/domain/models/DatasetMother'
import { LinkDatasetButton } from '../../../../../../src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton'

describe('LinkDatasetButton', () => {
it('renders the LinkDatasetButton if the user is authenticated and the dataset version is not deaccessioned and the dataset is released', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDraft(),
isReleased: true
})

cy.customMount(<LinkDatasetButton dataset={dataset} />)

cy.findByRole('button', { name: 'Link Dataset' }).should('exist')
})

it('does not render the LinkDatasetButton if the user is not authenticated', () => {
// TODO - Add session context
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDraft(),
isReleased: true
})

cy.customMount(<LinkDatasetButton dataset={dataset} />)

cy.findByRole('button', { name: 'Link Dataset' }).should('not.exist')
})

it('does not render the LinkDatasetButton if the dataset version is deaccessioned', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDeaccessioned(),
isReleased: true
})

cy.customMount(<LinkDatasetButton dataset={dataset} />)

cy.findByRole('button', { name: 'Link Dataset' }).should('not.exist')
})

it('does not render the LinkDatasetButton if the dataset is not released', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDraft(),
isReleased: false
})

cy.customMount(<LinkDatasetButton dataset={dataset} />)

cy.findByRole('button', { name: 'Link Dataset' }).should('not.exist')
})
})

0 comments on commit 6149156

Please sign in to comment.