diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.tsx index 3899b191a..dd3e3be5e 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.tsx @@ -2,13 +2,14 @@ import { FileIngest, FileIngestStatus } from '../../../../../../../files/domain/ import { QuestionMarkTooltip } from '@iqss/dataverse-design-system' import { InfoMessageBox } from './FileInfoMessages' import { useTranslation } from 'react-i18next' +import { useDataset } from '../../../../../DatasetContext' interface IngestInfoMessageProps { ingest: FileIngest } export function IngestInfoMessage({ ingest }: IngestInfoMessageProps) { const { t } = useTranslation('files') - const userHasDatasetUpdatePermissions = true // TODO - Implement dataset permissions + const { dataset } = useDataset() if (ingest.status === FileIngestStatus.IN_PROGRESS) { return ( @@ -18,7 +19,7 @@ export function IngestInfoMessage({ ingest }: IngestInfoMessageProps) { ) } - if (ingest.status === FileIngestStatus.ERROR && userHasDatasetUpdatePermissions) { + if (ingest.status === FileIngestStatus.ERROR && dataset?.permissions.canUpdateDataset) { return ( @@ -43,5 +44,5 @@ export function IngestInfoMessage({ ingest }: IngestInfoMessageProps) { ) } - return null + return <> } diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/file-info-messages/FileInfoMessages.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/file-info-messages/FileInfoMessages.stories.tsx index cf8bc273a..7d4e4418a 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/file-info-messages/FileInfoMessages.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/file-info-messages/FileInfoMessages.stories.tsx @@ -3,12 +3,13 @@ import { WithI18next } from '../../../../../WithI18next' import { WithSettings } from '../../../../../WithSettings' import { FileInfoMessages } from '../../../../../../sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages' import { FileMother } from '../../../../../../../tests/component/files/domain/models/FileMother' +import { WithDatasetAllPermissionsGranted } from '../../../../WithDatasetAllPermissionsGranted' const meta: Meta = { title: 'Sections/Dataset Page/DatasetFiles/FilesTable/FileActionsCell/FileInfoMessages/FileInfoMessages', component: FileInfoMessages, - decorators: [WithI18next, WithSettings] + decorators: [WithI18next, WithSettings, WithDatasetAllPermissionsGranted] } export default meta diff --git a/tests/component/files/domain/models/FileMother.ts b/tests/component/files/domain/models/FileMother.ts index 79dad6101..8952971f6 100644 --- a/tests/component/files/domain/models/FileMother.ts +++ b/tests/component/files/domain/models/FileMother.ts @@ -53,6 +53,10 @@ export class FileIngestMother { reportMessage: reportMessage }) } + + static createIngestNone(): FileIngest { + return this.create({ status: FileIngestStatus.NONE }) + } } export class FileChecksumMother { diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.spec.tsx index 30506db98..ada6d3be3 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage.spec.tsx @@ -1,7 +1,32 @@ import { IngestInfoMessage } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage' import { FileIngestMother } from '../../../../../../../files/domain/models/FileMother' +import { ReactNode } from 'react' +import { Dataset as DatasetModel } from '../../../../../../../../../src/dataset/domain/models/Dataset' +import { DatasetProvider } from '../../../../../../../../../src/sections/dataset/DatasetProvider' +import { DatasetRepository } from '../../../../../../../../../src/dataset/domain/repositories/DatasetRepository' +import { + DatasetMother, + DatasetPermissionsMother +} from '../../../../../../../dataset/domain/models/DatasetMother' +const datasetRepository: DatasetRepository = {} as DatasetRepository +const datasetWithUpdatePermissions = DatasetMother.create({ + permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed() +}) describe('IngestInfoMessage', () => { + const withDataset = (component: ReactNode, dataset: DatasetModel | undefined) => { + datasetRepository.getByPersistentId = cy.stub().resolves(dataset) + datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) + + return ( + + {component} + + ) + } + it('renders the ingest in progress message', () => { cy.customMount() @@ -11,9 +36,12 @@ describe('IngestInfoMessage', () => { it('renders the ingest problem when there is an error and the user has update dataset permissions with no report message ', () => { cy.customMount( -
- -
+ withDataset( +
+ +
, + datasetWithUpdatePermissions + ) ) cy.findByText('Ingest in progress...').should('not.exist') @@ -29,9 +57,12 @@ describe('IngestInfoMessage', () => { it('renders the ingest problem when there is an error and the user has update dataset permissions with a report message', () => { cy.customMount( -
- -
+ withDataset( +
+ +
, + datasetWithUpdatePermissions + ) ) cy.findByText('Ingest in progress...').should('not.exist') @@ -42,4 +73,35 @@ describe('IngestInfoMessage', () => { cy.findByRole('link', { name: 'Tabular ingest' }).should('exist') cy.findByText(/was unsuccessful. Some message./).should('exist') }) + + it('does not render the ingest problem when there is an error and the user does not have update dataset permissions', () => { + const datasetWithoutUpdatePermissions = DatasetMother.create({ + permissions: DatasetPermissionsMother.createWithUpdateDatasetNotAllowed() + }) + cy.customMount( + withDataset( +
+ +
, + datasetWithoutUpdatePermissions + ) + ) + + cy.findByText('Ingest in progress...').should('not.exist') + cy.findByText('File available in original format only').should('not.exist') + }) + + it('does not render any message when there is no ingest status', () => { + cy.customMount( + withDataset( +
+ +
, + datasetWithUpdatePermissions + ) + ) + + cy.findByText('Ingest in progress...').should('not.exist') + cy.findByText('File available in original format only').should('not.exist') + }) })