From 6149156228f426cf57aa8018448571928aa43c39 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Tue, 12 Sep 2023 15:15:42 +0200 Subject: [PATCH] feat(DatasetActionButtons): add LinkDatasetButton component --- src/dataset/domain/models/Dataset.ts | 9 ++-- .../DatasetActionButtons.tsx | 2 + .../link-dataset-button/LinkDatasetButton.tsx | 13 +++++ .../dataset/domain/models/DatasetMother.ts | 4 +- .../DatasetActionButtons.spec.tsx | 9 ++-- .../LinkDatasetButton.spec.tsx | 52 +++++++++++++++++++ 6 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.tsx create mode 100644 tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 150e77863..eafb21d34 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -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 { @@ -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() } @@ -361,7 +363,8 @@ export class Dataset { this.permissions, this.locks, this.hasValidTermsOfAccess, - this.isValid + this.isValid, + this.isReleased ) } } diff --git a/src/sections/dataset/dataset-action-buttons/DatasetActionButtons.tsx b/src/sections/dataset/dataset-action-buttons/DatasetActionButtons.tsx index f5d535cb9..c104d248b 100644 --- a/src/sections/dataset/dataset-action-buttons/DatasetActionButtons.tsx +++ b/src/sections/dataset/dataset-action-buttons/DatasetActionButtons.tsx @@ -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 @@ -17,6 +18,7 @@ export function DatasetActionButtons({ dataset }: DatasetActionButtonsProps) { + ) } diff --git a/src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.tsx new file mode 100644 index 000000000..b23627be6 --- /dev/null +++ b/src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.tsx @@ -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 +} diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 827aa9998..a17fc57b6 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -262,6 +262,7 @@ export class DatasetMother { locks: [], hasValidTermsOfAccess: faker.datatype.boolean(), isValid: faker.datatype.boolean(), + isReleased: faker.datatype.boolean(), ...props } @@ -275,7 +276,8 @@ export class DatasetMother { dataset.permissions, dataset.locks, dataset.hasValidTermsOfAccess, - dataset.isValid + dataset.isValid, + dataset.isReleased ).build() } diff --git a/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx index f23bd04cf..c0d1e53a1 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx @@ -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() @@ -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', () => { @@ -28,7 +29,8 @@ describe('DatasetActionButtons', () => { canDownloadFiles: true, canUpdateDataset: true, canPublishDataset: false - }) + }), + isReleased: true }) cy.customMount() @@ -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') }) }) diff --git a/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx new file mode 100644 index 000000000..073cb2ca8 --- /dev/null +++ b/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx @@ -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() + + 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() + + 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() + + 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() + + cy.findByRole('button', { name: 'Link Dataset' }).should('not.exist') + }) +})