From c5852c69c70e6f899137669849ccf5b7ee888fd0 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Wed, 13 Dec 2023 16:13:44 +0100 Subject: [PATCH 01/15] feat(FilePage): add the File Page --- public/locales/en/file.json | 6 + src/dataset/domain/models/Dataset.ts | 2 +- src/files/domain/models/File.ts | 209 +--------- src/files/domain/models/FileCriteria.ts | 2 +- src/files/domain/models/FilePreview.ts | 207 ++++++++++ src/files/domain/models/FilesCountInfo.ts | 2 +- .../domain/repositories/FileRepository.ts | 6 +- .../useCases/checkFileDownloadPermission.ts | 4 +- .../checkFileEditDatasetPermission.ts | 4 +- src/files/domain/useCases/getFileById.ts | 8 + .../useCases/getFilesByDatasetPersistentId.ts | 4 +- .../FileJSDataverseRepository.ts | 15 +- .../mappers/DomainFileMapper.ts | 2 +- .../infrastructure/mappers/JSFileMapper.ts | 8 +- .../access-dataset-menu/AccessDatasetMenu.tsx | 2 +- .../FileCriteriaFilterByType.tsx | 2 +- .../dataset-files/files-table/FilesTable.tsx | 4 +- .../files-table/FilesTableBody.tsx | 4 +- .../FilesTableColumnsDefinition.tsx | 4 +- .../files-table/FilesTableHeader.tsx | 4 +- .../file-actions/FileActionsHeader.tsx | 4 +- .../download-files/DownloadFilesButton.tsx | 4 +- .../edit-files-menu/EditFilesMenu.tsx | 4 +- .../edit-files-menu/EditFilesOptions.tsx | 4 +- .../file-actions-cell/FileActionsCell.tsx | 4 +- .../file-action-buttons/FileActionButtons.tsx | 4 +- .../access-file-menu/AccessFileMenu.tsx | 4 +- .../access-file-menu/AccessStatus.tsx | 6 +- .../access-file-menu/FileDownloadOptions.tsx | 4 +- .../FileNonTabularDownloadOptions.tsx | 7 +- .../FileTabularDownloadOptions.tsx | 7 +- .../access-file-menu/RequestAccessOption.tsx | 7 +- .../file-options-menu/FileOptionsMenu.tsx | 4 +- .../file-info-messages/FileInfoMessages.tsx | 4 +- .../file-info-messages/IngestInfoMessage.tsx | 2 +- .../file-info/file-info-cell/FileInfoCell.tsx | 4 +- .../file-info-data/FileChecksum.tsx | 2 +- .../file-info-data/FileDate.tsx | 2 +- .../file-info-data/FileDownloads.tsx | 2 +- .../file-info-data/FileEmbargoDate.tsx | 5 +- .../file-info-data/FileLabels.tsx | 2 +- .../file-info-data/FileTabularData.tsx | 2 +- .../file-info-data/FileType.tsx | 5 +- .../file-thumbnail/FileThumbnail.tsx | 4 +- .../file-thumbnail/FileThumbnailIcon.tsx | 2 +- .../FileThumbnailRestrictedIcon.tsx | 4 +- .../row-selection/useFileSelection.ts | 6 +- .../files-table/useFilesTable.tsx | 6 +- .../ZipDownloadLimitMessage.tsx | 2 +- .../dataset/dataset-files/useFiles.tsx | 8 +- src/sections/file/File.module.scss | 18 + src/sections/file/File.tsx | 40 ++ .../FilePermissionsContext.ts | 9 +- .../FilePermissionsProvider.tsx | 13 +- .../useFileDownloadPermission.tsx | 4 +- src/sections/file/useFile.tsx | 28 ++ .../domain/models/ZipDownloadLimit.ts | 2 +- .../SettingJSDataverseRepository.ts | 2 +- src/stories/WithSettings.tsx | 2 +- .../DownloadFilesButton.stories.tsx | 6 +- .../edit-files-menu/EditFilesMenu.stories.tsx | 4 +- .../AccessFileMenu.stories.tsx | 22 +- .../FileOptionsMenu.stories.tsx | 10 +- .../FileInfoMessages.stories.tsx | 10 +- .../file-info-cell/FileInfoCell.stories.tsx | 16 +- .../file-thumbnail/FileThumbnail.stories.tsx | 12 +- src/stories/files/File.stories.tsx | 22 + src/stories/files/FileMockData.ts | 10 +- .../files/FileMockLoadingRepository.ts | 34 +- src/stories/files/FileMockNoDataRepository.ts | 18 +- .../files/FileMockNoFiltersRepository.ts | 34 +- src/stories/files/FileMockRepository.ts | 15 +- .../dataset/domain/models/DatasetMother.ts | 2 +- .../files/domain/models/FileMother.ts | 383 +---------------- .../files/domain/models/FilePreviewMother.ts | 389 ++++++++++++++++++ .../domain/models/FilesCountInfoMother.tsx | 2 +- .../dataset-files/DatasetFiles.spec.tsx | 14 +- .../FileCriteriaFilterByType.spec.tsx | 2 +- .../FileCriteriaFilters.spec.tsx | 2 +- .../FileCriteriaForm.spec.tsx | 2 +- .../files-table/FilesTable.spec.tsx | 10 +- .../file-actions/FileActionsHeader.spec.tsx | 4 +- .../DownloadFilesButton.spec.tsx | 18 +- .../edit-files-menu/EditFilesMenu.spec.tsx | 4 +- .../edit-files-menu/EditFilesOptions.spec.tsx | 13 +- .../FileActionsCell.spec.tsx | 4 +- .../FileActionButtons.spec.tsx | 4 +- .../access-file-menu/AccessFileMenu.spec.tsx | 11 +- .../access-file-menu/AccessStatus.spec.tsx | 18 +- .../FileDownloadOptions.spec.tsx | 6 +- .../FileNonTabularDownloadOptions.spec.tsx | 12 +- .../FileTabularDownloadOptions.spec.tsx | 14 +- .../RequestAccessModal.spec.tsx | 8 +- .../RequestAccessOption.spec.tsx | 18 +- .../FileOptionsMenu.spec.tsx | 6 +- .../FileInfoMessages.spec.tsx | 6 +- .../IngestInfoMessage.spec.tsx | 2 +- .../file-info-data/FileChecksum.spec.tsx | 2 +- .../file-info-data/FileDate.spec.tsx | 2 +- .../file-info-data/FileDownloads.spec.tsx | 2 +- .../file-info-data/FileEmbargoDate.spec.tsx | 4 +- .../file-info-data/FileLabels.spec.tsx | 2 +- .../file-info-data/FileTitle.spec.tsx | 6 +- .../file-info-data/FileType.spec.tsx | 10 +- .../file-thumbnail/FileThumbnail.spec.tsx | 18 +- .../RowSelectionMessage.spec.tsx | 12 +- .../ZipDownloadLimitMessage.spec.tsx | 48 +-- .../dataset/dataset-files/useFiles.spec.tsx | 6 +- tests/component/sections/file/File.spec.tsx | 19 + .../useFileDownloadPermission.spec.tsx | 10 +- .../useFilePermissions.spec.tsx | 30 +- .../settings/domain/models/SettingMother.ts | 2 +- .../files/FileJSDataverseRepository.spec.ts | 6 +- .../shared/files/FileHelper.ts | 2 +- 114 files changed, 1127 insertions(+), 963 deletions(-) create mode 100644 public/locales/en/file.json create mode 100644 src/files/domain/models/FilePreview.ts create mode 100644 src/files/domain/useCases/getFileById.ts create mode 100644 src/sections/file/File.module.scss create mode 100644 src/sections/file/File.tsx create mode 100644 src/sections/file/useFile.tsx create mode 100644 src/stories/files/File.stories.tsx create mode 100644 tests/component/files/domain/models/FilePreviewMother.ts create mode 100644 tests/component/sections/file/File.spec.tsx diff --git a/public/locales/en/file.json b/public/locales/en/file.json new file mode 100644 index 000000000..9e3bd1b68 --- /dev/null +++ b/public/locales/en/file.json @@ -0,0 +1,6 @@ +{ + "tabs": { + "metadata": "Metadata" + }, + "subtext": "This file is part of \"{{datasetTitle}}\"." +} diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index f500394ae..54f97d0fc 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -1,5 +1,5 @@ import { Alert, AlertMessageKey } from '../../../alert/domain/models/Alert' -import { FileDownloadSize } from '../../../files/domain/models/File' +import { FileDownloadSize } from '../../../files/domain/models/FilePreview' export enum DatasetLabelSemanticMeaning { DATASET = 'dataset', diff --git a/src/files/domain/models/File.ts b/src/files/domain/models/File.ts index 7b78f9a47..3ee029df4 100644 --- a/src/files/domain/models/File.ts +++ b/src/files/domain/models/File.ts @@ -1,207 +1,4 @@ -import FileTypeToFriendlyTypeMap from './FileTypeToFriendlyTypeMap' - -export enum FileSizeUnit { - BYTES = 'B', - KILOBYTES = 'KB', - MEGABYTES = 'MB', - GIGABYTES = 'GB', - TERABYTES = 'TB', - PETABYTES = 'PB' -} - -export class FileSize { - static readonly multiplier = { - [FileSizeUnit.BYTES]: 1, - [FileSizeUnit.KILOBYTES]: 1024, - [FileSizeUnit.MEGABYTES]: 1024 ** 2, - [FileSizeUnit.GIGABYTES]: 1024 ** 3, - [FileSizeUnit.TERABYTES]: 1024 ** 4, - [FileSizeUnit.PETABYTES]: 1024 ** 5 - } - - constructor(readonly value: number, readonly unit: FileSizeUnit) { - ;[this.value, this.unit] = this.convertToLargestUnit(value, unit) - } - - toString(): string { - const formattedValue = - this.value % 1 === 0 ? this.value.toFixed(0) : (Math.round(this.value * 10) / 10).toString() - return `${formattedValue} ${this.unit}` - } - - toBytes(): number { - return this.value * FileSize.multiplier[this.unit] - } - - private convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] { - let convertedValue = value - let convertedUnit = unit - - while (convertedValue >= 1024 && convertedUnit !== FileSizeUnit.PETABYTES) { - convertedValue /= 1024 - convertedUnit = this.getNextUnit(convertedUnit) - } - - return [convertedValue, convertedUnit] - } - - private getNextUnit(unit: FileSizeUnit): FileSizeUnit { - switch (unit) { - case FileSizeUnit.BYTES: - return FileSizeUnit.KILOBYTES - case FileSizeUnit.KILOBYTES: - return FileSizeUnit.MEGABYTES - case FileSizeUnit.MEGABYTES: - return FileSizeUnit.GIGABYTES - case FileSizeUnit.GIGABYTES: - return FileSizeUnit.TERABYTES - case FileSizeUnit.TERABYTES: - return FileSizeUnit.PETABYTES - default: - return unit - } - } -} - -export enum FileDownloadSizeMode { - ALL = 'All', - ORIGINAL = 'Original', - ARCHIVAL = 'Archival' -} - -export class FileDownloadSize extends FileSize { - constructor( - readonly value: number, - readonly unit: FileSizeUnit, - readonly mode: FileDownloadSizeMode - ) { - super(value, unit) - } -} - -export interface FileAccess { - restricted: boolean - latestVersionRestricted: boolean - canBeRequested: boolean - requested: boolean -} - -export enum FilePublishingStatus { - DRAFT = 'draft', - RELEASED = 'released', - DEACCESSIONED = 'deaccessioned' -} - -export interface FileVersion { - number: number - publishingStatus: FilePublishingStatus -} - -export enum FileDateType { - METADATA_RELEASED = 'metadataReleased', - PUBLISHED = 'published', - DEPOSITED = 'deposited' -} - -export enum FileVersionNotNumber { - LATEST = 'latest', - DRAFT = 'draft' -} - -export interface FileDate { - type: FileDateType - date: Date -} - -export class FileEmbargo { - constructor(readonly dateAvailable: Date) {} - - get isActive(): boolean { - return this.dateAvailable > new Date() - } -} - -export interface FileTabularData { - variablesCount: number - observationsCount: number - unf?: string -} - -export enum FileLabelType { - CATEGORY = 'category', - TAG = 'tag' -} - -export interface FileLabel { - type: FileLabelType - value: string -} - -export class FileType { - constructor(readonly value: string, readonly original?: string) {} - - toDisplayFormat(): string { - return FileTypeToFriendlyTypeMap[this.value] || FileTypeToFriendlyTypeMap.unknown - } -} - -export interface FileChecksum { - algorithm: string - value: string -} - -export enum FileIngestStatus { - NONE = 'none', - IN_PROGRESS = 'inProgress', - SCHEDULED = 'scheduled', - ERROR = 'error' -} - -export interface FileIngest { - status: FileIngestStatus - reportMessage?: string -} - -export interface FileDownloadUrls { - original: string - tabular?: string - rData?: string -} - -export class File { - constructor( - readonly id: number, - readonly version: FileVersion, - readonly name: string, - readonly access: FileAccess, - readonly type: FileType, - readonly size: FileSize, - readonly date: FileDate, - readonly downloadCount: number, - readonly labels: FileLabel[], - public readonly isDeleted: boolean, - public readonly ingest: FileIngest, - public readonly downloadUrls: FileDownloadUrls, - public thumbnail?: string, - readonly directory?: string, - readonly embargo?: FileEmbargo, - readonly tabularData?: FileTabularData, - readonly description?: string, - readonly checksum?: FileChecksum - ) {} - - getLink(): string { - return `/file?id=${this.id}&version=${this.version.number}` - } - - get isActivelyEmbargoed(): boolean { - if (this.embargo) { - return this.embargo.isActive - } - return false - } - - get isTabularData(): boolean { - return this.tabularData !== undefined - } +export interface File { + name: string + datasetTitle: string } diff --git a/src/files/domain/models/FileCriteria.ts b/src/files/domain/models/FileCriteria.ts index 30720deba..11d45fbdc 100644 --- a/src/files/domain/models/FileCriteria.ts +++ b/src/files/domain/models/FileCriteria.ts @@ -1,4 +1,4 @@ -import { FileType } from './File' +import { FileType } from './FilePreview' export class FileCriteria { constructor( diff --git a/src/files/domain/models/FilePreview.ts b/src/files/domain/models/FilePreview.ts new file mode 100644 index 000000000..28ae70723 --- /dev/null +++ b/src/files/domain/models/FilePreview.ts @@ -0,0 +1,207 @@ +import FileTypeToFriendlyTypeMap from './FileTypeToFriendlyTypeMap' + +export enum FileSizeUnit { + BYTES = 'B', + KILOBYTES = 'KB', + MEGABYTES = 'MB', + GIGABYTES = 'GB', + TERABYTES = 'TB', + PETABYTES = 'PB' +} + +export class FileSize { + static readonly multiplier = { + [FileSizeUnit.BYTES]: 1, + [FileSizeUnit.KILOBYTES]: 1024, + [FileSizeUnit.MEGABYTES]: 1024 ** 2, + [FileSizeUnit.GIGABYTES]: 1024 ** 3, + [FileSizeUnit.TERABYTES]: 1024 ** 4, + [FileSizeUnit.PETABYTES]: 1024 ** 5 + } + + constructor(readonly value: number, readonly unit: FileSizeUnit) { + ;[this.value, this.unit] = this.convertToLargestUnit(value, unit) + } + + toString(): string { + const formattedValue = + this.value % 1 === 0 ? this.value.toFixed(0) : (Math.round(this.value * 10) / 10).toString() + return `${formattedValue} ${this.unit}` + } + + toBytes(): number { + return this.value * FileSize.multiplier[this.unit] + } + + private convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] { + let convertedValue = value + let convertedUnit = unit + + while (convertedValue >= 1024 && convertedUnit !== FileSizeUnit.PETABYTES) { + convertedValue /= 1024 + convertedUnit = this.getNextUnit(convertedUnit) + } + + return [convertedValue, convertedUnit] + } + + private getNextUnit(unit: FileSizeUnit): FileSizeUnit { + switch (unit) { + case FileSizeUnit.BYTES: + return FileSizeUnit.KILOBYTES + case FileSizeUnit.KILOBYTES: + return FileSizeUnit.MEGABYTES + case FileSizeUnit.MEGABYTES: + return FileSizeUnit.GIGABYTES + case FileSizeUnit.GIGABYTES: + return FileSizeUnit.TERABYTES + case FileSizeUnit.TERABYTES: + return FileSizeUnit.PETABYTES + default: + return unit + } + } +} + +export enum FileDownloadSizeMode { + ALL = 'All', + ORIGINAL = 'Original', + ARCHIVAL = 'Archival' +} + +export class FileDownloadSize extends FileSize { + constructor( + readonly value: number, + readonly unit: FileSizeUnit, + readonly mode: FileDownloadSizeMode + ) { + super(value, unit) + } +} + +export interface FileAccess { + restricted: boolean + latestVersionRestricted: boolean + canBeRequested: boolean + requested: boolean +} + +export enum FilePublishingStatus { + DRAFT = 'draft', + RELEASED = 'released', + DEACCESSIONED = 'deaccessioned' +} + +export interface FileVersion { + number: number + publishingStatus: FilePublishingStatus +} + +export enum FileDateType { + METADATA_RELEASED = 'metadataReleased', + PUBLISHED = 'published', + DEPOSITED = 'deposited' +} + +export enum FileVersionNotNumber { + LATEST = 'latest', + DRAFT = 'draft' +} + +export interface FileDate { + type: FileDateType + date: Date +} + +export class FileEmbargo { + constructor(readonly dateAvailable: Date) {} + + get isActive(): boolean { + return this.dateAvailable > new Date() + } +} + +export interface FileTabularData { + variablesCount: number + observationsCount: number + unf?: string +} + +export enum FileLabelType { + CATEGORY = 'category', + TAG = 'tag' +} + +export interface FileLabel { + type: FileLabelType + value: string +} + +export class FileType { + constructor(readonly value: string, readonly original?: string) {} + + toDisplayFormat(): string { + return FileTypeToFriendlyTypeMap[this.value] || FileTypeToFriendlyTypeMap.unknown + } +} + +export interface FileChecksum { + algorithm: string + value: string +} + +export enum FileIngestStatus { + NONE = 'none', + IN_PROGRESS = 'inProgress', + SCHEDULED = 'scheduled', + ERROR = 'error' +} + +export interface FileIngest { + status: FileIngestStatus + reportMessage?: string +} + +export interface FileDownloadUrls { + original: string + tabular?: string + rData?: string +} + +export class FilePreview { + constructor( + readonly id: number, + readonly version: FileVersion, + readonly name: string, + readonly access: FileAccess, + readonly type: FileType, + readonly size: FileSize, + readonly date: FileDate, + readonly downloadCount: number, + readonly labels: FileLabel[], + public readonly isDeleted: boolean, + public readonly ingest: FileIngest, + public readonly downloadUrls: FileDownloadUrls, + public thumbnail?: string, + readonly directory?: string, + readonly embargo?: FileEmbargo, + readonly tabularData?: FileTabularData, + readonly description?: string, + readonly checksum?: FileChecksum + ) {} + + getLink(): string { + return `/file?id=${this.id}&version=${this.version.number}` + } + + get isActivelyEmbargoed(): boolean { + if (this.embargo) { + return this.embargo.isActive + } + return false + } + + get isTabularData(): boolean { + return this.tabularData !== undefined + } +} diff --git a/src/files/domain/models/FilesCountInfo.ts b/src/files/domain/models/FilesCountInfo.ts index d8a12ee99..bc7aae4ef 100644 --- a/src/files/domain/models/FilesCountInfo.ts +++ b/src/files/domain/models/FilesCountInfo.ts @@ -1,4 +1,4 @@ -import { FileType } from './File' +import { FileType } from './FilePreview' import { FileAccessOption, FileTag } from './FileCriteria' export interface FilesCountInfo { diff --git a/src/files/domain/repositories/FileRepository.ts b/src/files/domain/repositories/FileRepository.ts index 976fd5a66..8b46323e4 100644 --- a/src/files/domain/repositories/FileRepository.ts +++ b/src/files/domain/repositories/FileRepository.ts @@ -1,9 +1,10 @@ -import { File } from '../models/File' +import { FilePreview } from '../models/FilePreview' import { FileCriteria } from '../models/FileCriteria' import { FilesCountInfo } from '../models/FilesCountInfo' import { FilePaginationInfo } from '../models/FilePaginationInfo' import { FileUserPermissions } from '../models/FileUserPermissions' import { DatasetVersion } from '../../../dataset/domain/models/Dataset' +import { File } from '../models/File' export interface FileRepository { getAllByDatasetPersistentId: ( @@ -11,7 +12,7 @@ export interface FileRepository { datasetVersion: DatasetVersion, paginationInfo?: FilePaginationInfo, criteria?: FileCriteria - ) => Promise + ) => Promise getFilesCountInfoByDatasetPersistentId: ( datasetPersistentId: string, datasetVersion: DatasetVersion, @@ -23,4 +24,5 @@ export interface FileRepository { criteria?: FileCriteria ) => Promise getUserPermissionsById: (id: number) => Promise + getById: (id: number) => Promise } diff --git a/src/files/domain/useCases/checkFileDownloadPermission.ts b/src/files/domain/useCases/checkFileDownloadPermission.ts index 974f0dd5b..091064a07 100644 --- a/src/files/domain/useCases/checkFileDownloadPermission.ts +++ b/src/files/domain/useCases/checkFileDownloadPermission.ts @@ -1,9 +1,9 @@ import { FileRepository } from '../repositories/FileRepository' -import { File, FilePublishingStatus } from '../models/File' +import { FilePreview, FilePublishingStatus } from '../models/FilePreview' export async function checkFileDownloadPermission( fileRepository: FileRepository, - file: File + file: FilePreview ): Promise { if (file.version.publishingStatus === FilePublishingStatus.DEACCESSIONED) { return fileRepository.getUserPermissionsById(file.id).then((permissions) => { diff --git a/src/files/domain/useCases/checkFileEditDatasetPermission.ts b/src/files/domain/useCases/checkFileEditDatasetPermission.ts index a2a69206f..cbb4c8f0c 100644 --- a/src/files/domain/useCases/checkFileEditDatasetPermission.ts +++ b/src/files/domain/useCases/checkFileEditDatasetPermission.ts @@ -1,9 +1,9 @@ import { FileRepository } from '../repositories/FileRepository' -import { File } from '../models/File' +import { FilePreview } from '../models/FilePreview' export async function checkFileEditDatasetPermission( fileRepository: FileRepository, - file: File + file: FilePreview ): Promise { return fileRepository.getUserPermissionsById(file.id).then((permissions) => { return permissions.canEditDataset diff --git a/src/files/domain/useCases/getFileById.ts b/src/files/domain/useCases/getFileById.ts new file mode 100644 index 000000000..9cefdae31 --- /dev/null +++ b/src/files/domain/useCases/getFileById.ts @@ -0,0 +1,8 @@ +import { FileRepository } from '../repositories/FileRepository' +import { File } from '../models/File' + +export async function getFileById(repository: FileRepository, id: number): Promise { + return repository.getById(id).catch((error: Error) => { + throw new Error(error.message) + }) +} diff --git a/src/files/domain/useCases/getFilesByDatasetPersistentId.ts b/src/files/domain/useCases/getFilesByDatasetPersistentId.ts index 326633b7d..0f0fa13e9 100644 --- a/src/files/domain/useCases/getFilesByDatasetPersistentId.ts +++ b/src/files/domain/useCases/getFilesByDatasetPersistentId.ts @@ -1,5 +1,5 @@ import { FileRepository } from '../repositories/FileRepository' -import { File } from '../models/File' +import { FilePreview } from '../models/FilePreview' import { FileCriteria } from '../models/FileCriteria' import { FilePaginationInfo } from '../models/FilePaginationInfo' import { DatasetVersion } from '../../../dataset/domain/models/Dataset' @@ -10,7 +10,7 @@ export async function getFilesByDatasetPersistentId( datasetVersion: DatasetVersion, paginationInfo?: FilePaginationInfo, criteria?: FileCriteria -): Promise { +): Promise { return fileRepository .getAllByDatasetPersistentId(datasetPersistentId, datasetVersion, paginationInfo, criteria) .catch((error: Error) => { diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index e96c994bf..7579168e6 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -1,5 +1,5 @@ import { FileRepository } from '../domain/repositories/FileRepository' -import { File } from '../domain/models/File' +import { FilePreview } from '../domain/models/FilePreview' import { FilesCountInfo } from '../domain/models/FilesCountInfo' import { FilePaginationInfo } from '../domain/models/FilePaginationInfo' import { FileUserPermissions } from '../domain/models/FileUserPermissions' @@ -19,6 +19,8 @@ import { FileCriteria } from '../domain/models/FileCriteria' import { DomainFileMapper } from './mappers/DomainFileMapper' import { JSFileMapper } from './mappers/JSFileMapper' import { DatasetVersion } from '../../dataset/domain/models/Dataset' +import { File } from '../domain/models/File' +import { FileMother } from '../../../tests/component/files/domain/models/FileMother' const includeDeaccessioned = true @@ -31,7 +33,7 @@ export class FileJSDataverseRepository implements FileRepository { datasetVersion: DatasetVersion, paginationInfo: FilePaginationInfo = new FilePaginationInfo(), criteria: FileCriteria = new FileCriteria() - ): Promise { + ): Promise { const jsPagination = DomainFileMapper.toJSPagination(paginationInfo) return getDatasetFiles .execute( @@ -155,4 +157,13 @@ export class FileJSDataverseRepository implements FileRepository { throw new Error(error.message) }) } + + // eslint-disable-next-line unused-imports/no-unused-vars + getById(id: number): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve(FileMother.createRealistic()) + }, 1000) + }) + } } diff --git a/src/files/infrastructure/mappers/DomainFileMapper.ts b/src/files/infrastructure/mappers/DomainFileMapper.ts index 71082838d..924d4e6fc 100644 --- a/src/files/infrastructure/mappers/DomainFileMapper.ts +++ b/src/files/infrastructure/mappers/DomainFileMapper.ts @@ -10,7 +10,7 @@ import { FileSearchCriteria as JSFileSearchCriteria, FileOrderCriteria as JSFileOrderCriteria } from '@iqss/dataverse-client-javascript' -import { FileType } from '../../domain/models/File' +import { FileType } from '../../domain/models/FilePreview' export class DomainFileMapper { static toJSPagination(paginationInfo: FilePaginationInfo): { diff --git a/src/files/infrastructure/mappers/JSFileMapper.ts b/src/files/infrastructure/mappers/JSFileMapper.ts index d16f872b9..b6ea1128e 100644 --- a/src/files/infrastructure/mappers/JSFileMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMapper.ts @@ -1,5 +1,5 @@ import { - File, + FilePreview, FileAccess, FileChecksum, FileDate, @@ -15,7 +15,7 @@ import { FileTabularData, FileType, FileVersion -} from '../../domain/models/File' +} from '../../domain/models/FilePreview' import { File as JSFile, FileEmbargo as JSFileEmbargo, @@ -44,8 +44,8 @@ export class JSFileMapper { downloadsCount: number, thumbnail?: string, jsTabularData?: JSFileTabularData[] - ): File { - return new File( + ): FilePreview { + return new FilePreview( this.toFileId(jsFile.id), this.toFileVersion(jsFile.version, datasetVersion, jsFile.publicationDate), this.toFileName(jsFile.name), diff --git a/src/sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu.tsx b/src/sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu.tsx index 23a52d5a5..2cb7bc3a6 100644 --- a/src/sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu.tsx +++ b/src/sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu.tsx @@ -6,7 +6,7 @@ import { import { DropdownButton, DropdownButtonItem, DropdownHeader } from '@iqss/dataverse-design-system' import { useTranslation } from 'react-i18next' -import { FileDownloadSize, FileDownloadSizeMode } from '../../../../files/domain/models/File' +import { FileDownloadSize, FileDownloadSizeMode } from '../../../../files/domain/models/FilePreview' import { Download } from 'react-bootstrap-icons' interface AccessDatasetMenuProps { diff --git a/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.tsx b/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.tsx index ff1bd0d61..4367da6be 100644 --- a/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.tsx +++ b/src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.tsx @@ -7,7 +7,7 @@ import { import { FilesCountInfo } from '../../../../files/domain/models/FilesCountInfo' import styles from './FileCriteriaForm.module.scss' import { useState } from 'react' -import { FileType } from '../../../../files/domain/models/File' +import { FileType } from '../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' interface FileCriteriaFilterByTypeProps { diff --git a/src/sections/dataset/dataset-files/files-table/FilesTable.tsx b/src/sections/dataset/dataset-files/files-table/FilesTable.tsx index fc71ef801..4ff8e8c4f 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTable.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTable.tsx @@ -2,7 +2,7 @@ import { Table } from '@iqss/dataverse-design-system' import { FilesTableHeader } from './FilesTableHeader' import { FilesTableBody } from './FilesTableBody' import { useFilesTable } from './useFilesTable' -import { File } from '../../../../files/domain/models/File' +import { FilePreview } from '../../../../files/domain/models/FilePreview' import { RowSelectionMessage } from './row-selection/RowSelectionMessage' import { ZipDownloadLimitMessage } from './zip-download-limit-message/ZipDownloadLimitMessage' import { SpinnerSymbol } from './spinner-symbol/SpinnerSymbol' @@ -12,7 +12,7 @@ import { FileSelection } from './row-selection/useFileSelection' import { FileCriteria } from '../../../../files/domain/models/FileCriteria' interface FilesTableProps { - files: File[] + files: FilePreview[] isLoading: boolean paginationInfo: FilePaginationInfo filesTotalDownloadSize: number diff --git a/src/sections/dataset/dataset-files/files-table/FilesTableBody.tsx b/src/sections/dataset/dataset-files/files-table/FilesTableBody.tsx index b91591ef7..91e09d4ea 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTableBody.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTableBody.tsx @@ -1,11 +1,11 @@ import { flexRender, Row } from '@tanstack/react-table' -import { File } from '../../../../files/domain/models/File' +import { FilePreview } from '../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' import styles from './FilesTable.module.scss' import { getCellStyle } from './FilesTable' interface FilesTableBodyProps { - rows: Row[] + rows: Row[] } export function FilesTableBody({ rows }: FilesTableBodyProps) { if (rows.length === 0) { diff --git a/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx b/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx index bdf534f62..2d437c78f 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx @@ -1,5 +1,5 @@ import { ColumnDef } from '@tanstack/react-table' -import { File } from '../../../../files/domain/models/File' +import { FilePreview } from '../../../../files/domain/models/FilePreview' import { RowSelectionCheckbox } from './row-selection/RowSelectionCheckbox' import { FileInfoCell } from './file-info/file-info-cell/FileInfoCell' import { FileInfoHeader } from './file-info/FileInfoHeader' @@ -11,7 +11,7 @@ import { FileSelection } from './row-selection/useFileSelection' export const createColumnsDefinition = ( paginationInfo: FilePaginationInfo, fileSelection: FileSelection -): ColumnDef[] => [ +): ColumnDef[] => [ { id: 'select', header: ({ table }) => ( diff --git a/src/sections/dataset/dataset-files/files-table/FilesTableHeader.tsx b/src/sections/dataset/dataset-files/files-table/FilesTableHeader.tsx index 033ed4b9b..a18e8134f 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTableHeader.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTableHeader.tsx @@ -1,10 +1,10 @@ import { flexRender, HeaderGroup } from '@tanstack/react-table' -import { File } from '../../../../files/domain/models/File' +import { FilePreview } from '../../../../files/domain/models/FilePreview' import styles from './FilesTable.module.scss' import { getCellStyle } from './FilesTable' interface FilesTableHeaderProps { - headers: HeaderGroup[] + headers: HeaderGroup[] } export function FilesTableHeader({ headers }: FilesTableHeaderProps) { diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx index 204ad474e..269ca6938 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx @@ -1,11 +1,11 @@ import { EditFilesMenu } from './edit-files-menu/EditFilesMenu' -import { File } from '../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../files/domain/models/FilePreview' import styles from './FileActionsHeader.module.scss' import { useTranslation } from 'react-i18next' import { DownloadFilesButton } from './download-files/DownloadFilesButton' import { FileSelection } from '../row-selection/useFileSelection' interface FileActionsHeaderProps { - files: File[] + files: FilePreview[] fileSelection: FileSelection } export function FileActionsHeader({ files, fileSelection }: FileActionsHeaderProps) { diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.tsx index 887b4c940..707b7c348 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.tsx @@ -1,4 +1,4 @@ -import { File } from '../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../files/domain/models/FilePreview' import { useDataset } from '../../../../DatasetContext' import { Button, DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system' import { Download } from 'react-bootstrap-icons' @@ -10,7 +10,7 @@ import { useState } from 'react' import { useNotImplementedModal } from '../../../../../not-implemented/NotImplementedModalContext' interface DownloadFilesButtonProps { - files: File[] + files: FilePreview[] fileSelection: FileSelection } diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx index 23f34bd02..67869fcf0 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx @@ -3,13 +3,13 @@ import { PencilFill } from 'react-bootstrap-icons' import { useSession } from '../../../../../session/SessionContext' import styles from './EditFilesMenu.module.scss' import { EditFilesOptions } from './EditFilesOptions' -import { File } from '../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' import { useDataset } from '../../../../DatasetContext' import { FileSelection } from '../../row-selection/useFileSelection' interface EditFilesMenuProps { - files: File[] + files: FilePreview[] fileSelection: FileSelection } const MINIMUM_FILES_COUNT_TO_SHOW_EDIT_FILES_BUTTON = 1 diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx index 4f21ec3a2..aa97a9ad2 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx @@ -1,5 +1,5 @@ import { DropdownButtonItem } from '@iqss/dataverse-design-system' -import { File } from '../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' import { useState } from 'react' import { FileSelection } from '../../row-selection/useFileSelection' @@ -7,7 +7,7 @@ import { NoSelectedFilesModal } from '../no-selected-files-modal/NoSelectedFiles import { useNotImplementedModal } from '../../../../../not-implemented/NotImplementedModalContext' interface EditFileOptionsProps { - files: File[] + files: FilePreview[] fileSelection: FileSelection } diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.tsx index 8a1053d6b..111ca468f 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.tsx @@ -1,10 +1,10 @@ -import { File } from '../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../files/domain/models/FilePreview' import { FileActionButtons } from './file-action-buttons/FileActionButtons' import { FileInfoMessages } from './file-info-messages/FileInfoMessages' import styles from './FileActionsCell.module.scss' interface FileActionsCellProps { - file: File + file: FilePreview } export function FileActionsCell({ file }: FileActionsCellProps) { return ( diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx index 20231afee..9703b36d0 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx @@ -1,11 +1,11 @@ import { AccessFileMenu } from './access-file-menu/AccessFileMenu' -import { File } from '../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../files/domain/models/FilePreview' import { FileOptionsMenu } from './file-options-menu/FileOptionsMenu' import { ButtonGroup } from '@iqss/dataverse-design-system' import { useTranslation } from 'react-i18next' interface FileActionButtonsProps { - file: File + file: FilePreview } export function FileActionButtons({ file }: FileActionButtonsProps) { const { t } = useTranslation('files') diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.tsx index 98f157ef9..bc346227c 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.tsx @@ -1,4 +1,4 @@ -import { File } from '../../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' import { Download, FileEarmark } from 'react-bootstrap-icons' import { AccessStatus } from './AccessStatus' import { RequestAccessOption } from './RequestAccessOption' @@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next' import { FileDownloadOptions } from './FileDownloadOptions' interface FileActionButtonAccessFileProps { - file: File + file: FilePreview } export function AccessFileMenu({ file }: FileActionButtonAccessFileProps) { const { t } = useTranslation('files') diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx index 2cff5b898..ea4a67a8d 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx @@ -1,4 +1,4 @@ -import { File } from '../../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' import { Globe, LockFill, UnlockFill } from 'react-bootstrap-icons' import { useTranslation } from 'react-i18next' import styles from './AccessFileMenu.module.scss' @@ -6,7 +6,7 @@ import { DropdownButtonItem } from '@iqss/dataverse-design-system' import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' interface AccessStatusProps { - file: File + file: FilePreview } export function AccessStatus({ file }: AccessStatusProps) { @@ -60,7 +60,7 @@ function AccessStatusText({ file, sessionUserHasFileDownloadPermission }: { - file: File + file: FilePreview sessionUserHasFileDownloadPermission: boolean }) { const { t } = useTranslation('files') diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.tsx index a1b98acf9..a6a735e8e 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.tsx @@ -1,13 +1,13 @@ import { DropdownHeader } from '@iqss/dataverse-design-system' import { Download } from 'react-bootstrap-icons' -import { File } from '../../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' import { FileTabularDownloadOptions } from './FileTabularDownloadOptions' import { FileNonTabularDownloadOptions } from './FileNonTabularDownloadOptions' import { useTranslation } from 'react-i18next' import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' interface FileDownloadOptionsProps { - file: File + file: FilePreview } export function FileDownloadOptions({ file }: FileDownloadOptionsProps) { diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.tsx index eb64a832d..6dfabd9a8 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.tsx @@ -1,11 +1,14 @@ -import { File, FileIngestStatus } from '../../../../../../../../files/domain/models/File' +import { + FilePreview, + FileIngestStatus +} from '../../../../../../../../files/domain/models/FilePreview' import FileTypeToFriendlyTypeMap from '../../../../../../../../files/domain/models/FileTypeToFriendlyTypeMap' import { DropdownButtonItem } from '@iqss/dataverse-design-system' import { useDataset } from '../../../../../../DatasetContext' import { useTranslation } from 'react-i18next' interface FileNonTabularDownloadOptionsProps { - file: File + file: FilePreview } export function FileNonTabularDownloadOptions({ file }: FileNonTabularDownloadOptionsProps) { diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.tsx index 0afd6d22b..3e7e8bcf6 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.tsx @@ -1,10 +1,13 @@ -import { File, FileIngestStatus } from '../../../../../../../../files/domain/models/File' +import { + FilePreview, + FileIngestStatus +} from '../../../../../../../../files/domain/models/FilePreview' import { DropdownButtonItem } from '@iqss/dataverse-design-system' import { useDataset } from '../../../../../../DatasetContext' import { useTranslation } from 'react-i18next' interface FileTabularDownloadOptionsProps { - file: File + file: FilePreview } export function FileTabularDownloadOptions({ file }: FileTabularDownloadOptionsProps) { diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.tsx index 230df2df5..c2ce0687a 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.tsx @@ -1,12 +1,15 @@ import { DropdownButtonItem } from '@iqss/dataverse-design-system' import styles from './AccessFileMenu.module.scss' import { RequestAccessModal } from './RequestAccessModal' -import { File, FilePublishingStatus } from '../../../../../../../../files/domain/models/File' +import { + FilePreview, + FilePublishingStatus +} from '../../../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' interface RequestAccessButtonProps { - file: File + file: FilePreview } export function RequestAccessOption({ file }: RequestAccessButtonProps) { const { t } = useTranslation('files') diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx index f336fe594..4bf4f89a8 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx @@ -1,4 +1,4 @@ -import { File } from '../../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' import { Button, DropdownButton, DropdownHeader, Tooltip } from '@iqss/dataverse-design-system' import { PencilFill, ThreeDotsVertical } from 'react-bootstrap-icons' import { useSession } from '../../../../../../../session/SessionContext' @@ -8,7 +8,7 @@ import { useState } from 'react' import { FileAlreadyDeletedModal } from './FileAlreadyDeletedModal' import { useDataset } from '../../../../../../DatasetContext' -export function FileOptionsMenu({ file }: { file: File }) { +export function FileOptionsMenu({ file }: { file: FilePreview }) { const { t } = useTranslation('files') const { user } = useSession() const { dataset } = useDataset() diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.tsx index c7eb6292c..c9362de9c 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.tsx @@ -1,12 +1,12 @@ import styles from './FileInfoMessages.module.scss' import { ReactNode } from 'react' import { InfoCircleFill } from 'react-bootstrap-icons' -import { File } from '../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../files/domain/models/FilePreview' import { IngestInfoMessage } from './IngestInfoMessage' import { AccessRequestedInfoMessage } from './AccessRequestedInfoMessage' interface FileInfoMessagesProps { - file: File + file: FilePreview } export function FileInfoMessages({ file }: FileInfoMessagesProps) { 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 dd3e3be5e..8dbf671af 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 @@ -1,4 +1,4 @@ -import { FileIngest, FileIngestStatus } from '../../../../../../../files/domain/models/File' +import { FileIngest, FileIngestStatus } from '../../../../../../../files/domain/models/FilePreview' import { QuestionMarkTooltip } from '@iqss/dataverse-design-system' import { InfoMessageBox } from './FileInfoMessages' import { useTranslation } from 'react-i18next' diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx index 1faa1a494..f83f18ba1 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx @@ -1,4 +1,4 @@ -import { File } from '../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../files/domain/models/FilePreview' import styles from './FileInfoCell.module.scss' import { FileThumbnail } from './file-info-data/file-thumbnail/FileThumbnail' import { FileTitle } from './file-info-data/FileTitle' @@ -12,7 +12,7 @@ import { FileTabularData } from './file-info-data/FileTabularData' import { FileDescription } from './file-info-data/FileDescription' import { FileLabels } from './file-info-data/FileLabels' -export function FileInfoCell({ file }: { file: File }) { +export function FileInfoCell({ file }: { file: FilePreview }) { return (
diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileChecksum.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileChecksum.tsx index dc7d6d8d4..a853c2ad2 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileChecksum.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileChecksum.tsx @@ -1,6 +1,6 @@ import styles from '../FileInfoCell.module.scss' import { CopyToClipboardButton } from './copy-to-clipboard-button/CopyToClipboardButton' -import { FileChecksum as FileChecksumModel } from '../../../../../../../files/domain/models/File' +import { FileChecksum as FileChecksumModel } from '../../../../../../../files/domain/models/FilePreview' export function FileChecksum({ checksum }: { checksum: FileChecksumModel | undefined }) { if (!checksum) { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx index 61ddb0c44..597ec8a87 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx @@ -1,4 +1,4 @@ -import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/File' +import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' export function FileDate({ date }: { date: FileDateModel }) { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDownloads.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDownloads.tsx index 976863a23..b829859fb 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDownloads.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDownloads.tsx @@ -1,4 +1,4 @@ -import { FilePublishingStatus } from '../../../../../../../files/domain/models/File' +import { FilePublishingStatus } from '../../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' interface FileDownloadsProps { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx index 4c61171b9..b05471d8e 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx @@ -1,4 +1,7 @@ -import { FileEmbargo, FilePublishingStatus } from '../../../../../../../files/domain/models/File' +import { + FileEmbargo, + FilePublishingStatus +} from '../../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' interface FileEmbargoDateProps { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileLabels.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileLabels.tsx index 8b3ae274a..8c51df433 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileLabels.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileLabels.tsx @@ -1,4 +1,4 @@ -import { FileLabel, FileLabelType } from '../../../../../../../files/domain/models/File' +import { FileLabel, FileLabelType } from '../../../../../../../files/domain/models/FilePreview' import { Badge } from '@iqss/dataverse-design-system' import styles from '../FileInfoCell.module.scss' diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTabularData.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTabularData.tsx index 21770da2e..c61a5b9d6 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTabularData.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTabularData.tsx @@ -1,4 +1,4 @@ -import { FileTabularData as FileTabularDataModel } from '../../../../../../../files/domain/models/File' +import { FileTabularData as FileTabularDataModel } from '../../../../../../../files/domain/models/FilePreview' import { CopyToClipboardButton } from './copy-to-clipboard-button/CopyToClipboardButton' import { useTranslation } from 'react-i18next' diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileType.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileType.tsx index e7fb9725b..c4ab50a0c 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileType.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileType.tsx @@ -1,4 +1,7 @@ -import { FileSize, FileType as FileTypeModel } from '../../../../../../../files/domain/models/File' +import { + FileSize, + FileType as FileTypeModel +} from '../../../../../../../files/domain/models/FilePreview' import { useTranslation } from 'react-i18next' interface FileTypeProps { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx index c4176dabb..ed343cf42 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx @@ -1,12 +1,12 @@ import { FileThumbnailIcon } from './FileThumbnailIcon' import { FileThumbnailPreviewImage } from './FileThumbnailPreviewImage' -import { File } from '../../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' import { FileThumbnailRestrictedIcon } from './FileThumbnailRestrictedIcon' import styles from './FileThumbnail.module.scss' import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' interface FileThumbnailProps { - file: File + file: FilePreview } export function FileThumbnail({ file }: FileThumbnailProps) { diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailIcon.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailIcon.tsx index 7d406f9c9..1f4749630 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailIcon.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailIcon.tsx @@ -1,5 +1,5 @@ import styles from './FileThumbnail.module.scss' -import { FileType } from '../../../../../../../../files/domain/models/File' +import { FileType } from '../../../../../../../../files/domain/models/FilePreview' import { FileTypeToFileIconMap } from './FileTypeToFileIconMap' import { IconName } from '@iqss/dataverse-design-system' diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx index 167a14545..23f620942 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx @@ -2,10 +2,10 @@ import { LockFill, UnlockFill } from 'react-bootstrap-icons' import styles from './FileThumbnail.module.scss' import { useTranslation } from 'react-i18next' import { Tooltip } from '@iqss/dataverse-design-system' -import { File } from '../../../../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' -export function FileThumbnailRestrictedIcon({ file }: { file: File }) { +export function FileThumbnailRestrictedIcon({ file }: { file: FilePreview }) { if (!file.access.restricted) { return <> } diff --git a/src/sections/dataset/dataset-files/files-table/row-selection/useFileSelection.ts b/src/sections/dataset/dataset-files/files-table/row-selection/useFileSelection.ts index ede451ad0..8d6b540ea 100644 --- a/src/sections/dataset/dataset-files/files-table/row-selection/useFileSelection.ts +++ b/src/sections/dataset/dataset-files/files-table/row-selection/useFileSelection.ts @@ -1,15 +1,15 @@ import { useEffect, useState } from 'react' import { FilePaginationInfo } from '../../../../../files/domain/models/FilePaginationInfo' -import { File } from '../../../../../files/domain/models/File' +import { FilePreview } from '../../../../../files/domain/models/FilePreview' import { Row } from '@tanstack/react-table' import { RowSelection } from '../useFilesTable' export type FileSelection = { - [key: string]: File | undefined + [key: string]: FilePreview | undefined } export function useFileSelection( - currentPageSelectedRowModel: Record>, + currentPageSelectedRowModel: Record>, setCurrentPageRowSelection: (rowSelection: RowSelection) => void, paginationInfo: FilePaginationInfo ) { diff --git a/src/sections/dataset/dataset-files/files-table/useFilesTable.tsx b/src/sections/dataset/dataset-files/files-table/useFilesTable.tsx index b403e9782..3016c2f0e 100644 --- a/src/sections/dataset/dataset-files/files-table/useFilesTable.tsx +++ b/src/sections/dataset/dataset-files/files-table/useFilesTable.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react' -import { File } from '../../../../files/domain/models/File' +import { FilePreview } from '../../../../files/domain/models/FilePreview' import { getCoreRowModel, Row, useReactTable } from '@tanstack/react-table' import { createColumnsDefinition } from './FilesTableColumnsDefinition' import { FilePaginationInfo } from '../../../../files/domain/models/FilePaginationInfo' @@ -9,10 +9,10 @@ export type RowSelection = { [key: string]: boolean } -export function useFilesTable(files: File[], paginationInfo: FilePaginationInfo) { +export function useFilesTable(files: FilePreview[], paginationInfo: FilePaginationInfo) { const [currentPageRowSelection, setCurrentPageRowSelection] = useState({}) const [currentPageSelectedRowModel, setCurrentPageSelectedRowModel] = useState< - Record> + Record> >({}) const { fileSelection, selectAllFiles, clearFileSelection } = useFileSelection( currentPageSelectedRowModel, diff --git a/src/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.tsx b/src/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.tsx index 8181e34b5..7512fcdcd 100644 --- a/src/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.tsx +++ b/src/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.tsx @@ -1,6 +1,6 @@ import { useTranslation } from 'react-i18next' import styles from './ZipLimitMessage.module.scss' -import { FileSizeUnit } from '../../../../../files/domain/models/File' +import { FileSizeUnit } from '../../../../../files/domain/models/FilePreview' import { useSettings } from '../../../../settings/SettingsContext' import { SettingName } from '../../../../../settings/domain/models/Setting' import { ZipDownloadLimit } from '../../../../../settings/domain/models/ZipDownloadLimit' diff --git a/src/sections/dataset/dataset-files/useFiles.tsx b/src/sections/dataset/dataset-files/useFiles.tsx index 538da0921..a013be21b 100644 --- a/src/sections/dataset/dataset-files/useFiles.tsx +++ b/src/sections/dataset/dataset-files/useFiles.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react' import { FileRepository } from '../../../files/domain/repositories/FileRepository' -import { File } from '../../../files/domain/models/File' +import { FilePreview } from '../../../files/domain/models/FilePreview' import { getFilesByDatasetPersistentId } from '../../../files/domain/useCases/getFilesByDatasetPersistentId' import { FileCriteria } from '../../../files/domain/models/FileCriteria' import { FilesCountInfo } from '../../../files/domain/models/FilesCountInfo' @@ -20,7 +20,7 @@ export function useFiles( criteria?: FileCriteria ) { const { fetchFilesPermission } = useFilePermissions() - const [files, setFiles] = useState([]) + const [files, setFiles] = useState([]) const [isLoading, setIsLoading] = useState(true) const [filesCountInfo, setFilesCountInfo] = useState() const [filesTotalDownloadSize, setFilesTotalDownloadSize] = useState(0) @@ -56,11 +56,11 @@ export function useFiles( paginationInfo.withTotal(filesCount.total), criteria ) - .then((files: File[]) => { + .then((files: FilePreview[]) => { setFiles(files) return files }) - .then((files: File[]) => + .then((files: FilePreview[]) => fetchFilesPermission(FilePermission.DOWNLOAD_FILE, files).then(() => setIsLoading(false)) ) .catch(() => { diff --git a/src/sections/file/File.module.scss b/src/sections/file/File.module.scss new file mode 100644 index 000000000..2c924a81a --- /dev/null +++ b/src/sections/file/File.module.scss @@ -0,0 +1,18 @@ +@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module"; + +.header { + margin: 0.5em 0; +} + +.subtext { + color: $dv-subtext-color; +} + +.container { + margin: 0.5rem 0; +} + +.separation-line { + margin: 1em 0; + border-bottom: 1px solid #dee2e6; +} \ No newline at end of file diff --git a/src/sections/file/File.tsx b/src/sections/file/File.tsx new file mode 100644 index 000000000..3378fc9e8 --- /dev/null +++ b/src/sections/file/File.tsx @@ -0,0 +1,40 @@ +import { useTranslation } from 'react-i18next' +import { PageNotFound } from '../page-not-found/PageNotFound' +import styles from './File.module.scss' +import { Tabs } from '@iqss/dataverse-design-system' +import { FileRepository } from '../../files/domain/repositories/FileRepository' +import { useFile } from './useFile' + +interface FileProps { + repository: FileRepository + id: number +} +export function File({ repository, id }: FileProps) { + const { t } = useTranslation('file') + const { file } = useFile(repository, id) + + return ( + <> + {!file ? ( + + ) : ( +
+
+

{file.name}

+ + {t('subtext', { datasetTitle: file.datasetTitle })} + +
+
+ + + + + +
+
+
+ )} + + ) +} diff --git a/src/sections/file/file-permissions/FilePermissionsContext.ts b/src/sections/file/file-permissions/FilePermissionsContext.ts index 244d5ea52..f93adea17 100644 --- a/src/sections/file/file-permissions/FilePermissionsContext.ts +++ b/src/sections/file/file-permissions/FilePermissionsContext.ts @@ -1,10 +1,13 @@ import { createContext, useContext } from 'react' import { FilePermission } from '../../../files/domain/models/FileUserPermissions' -import { File } from '../../../files/domain/models/File' +import { FilePreview } from '../../../files/domain/models/FilePreview' interface FilePermissionsContextProps { - checkSessionUserHasFilePermission: (permission: FilePermission, file: File) => Promise - fetchFilesPermission: (permission: FilePermission, files: File[]) => Promise + checkSessionUserHasFilePermission: ( + permission: FilePermission, + file: FilePreview + ) => Promise + fetchFilesPermission: (permission: FilePermission, files: FilePreview[]) => Promise } export const FilePermissionsContext = createContext({ diff --git a/src/sections/file/file-permissions/FilePermissionsProvider.tsx b/src/sections/file/file-permissions/FilePermissionsProvider.tsx index 00945be58..bbb95649b 100644 --- a/src/sections/file/file-permissions/FilePermissionsProvider.tsx +++ b/src/sections/file/file-permissions/FilePermissionsProvider.tsx @@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react' import { FileRepository } from '../../../files/domain/repositories/FileRepository' import { FilePermission } from '../../../files/domain/models/FileUserPermissions' import { FilePermissionsContext } from './FilePermissionsContext' -import { File } from '../../../files/domain/models/File' +import { FilePreview } from '../../../files/domain/models/FilePreview' import { checkFileDownloadPermission } from '../../../files/domain/useCases/checkFileDownloadPermission' import { checkFileEditDatasetPermission } from '../../../files/domain/useCases/checkFileEditDatasetPermission' import { useAnonymized } from '../../dataset/anonymized/AnonymizedContext' @@ -35,7 +35,7 @@ export function FilePermissionsProvider({ filePermissionsMap.set(fileIdToUpdate, newValue) } } - const checkSessionUserHasFileDownloadPermission = (file: File): Promise => { + const checkSessionUserHasFileDownloadPermission = (file: FilePreview): Promise => { if (anonymizedView) { return Promise.resolve(true) // If the user is in anonymized view, they can always download the file } @@ -49,7 +49,7 @@ export function FilePermissionsProvider({ return false }) } - const checkSessionUserHasEditDatasetPermission = (file: File): Promise => { + const checkSessionUserHasEditDatasetPermission = (file: FilePreview): Promise => { return checkFileEditDatasetPermission(repository, file) .then((canEditDataset) => { updateFilePermissionsMap(file.id, FilePermission.EDIT_DATASET, canEditDataset) @@ -63,7 +63,7 @@ export function FilePermissionsProvider({ function checkSessionUserHasFilePermission( permission: FilePermission, - file: File + file: FilePreview ): Promise { if (filePermissionsMap.has(file.id)) { const savedPermission = filePermissionsMap.get(file.id)?.[permission] @@ -80,7 +80,10 @@ export function FilePermissionsProvider({ } } - function fetchFilesPermission(permission: FilePermission, files: File[]): Promise { + function fetchFilesPermission( + permission: FilePermission, + files: FilePreview[] + ): Promise { return Promise.all( files.map((file) => checkSessionUserHasFilePermission(permission, file) diff --git a/src/sections/file/file-permissions/useFileDownloadPermission.tsx b/src/sections/file/file-permissions/useFileDownloadPermission.tsx index 61e02bff7..66a9a9d7e 100644 --- a/src/sections/file/file-permissions/useFileDownloadPermission.tsx +++ b/src/sections/file/file-permissions/useFileDownloadPermission.tsx @@ -1,9 +1,9 @@ import { useEffect, useState } from 'react' import { FilePermission } from '../../../files/domain/models/FileUserPermissions' import { useFilePermissions } from './FilePermissionsContext' -import { File } from '../../../files/domain/models/File' +import { FilePreview } from '../../../files/domain/models/FilePreview' -export function useFileDownloadPermission(file: File) { +export function useFileDownloadPermission(file: FilePreview) { const { checkSessionUserHasFilePermission } = useFilePermissions() const [sessionUserHasFileDownloadPermission, setSessionUserHasFileDownloadPermission] = useState(false) diff --git a/src/sections/file/useFile.tsx b/src/sections/file/useFile.tsx new file mode 100644 index 000000000..49ff6a7d3 --- /dev/null +++ b/src/sections/file/useFile.tsx @@ -0,0 +1,28 @@ +import { useEffect, useState } from 'react' +import { FileRepository } from '../../files/domain/repositories/FileRepository' +import { getFileById } from '../../files/domain/useCases/getFileById' +import { File } from '../../files/domain/models/File' + +export function useFile(repository: FileRepository, id: number) { + const [file, setFile] = useState() + const [isLoading, setIsLoading] = useState(true) + + useEffect(() => { + setIsLoading(true) + + getFileById(repository, id) + .then((file: File) => { + setFile(file) + setIsLoading(false) + }) + .catch(() => { + throw new Error('There was an error getting the file') + setIsLoading(false) + }) + }, [repository, id]) + + return { + file, + isLoading + } +} diff --git a/src/settings/domain/models/ZipDownloadLimit.ts b/src/settings/domain/models/ZipDownloadLimit.ts index d6a6b415e..335847212 100644 --- a/src/settings/domain/models/ZipDownloadLimit.ts +++ b/src/settings/domain/models/ZipDownloadLimit.ts @@ -1,3 +1,3 @@ -import { FileSize } from '../../../files/domain/models/File' +import { FileSize } from '../../../files/domain/models/FilePreview' export class ZipDownloadLimit extends FileSize {} diff --git a/src/settings/infrastructure/SettingJSDataverseRepository.ts b/src/settings/infrastructure/SettingJSDataverseRepository.ts index e55e995fe..1a9192f7f 100644 --- a/src/settings/infrastructure/SettingJSDataverseRepository.ts +++ b/src/settings/infrastructure/SettingJSDataverseRepository.ts @@ -1,7 +1,7 @@ import { SettingRepository } from '../domain/repositories/SettingRepository' import { Setting, SettingName } from '../domain/models/Setting' import { ZipDownloadLimit } from '../domain/models/ZipDownloadLimit' -import { FileSizeUnit } from '../../files/domain/models/File' +import { FileSizeUnit } from '../../files/domain/models/FilePreview' export class SettingJSDataverseRepository implements SettingRepository { // eslint-disable-next-line unused-imports/no-unused-vars diff --git a/src/stories/WithSettings.tsx b/src/stories/WithSettings.tsx index 24764ef45..efe9a44fb 100644 --- a/src/stories/WithSettings.tsx +++ b/src/stories/WithSettings.tsx @@ -3,7 +3,7 @@ import { SettingsContext } from '../sections/settings/SettingsContext' import { Setting, SettingName } from '../settings/domain/models/Setting' import { SettingMother } from '../../tests/component/settings/domain/models/SettingMother' import { ZipDownloadLimit } from '../settings/domain/models/ZipDownloadLimit' -import { FileSizeUnit } from '../files/domain/models/File' +import { FileSizeUnit } from '../files/domain/models/FilePreview' const zipDownloadLimitMock = new ZipDownloadLimit(1, FileSizeUnit.BYTES) export const WithSettings = (Story: StoryFn) => { diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.stories.tsx index 87836ad96..8083e507f 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.stories.tsx @@ -4,7 +4,7 @@ import { WithI18next } from '../../../../../WithI18next' import { WithSettings } from '../../../../../WithSettings' import { WithLoggedInUser } from '../../../../../WithLoggedInUser' import { WithDatasetAllPermissionsGranted } from '../../../../WithDatasetAllPermissionsGranted' -import { FileMother } from '../../../../../../../tests/component/files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../tests/component/files/domain/models/FilePreviewMother' import { DownloadFilesButton } from '../../../../../../sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton' const meta: Meta = { @@ -19,7 +19,7 @@ type Story = StoryObj export const NonTabularFiles: Story = { render: () => ( ) @@ -28,7 +28,7 @@ export const NonTabularFiles: Story = { export const TabularFiles: Story = { render: () => ( export const Default: Story = { - render: () => + render: () => } diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx index b016c7722..73bc899db 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx @@ -3,7 +3,7 @@ import { AccessFileMenu } from '../../../../../../../sections/dataset/dataset-fi import { WithI18next } from '../../../../../../WithI18next' import { WithSettings } from '../../../../../../WithSettings' import { WithFilePermissionsGranted } from '../../../../../../files/file-permission/WithFilePermissionsGranted' -import { FileMother } from '../../../../../../../../tests/component/files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../tests/component/files/domain/models/FilePreviewMother' const meta: Meta = { title: @@ -17,39 +17,41 @@ type Story = StoryObj export const Default: Story = { decorators: [WithFilePermissionsGranted], - render: () => + render: () => } export const NonTabularFiles: Story = { - render: () => + render: () => } export const TabularFiles: Story = { - render: () => + render: () => } export const Restricted: Story = { - render: () => + render: () => } export const RestrictedWithAccessRequestAllowed: Story = { - render: () => + render: () => } export const RestrictedWithAccessRequestPending: Story = { - render: () => + render: () => } export const RestrictedWithAccessGranted: Story = { decorators: [WithFilePermissionsGranted], - render: () => + render: () => ( + + ) } export const WithEmbargo: Story = { decorators: [WithFilePermissionsGranted], - render: () => + render: () => } export const WithEmbargoAndRestricted: Story = { - render: () => + render: () => } diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx index 8c99a7846..9ab9cbe0d 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx @@ -3,7 +3,7 @@ import { FileOptionsMenu } from '../../../../../../../sections/dataset/dataset-f import { WithI18next } from '../../../../../../WithI18next' import { WithSettings } from '../../../../../../WithSettings' import { WithLoggedInUser } from '../../../../../../WithLoggedInUser' -import { FileMother } from '../../../../../../../../tests/component/files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../tests/component/files/domain/models/FilePreviewMother' import { WithDatasetAllPermissionsGranted } from '../../../../../WithDatasetAllPermissionsGranted' import { WithDatasetLockedFromEdits } from '../../../../../WithDatasetLockedFromEdits' @@ -19,22 +19,22 @@ type Story = StoryObj export const DefaultWithLoggedInUser: Story = { decorators: [WithDatasetAllPermissionsGranted], - render: () => + render: () => } export const Restricted: Story = { decorators: [WithDatasetAllPermissionsGranted], - render: () => + render: () => } export const WithDatasetLocked: Story = { decorators: [WithDatasetLockedFromEdits], - render: () => + render: () => } export const WithFileAlreadyDeleted: Story = { decorators: [WithDatasetAllPermissionsGranted], - render: () => + render: () => } // 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 7d4e4418a..9bb9f376d 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 @@ -2,7 +2,7 @@ import { Meta, StoryObj } from '@storybook/react' 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 { FilePreviewMother } from '../../../../../../../tests/component/files/domain/models/FilePreviewMother' import { WithDatasetAllPermissionsGranted } from '../../../../WithDatasetAllPermissionsGranted' const meta: Meta = { @@ -16,13 +16,13 @@ export default meta type Story = StoryObj export const IngestInProgress: Story = { - render: () => + render: () => } export const IngestProblemDefaultReportMessage: Story = { render: () => (
- +
) } @@ -31,12 +31,12 @@ export const IngestProblemCustomReportMessage: Story = { render: () => (
) } export const AccessRequested: Story = { - render: () => + render: () => } diff --git a/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx index 7cd2f550d..b992e8c0f 100644 --- a/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx @@ -1,7 +1,7 @@ import { Meta, StoryObj } from '@storybook/react' import { WithI18next } from '../../../../../WithI18next' import { FileInfoCell } from '../../../../../../sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell' -import { FileMother } from '../../../../../../../tests/component/files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../tests/component/files/domain/models/FilePreviewMother' const meta: Meta = { title: 'Sections/Dataset Page/DatasetFiles/FilesTable/FileInfoCell', @@ -13,29 +13,29 @@ export default meta type Story = StoryObj export const Default: Story = { - render: () => + render: () => } export const WithLabels: Story = { - render: () => + render: () => } export const WithDirectory: Story = { - render: () => + render: () => } export const WithEmbargo: Story = { - render: () => + render: () => } export const WithTabularData: Story = { - render: () => + render: () => } export const WithDescription: Story = { - render: () => + render: () => } export const WithChecksum: Story = { - render: () => + render: () => } diff --git a/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.stories.tsx index fdecf889a..a77f0de4a 100644 --- a/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.stories.tsx @@ -1,7 +1,7 @@ import { Meta, StoryObj } from '@storybook/react' import { FileThumbnail } from '../../../../../../../../sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail' import { WithI18next } from '../../../../../../../WithI18next' -import { FileMother } from '../../../../../../../../../tests/component/files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../../tests/component/files/domain/models/FilePreviewMother' import { WithFilePermissionsGranted } from '../../../../../../../files/file-permission/WithFilePermissionsGranted' const meta: Meta = { @@ -16,7 +16,7 @@ type Story = StoryObj export const WithIcon: Story = { decorators: [WithFilePermissionsGranted], render: () => { - const file = FileMother.createDefault() + const file = FilePreviewMother.createDefault() return } } @@ -24,14 +24,14 @@ export const WithIcon: Story = { export const WithThumbnailPreview: Story = { decorators: [WithFilePermissionsGranted], render: () => { - const file = FileMother.createWithThumbnail() + const file = FilePreviewMother.createWithThumbnail() return } } export const WithThumbnailRestrictedLockedIcon: Story = { render: () => { - const file = FileMother.createWithRestrictedAccess() + const file = FilePreviewMother.createWithRestrictedAccess() return } } @@ -39,7 +39,7 @@ export const WithThumbnailRestrictedLockedIcon: Story = { export const WithThumbnailRestrictedUnlockedIcon: Story = { decorators: [WithFilePermissionsGranted], render: () => { - const file = FileMother.createWithRestrictedAccessWithAccessGranted() + const file = FilePreviewMother.createWithRestrictedAccessWithAccessGranted() return } } @@ -47,7 +47,7 @@ export const WithThumbnailRestrictedUnlockedIcon: Story = { export const WithThumbnailPreviewRestrictedUnlockedIcon: Story = { decorators: [WithFilePermissionsGranted], render: () => { - const file = FileMother.createWithThumbnailRestrictedWithAccessGranted() + const file = FilePreviewMother.createWithThumbnailRestrictedWithAccessGranted() return } } diff --git a/src/stories/files/File.stories.tsx b/src/stories/files/File.stories.tsx new file mode 100644 index 000000000..fa9697942 --- /dev/null +++ b/src/stories/files/File.stories.tsx @@ -0,0 +1,22 @@ +import { Meta, StoryObj } from '@storybook/react' +import { WithI18next } from '../WithI18next' +import { FileMockRepository } from './FileMockRepository' +import { File } from '../../sections/file/File' +import { WithLayout } from '../WithLayout' + +const meta: Meta = { + title: 'Pages/File', + component: File, + decorators: [WithI18next, WithLayout], + parameters: { + // Sets the delay for all stories. + chromatic: { delay: 15000, pauseAnimationAtEnd: true } + } +} + +export default meta +type Story = StoryObj + +export const Default: Story = { + render: () => +} diff --git a/src/stories/files/FileMockData.ts b/src/stories/files/FileMockData.ts index 183b5b2e9..366ab78cb 100644 --- a/src/stories/files/FileMockData.ts +++ b/src/stories/files/FileMockData.ts @@ -1,5 +1,5 @@ -import { File, FileSize, FileSizeUnit } from '../../files/domain/models/File' -import { FileMother } from '../../../tests/component/files/domain/models/FileMother' +import { FilePreview, FileSize, FileSizeUnit } from '../../files/domain/models/FilePreview' +import { FilePreviewMother } from '../../../tests/component/files/domain/models/FilePreviewMother' import { FilePaginationInfo } from '../../files/domain/models/FilePaginationInfo' const range = (len: number) => { @@ -10,9 +10,9 @@ const range = (len: number) => { return arr } -export function makeFiles(paginationInfo: FilePaginationInfo): File[] { +export function makeFiles(paginationInfo: FilePaginationInfo): FilePreview[] { return range(paginationInfo.pageSize).map((value, index) => { - return FileMother.create({ + return FilePreviewMother.create({ id: (paginationInfo.page - 1) * paginationInfo.pageSize + index, size: new FileSize( (paginationInfo.page - 1) * paginationInfo.pageSize + index, @@ -24,4 +24,4 @@ export function makeFiles(paginationInfo: FilePaginationInfo): File[] { export const FilesMockData = ( paginationInfo: FilePaginationInfo = new FilePaginationInfo() -): File[] => makeFiles(paginationInfo) +): FilePreview[] => makeFiles(paginationInfo) diff --git a/src/stories/files/FileMockLoadingRepository.ts b/src/stories/files/FileMockLoadingRepository.ts index eff4bd897..5210f5765 100644 --- a/src/stories/files/FileMockLoadingRepository.ts +++ b/src/stories/files/FileMockLoadingRepository.ts @@ -1,18 +1,17 @@ import { FileRepository } from '../../files/domain/repositories/FileRepository' -import { File } from '../../files/domain/models/File' +import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' -import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions' -import { FileUserPermissionsMother } from '../../../tests/component/files/domain/models/FileUserPermissionsMother' import { DatasetVersion } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' +import { FileMockRepository } from './FileMockRepository' -export class FileMockLoadingRepository implements FileRepository { +export class FileMockLoadingRepository extends FileMockRepository implements FileRepository { getAllByDatasetPersistentId( // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars datasetVersion: DatasetVersion - ): Promise { + ): Promise { return new Promise(() => { setTimeout(() => { // Do nothing @@ -26,7 +25,7 @@ export class FileMockLoadingRepository implements FileRepository { // eslint-disable-next-line unused-imports/no-unused-vars datasetVersion: DatasetVersion, // eslint-disable-next-line unused-imports/no-unused-vars - criteria: FileCriteria + criteria?: FileCriteria ): Promise { return new Promise(() => { setTimeout(() => { @@ -34,27 +33,4 @@ export class FileMockLoadingRepository implements FileRepository { }, 1000) }) } - // eslint-disable-next-line unused-imports/no-unused-vars - getUserPermissionsById(id: number): Promise { - return new Promise((resolve) => { - setTimeout(() => { - resolve(FileUserPermissionsMother.create()) - }, 1000) - }) - } - - getFilesTotalDownloadSizeByDatasetPersistentId( - // eslint-disable-next-line unused-imports/no-unused-vars - datasetPersistentId: string, - // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion, - // eslint-disable-next-line unused-imports/no-unused-vars - criteria?: FileCriteria - ): Promise { - return new Promise((resolve) => { - setTimeout(() => { - resolve(19900) - }, 1000) - }) - } } diff --git a/src/stories/files/FileMockNoDataRepository.ts b/src/stories/files/FileMockNoDataRepository.ts index ba7c10a3b..22a1ad3a5 100644 --- a/src/stories/files/FileMockNoDataRepository.ts +++ b/src/stories/files/FileMockNoDataRepository.ts @@ -1,19 +1,18 @@ import { FileRepository } from '../../files/domain/repositories/FileRepository' -import { File } from '../../files/domain/models/File' +import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' import { FilesCountInfoMother } from '../../../tests/component/files/domain/models/FilesCountInfoMother' -import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions' -import { FileUserPermissionsMother } from '../../../tests/component/files/domain/models/FileUserPermissionsMother' import { DatasetVersion } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' +import { FileMockRepository } from './FileMockRepository' -export class FileMockNoDataRepository implements FileRepository { +export class FileMockNoDataRepository extends FileMockRepository implements FileRepository { getAllByDatasetPersistentId( // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars datasetVersion: DatasetVersion - ): Promise { + ): Promise { return new Promise((resolve) => { setTimeout(() => { resolve([]) @@ -48,13 +47,4 @@ export class FileMockNoDataRepository implements FileRepository { }, 1000) }) } - - // eslint-disable-next-line unused-imports/no-unused-vars - getUserPermissionsById(id: number): Promise { - return new Promise((resolve) => { - setTimeout(() => { - resolve(FileUserPermissionsMother.create()) - }, 1000) - }) - } } diff --git a/src/stories/files/FileMockNoFiltersRepository.ts b/src/stories/files/FileMockNoFiltersRepository.ts index eec689eaa..cdddea3ef 100644 --- a/src/stories/files/FileMockNoFiltersRepository.ts +++ b/src/stories/files/FileMockNoFiltersRepository.ts @@ -1,20 +1,19 @@ import { FileRepository } from '../../files/domain/repositories/FileRepository' -import { File } from '../../files/domain/models/File' +import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' import { FilesCountInfoMother } from '../../../tests/component/files/domain/models/FilesCountInfoMother' import { FilesMockData } from './FileMockData' -import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions' -import { FileUserPermissionsMother } from '../../../tests/component/files/domain/models/FileUserPermissionsMother' import { DatasetVersion } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' +import { FileMockRepository } from './FileMockRepository' -export class FileMockNoFiltersRepository implements FileRepository { +export class FileMockNoFiltersRepository extends FileMockRepository implements FileRepository { getAllByDatasetPersistentId( // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars datasetVersion: DatasetVersion - ): Promise { + ): Promise { return new Promise((resolve) => { setTimeout(() => { resolve(FilesMockData()) @@ -28,7 +27,7 @@ export class FileMockNoFiltersRepository implements FileRepository { // eslint-disable-next-line unused-imports/no-unused-vars datasetVersion: DatasetVersion, // eslint-disable-next-line unused-imports/no-unused-vars - criteria: FileCriteria + criteria?: FileCriteria ): Promise { return new Promise((resolve) => { setTimeout(() => { @@ -36,27 +35,4 @@ export class FileMockNoFiltersRepository implements FileRepository { }, 1000) }) } - // eslint-disable-next-line unused-imports/no-unused-vars - getUserPermissionsById(id: number): Promise { - return new Promise((resolve) => { - setTimeout(() => { - resolve(FileUserPermissionsMother.create()) - }, 1000) - }) - } - - getFilesTotalDownloadSizeByDatasetPersistentId( - // eslint-disable-next-line unused-imports/no-unused-vars - datasetPersistentId: string, - // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion, - // eslint-disable-next-line unused-imports/no-unused-vars - criteria?: FileCriteria - ): Promise { - return new Promise((resolve) => { - setTimeout(() => { - resolve(19900) - }, 1000) - }) - } } diff --git a/src/stories/files/FileMockRepository.ts b/src/stories/files/FileMockRepository.ts index 63e1499fa..ecd9036ab 100644 --- a/src/stories/files/FileMockRepository.ts +++ b/src/stories/files/FileMockRepository.ts @@ -1,6 +1,6 @@ import { FileRepository } from '../../files/domain/repositories/FileRepository' import { FilesMockData } from './FileMockData' -import { File } from '../../files/domain/models/File' +import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' import { FilesCountInfoMother } from '../../../tests/component/files/domain/models/FilesCountInfoMother' import { FilePaginationInfo } from '../../files/domain/models/FilePaginationInfo' @@ -8,6 +8,8 @@ import { FileUserPermissionsMother } from '../../../tests/component/files/domain import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions' import { DatasetVersion } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' +import { File } from '../../files/domain/models/File' +import { FileMother } from '../../../tests/component/files/domain/models/FileMother' export class FileMockRepository implements FileRepository { // eslint-disable-next-line unused-imports/no-unused-vars @@ -15,7 +17,7 @@ export class FileMockRepository implements FileRepository { datasetPersistentId: string, datasetVersion: DatasetVersion, paginationInfo?: FilePaginationInfo - ): Promise { + ): Promise { return new Promise((resolve) => { setTimeout(() => { resolve(FilesMockData(paginationInfo)) @@ -59,4 +61,13 @@ export class FileMockRepository implements FileRepository { }, 1000) }) } + + // eslint-disable-next-line unused-imports/no-unused-vars + getById(id: number): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve(FileMother.createRealistic()) + }, 1000) + }) + } } diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 460ecfb53..b93a3a41b 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -16,7 +16,7 @@ import { FileDownloadSize, FileDownloadSizeMode, FileSizeUnit -} from '../../../../../src/files/domain/models/File' +} from '../../../../../src/files/domain/models/FilePreview' export class DatasetVersionMother { static create(props?: Partial): DatasetVersion { diff --git a/tests/component/files/domain/models/FileMother.ts b/tests/component/files/domain/models/FileMother.ts index 880cbb459..f1b97fbd5 100644 --- a/tests/component/files/domain/models/FileMother.ts +++ b/tests/component/files/domain/models/FileMother.ts @@ -1,389 +1,20 @@ +import { File } from '../../../../../src/files/domain/models/File' import { faker } from '@faker-js/faker' -import { - File, - FileDateType, - FileEmbargo, - FileIngest, - FileIngestStatus, - FileLabel, - FileLabelType, - FileSize, - FileSizeUnit, - FilePublishingStatus, - FileType, - FileChecksum -} from '../../../../../src/files/domain/models/File' -import FileTypeToFriendlyTypeMap from '../../../../../src/files/domain/models/FileTypeToFriendlyTypeMap' - -const valueOrUndefined: (value: T) => T | undefined = (value) => { - const shouldShowValue = faker.datatype.boolean() - return shouldShowValue ? value : undefined -} - -const createFakeFileLabel = (): FileLabel => ({ - type: faker.helpers.arrayElement(Object.values(FileLabelType)), - value: faker.lorem.word() -}) - -export class FileEmbargoMother { - static create(dateAvailable?: Date): FileEmbargo { - return new FileEmbargo(dateAvailable ?? faker.date.future()) - } - - static createNotActive(): FileEmbargo { - const dateAvailable = faker.date.past() - return new FileEmbargo(dateAvailable) - } -} -export class FileIngestMother { - static create(props?: Partial): FileIngest { - return { - status: faker.helpers.arrayElement(Object.values(FileIngestStatus)), - reportMessage: valueOrUndefined(faker.lorem.sentence()), - ...props - } - } - - static createInProgress(): FileIngest { - return this.create({ status: FileIngestStatus.IN_PROGRESS }) - } - - static createIngestProblem(reportMessage?: string): FileIngest { - return this.create({ - status: FileIngestStatus.ERROR, - reportMessage: reportMessage - }) - } - - static createIngestNone(): FileIngest { - return this.create({ status: FileIngestStatus.NONE }) - } -} - -export class FileChecksumMother { - static create(props?: Partial): FileChecksum { - return { - algorithm: faker.lorem.word(), - value: faker.datatype.uuid(), - ...props - } - } -} export class FileMother { static create(props?: Partial): File { - const thumbnail = valueOrUndefined(faker.image.imageUrl()) - const fileType = faker.helpers.arrayElement(Object.keys(FileTypeToFriendlyTypeMap)) - const checksum = valueOrUndefined(faker.datatype.uuid()) - const fileMockedData = { - id: faker.datatype.number(), + return { name: faker.system.fileName(), - access: { - restricted: faker.datatype.boolean(), - latestVersionRestricted: faker.datatype.boolean(), - canBeRequested: faker.datatype.boolean(), - requested: faker.datatype.boolean() - }, - version: { - number: faker.datatype.number(), - publishingStatus: faker.helpers.arrayElement(Object.values(FilePublishingStatus)) - }, - type: - fileType === 'text/tab-separated-values' - ? new FileType('text/tab-separated-values', 'Comma Separated Values') - : new FileType(thumbnail ? 'image' : fileType), - size: { - value: faker.datatype.number({ max: 1024, precision: 2 }), - unit: faker.helpers.arrayElement(Object.values(FileSizeUnit)) - }, - date: { - type: faker.helpers.arrayElement(Object.values(FileDateType)), - date: faker.date.recent() - }, - downloadCount: faker.datatype.number(40), - labels: faker.datatype.boolean() - ? faker.helpers.arrayElements([ - createFakeFileLabel(), - createFakeFileLabel(), - createFakeFileLabel(), - createFakeFileLabel() - ]) - : [], - checksum: FileChecksumMother.create(), - thumbnail: thumbnail, - directory: valueOrUndefined(faker.system.directoryPath()), - embargo: valueOrUndefined(FileEmbargoMother.create()), - tabularData: - fileType === 'text/tab-separated-values' && !checksum - ? { - variablesCount: faker.datatype.number(100), - observationsCount: faker.datatype.number(100), - unf: `UNF:6:${faker.datatype.uuid()}==` - } - : undefined, - description: valueOrUndefined(faker.lorem.paragraph()), - isDeleted: faker.datatype.boolean(), - ingest: { status: FileIngestStatus.NONE }, - downloadUrls: { - original: this.createDownloadUrl(), - tabular: this.createDownloadUrl(), - rData: this.createDownloadUrl() - }, - ...props - } - - return new File( - fileMockedData.id, - fileMockedData.version, - fileMockedData.name, - fileMockedData.access, - fileMockedData.type, - new FileSize(fileMockedData.size.value, fileMockedData.size.unit), - fileMockedData.date, - fileMockedData.downloadCount, - fileMockedData.labels, - fileMockedData.isDeleted, - fileMockedData.ingest, - fileMockedData.downloadUrls, - fileMockedData.thumbnail, - fileMockedData.directory, - fileMockedData.embargo, - fileMockedData.tabularData, - fileMockedData.description, - fileMockedData.checksum - ) - } - - static createDownloadUrl(): string { - const blob = new Blob(['Name,Age,Location\nJohn,25,New York\nJane,30,San Francisco'], { - type: 'text/csv' - }) - return URL.createObjectURL(blob) - } - - static createMany(quantity: number, props?: Partial): File[] { - return Array.from({ length: quantity }).map(() => this.create(props)) - } - - static createDefault(props?: Partial): File { - const defaultFile = { - type: new FileType('text/plain'), - version: { - number: 1, - publishingStatus: FilePublishingStatus.RELEASED - }, - access: { - restricted: false, - latestVersionRestricted: false, - canBeRequested: false, - requested: false - }, - permissions: { canDownload: true }, - labels: [], - checksum: undefined, - thumbnail: undefined, - directory: undefined, - embargo: undefined, - tabularData: undefined, - description: undefined, - isDeleted: false, + datasetTitle: faker.lorem.words(3), ...props } - return this.create(defaultFile) - } - - static createWithLabels(): File { - return this.createDefault({ - labels: faker.helpers.arrayElements([ - createFakeFileLabel(), - createFakeFileLabel(), - createFakeFileLabel(), - createFakeFileLabel() - ]) - }) - } - - static createWithDirectory(): File { - return this.createDefault({ directory: faker.system.directoryPath() }) - } - - static createWithEmbargo(): File { - return this.createDefault({ - embargo: FileEmbargoMother.create() - }) - } - - static createWithEmbargoRestricted(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: false, - requested: false - }, - embargo: FileEmbargoMother.create() - }) } - static createTabular(props?: Partial): File { - return this.createDefault({ - type: new FileType('text/tab-separated-values', 'Comma Separated Values'), - tabularData: { - variablesCount: faker.datatype.number(100), - observationsCount: faker.datatype.number(100), - unf: `UNF:${faker.datatype.uuid()}==` - }, - ...props - }) - } - - static createNonTabular(props?: Partial): File { - return this.createDefault({ - type: new FileType('text/plain'), - tabularData: undefined, + static createRealistic(props?: Partial): File { + return this.create({ + name: 'file.csv', + datasetTitle: 'Dataset title', ...props }) } - - static createWithDescription(): File { - return this.createDefault({ - description: faker.lorem.paragraph() - }) - } - - static createWithChecksum(): File { - return this.createDefault({ - checksum: FileChecksumMother.create() - }) - } - - static createWithPublicAccess(): File { - return this.createDefault({ - access: { - restricted: false, - latestVersionRestricted: false, - canBeRequested: false, - requested: false - }, - embargo: undefined - }) - } - - static createWithPublicAccessButLatestVersionRestricted(): File { - return this.createDefault({ - access: { - restricted: false, - latestVersionRestricted: true, - canBeRequested: false, - requested: false - }, - embargo: undefined - }) - } - - static createWithRestrictedAccess(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: false, - requested: false - }, - embargo: undefined - }) - } - - static createWithRestrictedAccessWithAccessGranted(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: true, - requested: false - }, - embargo: undefined - }) - } - - static createWithAccessRequestAllowed(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: true, - requested: false - }, - embargo: undefined - }) - } - - static createWithAccessRequestPending(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: true, - requested: true - }, - embargo: undefined - }) - } - - static createWithThumbnail(): File { - return this.createDefault({ - thumbnail: faker.image.imageUrl() - }) - } - - static createWithThumbnailRestrictedWithAccessGranted(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: true, - requested: false - }, - thumbnail: faker.image.imageUrl(), - type: new FileType('image') - }) - } - - static createWithThumbnailRestricted(): File { - return this.createDefault({ - access: { - restricted: true, - latestVersionRestricted: true, - canBeRequested: false, - requested: false - }, - thumbnail: faker.image.imageUrl(), - type: new FileType('image') - }) - } - - static createDeaccessioned(): File { - return this.createDefault({ - version: { - number: 1, - publishingStatus: FilePublishingStatus.DEACCESSIONED - } - }) - } - static createDeleted(): File { - return this.createDefault({ - isDeleted: true - }) - } - - static createIngestInProgress(): File { - return this.createDefault({ - ingest: FileIngestMother.createInProgress() - }) - } - - static createIngestProblem(reportMessage?: string): File { - return this.createDefault({ - ingest: FileIngestMother.createIngestProblem(reportMessage) - }) - } } diff --git a/tests/component/files/domain/models/FilePreviewMother.ts b/tests/component/files/domain/models/FilePreviewMother.ts new file mode 100644 index 000000000..020523068 --- /dev/null +++ b/tests/component/files/domain/models/FilePreviewMother.ts @@ -0,0 +1,389 @@ +import { faker } from '@faker-js/faker' +import { + FilePreview, + FileDateType, + FileEmbargo, + FileIngest, + FileIngestStatus, + FileLabel, + FileLabelType, + FileSize, + FileSizeUnit, + FilePublishingStatus, + FileType, + FileChecksum +} from '../../../../../src/files/domain/models/FilePreview' +import FileTypeToFriendlyTypeMap from '../../../../../src/files/domain/models/FileTypeToFriendlyTypeMap' + +const valueOrUndefined: (value: T) => T | undefined = (value) => { + const shouldShowValue = faker.datatype.boolean() + return shouldShowValue ? value : undefined +} + +const createFakeFileLabel = (): FileLabel => ({ + type: faker.helpers.arrayElement(Object.values(FileLabelType)), + value: faker.lorem.word() +}) + +export class FileEmbargoMother { + static create(dateAvailable?: Date): FileEmbargo { + return new FileEmbargo(dateAvailable ?? faker.date.future()) + } + + static createNotActive(): FileEmbargo { + const dateAvailable = faker.date.past() + return new FileEmbargo(dateAvailable) + } +} +export class FileIngestMother { + static create(props?: Partial): FileIngest { + return { + status: faker.helpers.arrayElement(Object.values(FileIngestStatus)), + reportMessage: valueOrUndefined(faker.lorem.sentence()), + ...props + } + } + + static createInProgress(): FileIngest { + return this.create({ status: FileIngestStatus.IN_PROGRESS }) + } + + static createIngestProblem(reportMessage?: string): FileIngest { + return this.create({ + status: FileIngestStatus.ERROR, + reportMessage: reportMessage + }) + } + + static createIngestNone(): FileIngest { + return this.create({ status: FileIngestStatus.NONE }) + } +} + +export class FileChecksumMother { + static create(props?: Partial): FileChecksum { + return { + algorithm: faker.lorem.word(), + value: faker.datatype.uuid(), + ...props + } + } +} + +export class FilePreviewMother { + static create(props?: Partial): FilePreview { + const thumbnail = valueOrUndefined(faker.image.imageUrl()) + const fileType = faker.helpers.arrayElement(Object.keys(FileTypeToFriendlyTypeMap)) + const checksum = valueOrUndefined(faker.datatype.uuid()) + const fileMockedData = { + id: faker.datatype.number(), + name: faker.system.fileName(), + access: { + restricted: faker.datatype.boolean(), + latestVersionRestricted: faker.datatype.boolean(), + canBeRequested: faker.datatype.boolean(), + requested: faker.datatype.boolean() + }, + version: { + number: faker.datatype.number(), + publishingStatus: faker.helpers.arrayElement(Object.values(FilePublishingStatus)) + }, + type: + fileType === 'text/tab-separated-values' + ? new FileType('text/tab-separated-values', 'Comma Separated Values') + : new FileType(thumbnail ? 'image' : fileType), + size: { + value: faker.datatype.number({ max: 1024, precision: 2 }), + unit: faker.helpers.arrayElement(Object.values(FileSizeUnit)) + }, + date: { + type: faker.helpers.arrayElement(Object.values(FileDateType)), + date: faker.date.recent() + }, + downloadCount: faker.datatype.number(40), + labels: faker.datatype.boolean() + ? faker.helpers.arrayElements([ + createFakeFileLabel(), + createFakeFileLabel(), + createFakeFileLabel(), + createFakeFileLabel() + ]) + : [], + checksum: FileChecksumMother.create(), + thumbnail: thumbnail, + directory: valueOrUndefined(faker.system.directoryPath()), + embargo: valueOrUndefined(FileEmbargoMother.create()), + tabularData: + fileType === 'text/tab-separated-values' && !checksum + ? { + variablesCount: faker.datatype.number(100), + observationsCount: faker.datatype.number(100), + unf: `UNF:6:${faker.datatype.uuid()}==` + } + : undefined, + description: valueOrUndefined(faker.lorem.paragraph()), + isDeleted: faker.datatype.boolean(), + ingest: { status: FileIngestStatus.NONE }, + downloadUrls: { + original: this.createDownloadUrl(), + tabular: this.createDownloadUrl(), + rData: this.createDownloadUrl() + }, + ...props + } + + return new FilePreview( + fileMockedData.id, + fileMockedData.version, + fileMockedData.name, + fileMockedData.access, + fileMockedData.type, + new FileSize(fileMockedData.size.value, fileMockedData.size.unit), + fileMockedData.date, + fileMockedData.downloadCount, + fileMockedData.labels, + fileMockedData.isDeleted, + fileMockedData.ingest, + fileMockedData.downloadUrls, + fileMockedData.thumbnail, + fileMockedData.directory, + fileMockedData.embargo, + fileMockedData.tabularData, + fileMockedData.description, + fileMockedData.checksum + ) + } + + static createDownloadUrl(): string { + const blob = new Blob(['Name,Age,Location\nJohn,25,New York\nJane,30,San Francisco'], { + type: 'text/csv' + }) + return URL.createObjectURL(blob) + } + + static createMany(quantity: number, props?: Partial): FilePreview[] { + return Array.from({ length: quantity }).map(() => this.create(props)) + } + + static createDefault(props?: Partial): FilePreview { + const defaultFile = { + type: new FileType('text/plain'), + version: { + number: 1, + publishingStatus: FilePublishingStatus.RELEASED + }, + access: { + restricted: false, + latestVersionRestricted: false, + canBeRequested: false, + requested: false + }, + permissions: { canDownload: true }, + labels: [], + checksum: undefined, + thumbnail: undefined, + directory: undefined, + embargo: undefined, + tabularData: undefined, + description: undefined, + isDeleted: false, + ...props + } + return this.create(defaultFile) + } + + static createWithLabels(): FilePreview { + return this.createDefault({ + labels: faker.helpers.arrayElements([ + createFakeFileLabel(), + createFakeFileLabel(), + createFakeFileLabel(), + createFakeFileLabel() + ]) + }) + } + + static createWithDirectory(): FilePreview { + return this.createDefault({ directory: faker.system.directoryPath() }) + } + + static createWithEmbargo(): FilePreview { + return this.createDefault({ + embargo: FileEmbargoMother.create() + }) + } + + static createWithEmbargoRestricted(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: false, + requested: false + }, + embargo: FileEmbargoMother.create() + }) + } + + static createTabular(props?: Partial): FilePreview { + return this.createDefault({ + type: new FileType('text/tab-separated-values', 'Comma Separated Values'), + tabularData: { + variablesCount: faker.datatype.number(100), + observationsCount: faker.datatype.number(100), + unf: `UNF:${faker.datatype.uuid()}==` + }, + ...props + }) + } + + static createNonTabular(props?: Partial): FilePreview { + return this.createDefault({ + type: new FileType('text/plain'), + tabularData: undefined, + ...props + }) + } + + static createWithDescription(): FilePreview { + return this.createDefault({ + description: faker.lorem.paragraph() + }) + } + + static createWithChecksum(): FilePreview { + return this.createDefault({ + checksum: FileChecksumMother.create() + }) + } + + static createWithPublicAccess(): FilePreview { + return this.createDefault({ + access: { + restricted: false, + latestVersionRestricted: false, + canBeRequested: false, + requested: false + }, + embargo: undefined + }) + } + + static createWithPublicAccessButLatestVersionRestricted(): FilePreview { + return this.createDefault({ + access: { + restricted: false, + latestVersionRestricted: true, + canBeRequested: false, + requested: false + }, + embargo: undefined + }) + } + + static createWithRestrictedAccess(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: false, + requested: false + }, + embargo: undefined + }) + } + + static createWithRestrictedAccessWithAccessGranted(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: true, + requested: false + }, + embargo: undefined + }) + } + + static createWithAccessRequestAllowed(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: true, + requested: false + }, + embargo: undefined + }) + } + + static createWithAccessRequestPending(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: true, + requested: true + }, + embargo: undefined + }) + } + + static createWithThumbnail(): FilePreview { + return this.createDefault({ + thumbnail: faker.image.imageUrl() + }) + } + + static createWithThumbnailRestrictedWithAccessGranted(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: true, + requested: false + }, + thumbnail: faker.image.imageUrl(), + type: new FileType('image') + }) + } + + static createWithThumbnailRestricted(): FilePreview { + return this.createDefault({ + access: { + restricted: true, + latestVersionRestricted: true, + canBeRequested: false, + requested: false + }, + thumbnail: faker.image.imageUrl(), + type: new FileType('image') + }) + } + + static createDeaccessioned(): FilePreview { + return this.createDefault({ + version: { + number: 1, + publishingStatus: FilePublishingStatus.DEACCESSIONED + } + }) + } + static createDeleted(): FilePreview { + return this.createDefault({ + isDeleted: true + }) + } + + static createIngestInProgress(): FilePreview { + return this.createDefault({ + ingest: FileIngestMother.createInProgress() + }) + } + + static createIngestProblem(reportMessage?: string): FilePreview { + return this.createDefault({ + ingest: FileIngestMother.createIngestProblem(reportMessage) + }) + } +} diff --git a/tests/component/files/domain/models/FilesCountInfoMother.tsx b/tests/component/files/domain/models/FilesCountInfoMother.tsx index 43122d743..0ad542504 100644 --- a/tests/component/files/domain/models/FilesCountInfoMother.tsx +++ b/tests/component/files/domain/models/FilesCountInfoMother.tsx @@ -1,4 +1,4 @@ -import { FileType } from '../../../../../src/files/domain/models/File' +import { FileType } from '../../../../../src/files/domain/models/FilePreview' import { faker } from '@faker-js/faker' import { FilesCountInfo } from '../../../../../src/files/domain/models/FilesCountInfo' import { FileAccessOption, FileTag } from '../../../../../src/files/domain/models/FileCriteria' diff --git a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx index 77c287336..5da621756 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx @@ -1,4 +1,4 @@ -import { FileMother } from '../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../files/domain/models/FilePreviewMother' import { DatasetFiles } from '../../../../../src/sections/dataset/dataset-files/DatasetFiles' import { FileRepository } from '../../../../../src/files/domain/repositories/FileRepository' import { @@ -9,7 +9,11 @@ import { } from '../../../../../src/files/domain/models/FileCriteria' import { FilesCountInfoMother } from '../../../files/domain/models/FilesCountInfoMother' import { FilePaginationInfo } from '../../../../../src/files/domain/models/FilePaginationInfo' -import { FileSize, FileSizeUnit, FileType } from '../../../../../src/files/domain/models/File' +import { + FileSize, + FileSizeUnit, + FileType +} from '../../../../../src/files/domain/models/FilePreview' import styles from '../../../../../src/sections/dataset/dataset-files/files-table/FilesTable.module.scss' import { DatasetMother } from '../../../dataset/domain/models/DatasetMother' import { SettingMother } from '../../../settings/domain/models/SettingMother' @@ -17,7 +21,7 @@ import { ZipDownloadLimit } from '../../../../../src/settings/domain/models/ZipD import { SettingsProvider } from '../../../../../src/sections/settings/SettingsProvider' import { SettingRepository } from '../../../../../src/settings/domain/repositories/SettingRepository' -const testFiles = FileMother.createMany(10) +const testFiles = FilePreviewMother.createMany(10) const datasetPersistentId = 'test-dataset-persistent-id' const datasetVersion = DatasetMother.create().version const fileRepository: FileRepository = {} as FileRepository @@ -308,11 +312,11 @@ describe('DatasetFiles', () => { }) it('renders the zip download limit message when selecting rows from different pages', () => { - testFiles[1] = FileMother.create({ + testFiles[1] = FilePreviewMother.create({ size: new FileSize(1, FileSizeUnit.BYTES) }) - testFiles[2] = FileMother.create({ + testFiles[2] = FilePreviewMother.create({ size: new FileSize(2, FileSizeUnit.BYTES) }) diff --git a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.spec.tsx b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.spec.tsx index 20a5a4435..bda967772 100644 --- a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType.spec.tsx @@ -1,6 +1,6 @@ import { FileCriteria } from '../../../../../../src/files/domain/models/FileCriteria' import { FilesCountInfoMother } from '../../../../files/domain/models/FilesCountInfoMother' -import { FileType } from '../../../../../../src/files/domain/models/File' +import { FileType } from '../../../../../../src/files/domain/models/FilePreview' import styles from '../../../../../../src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.module.scss' import { FileCriteriaFilterByType } from '../../../../../../src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilterByType' diff --git a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilters.spec.tsx b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilters.spec.tsx index 88ec100ed..1bb22ba44 100644 --- a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilters.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilters.spec.tsx @@ -1,7 +1,7 @@ import { FileCriteria } from '../../../../../../src/files/domain/models/FileCriteria' import { FileCriteriaFilters } from '../../../../../../src/sections/dataset/dataset-files/file-criteria-form/FileCriteriaFilters' import { FilesCountInfoMother } from '../../../../files/domain/models/FilesCountInfoMother' -import { FileType } from '../../../../../../src/files/domain/models/File' +import { FileType } from '../../../../../../src/files/domain/models/FilePreview' const defaultCriteria = new FileCriteria() const filesCountInfo = FilesCountInfoMother.create({ diff --git a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx index e40d20a84..9809caff6 100644 --- a/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/file-criteria-form/FileCriteriaForm.spec.tsx @@ -6,7 +6,7 @@ import { FileTag } from '../../../../../../src/files/domain/models/FileCriteria' import { FilesCountInfoMother } from '../../../../files/domain/models/FilesCountInfoMother' -import { FileType } from '../../../../../../src/files/domain/models/File' +import { FileType } from '../../../../../../src/files/domain/models/FilePreview' import { DatasetRepository } from '../../../../../../src/dataset/domain/repositories/DatasetRepository' import { DatasetMother, diff --git a/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx index b56ea78d6..4ff5fda66 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx @@ -1,9 +1,9 @@ -import { FileMother } from '../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../files/domain/models/FilePreviewMother' import { FilesTable, getCellStyle } from '../../../../../../src/sections/dataset/dataset-files/files-table/FilesTable' -import { FileSize, FileSizeUnit } from '../../../../../../src/files/domain/models/File' +import { FileSize, FileSizeUnit } from '../../../../../../src/files/domain/models/FilePreview' import { SettingMother } from '../../../../settings/domain/models/SettingMother' import { ZipDownloadLimit } from '../../../../../../src/settings/domain/models/ZipDownloadLimit' import { SettingsContext } from '../../../../../../src/sections/settings/SettingsContext' @@ -11,7 +11,7 @@ import styles from '../../../../../../src/sections/dataset/dataset-files/files-t import { FilePaginationInfo } from '../../../../../../src/files/domain/models/FilePaginationInfo' import { FileCriteria } from '../../../../../../src/files/domain/models/FileCriteria' -const testFiles = FileMother.createMany(10) +const testFiles = FilePreviewMother.createMany(10) const paginationInfo = new FilePaginationInfo(1, 10, 200) const testFilesTotalDownloadSize = 19900 const defaultCriteria = new FileCriteria() @@ -169,8 +169,8 @@ describe('FilesTable', () => { it('renders the zip download limit message when the zip download limit is reached', () => { const testFiles = [ - FileMother.create({ size: new FileSize(1024, FileSizeUnit.BYTES) }), - FileMother.create({ size: new FileSize(2048, FileSizeUnit.BYTES) }) + FilePreviewMother.create({ size: new FileSize(1024, FileSizeUnit.BYTES) }), + FilePreviewMother.create({ size: new FileSize(2048, FileSizeUnit.BYTES) }) ] const getSettingByName = cy .stub() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx index 1baf2e865..df3315c07 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx @@ -1,5 +1,5 @@ import { FileActionsHeader } from '../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader' -import { FileMother } from '../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../files/domain/models/FilePreviewMother' import { DatasetProvider } from '../../../../../../../src/sections/dataset/DatasetProvider' import { DatasetRepository } from '../../../../../../../src/dataset/domain/repositories/DatasetRepository' import { @@ -15,7 +15,7 @@ describe('FileActionsHeader', () => { hasValidTermsOfAccess: true }) datasetRepository.getByPersistentId = cy.stub().resolves(datasetWithUpdatePermissions) - const files = FileMother.createMany(2) + const files = FilePreviewMother.createMany(2) cy.mountAuthenticated( { @@ -28,7 +28,7 @@ describe('DownloadFilesButton', () => { const datasetWithDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadAllowed() }) - const files = FileMother.createMany(2) + const files = FilePreviewMother.createMany(2) cy.mountAuthenticated( withDataset( , @@ -43,7 +43,7 @@ describe('DownloadFilesButton', () => { const datasetWithDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadAllowed() }) - const files = FileMother.createMany(1) + const files = FilePreviewMother.createMany(1) cy.mountAuthenticated( withDataset( , @@ -58,7 +58,7 @@ describe('DownloadFilesButton', () => { const datasetWithoutDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadNotAllowed() }) - const files = FileMother.createMany(2) + const files = FilePreviewMother.createMany(2) cy.mountAuthenticated( withDataset( , @@ -73,7 +73,7 @@ describe('DownloadFilesButton', () => { const datasetWithDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadAllowed() }) - const files = FileMother.createMany(2, { + const files = FilePreviewMother.createMany(2, { tabularData: { variablesCount: 2, observationsCount: 3, @@ -96,7 +96,7 @@ describe('DownloadFilesButton', () => { const datasetWithDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadAllowed() }) - const files = FileMother.createMany(2, { tabularData: undefined }) + const files = FilePreviewMother.createMany(2, { tabularData: undefined }) cy.mountAuthenticated( withDataset( , @@ -113,7 +113,7 @@ describe('DownloadFilesButton', () => { const datasetWithDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadAllowed() }) - const files = FileMother.createMany(2, { tabularData: undefined }) + const files = FilePreviewMother.createMany(2, { tabularData: undefined }) cy.mountAuthenticated( withDataset( , @@ -129,12 +129,12 @@ describe('DownloadFilesButton', () => { const datasetWithDownloadFilesPermission = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithFilesDownloadAllowed() }) - const files = FileMother.createMany(2) + const files = FilePreviewMother.createMany(2) cy.mountAuthenticated( withDataset( , datasetWithDownloadFilesPermission ) diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx index 0cc9ac5b9..b60acf569 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx @@ -1,5 +1,5 @@ import { EditFilesMenu } from '../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu' -import { FileMother } from '../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../files/domain/models/FilePreviewMother' import { ReactNode } from 'react' import { Dataset as DatasetModel } from '../../../../../../../../src/dataset/domain/models/Dataset' import { DatasetProvider } from '../../../../../../../../src/sections/dataset/DatasetProvider' @@ -15,7 +15,7 @@ const datasetWithUpdatePermissions = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), hasValidTermsOfAccess: true }) -const files = FileMother.createMany(2) +const files = FilePreviewMother.createMany(2) describe('EditFilesMenu', () => { const withDataset = (component: ReactNode, dataset: DatasetModel | undefined) => { datasetRepository.getByPersistentId = cy.stub().resolves(dataset) diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx index 2571bfcf9..1ea198c90 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx @@ -1,7 +1,7 @@ import { EditFilesOptions } from '../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions' -import { FileMother } from '../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../files/domain/models/FilePreviewMother' -const files = FileMother.createMany(2) +const files = FilePreviewMother.createMany(2) describe('EditFilesOptions', () => { it('renders the EditFilesOptions', () => { cy.customMount() @@ -14,7 +14,7 @@ describe('EditFilesOptions', () => { }) it('renders the restrict option if some file is unrestricted', () => { - const fileUnrestricted = FileMother.createDefault() + const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount() cy.findByRole('button', { name: 'Restrict' }).should('exist').click() @@ -23,7 +23,7 @@ describe('EditFilesOptions', () => { }) it('renders the unrestrict option if some file is restricted', () => { - const fileRestricted = FileMother.createWithRestrictedAccess() + const fileRestricted = FilePreviewMother.createWithRestrictedAccess() cy.customMount() cy.findByRole('button', { name: 'Unrestrict' }).should('exist').click() @@ -65,7 +65,10 @@ describe('EditFilesOptions', () => { it('does not show the No Selected Files message when files are selected and one option is clicked', () => { cy.customMount( - + ) cy.findByRole('button', { name: 'Metadata' }).click() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.spec.tsx index db2307af0..b7a44fc66 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell.spec.tsx @@ -1,7 +1,7 @@ import { FileActionsCell } from '../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/FileActionsCell' -import { FileMother } from '../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../files/domain/models/FilePreviewMother' -const file = FileMother.create() +const file = FilePreviewMother.create() describe('FileActionsCell', () => { it('renders the file action buttons', () => { cy.customMount() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx index bef0f5345..466c2751f 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx @@ -1,5 +1,5 @@ import { FileActionButtons } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons' -import { FileMother } from '../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../files/domain/models/FilePreviewMother' import { DatasetRepository } from '../../../../../../../../../src/dataset/domain/repositories/DatasetRepository' import { DatasetMother, @@ -7,7 +7,7 @@ import { } from '../../../../../../../dataset/domain/models/DatasetMother' import { DatasetProvider } from '../../../../../../../../../src/sections/dataset/DatasetProvider' -const file = FileMother.createDefault() +const file = FilePreviewMother.createDefault() describe('FileActionButtons', () => { it('renders the file action buttons', () => { cy.customMount() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx index 460cfab8d..d49d6b0d5 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx @@ -1,11 +1,11 @@ import { AccessFileMenu } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu' -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { Suspense } from 'react' import { FilePermissionsProvider } from '../../../../../../../../../../src/sections/file/file-permissions/FilePermissionsProvider' import { FileRepository } from '../../../../../../../../../../src/files/domain/repositories/FileRepository' import { FileUserPermissionsMother } from '../../../../../../../../files/domain/models/FileUserPermissionsMother' -const file = FileMother.create() +const file = FilePreviewMother.create() const fileRepository = {} as FileRepository describe('AccessFileMenu', () => { @@ -41,7 +41,7 @@ describe('AccessFileMenu', () => { }) it('renders the access status of the file', () => { - const filePublic = FileMother.createWithPublicAccess() + const filePublic = FilePreviewMother.createWithPublicAccess() cy.customMount( @@ -53,7 +53,8 @@ describe('AccessFileMenu', () => { }) it('renders the request access button', () => { - const fileRestrictedWithAccessRequestAllowed = FileMother.createWithAccessRequestAllowed() + const fileRestrictedWithAccessRequestAllowed = + FilePreviewMother.createWithAccessRequestAllowed() cy.customMount( @@ -65,7 +66,7 @@ describe('AccessFileMenu', () => { }) it('renders the download options header', () => { - const filePublic = FileMother.createWithPublicAccess() + const filePublic = FilePreviewMother.createWithPublicAccess() cy.customMount( diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.spec.tsx index c1ba17998..3003b6c29 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.spec.tsx @@ -1,4 +1,4 @@ -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { AccessStatus } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus' import styles from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.module.scss' import { FileRepository } from '../../../../../../../../../../src/files/domain/repositories/FileRepository' @@ -7,7 +7,7 @@ import { FilePermissionsProvider } from '../../../../../../../../../../src/secti describe('AccessStatus', () => { it('renders the access status public', () => { - const filePublic = FileMother.createWithPublicAccess() + const filePublic = FilePreviewMother.createWithPublicAccess() cy.customMount() cy.findByText('Public').should('exist').should('have.class', styles.success) @@ -15,7 +15,7 @@ describe('AccessStatus', () => { }) it('renders the access status restricted', () => { - const fileRestricted = FileMother.createWithRestrictedAccess() + const fileRestricted = FilePreviewMother.createWithRestrictedAccess() cy.customMount() cy.findByText('Restricted').should('exist').should('have.class', styles.danger) @@ -23,7 +23,7 @@ describe('AccessStatus', () => { }) it('renders the access status restricted with access', () => { - const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted() + const fileRestrictedWithAccess = FilePreviewMother.createWithRestrictedAccessWithAccessGranted() const fileRepository: FileRepository = {} as FileRepository fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ @@ -45,7 +45,7 @@ describe('AccessStatus', () => { }) it('renders the access status embargoed', () => { - const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted() + const fileRestrictedWithAccess = FilePreviewMother.createWithRestrictedAccessWithAccessGranted() const fileRepository: FileRepository = {} as FileRepository fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ @@ -53,7 +53,7 @@ describe('AccessStatus', () => { canDownloadFile: true }) ) - const fileEmbargoed = FileMother.createWithEmbargo() + const fileEmbargoed = FilePreviewMother.createWithEmbargo() cy.customMount( {' '} @@ -65,7 +65,7 @@ describe('AccessStatus', () => { }) it('renders the access status embargoed restricted', () => { - const fileEmbargoedRestricted = FileMother.createWithEmbargoRestricted() + const fileEmbargoedRestricted = FilePreviewMother.createWithEmbargoRestricted() cy.customMount() cy.findByText('Embargoed').should('exist').should('have.class', styles.danger) @@ -73,7 +73,7 @@ describe('AccessStatus', () => { }) it('renders the access status embargoed restricted with access', () => { - const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted() + const fileRestrictedWithAccess = FilePreviewMother.createWithRestrictedAccessWithAccessGranted() const fileRepository: FileRepository = {} as FileRepository fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ @@ -81,7 +81,7 @@ describe('AccessStatus', () => { canDownloadFile: true }) ) - const fileEmbargoedRestricted = FileMother.createWithEmbargoRestricted() + const fileEmbargoedRestricted = FilePreviewMother.createWithEmbargoRestricted() cy.customMount( {' '} diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx index 912c63a18..4eb9e7ff8 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx @@ -1,11 +1,11 @@ import { FileDownloadOptions } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions' -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { FileUserPermissionsMother } from '../../../../../../../../files/domain/models/FileUserPermissionsMother' import { FilePermissionsProvider } from '../../../../../../../../../../src/sections/file/file-permissions/FilePermissionsProvider' import { FileRepository } from '../../../../../../../../../../src/files/domain/repositories/FileRepository' -const fileNonTabular = FileMother.createNonTabular() -const fileTabular = FileMother.createTabular() +const fileNonTabular = FilePreviewMother.createNonTabular() +const fileTabular = FilePreviewMother.createTabular() const fileRepository = {} as FileRepository describe('FileDownloadOptions', () => { beforeEach(() => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx index 2d9cf8c17..b767a7ba0 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx @@ -1,8 +1,8 @@ -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { FileIngestStatus, FileType -} from '../../../../../../../../../../src/files/domain/models/File' +} from '../../../../../../../../../../src/files/domain/models/FilePreview' import { FileNonTabularDownloadOptions } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions' import { DatasetProvider } from '../../../../../../../../../../src/sections/dataset/DatasetProvider' import { DatasetRepository } from '../../../../../../../../../../src/dataset/domain/repositories/DatasetRepository' @@ -11,13 +11,13 @@ import { DatasetMother } from '../../../../../../../../dataset/domain/models/DatasetMother' -const fileNonTabular = FileMother.create({ +const fileNonTabular = FilePreviewMother.create({ tabularData: undefined, type: new FileType('text/plain') }) describe('FileNonTabularDownloadOptions', () => { it('renders the download options for a non-tabular file of unknown type', () => { - const fileNonTabularUnknown = FileMother.create({ + const fileNonTabularUnknown = FilePreviewMother.create({ tabularData: undefined, type: new FileType('unknown') }) @@ -39,7 +39,7 @@ describe('FileNonTabularDownloadOptions', () => { }) it('does not render the download options for a tabular file', () => { - const fileTabular = FileMother.createTabular() + const fileTabular = FilePreviewMother.createTabular() cy.customMount() cy.findByRole('link', { name: 'Original File Format' }).should('not.exist') @@ -47,7 +47,7 @@ describe('FileNonTabularDownloadOptions', () => { }) it('renders the options as disabled when the file ingest is in progress', () => { - const fileNonTabularInProgress = FileMother.create({ + const fileNonTabularInProgress = FilePreviewMother.create({ tabularData: undefined, type: new FileType('text/plain'), ingest: { diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx index 8dad61fb6..85f9d3582 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx @@ -1,8 +1,8 @@ -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { FileIngestStatus, FileType -} from '../../../../../../../../../../src/files/domain/models/File' +} from '../../../../../../../../../../src/files/domain/models/FilePreview' import { FileTabularDownloadOptions } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions' import { DatasetRepository } from '../../../../../../../../../../src/dataset/domain/repositories/DatasetRepository' import { @@ -11,12 +11,12 @@ import { } from '../../../../../../../../dataset/domain/models/DatasetMother' import { DatasetProvider } from '../../../../../../../../../../src/sections/dataset/DatasetProvider' -const fileNonTabular = FileMother.create({ +const fileNonTabular = FilePreviewMother.create({ tabularData: undefined, type: new FileType('text/plain') }) -const fileTabular = FileMother.createTabular() -const fileTabularUnknown = FileMother.createTabular({ +const fileTabular = FilePreviewMother.createTabular() +const fileTabularUnknown = FilePreviewMother.createTabular({ type: new FileType('text/tab-separated-values', 'Unknown') }) describe('FileTabularDownloadOptions', () => { @@ -55,7 +55,7 @@ describe('FileTabularDownloadOptions', () => { }) it('renders the options as disabled when the file ingest is in progress', () => { - const fileTabularInProgress = FileMother.createTabular({ + const fileTabularInProgress = FilePreviewMother.createTabular({ ingest: { status: FileIngestStatus.IN_PROGRESS } @@ -96,7 +96,7 @@ describe('FileTabularDownloadOptions', () => { }) it('does not render the RData option if the file type is already R Data', () => { - const fileTabularRData = FileMother.createTabular({ + const fileTabularRData = FilePreviewMother.createTabular({ type: new FileType('text/tab-separated-values', 'R Data') }) cy.customMount() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessModal.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessModal.spec.tsx index 88002146f..d1190a20e 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessModal.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessModal.spec.tsx @@ -1,19 +1,19 @@ import { RequestAccessModal } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessModal' -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { UserMother } from '../../../../../../../../users/domain/models/UserMother' import { UserRepository } from '../../../../../../../../../../src/users/domain/repositories/UserRepository' import { SessionProvider } from '../../../../../../../../../../src/sections/session/SessionProvider' import { Route } from '../../../../../../../../../../src/sections/Route.enum' describe('RequestAccessModal', () => { it('renders the RequestAccessModal', () => { - const file = FileMother.create() + const file = FilePreviewMother.create() cy.customMount() cy.findByRole('button', { name: 'Request Access' }).should('exist') }) it('shows login modal when button is clicked and user is not logged in', () => { - const file = FileMother.create() + const file = FilePreviewMother.create() cy.customMount() cy.findByRole('button', { name: 'Request Access' }).click() @@ -33,7 +33,7 @@ describe('RequestAccessModal', () => { }) it('shows request access modal when button is clicked and user is logged in', () => { - const file = FileMother.create() + const file = FilePreviewMother.create() const user = UserMother.create() const userRepository = {} as UserRepository userRepository.getAuthenticated = cy.stub().resolves(user) diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.spec.tsx index edf2eb32d..ef6f0e668 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption.spec.tsx @@ -1,12 +1,12 @@ import { RequestAccessOption } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/RequestAccessOption' -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '../../../../../../../../../../src/files/domain/repositories/FileRepository' import { FileUserPermissionsMother } from '../../../../../../../../files/domain/models/FileUserPermissionsMother' import { FilePermissionsProvider } from '../../../../../../../../../../src/sections/file/file-permissions/FilePermissionsProvider' describe('RequestAccessOption', () => { it('renders the embargoed message when the file is embargoed', () => { - const fileEmbargoed = FileMother.createWithEmbargo() + const fileEmbargoed = FilePreviewMother.createWithEmbargo() cy.customMount() cy.findByRole('button', { name: 'Files are unavailable during the specified embargo.' }) @@ -15,7 +15,7 @@ describe('RequestAccessOption', () => { }) it('renders the embargo then restricted message when the file is embargoed and restricted', () => { - const fileEmbargoedRestricted = FileMother.createWithEmbargoRestricted() + const fileEmbargoedRestricted = FilePreviewMother.createWithEmbargoRestricted() cy.customMount() cy.findByRole('button', { @@ -26,7 +26,7 @@ describe('RequestAccessOption', () => { }) it('renders the Users may not request access to files. message when the file is restricted and access request is not allowed', () => { - const fileRestricted = FileMother.createWithRestrictedAccess() + const fileRestricted = FilePreviewMother.createWithRestrictedAccess() cy.customMount() cy.findByRole('button', { name: 'Users may not request access to files.' }) @@ -35,14 +35,14 @@ describe('RequestAccessOption', () => { }) it('renders the request access button when the file is restricted and can be requested', () => { - const fileRestrictedCanBeRequested = FileMother.createWithAccessRequestAllowed() + const fileRestrictedCanBeRequested = FilePreviewMother.createWithAccessRequestAllowed() cy.customMount() cy.findByRole('button', { name: 'Request Access' }).should('exist') }) it('renders the access requested message when hen the file is restricted and the access has already been requested', () => { - const fileAlreadyRequested = FileMother.createWithAccessRequestPending() + const fileAlreadyRequested = FilePreviewMother.createWithAccessRequestPending() cy.customMount() @@ -52,7 +52,7 @@ describe('RequestAccessOption', () => { }) it('does not render the request access button when the file is deaccessioned', () => { - const fileDeaccessioned = FileMother.createDeaccessioned() + const fileDeaccessioned = FilePreviewMother.createDeaccessioned() cy.customMount() cy.findByRole('button', { name: 'Users may not request access to files.' }).should('not.exist') @@ -67,7 +67,7 @@ describe('RequestAccessOption', () => { }) it('does not render the request access button when the file status is public', () => { - const filePublic = FileMother.createWithPublicAccess() + const filePublic = FilePreviewMother.createWithPublicAccess() const fileRepository: FileRepository = {} as FileRepository fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ @@ -94,7 +94,7 @@ describe('RequestAccessOption', () => { }) it('does not render the request access button when the file status is restricted with access granted', () => { - const fileRestrictedWithAccess = FileMother.createWithRestrictedAccessWithAccessGranted() + const fileRestrictedWithAccess = FilePreviewMother.createWithRestrictedAccessWithAccessGranted() const fileRepository: FileRepository = {} as FileRepository fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx index e39c6dafb..d69579e11 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx @@ -1,5 +1,5 @@ import { FileOptionsMenu } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu' -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { ReactNode } from 'react' import { Dataset as DatasetModel } from '../../../../../../../../../../src/dataset/domain/models/Dataset' import { DatasetProvider } from '../../../../../../../../../../src/sections/dataset/DatasetProvider' @@ -10,7 +10,7 @@ import { DatasetPermissionsMother } from '../../../../../../../../dataset/domain/models/DatasetMother' -const file = FileMother.createDefault() +const file = FilePreviewMother.createDefault() const datasetRepository: DatasetRepository = {} as DatasetRepository const datasetWithUpdatePermissions = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), @@ -91,7 +91,7 @@ describe('FileOptionsMenu', () => { }) it('opens fileAlreadyDeletedPrevious modal if file is already deleted', () => { - const file = FileMother.createDeleted() + const file = FilePreviewMother.createDeleted() cy.mountAuthenticated( withDataset(, datasetWithUpdatePermissions) diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.spec.tsx index 8fe8355b3..37cc59003 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages.spec.tsx @@ -1,16 +1,16 @@ import { FileInfoMessages } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages' -import { FileMother } from '../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../files/domain/models/FilePreviewMother' describe('FileInfoMessages', () => { it('renders the ingest message', () => { - const file = FileMother.createIngestInProgress() + const file = FilePreviewMother.createIngestInProgress() cy.customMount() cy.findByText('Ingest in progress...').should('exist') }) it('renders the access requested message', () => { - const file = FileMother.createWithAccessRequestPending() + const file = FilePreviewMother.createWithAccessRequestPending() cy.customMount() cy.findByText('Access Requested').should('exist') 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 ada6d3be3..3ac7e9ea6 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,5 +1,5 @@ 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 { FileIngestMother } from '../../../../../../../files/domain/models/FilePreviewMother' import { ReactNode } from 'react' import { Dataset as DatasetModel } from '../../../../../../../../../src/dataset/domain/models/Dataset' import { DatasetProvider } from '../../../../../../../../../src/sections/dataset/DatasetProvider' diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileChecksum.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileChecksum.spec.tsx index 8367973d0..671817a72 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileChecksum.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileChecksum.spec.tsx @@ -1,6 +1,6 @@ import { FileChecksum } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileChecksum' import styles from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.module.scss' -import { FileChecksumMother } from '../../../../../../../files/domain/models/FileMother' +import { FileChecksumMother } from '../../../../../../../files/domain/models/FilePreviewMother' describe('FileChecksum', () => { it('renders the checksum and CopyToClipboardButton when checksum is provided', () => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx index 851029fa5..feb5659ac 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx @@ -1,5 +1,5 @@ import { FileDate } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate' -import { FileDateType } from '../../../../../../../../../src/files/domain/models/File' +import { FileDateType } from '../../../../../../../../../src/files/domain/models/FilePreview' describe('FileDate', () => { it('renders the date', () => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDownloads.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDownloads.spec.tsx index dfe971866..1e9bddcb3 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDownloads.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDownloads.spec.tsx @@ -1,4 +1,4 @@ -import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/File' +import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/FilePreview' import { FileDownloads } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDownloads' describe('FileDownloads', () => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx index 0e72039f8..95a8d9296 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx @@ -1,6 +1,6 @@ import { FileEmbargoDate } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate' -import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/File' -import { FileEmbargoMother } from '../../../../../../../files/domain/models/FileMother' +import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/FilePreview' +import { FileEmbargoMother } from '../../../../../../../files/domain/models/FilePreviewMother' describe('FileEmbargoDate', () => { it('renders the embargo date when embargo exists', () => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileLabels.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileLabels.spec.tsx index fae3d5c90..41ae6a06c 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileLabels.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileLabels.spec.tsx @@ -1,4 +1,4 @@ -import { FileLabelType } from '../../../../../../../../../src/files/domain/models/File' +import { FileLabelType } from '../../../../../../../../../src/files/domain/models/FilePreview' import { FileLabels } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileLabels' import styles from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.module.scss' diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx index 11bee34de..536fc64c7 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx @@ -1,13 +1,13 @@ -import { FileMother } from '../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../files/domain/models/FilePreviewMother' import { FileTitle } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle' -import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/File' +import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/FilePreview' describe('FileTitle', () => { it('renders the link and name correctly', () => { const id = 12345 const versionParameter = '&version=1' const name = 'file-name.txt' - const file = FileMother.create({ + const file = FilePreviewMother.create({ id: id, version: { number: 1, publishingStatus: FilePublishingStatus.RELEASED }, name: name diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx index e68ae02c7..47731f3b8 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx @@ -1,14 +1,14 @@ -import { FileMother } from '../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../files/domain/models/FilePreviewMother' import { FileType } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileType' import { FileSize, FileSizeUnit, FileType as FileTypeModel -} from '../../../../../../../../../src/files/domain/models/File' +} from '../../../../../../../../../src/files/domain/models/FilePreview' describe('FileType', () => { it('renders the type and size correctly when there are no decimals', () => { - const file = FileMother.create({ + const file = FilePreviewMother.create({ type: new FileTypeModel('text/plain'), size: new FileSize(123.03932894722, FileSizeUnit.BYTES) }) @@ -18,7 +18,7 @@ describe('FileType', () => { }) it('renders the type and size correctly when there are decimals', () => { - const file = FileMother.create({ + const file = FilePreviewMother.create({ type: new FileTypeModel('text/plain'), size: new FileSize(123.932894722, FileSizeUnit.MEGABYTES) }) @@ -28,7 +28,7 @@ describe('FileType', () => { }) it('renders the type correctly when is a tabular file', () => { - const file = FileMother.createTabular({ + const file = FilePreviewMother.createTabular({ size: new FileSize(123.03932894722, FileSizeUnit.BYTES) }) diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.spec.tsx index 48eadf5d1..1689053e8 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.spec.tsx @@ -1,14 +1,14 @@ import { FileThumbnail } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail' -import { FileMother } from '../../../../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '../../../../../../../../../../src/files/domain/repositories/FileRepository' import { FileUserPermissionsMother } from '../../../../../../../../files/domain/models/FileUserPermissionsMother' import { FilePermissionsProvider } from '../../../../../../../../../../src/sections/file/file-permissions/FilePermissionsProvider' -import { FileType } from '../../../../../../../../../../src/files/domain/models/File' +import { FileType } from '../../../../../../../../../../src/files/domain/models/FilePreview' const fileRepository: FileRepository = {} as FileRepository describe('FileThumbnail', () => { it('renders FileThumbnailPreviewImage when thumbnail is provided and file can be downloaded', () => { - const file = FileMother.createWithThumbnail() + const file = FilePreviewMother.createWithThumbnail() fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ fileId: file.id, @@ -31,7 +31,7 @@ describe('FileThumbnail', () => { }) it('does not render FileThumbnailPreviewImage when thumbnail is provided and file cannot be downloaded', () => { - const file = FileMother.createWithThumbnail() + const file = FilePreviewMother.createWithThumbnail() cy.customMount() cy.findByAltText(file.name).should('not.exist') @@ -40,7 +40,7 @@ describe('FileThumbnail', () => { }) it('renders FileThumbnailPreviewImage when thumbnail is provided with unlocked icon if restricted with access', () => { - const file = FileMother.createWithThumbnailRestrictedWithAccessGranted() + const file = FilePreviewMother.createWithThumbnailRestrictedWithAccessGranted() fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ fileId: file.id, @@ -64,7 +64,7 @@ describe('FileThumbnail', () => { }) it('does not render FileThumbnailPreviewImage when thumbnail is provided if restricted with no access', () => { - const file = FileMother.createWithThumbnailRestricted() + const file = FilePreviewMother.createWithThumbnailRestricted() cy.customMount() @@ -77,7 +77,7 @@ describe('FileThumbnail', () => { }) it('renders FileThumbnailIcon when thumbnail is not provided', () => { - const file = FileMother.createDefault({ type: new FileType('application/pdf') }) + const file = FilePreviewMother.createDefault({ type: new FileType('application/pdf') }) cy.customMount() @@ -88,7 +88,7 @@ describe('FileThumbnail', () => { }) it('renders FileThumbnailIcon when thumbnail is not provided with lock icon when restricted with no access', () => { - const file = FileMother.createWithRestrictedAccess() + const file = FilePreviewMother.createWithRestrictedAccess() cy.customMount() @@ -101,7 +101,7 @@ describe('FileThumbnail', () => { }) it('renders FileThumbnailIcon when thumbnail is not provided with unlock icon when restricted with access', () => { - const file = FileMother.createWithRestrictedAccessWithAccessGranted() + const file = FilePreviewMother.createWithRestrictedAccessWithAccessGranted() fileRepository.getUserPermissionsById = cy.stub().resolves( FileUserPermissionsMother.create({ fileId: file.id, diff --git a/tests/component/sections/dataset/dataset-files/files-table/row-selection/RowSelectionMessage.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/row-selection/RowSelectionMessage.spec.tsx index c36626009..39a673bb0 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/row-selection/RowSelectionMessage.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/row-selection/RowSelectionMessage.spec.tsx @@ -1,5 +1,5 @@ import { RowSelectionMessage } from '../../../../../../../src/sections/dataset/dataset-files/files-table/row-selection/RowSelectionMessage' -import { FileMother } from '../../../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../../../files/domain/models/FilePreviewMother' let selectAllRows = () => {} let clearRowSelection = () => {} @@ -12,7 +12,7 @@ describe('RowSelectionMessage', () => { it('renders the message when there are more than 10 files and some row is selected', () => { cy.customMount( { it('does not render the message when there are less than 10 files', () => { cy.customMount( { it('renders the plural form of the message when there is more than 1 row selected', () => { cy.customMount( { it("calls selectAllRows when the 'Select all' button is clicked", () => { cy.customMount( { it("calls clearRowSelection when the 'Clear selection.' button is clicked", () => { cy.customMount( { cy.customMount( @@ -39,8 +41,8 @@ describe('ZipDownloadLimitMessage', () => { { { { { { }) it('calls the file repository to get the permissions before removing the loading', () => { - const files = FileMother.createMany(5) + const files = FilePreviewMother.createMany(5) fileRepository.getAllByDatasetPersistentId = cy.stub().resolves(files) fileRepository.getUserPermissionsById = cy.stub().resolves( new Promise((resolve) => { diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx new file mode 100644 index 000000000..e2e7fd3cb --- /dev/null +++ b/tests/component/sections/file/File.spec.tsx @@ -0,0 +1,19 @@ +import { FileRepository } from '../../../../src/files/domain/repositories/FileRepository' +import { FileMother } from '../../files/domain/models/FileMother' +import { File } from '../../../../src/sections/file/File' + +const fileRepository: FileRepository = {} as FileRepository + +describe('File', () => { + it('renders the File page title and details', () => { + const testFile = FileMother.createRealistic() + fileRepository.getById = cy.stub().resolves(testFile) + + cy.customMount() + + cy.wrap(fileRepository.getById).should('be.calledWith', 19) + + cy.findAllByText(testFile.name).should('exist') + cy.findByText(`This file is part of "${testFile.datasetTitle}".`).should('exist') + }) +}) diff --git a/tests/component/sections/file/file-permissions/useFileDownloadPermission.spec.tsx b/tests/component/sections/file/file-permissions/useFileDownloadPermission.spec.tsx index 9492c88d3..6254bcad8 100644 --- a/tests/component/sections/file/file-permissions/useFileDownloadPermission.spec.tsx +++ b/tests/component/sections/file/file-permissions/useFileDownloadPermission.spec.tsx @@ -1,13 +1,13 @@ -import { FileMother } from '../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../files/domain/models/FilePreviewMother' import { FilePermissionsProvider } from '../../../../../src/sections/file/file-permissions/FilePermissionsProvider' import { FileRepository } from '../../../../../src/files/domain/repositories/FileRepository' -import { File } from '../../../../../src/files/domain/models/File' +import { FilePreview } from '../../../../../src/files/domain/models/FilePreview' import { FileUserPermissionsMother } from '../../../files/domain/models/FileUserPermissionsMother' import { FilesCountInfoMother } from '../../../files/domain/models/FilesCountInfoMother' import { useFileDownloadPermission } from '../../../../../src/sections/file/file-permissions/useFileDownloadPermission' const fileRepository: FileRepository = {} as FileRepository -function TestComponent({ file }: { file: File }) { +function TestComponent({ file }: { file: FilePreview }) { const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file) return ( @@ -30,7 +30,7 @@ describe('useFileDownloadPermission', () => { }) it('should return file download permission', () => { - const file = FileMother.createDeaccessioned() + const file = FilePreviewMother.createDeaccessioned() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canEditDataset: true })) @@ -46,7 +46,7 @@ describe('useFileDownloadPermission', () => { }) it('should return false for file download permission if there is an error', () => { - const file = FileMother.createDeaccessioned() + const file = FilePreviewMother.createDeaccessioned() fileRepository.getUserPermissionsById = cy .stub() .rejects(new Error('Error getting file user permissions')) diff --git a/tests/component/sections/file/file-permissions/useFilePermissions.spec.tsx b/tests/component/sections/file/file-permissions/useFilePermissions.spec.tsx index 127ae2f9b..89ae6215d 100644 --- a/tests/component/sections/file/file-permissions/useFilePermissions.spec.tsx +++ b/tests/component/sections/file/file-permissions/useFilePermissions.spec.tsx @@ -1,10 +1,10 @@ import { useFilePermissions } from '../../../../../src/sections/file/file-permissions/FilePermissionsContext' import { FilePermission } from '../../../../../src/files/domain/models/FileUserPermissions' -import { FileMother } from '../../../files/domain/models/FileMother' +import { FilePreviewMother } from '../../../files/domain/models/FilePreviewMother' import { useEffect, useState } from 'react' import { FilePermissionsProvider } from '../../../../../src/sections/file/file-permissions/FilePermissionsProvider' import { FileRepository } from '../../../../../src/files/domain/repositories/FileRepository' -import { File } from '../../../../../src/files/domain/models/File' +import { FilePreview } from '../../../../../src/files/domain/models/FilePreview' import { FileUserPermissionsMother } from '../../../files/domain/models/FileUserPermissionsMother' import { FilesCountInfoMother } from '../../../files/domain/models/FilesCountInfoMother' import { AnonymizedContext } from '../../../../../src/sections/dataset/anonymized/AnonymizedContext' @@ -15,7 +15,7 @@ function SavedPermissionsTestComponent({ file, permission }: { - file: File + file: FilePreview permission: FilePermission }) { const { checkSessionUserHasFilePermission } = useFilePermissions() @@ -52,7 +52,7 @@ function SavedPermissionsTestComponent({ ) } -function TestComponent({ file, permission }: { file: File; permission: FilePermission }) { +function TestComponent({ file, permission }: { file: FilePreview; permission: FilePermission }) { const { checkSessionUserHasFilePermission } = useFilePermissions() const [hasFilePermission, setHasFilePermission] = useState(false) useEffect(() => { @@ -86,7 +86,7 @@ describe('useFilePermissions', () => { describe('Download permission', () => { it('should not call getFileUserPermissionsById when the file is not deaccessioned nor restricted nor embargoed', () => { - const file = FileMother.createDefault() + const file = FilePreviewMother.createDefault() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id })) @@ -101,7 +101,7 @@ describe('useFilePermissions', () => { }) it('should call getFileUserPermissionsById when the file is deaccessioned', () => { - const file = FileMother.createDeaccessioned() + const file = FilePreviewMother.createDeaccessioned() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canEditDataset: true })) @@ -117,7 +117,7 @@ describe('useFilePermissions', () => { }) it('should call getFileUserPermissionsById when the file is restricted', () => { - const file = FileMother.createWithRestrictedAccess() + const file = FilePreviewMother.createWithRestrictedAccess() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canDownloadFile: true })) @@ -132,7 +132,7 @@ describe('useFilePermissions', () => { }) it('should call getFileUserPermissionsById when the file is public but latest version is restricted', () => { - const file = FileMother.createWithPublicAccessButLatestVersionRestricted() + const file = FilePreviewMother.createWithPublicAccessButLatestVersionRestricted() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canDownloadFile: true })) @@ -147,7 +147,7 @@ describe('useFilePermissions', () => { }) it('should call getFileUserPermissionsById when the file is embargoed', () => { - const file = FileMother.createWithEmbargo() + const file = FilePreviewMother.createWithEmbargo() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canDownloadFile: true })) @@ -162,7 +162,7 @@ describe('useFilePermissions', () => { }) it('should return false if there is an error in the use case request', () => { - const file = FileMother.createWithEmbargo() + const file = FilePreviewMother.createWithEmbargo() fileRepository.getUserPermissionsById = cy .stub() .rejects(new Error('There was an error getting the file user permissions')) @@ -177,7 +177,7 @@ describe('useFilePermissions', () => { }) it('should use the saved state of the permission the second time the file is being consulted', () => { - const file = FileMother.createWithRestrictedAccess() + const file = FilePreviewMother.createWithRestrictedAccess() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canDownloadFile: true })) @@ -193,7 +193,7 @@ describe('useFilePermissions', () => { }) it('should always allow to download if the user is in anonymized view (privateUrl)', () => { - const file = FileMother.createWithRestrictedAccess() + const file = FilePreviewMother.createWithRestrictedAccess() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canDownloadFile: false })) @@ -215,7 +215,7 @@ describe('useFilePermissions', () => { describe('Edit dataset permission', () => { it('should call getFileUserPermissionsById when asking for edit dataset permission', () => { - const file = FileMother.createDefault() + const file = FilePreviewMother.createDefault() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canEditDataset: true })) @@ -231,7 +231,7 @@ describe('useFilePermissions', () => { }) it('should return false if there is an error in the use case request', () => { - const file = FileMother.createDefault() + const file = FilePreviewMother.createDefault() fileRepository.getUserPermissionsById = cy .stub() .rejects(new Error('There was an error getting the file user permissions')) @@ -246,7 +246,7 @@ describe('useFilePermissions', () => { }) it('should use the saved state of the edit dataset permission the second time the file is being consulted', () => { - const file = FileMother.createDefault() + const file = FilePreviewMother.createDefault() fileRepository.getUserPermissionsById = cy .stub() .resolves(FileUserPermissionsMother.create({ fileId: file.id, canEditDataset: true })) diff --git a/tests/component/settings/domain/models/SettingMother.ts b/tests/component/settings/domain/models/SettingMother.ts index 59574ba60..b3066153c 100644 --- a/tests/component/settings/domain/models/SettingMother.ts +++ b/tests/component/settings/domain/models/SettingMother.ts @@ -1,7 +1,7 @@ import { faker } from '@faker-js/faker' import { Setting, SettingName } from '../../../../../src/settings/domain/models/Setting' import { ZipDownloadLimit } from '../../../../../src/settings/domain/models/ZipDownloadLimit' -import { FileSizeUnit } from '../../../../../src/files/domain/models/File' +import { FileSizeUnit } from '../../../../../src/files/domain/models/FilePreview' export class SettingMother { static createZipDownloadLimit(value?: ZipDownloadLimit): Setting { diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index df8d92afe..4f2c8b1a2 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -1,7 +1,7 @@ import { TestsUtils } from '../../shared/TestsUtils' import { FileJSDataverseRepository } from '../../../../src/files/infrastructure/FileJSDataverseRepository' import { - File, + FilePreview, FileDateType, FileEmbargo, FileIngestStatus, @@ -10,7 +10,7 @@ import { FileSize, FileSizeUnit, FileType -} from '../../../../src/files/domain/models/File' +} from '../../../../src/files/domain/models/FilePreview' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import { DatasetJSDataverseRepository } from '../../../../src/dataset/infrastructure/repositories/DatasetJSDataverseRepository' @@ -37,7 +37,7 @@ const datasetRepository = new DatasetJSDataverseRepository() const dateNow = new Date() dateNow.setHours(2, 0, 0, 0) const fileData = (id: number) => { - return new File( + return new FilePreview( id, { number: 1, publishingStatus: FilePublishingStatus.DRAFT }, 'blob', diff --git a/tests/e2e-integration/shared/files/FileHelper.ts b/tests/e2e-integration/shared/files/FileHelper.ts index 7ae2c1b33..ad59011ec 100644 --- a/tests/e2e-integration/shared/files/FileHelper.ts +++ b/tests/e2e-integration/shared/files/FileHelper.ts @@ -1,5 +1,5 @@ import { DataverseApiHelper } from '../DataverseApiHelper' -import { FileLabel, FileLabelType } from '../../../../src/files/domain/models/File' +import { FileLabel, FileLabelType } from '../../../../src/files/domain/models/FilePreview' import { faker } from '@faker-js/faker' interface FileResponse { From df0a00b8ce36f600fde3602ebe5427cd9b8f798a Mon Sep 17 00:00:00 2001 From: MellyGray Date: Wed, 13 Dec 2023 16:45:02 +0100 Subject: [PATCH 02/15] feat(FilePage): add loading state --- src/sections/file/File.tsx | 18 ++++++++++--- src/sections/file/FileSkeleton.tsx | 25 +++++++++++++++++++ src/stories/files/File.stories.tsx | 11 ++++---- .../files/FileMockLoadingRepository.ts | 10 ++++++++ tests/component/sections/file/File.spec.tsx | 11 ++++++++ 5 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/sections/file/FileSkeleton.tsx diff --git a/src/sections/file/File.tsx b/src/sections/file/File.tsx index 3378fc9e8..3fcb882b3 100644 --- a/src/sections/file/File.tsx +++ b/src/sections/file/File.tsx @@ -4,14 +4,26 @@ import styles from './File.module.scss' import { Tabs } from '@iqss/dataverse-design-system' import { FileRepository } from '../../files/domain/repositories/FileRepository' import { useFile } from './useFile' +import { useEffect } from 'react' +import { useLoading } from '../loading/LoadingContext' +import { FileSkeleton } from './FileSkeleton' interface FileProps { repository: FileRepository id: number } export function File({ repository, id }: FileProps) { + const { setIsLoading } = useLoading() const { t } = useTranslation('file') - const { file } = useFile(repository, id) + const { file, isLoading } = useFile(repository, id) + + useEffect(() => { + setIsLoading(isLoading) + }, [isLoading]) + + if (isLoading) { + return + } return ( <> @@ -26,8 +38,8 @@ export function File({ repository, id }: FileProps) {
- - + + diff --git a/src/sections/file/FileSkeleton.tsx b/src/sections/file/FileSkeleton.tsx new file mode 100644 index 000000000..c92f46c0b --- /dev/null +++ b/src/sections/file/FileSkeleton.tsx @@ -0,0 +1,25 @@ +import styles from '../dataset/Dataset.module.scss' +import Skeleton, { SkeletonTheme } from 'react-loading-skeleton' +import { Tabs } from '@iqss/dataverse-design-system' + +export function FileSkeleton() { + return ( + +
+
+

+ +

+ +
+
+ + + + + +
+
+
+ ) +} diff --git a/src/stories/files/File.stories.tsx b/src/stories/files/File.stories.tsx index fa9697942..28ea47dd4 100644 --- a/src/stories/files/File.stories.tsx +++ b/src/stories/files/File.stories.tsx @@ -3,15 +3,12 @@ import { WithI18next } from '../WithI18next' import { FileMockRepository } from './FileMockRepository' import { File } from '../../sections/file/File' import { WithLayout } from '../WithLayout' +import { FileMockLoadingRepository } from './FileMockLoadingRepository' const meta: Meta = { title: 'Pages/File', component: File, - decorators: [WithI18next, WithLayout], - parameters: { - // Sets the delay for all stories. - chromatic: { delay: 15000, pauseAnimationAtEnd: true } - } + decorators: [WithI18next, WithLayout] } export default meta @@ -20,3 +17,7 @@ type Story = StoryObj export const Default: Story = { render: () => } + +export const Loading: Story = { + render: () => +} diff --git a/src/stories/files/FileMockLoadingRepository.ts b/src/stories/files/FileMockLoadingRepository.ts index 5210f5765..e7eaf02bb 100644 --- a/src/stories/files/FileMockLoadingRepository.ts +++ b/src/stories/files/FileMockLoadingRepository.ts @@ -4,6 +4,7 @@ import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' import { DatasetVersion } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' import { FileMockRepository } from './FileMockRepository' +import { File } from '../../files/domain/models/File' export class FileMockLoadingRepository extends FileMockRepository implements FileRepository { getAllByDatasetPersistentId( @@ -33,4 +34,13 @@ export class FileMockLoadingRepository extends FileMockRepository implements Fil }, 1000) }) } + + // eslint-disable-next-line unused-imports/no-unused-vars + getById(id: number): Promise { + return new Promise(() => { + setTimeout(() => { + // Do nothing + }, 1000) + }) + } } diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx index e2e7fd3cb..260bb676f 100644 --- a/tests/component/sections/file/File.spec.tsx +++ b/tests/component/sections/file/File.spec.tsx @@ -16,4 +16,15 @@ describe('File', () => { cy.findAllByText(testFile.name).should('exist') cy.findByText(`This file is part of "${testFile.datasetTitle}".`).should('exist') }) + + it('renders skeleton while loading', () => { + const testFile = FileMother.createRealistic() + fileRepository.getById = cy.stub().resolves(testFile) + + cy.customMount() + + cy.findByTestId('file-skeleton').should('exist') + cy.wrap(fileRepository.getById).should('be.calledWith', 19) + cy.findByText(testFile.name).should('not.exist') + }) }) From 4090af5afa39eb3357f754efdd4bc7d66038aa5a Mon Sep 17 00:00:00 2001 From: MellyGray Date: Wed, 13 Dec 2023 16:53:49 +0100 Subject: [PATCH 03/15] feat(FilePage): add file not found state --- src/files/domain/repositories/FileRepository.ts | 2 +- src/files/domain/useCases/getFileById.ts | 5 ++++- src/sections/file/useFile.tsx | 2 +- src/stories/files/File.stories.tsx | 5 +++++ src/stories/files/FileMockNoDataRepository.ts | 10 ++++++++++ src/stories/files/FileMockRepository.ts | 2 +- tests/component/sections/file/File.spec.tsx | 8 ++++++++ 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/files/domain/repositories/FileRepository.ts b/src/files/domain/repositories/FileRepository.ts index 8b46323e4..666f7ae2d 100644 --- a/src/files/domain/repositories/FileRepository.ts +++ b/src/files/domain/repositories/FileRepository.ts @@ -24,5 +24,5 @@ export interface FileRepository { criteria?: FileCriteria ) => Promise getUserPermissionsById: (id: number) => Promise - getById: (id: number) => Promise + getById: (id: number) => Promise } diff --git a/src/files/domain/useCases/getFileById.ts b/src/files/domain/useCases/getFileById.ts index 9cefdae31..226c9e711 100644 --- a/src/files/domain/useCases/getFileById.ts +++ b/src/files/domain/useCases/getFileById.ts @@ -1,7 +1,10 @@ import { FileRepository } from '../repositories/FileRepository' import { File } from '../models/File' -export async function getFileById(repository: FileRepository, id: number): Promise { +export async function getFileById( + repository: FileRepository, + id: number +): Promise { return repository.getById(id).catch((error: Error) => { throw new Error(error.message) }) diff --git a/src/sections/file/useFile.tsx b/src/sections/file/useFile.tsx index 49ff6a7d3..91ac72510 100644 --- a/src/sections/file/useFile.tsx +++ b/src/sections/file/useFile.tsx @@ -11,7 +11,7 @@ export function useFile(repository: FileRepository, id: number) { setIsLoading(true) getFileById(repository, id) - .then((file: File) => { + .then((file: File | undefined) => { setFile(file) setIsLoading(false) }) diff --git a/src/stories/files/File.stories.tsx b/src/stories/files/File.stories.tsx index 28ea47dd4..060fe8dfc 100644 --- a/src/stories/files/File.stories.tsx +++ b/src/stories/files/File.stories.tsx @@ -4,6 +4,7 @@ import { FileMockRepository } from './FileMockRepository' import { File } from '../../sections/file/File' import { WithLayout } from '../WithLayout' import { FileMockLoadingRepository } from './FileMockLoadingRepository' +import { FileMockNoDataRepository } from './FileMockNoDataRepository' const meta: Meta = { title: 'Pages/File', @@ -21,3 +22,7 @@ export const Default: Story = { export const Loading: Story = { render: () => } + +export const FileNotFound: Story = { + render: () => +} diff --git a/src/stories/files/FileMockNoDataRepository.ts b/src/stories/files/FileMockNoDataRepository.ts index 22a1ad3a5..0db3ae4e3 100644 --- a/src/stories/files/FileMockNoDataRepository.ts +++ b/src/stories/files/FileMockNoDataRepository.ts @@ -5,6 +5,7 @@ import { FilesCountInfoMother } from '../../../tests/component/files/domain/mode import { DatasetVersion } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' import { FileMockRepository } from './FileMockRepository' +import { File } from '../../files/domain/models/File' export class FileMockNoDataRepository extends FileMockRepository implements FileRepository { getAllByDatasetPersistentId( @@ -47,4 +48,13 @@ export class FileMockNoDataRepository extends FileMockRepository implements File }, 1000) }) } + + // eslint-disable-next-line unused-imports/no-unused-vars + getById(id: number): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve(undefined) + }, 1000) + }) + } } diff --git a/src/stories/files/FileMockRepository.ts b/src/stories/files/FileMockRepository.ts index ecd9036ab..c8b9eebbf 100644 --- a/src/stories/files/FileMockRepository.ts +++ b/src/stories/files/FileMockRepository.ts @@ -63,7 +63,7 @@ export class FileMockRepository implements FileRepository { } // eslint-disable-next-line unused-imports/no-unused-vars - getById(id: number): Promise { + getById(id: number): Promise { return new Promise((resolve) => { setTimeout(() => { resolve(FileMother.createRealistic()) diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx index 260bb676f..cfc07956e 100644 --- a/tests/component/sections/file/File.spec.tsx +++ b/tests/component/sections/file/File.spec.tsx @@ -27,4 +27,12 @@ describe('File', () => { cy.wrap(fileRepository.getById).should('be.calledWith', 19) cy.findByText(testFile.name).should('not.exist') }) + + it('renders page not found when file is not found', () => { + fileRepository.getById = cy.stub().resolves(undefined) + + cy.customMount() + + cy.findByText('Page Not Found').should('exist') + }) }) From 9864ba1ef213f0d34ffd624ce200ba15200abd04 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Wed, 13 Dec 2023 18:04:25 +0100 Subject: [PATCH 04/15] feat(FilePage): add route to the page --- .storybook/preview.tsx | 5 +++- src/Router.tsx | 7 +++++- src/files/domain/models/FilePreview.ts | 4 ---- src/sections/Route.enum.ts | 3 ++- .../file-info/file-info-cell/FileInfoCell.tsx | 2 +- .../file-info-data/FileTitle.tsx | 13 +++++++--- src/sections/file/FileFactory.tsx | 24 +++++++++++++++++++ .../shared/link-to-page/LinkToPage.tsx | 20 ++++++++++++++++ src/stories/WithLayout.tsx | 14 +++++------ .../file-info-data/FileTitle.spec.tsx | 11 ++------- .../shared/link-to-page/LinkToPage.spec.tsx | 14 +++++++++++ .../e2e/sections/file/File.spec.tsx | 6 +++++ tests/support/commands.tsx | 9 ++++--- 13 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 src/sections/file/FileFactory.tsx create mode 100644 src/sections/shared/link-to-page/LinkToPage.tsx create mode 100644 tests/component/sections/shared/link-to-page/LinkToPage.spec.tsx create mode 100644 tests/e2e-integration/e2e/sections/file/File.spec.tsx diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index 030e967bd..a7db0d900 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -1,5 +1,6 @@ import type { Preview } from '@storybook/react' import { ThemeProvider } from '@iqss/dataverse-design-system' +import { MemoryRouter } from 'react-router-dom' const preview: Preview = { parameters: { @@ -14,7 +15,9 @@ const preview: Preview = { decorators: [ (Story) => ( - + + + ) ] diff --git a/src/Router.tsx b/src/Router.tsx index 38d016834..47a48ede1 100644 --- a/src/Router.tsx +++ b/src/Router.tsx @@ -3,6 +3,7 @@ import { HelloDataverse } from './sections/hello-dataverse/HelloDataverse' import { Layout } from './sections/layout/Layout' import { Route } from './sections/Route.enum' import { DatasetFactory } from './sections/dataset/DatasetFactory' +import { FileFactory } from './sections/file/FileFactory' const router = createBrowserRouter( [ @@ -15,8 +16,12 @@ const router = createBrowserRouter( element: }, { - path: `${Route.DATASETS}`, + path: Route.DATASETS, element: DatasetFactory.create() + }, + { + path: Route.FILES, + element: FileFactory.create() } ] } diff --git a/src/files/domain/models/FilePreview.ts b/src/files/domain/models/FilePreview.ts index 28ae70723..439452601 100644 --- a/src/files/domain/models/FilePreview.ts +++ b/src/files/domain/models/FilePreview.ts @@ -190,10 +190,6 @@ export class FilePreview { readonly checksum?: FileChecksum ) {} - getLink(): string { - return `/file?id=${this.id}&version=${this.version.number}` - } - get isActivelyEmbargoed(): boolean { if (this.embargo) { return this.embargo.isActive diff --git a/src/sections/Route.enum.ts b/src/sections/Route.enum.ts index a63752a54..f2d93694e 100644 --- a/src/sections/Route.enum.ts +++ b/src/sections/Route.enum.ts @@ -3,5 +3,6 @@ export enum Route { SIGN_UP = '/dataverseuser.xhtml?editMode=CREATE&redirectPage=%2Fdataverse.xhtml', LOG_IN = '/loginpage.xhtml?redirectPage=%2Fdataverse.xhtml', LOG_OUT = '/', - DATASETS = 'datasets' + DATASETS = '/datasets', + FILES = '/files' } diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx index f83f18ba1..5265e2391 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.tsx @@ -19,7 +19,7 @@ export function FileInfoCell({ file }: { file: FilePreview }) {
- +
diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle.tsx index 40e9aa172..4b26ef7bf 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle.tsx @@ -1,8 +1,15 @@ +import { LinkToPage } from '../../../../../../shared/link-to-page/LinkToPage' +import { Route } from '../../../../../../Route.enum' + interface FileTitleProps { - link: string + id: number name: string } -export function FileTitle({ link, name }: FileTitleProps) { - return {name} +export function FileTitle({ id, name }: FileTitleProps) { + return ( + + {name} + + ) } diff --git a/src/sections/file/FileFactory.tsx b/src/sections/file/FileFactory.tsx new file mode 100644 index 000000000..27bec3498 --- /dev/null +++ b/src/sections/file/FileFactory.tsx @@ -0,0 +1,24 @@ +import { ReactElement } from 'react' +import { FileJSDataverseRepository } from '../../files/infrastructure/FileJSDataverseRepository' +import { File } from './File' +import { useSearchParams } from 'react-router-dom' +import { PageNotFound } from '../page-not-found/PageNotFound' + +const repository = new FileJSDataverseRepository() +export class FileFactory { + static create(): ReactElement { + return + } +} + +function FileWithSearchParams() { + const [searchParams] = useSearchParams() + const searchParamId = searchParams.get('id') ?? undefined + const id = searchParamId ? parseInt(searchParamId) : undefined + + if (!id) { + return + } + + return +} diff --git a/src/sections/shared/link-to-page/LinkToPage.tsx b/src/sections/shared/link-to-page/LinkToPage.tsx new file mode 100644 index 000000000..dd38a28af --- /dev/null +++ b/src/sections/shared/link-to-page/LinkToPage.tsx @@ -0,0 +1,20 @@ +import { Link } from 'react-router-dom' +import { PropsWithChildren } from 'react' +import { Route } from '../../Route.enum' + +interface LinkToPageProps { + page: Route + searchParams?: Record +} + +export function LinkToPage({ children, page, searchParams }: PropsWithChildren) { + const searchParamsString: string = searchParams ? '?' + encodeSearchParamsToURI(searchParams) : '' + + return {children} +} + +const encodeSearchParamsToURI = (searchParams: Record) => { + return Object.entries(searchParams) + .map(([key, value]) => `${key}=${value}`) + .join('&') +} diff --git a/src/stories/WithLayout.tsx b/src/stories/WithLayout.tsx index 2dc1dcc0d..34a5af36d 100644 --- a/src/stories/WithLayout.tsx +++ b/src/stories/WithLayout.tsx @@ -1,16 +1,14 @@ import { StoryFn } from '@storybook/react' -import { MemoryRouter as Router, Routes, Route } from 'react-router-dom' +import { Routes, Route } from 'react-router-dom' import { Layout } from '../sections/layout/Layout' import { LoadingProvider } from '../sections/loading/LoadingProvider' export const WithLayout = (Story: StoryFn) => ( - - - }> - } /> - - - + + }> + } /> + + ) diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx index 536fc64c7..55c45df94 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileTitle.spec.tsx @@ -1,24 +1,17 @@ import { FilePreviewMother } from '../../../../../../../files/domain/models/FilePreviewMother' import { FileTitle } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle' -import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/FilePreview' describe('FileTitle', () => { it('renders the link and name correctly', () => { const id = 12345 - const versionParameter = '&version=1' const name = 'file-name.txt' const file = FilePreviewMother.create({ id: id, - version: { number: 1, publishingStatus: FilePublishingStatus.RELEASED }, name: name }) - cy.customMount() + cy.customMount() - cy.findByRole('link', { name: name }).should( - 'have.attr', - 'href', - `/file?id=${id}${versionParameter}` - ) + cy.findByRole('link', { name: name }).should('have.attr', 'href', `/files?id=${id}`) }) }) diff --git a/tests/component/sections/shared/link-to-page/LinkToPage.spec.tsx b/tests/component/sections/shared/link-to-page/LinkToPage.spec.tsx new file mode 100644 index 000000000..25d166231 --- /dev/null +++ b/tests/component/sections/shared/link-to-page/LinkToPage.spec.tsx @@ -0,0 +1,14 @@ +import { LinkToPage } from '../../../../../src/sections/shared/link-to-page/LinkToPage' +import { Route } from '../../../../../src/sections/Route.enum' + +describe('LinkToPage', () => { + it('renders a link to the page with the given search params', () => { + cy.customMount() + cy.findByRole('link').should('have.attr', 'href', '/datasets?foo=bar') + }) + + it('renders a link to the page without search params', () => { + cy.customMount() + cy.findByRole('link').should('have.attr', 'href', '/datasets') + }) +}) diff --git a/tests/e2e-integration/e2e/sections/file/File.spec.tsx b/tests/e2e-integration/e2e/sections/file/File.spec.tsx new file mode 100644 index 000000000..dac419c86 --- /dev/null +++ b/tests/e2e-integration/e2e/sections/file/File.spec.tsx @@ -0,0 +1,6 @@ +describe('File', () => { + it('successfully loads', () => { + cy.visit('/spa/files?id=23') + cy.findAllByText('file.csv').should('exist') + }) +}) diff --git a/tests/support/commands.tsx b/tests/support/commands.tsx index 92229d209..d0f69cdf9 100644 --- a/tests/support/commands.tsx +++ b/tests/support/commands.tsx @@ -45,14 +45,17 @@ import { I18nextProvider } from 'react-i18next' import i18next from '../../src/i18n' import { UserRepository } from '../../src/users/domain/repositories/UserRepository' import { SessionProvider } from '../../src/sections/session/SessionProvider' +import { MemoryRouter } from 'react-router-dom' // Define your custom mount function Cypress.Commands.add('customMount', (component: ReactNode) => { return cy.mount( - - {component} - + + + {component} + + ) }) From 37180ad85259d370d2f5779fc63f7b455d7015da Mon Sep 17 00:00:00 2001 From: MellyGray Date: Fri, 15 Dec 2023 16:44:53 +0100 Subject: [PATCH 05/15] refactor: move citation to DatasetVersion --- src/dataset/domain/models/Dataset.ts | 6 +- .../infrastructure/mappers/JSDatasetMapper.ts | 16 ++--- src/sections/dataset/Dataset.tsx | 1 - .../dataset-citation/DatasetCitation.tsx | 18 ++++-- .../dataset-alerts/DatasetAlert.stories.tsx | 7 ++- .../DatasetCitation.stories.tsx | 58 ++++--------------- .../dataset/domain/models/DatasetMother.ts | 43 +++++++++----- .../dataset-citation/DatasetCitation.spec.tsx | 48 ++------------- .../dataset/dataset-files/useFiles.spec.tsx | 1 + .../DatasetJSDataverseRepository.spec.ts | 17 ++++-- .../files/FileJSDataverseRepository.spec.ts | 2 + 11 files changed, 90 insertions(+), 127 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 3decbc088..258f99b88 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -220,9 +220,10 @@ export class DatasetVersion { public readonly isLatest: boolean, public readonly isInReview: boolean, public readonly latestVersionStatus: DatasetPublishingStatus, + public readonly citation: string, public readonly majorNumber?: number, - public readonly minorNumber?: number, // requestedVersion will be set if the user requested a version that did not exist. + public readonly minorNumber?: number, public readonly requestedVersion?: string ) {} @@ -273,7 +274,6 @@ export class Dataset { constructor( public readonly persistentId: string, public readonly version: DatasetVersion, - public readonly citation: string, public readonly labels: DatasetLabel[], public readonly alerts: Alert[], public readonly summaryFields: DatasetMetadataBlock[], @@ -361,7 +361,6 @@ export class Dataset { constructor( public readonly persistentId: string, public readonly version: DatasetVersion, - public readonly citation: string, public readonly summaryFields: DatasetMetadataBlock[], public readonly license: DatasetLicense = defaultLicense, public readonly metadataBlocks: DatasetMetadataBlocks, @@ -470,7 +469,6 @@ export class Dataset { return new Dataset( this.persistentId, this.version, - this.citation, this.labels, this.alerts, this.summaryFields, diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index 95703678d..1feb01ce8 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -26,8 +26,8 @@ import { export class JSDatasetMapper { static toDataset( jsDataset: JSDataset, - citation: string, - summaryFieldsNames: string[], + jsDatasetCitation: string, + jsDatasetSummaryFieldsNames: string[], jsDatasetPermissions: JSDatasetPermissions, jsDatasetLocks: JSDatasetLock[], requestedVersion?: string, @@ -36,13 +36,13 @@ export class JSDatasetMapper { const version = JSDatasetMapper.toVersion( jsDataset.versionId, jsDataset.versionInfo, + jsDatasetCitation, requestedVersion ) return new Dataset.Builder( jsDataset.persistentId, version, - citation, - JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames), + JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, jsDatasetSummaryFieldsNames), jsDataset.license, JSDatasetMapper.toMetadataBlocks( jsDataset.metadataBlocks, @@ -66,14 +66,16 @@ export class JSDatasetMapper { static toVersion( jDatasetVersionId: number, jsDatasetVersionInfo: JSDatasetVersionInfo, + jsDatasetCitation: string, requestedVersion?: string ): DatasetVersion { return new DatasetVersion( jDatasetVersionId, JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), - true, // TODO Connect with dataset version isLatest - false, // TODO Connect with dataset version isInReview - JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), // TODO Connect with dataset version latestVersionState + true, + false, + JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), + jsDatasetCitation, jsDatasetVersionInfo.majorNumber, jsDatasetVersionInfo.minorNumber, requestedVersion diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index 8095e0ae8..27e0eb4ff 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -60,7 +60,6 @@ export function Dataset({ fileRepository }: DatasetProps) { diff --git a/src/sections/dataset/dataset-citation/DatasetCitation.tsx b/src/sections/dataset/dataset-citation/DatasetCitation.tsx index 9b523c7c7..fa29beee4 100644 --- a/src/sections/dataset/dataset-citation/DatasetCitation.tsx +++ b/src/sections/dataset/dataset-citation/DatasetCitation.tsx @@ -8,11 +8,10 @@ import { CitationThumbnail } from './CitationThumbnail' interface DatasetCitationProps { thumbnail?: string title: string - citation: string version: DatasetVersion } -export function DatasetCitation({ thumbnail, title, citation, version }: DatasetCitationProps) { +export function DatasetCitation({ thumbnail, title, version }: DatasetCitationProps) { const { t } = useTranslation('dataset') return ( <> @@ -32,7 +31,10 @@ export function DatasetCitation({ thumbnail, title, citation, version }: Dataset - +
@@ -53,13 +55,19 @@ export function DatasetCitation({ thumbnail, title, citation, version }: Dataset ) } -function CitationDescription({ citation, version }: { citation: string; version: DatasetVersion }) { +function CitationDescription({ + citation, + publishingStatus +}: { + citation: string + publishingStatus: DatasetPublishingStatus +}) { const citationAsReactElement = parse(citation) return ( {citationAsReactElement} - + ) } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 31de08bf7..0eabf83f2 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -62,7 +62,8 @@ export const DraftVersion: Story = { DatasetPublishingStatus.DRAFT, true, false, - DatasetPublishingStatus.DRAFT + DatasetPublishingStatus.DRAFT, + '' ), permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed() }) @@ -83,6 +84,7 @@ export const VersionNotFound: Story = { true, false, DatasetPublishingStatus.RELEASED, + '', 1, 0, '3.0' @@ -105,6 +107,7 @@ export const VersionNotFoundShowDraft: Story = { true, false, DatasetPublishingStatus.DRAFT, + '', 1, 0, '3.0' @@ -127,6 +130,7 @@ export const SharePrivateUrl: Story = { true, false, DatasetPublishingStatus.DRAFT, + '', 1, 0 ), @@ -153,6 +157,7 @@ export const UsePrivateUrl: Story = { true, false, DatasetPublishingStatus.DRAFT, + '', 1, 0 ), diff --git a/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx b/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx index cd7d511d4..359c5d133 100644 --- a/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx +++ b/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx @@ -1,9 +1,11 @@ import type { Meta, StoryObj } from '@storybook/react' import { WithI18next } from '../../WithI18next' import { DatasetCitation } from '../../../sections/dataset/dataset-citation/DatasetCitation' -import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset' import { faker } from '@faker-js/faker' -import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' +import { + DatasetMother, + DatasetVersionMother +} from '../../../../tests/component/dataset/domain/models/DatasetMother' const meta: Meta = { title: 'Sections/Dataset Page/DatasetCitation', @@ -21,11 +23,7 @@ export const Default: Story = {




- +
) } @@ -41,7 +39,6 @@ export const WithThumbnail: Story = {
@@ -52,15 +49,7 @@ export const WithThumbnail: Story = { export const DraftVersion: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - citation: - 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, DRAFT VERSION', - version: new DatasetVersion( - 1, - DatasetPublishingStatus.DRAFT, - true, - false, - DatasetPublishingStatus.DRAFT - ) + version: DatasetVersionMother.createDraft() }) /* @@ -70,11 +59,7 @@ export const DraftVersion: Story = {




- +
) } @@ -83,17 +68,7 @@ export const DraftVersion: Story = { export const Deaccessioned: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - citation: - 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1 DEACCESSIONED VERSION', - version: new DatasetVersion( - 1, - DatasetPublishingStatus.DEACCESSIONED, - true, - false, - DatasetPublishingStatus.DEACCESSIONED, - 1, - 0 - ) + version: DatasetVersionMother.createDeaccessioned() }) /* @@ -103,11 +78,7 @@ export const Deaccessioned: Story = {




- +
) } @@ -115,10 +86,7 @@ export const Deaccessioned: Story = { export const Anonymized: Story = { render: () => { - const dataset = DatasetMother.createRealistic({ - citation: - 'Author name(s) withheld, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1' - }) + const dataset = DatasetMother.createRealisticAnonymized() /* Includes extra breaks, so you can see the DRAFT tooltip message @@ -127,11 +95,7 @@ export const Anonymized: Story = {




- +
) } diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 60e8e7e14..65a535d57 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -26,6 +26,8 @@ export class DatasetVersionMother { props?.isLatest ?? false, props?.isInReview ?? false, props?.latestVersionStatus ?? DatasetPublishingStatus.RELEASED, + props?.citation ?? + 'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', props?.majorNumber ?? 1, props?.minorNumber ?? 0 ) @@ -36,20 +38,28 @@ export class DatasetVersionMother { } static createDeaccessioned(): DatasetVersion { - return this.create({ publishingStatus: DatasetPublishingStatus.DEACCESSIONED }) + return this.create({ + publishingStatus: DatasetPublishingStatus.DEACCESSIONED, + citation: + 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1 DEACCESSIONED VERSION' + }) } - static createDraftAsLatestVersion(): DatasetVersion { - return this.create({ publishingStatus: DatasetPublishingStatus.DRAFT, isLatest: true }) + static createDraft(props?: Partial): DatasetVersion { + return this.create({ + publishingStatus: DatasetPublishingStatus.DRAFT, + citation: + 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, DRAFT VERSION', + ...props + }) } - static createDraft(): DatasetVersion { - return this.create({ publishingStatus: DatasetPublishingStatus.DRAFT }) + static createDraftAsLatestVersion(): DatasetVersion { + return this.createDraft({ publishingStatus: DatasetPublishingStatus.DRAFT, isLatest: true }) } static createDraftAsLatestVersionInReview(): DatasetVersion { - return this.create({ - publishingStatus: DatasetPublishingStatus.DRAFT, + return this.createDraft({ isLatest: true, isInReview: true }) @@ -64,8 +74,7 @@ export class DatasetVersionMother { } static createDraftWithLatestVersionIsADraft(): DatasetVersion { - return this.create({ - publishingStatus: DatasetPublishingStatus.DRAFT, + return this.createDraft({ isLatest: true, latestVersionStatus: DatasetPublishingStatus.DRAFT }) @@ -78,6 +87,12 @@ export class DatasetVersionMother { latestVersionStatus: DatasetPublishingStatus.RELEASED }) } + + static createAnonymized(): DatasetVersion { + return this.create({ + citation: `Author name(s) withheld, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1` + }) + } } export class DatasetPermissionsMother { @@ -222,8 +237,6 @@ export class DatasetMother { persistentId: faker.datatype.uuid(), title: faker.lorem.sentence(), version: DatasetVersionMother.create(), - citation: - 'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', license: { name: 'CC0 1.0', uri: 'https://creativecommons.org/publicdomain/zero/1.0/', @@ -328,7 +341,6 @@ export class DatasetMother { return new Dataset.Builder( dataset.persistentId, dataset.version, - dataset.citation, dataset.summaryFields, dataset.license, dataset.metadataBlocks, @@ -354,8 +366,7 @@ export class DatasetMother { static createAnonymized(): Dataset { return this.create({ - citation: - 'Author name(s) withheld, 2023, "citation", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', + version: DatasetVersionMother.createAnonymized(), metadataBlocks: [ { name: MetadataBlockName.CITATION, @@ -385,13 +396,13 @@ export class DatasetMother { static createRealistic(props?: Partial): Dataset { return this.create({ persistentId: 'doi:10.5072/FK2/ABC123', - citation: `Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1`, version: new DatasetVersion( 1, DatasetPublishingStatus.RELEASED, false, false, DatasetPublishingStatus.RELEASED, + `Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1`, 1, 0 ), @@ -492,7 +503,7 @@ export class DatasetMother { static createRealisticAnonymized(): Dataset { return this.createRealistic({ - citation: `Author name(s) withheld, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1`, + version: DatasetVersionMother.createAnonymized(), metadataBlocks: [ { name: MetadataBlockName.CITATION, diff --git a/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx b/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx index 65d4c3fb3..d628fa278 100644 --- a/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx +++ b/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx @@ -1,20 +1,10 @@ import { DatasetCitation } from '../../../../../src/sections/dataset/dataset-citation/DatasetCitation' -import { DatasetMother } from '../../../dataset/domain/models/DatasetMother' -import { - DatasetPublishingStatus, - DatasetVersion -} from '../../../../../src/dataset/domain/models/Dataset' +import { DatasetMother, DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' describe('DatasetCitation', () => { it('renders the DatasetCitation fields of released Dataset', () => { const dataset = DatasetMother.create() - cy.customMount( - - ) + cy.customMount() cy.findByText('Data Citation Standards.').should('exist') cy.findByText(/Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title"/).should('exist') @@ -31,21 +21,9 @@ describe('DatasetCitation', () => { it('shows the draft tooltip when version is draft', () => { const dataset = DatasetMother.create({ - version: new DatasetVersion( - 1, - DatasetPublishingStatus.DRAFT, - true, - false, - DatasetPublishingStatus.DRAFT - ) + version: DatasetVersionMother.createDraft() }) - cy.customMount( - - ) + cy.customMount() cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover') cy.findByText( @@ -55,23 +33,9 @@ describe('DatasetCitation', () => { it('shows the deaccessioned tooltip when version is deaccessioned', () => { const dataset = DatasetMother.create({ - version: new DatasetVersion( - 1, - DatasetPublishingStatus.DEACCESSIONED, - true, - false, - DatasetPublishingStatus.DEACCESSIONED, - 1, - 0 - ) + version: DatasetVersionMother.createDeaccessioned() }) - cy.customMount( - - ) + cy.customMount() cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover') cy.findByText( diff --git a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx index 5ef68d479..8a0cb0378 100644 --- a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx @@ -21,6 +21,7 @@ const datasetVersion = new DatasetVersion( true, false, DatasetPublishingStatus.RELEASED, + '', 1, 0 ) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 1aa52c69a..0bb66adc4 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -19,10 +19,13 @@ function getCurrentDateInYYYYMMDDFormat() { ).padStart(2, '0')}` } +function getPersistentIdUrl(persistentId: string) { + return `https://doi.org/${persistentId.replace('doi:', '')}` +} + const datasetData = (persistentId: string, versionId: number) => { - const persistentIdUrl = `https://doi.org/${persistentId.replace('doi:', '')}` + const persistentIdUrl = getPersistentIdUrl(persistentId) return { - citation: `Finch, Fiona, 2023, "Darwin's Finches", ${persistentIdUrl}, Root, DRAFT VERSION`, labels: [ { semanticMeaning: 'dataset', value: 'Draft' }, { semanticMeaning: 'warning', value: 'Unpublished' } @@ -80,7 +83,8 @@ const datasetData = (persistentId: string, versionId: number) => { requestedVersion: undefined, latestVersionStatus: 'draft', isLatest: true, - isInReview: false + isInReview: false, + citation: `Finch, Fiona, 2023, "Darwin's Finches", ${persistentIdUrl}, Root, DRAFT VERSION` }, permissions: { canDownloadFiles: true, @@ -109,7 +113,6 @@ describe('Dataset JSDataverse Repository', () => { const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) - expect(dataset.citation).to.deep.equal(datasetExpected.citation) expect(dataset.labels).to.deep.equal(datasetExpected.labels) expect(dataset.license).to.deep.equal(datasetExpected.license) expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks) @@ -143,6 +146,9 @@ describe('Dataset JSDataverse Repository', () => { true, false, DatasetPublishingStatus.RELEASED, + `Finch, Fiona, 2023, "Darwin's Finches", ${getPersistentIdUrl(dataset.persistentId)}, Root, V1`, 1, 0 ) @@ -181,6 +187,9 @@ describe('Dataset JSDataverse Repository', () => { true, false, DatasetPublishingStatus.RELEASED, + `Finch, Fiona, 2023, "Darwin's Finches", ${getPersistentIdUrl(dataset.persistentId)}, Root, V1`, 1, 0 ) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 4f2c8b1a2..de359b7de 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -150,6 +150,7 @@ describe('File JSDataverse Repository', () => { true, false, DatasetPublishingStatus.RELEASED, + '', 1, 0 ) @@ -186,6 +187,7 @@ describe('File JSDataverse Repository', () => { true, false, DatasetPublishingStatus.DEACCESSIONED, + '', 1, 0 ) From 62b69b25b6496d9c451a79ead88b008dd35f5b8d Mon Sep 17 00:00:00 2001 From: MellyGray Date: Fri, 15 Dec 2023 17:04:47 +0100 Subject: [PATCH 06/15] refactor: move title to DatasetVersion --- src/dataset/domain/models/Dataset.ts | 7 ++--- .../infrastructure/mappers/JSDatasetMapper.ts | 3 ++ src/sections/dataset/Dataset.tsx | 8 ++--- .../dataset-citation/DatasetCitation.tsx | 5 ++- .../dataset-alerts/DatasetAlert.stories.tsx | 5 +++ .../DatasetCitation.stories.tsx | 25 +++++---------- .../dataset/domain/models/DatasetMother.ts | 31 ++++++++++++------- .../sections/dataset/Dataset.spec.tsx | 6 ++-- .../sections/dataset/DatasetProvider.spec.tsx | 8 ++--- .../dataset-citation/DatasetCitation.spec.tsx | 18 +++++------ .../dataset/dataset-files/useFiles.spec.tsx | 1 + .../DatasetJSDataverseRepository.spec.ts | 19 +++++++----- .../files/FileJSDataverseRepository.spec.ts | 2 ++ 13 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 258f99b88..841ea4a79 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -216,13 +216,14 @@ export enum DatasetNonNumericVersion { export class DatasetVersion { constructor( public readonly id: number, + public readonly title: string, public readonly publishingStatus: DatasetPublishingStatus, public readonly isLatest: boolean, public readonly isInReview: boolean, public readonly latestVersionStatus: DatasetPublishingStatus, public readonly citation: string, - public readonly majorNumber?: number, // requestedVersion will be set if the user requested a version that did not exist. + public readonly majorNumber?: number, public readonly minorNumber?: number, public readonly requestedVersion?: string ) {} @@ -291,10 +292,6 @@ export class Dataset { public readonly fileDownloadSizes?: FileDownloadSize[] ) {} - public getTitle(): string { - return this.metadataBlocks[0].fields.title - } - public checkIsLockedFromPublishing(userPersistentId: string): boolean { return this.checkIsLockedFromEdits(userPersistentId) } diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index 1feb01ce8..efda41029 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -36,6 +36,7 @@ export class JSDatasetMapper { const version = JSDatasetMapper.toVersion( jsDataset.versionId, jsDataset.versionInfo, + jsDataset.metadataBlocks, jsDatasetCitation, requestedVersion ) @@ -66,11 +67,13 @@ export class JSDatasetMapper { static toVersion( jDatasetVersionId: number, jsDatasetVersionInfo: JSDatasetVersionInfo, + jsDatasetMetadataBlocks: JSDatasetMetadataBlocks, jsDatasetCitation: string, requestedVersion?: string ): DatasetVersion { return new DatasetVersion( jDatasetVersionId, + jsDatasetMetadataBlocks[0].fields.title, JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), true, false, diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index 27e0eb4ff..5daefed86 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -51,17 +51,13 @@ export function Dataset({ fileRepository }: DatasetProps) {
-

{dataset.getTitle()}

+

{dataset.version.title}

- + diff --git a/src/sections/dataset/dataset-citation/DatasetCitation.tsx b/src/sections/dataset/dataset-citation/DatasetCitation.tsx index fa29beee4..976a17dc8 100644 --- a/src/sections/dataset/dataset-citation/DatasetCitation.tsx +++ b/src/sections/dataset/dataset-citation/DatasetCitation.tsx @@ -7,11 +7,10 @@ import { CitationThumbnail } from './CitationThumbnail' interface DatasetCitationProps { thumbnail?: string - title: string version: DatasetVersion } -export function DatasetCitation({ thumbnail, title, version }: DatasetCitationProps) { +export function DatasetCitation({ thumbnail, version }: DatasetCitationProps) { const { t } = useTranslation('dataset') return ( <> @@ -25,7 +24,7 @@ export function DatasetCitation({ thumbnail, title, version }: DatasetCitationPr diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 0eabf83f2..733bcb1fd 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -59,6 +59,7 @@ export const DraftVersion: Story = { const dataset = DatasetMother.createRealistic({ version: new DatasetVersion( 1, + '', DatasetPublishingStatus.DRAFT, true, false, @@ -80,6 +81,7 @@ export const VersionNotFound: Story = { const dataset = DatasetMother.createRealistic({ version: new DatasetVersion( 1, + '', DatasetPublishingStatus.RELEASED, true, false, @@ -103,6 +105,7 @@ export const VersionNotFoundShowDraft: Story = { const dataset = DatasetMother.createRealistic({ version: new DatasetVersion( 1, + '', DatasetPublishingStatus.DRAFT, true, false, @@ -126,6 +129,7 @@ export const SharePrivateUrl: Story = { const dataset = DatasetMother.createRealistic({ version: new DatasetVersion( 1, + '', DatasetPublishingStatus.RELEASED, true, false, @@ -153,6 +157,7 @@ export const UsePrivateUrl: Story = { const dataset = DatasetMother.createRealistic({ version: new DatasetVersion( 1, + '', DatasetPublishingStatus.RELEASED, true, false, diff --git a/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx b/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx index 359c5d133..4d8d201d2 100644 --- a/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx +++ b/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx @@ -18,12 +18,12 @@ type Story = StoryObj export const Default: Story = { render: () => { - const dataset = DatasetMother.createRealistic() + const version = DatasetVersionMother.createRealistic() return (




- +
) } @@ -36,11 +36,7 @@ export const WithThumbnail: Story = {




- +
) } @@ -48,10 +44,7 @@ export const WithThumbnail: Story = { export const DraftVersion: Story = { render: () => { - const dataset = DatasetMother.createRealistic({ - version: DatasetVersionMother.createDraft() - }) - + const version = DatasetVersionMother.createDraft() /* Includes extra breaks, so you can see the DRAFT tooltip message */ @@ -59,7 +52,7 @@ export const DraftVersion: Story = {




- +
) } @@ -67,9 +60,7 @@ export const DraftVersion: Story = { export const Deaccessioned: Story = { render: () => { - const dataset = DatasetMother.createRealistic({ - version: DatasetVersionMother.createDeaccessioned() - }) + const version = DatasetVersionMother.createDeaccessioned() /* Includes extra breaks, so you can see the DRAFT tooltip message @@ -78,7 +69,7 @@ export const Deaccessioned: Story = {




- +
) } @@ -95,7 +86,7 @@ export const Anonymized: Story = {




- +
) } diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 65a535d57..2b4cd81d5 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -22,6 +22,7 @@ export class DatasetVersionMother { static create(props?: Partial): DatasetVersion { return new DatasetVersion( props?.id ?? faker.datatype.number(), + props?.title ?? faker.lorem.sentence(), props?.publishingStatus ?? DatasetPublishingStatus.RELEASED, props?.isLatest ?? false, props?.isInReview ?? false, @@ -88,8 +89,24 @@ export class DatasetVersionMother { }) } - static createAnonymized(): DatasetVersion { + static createRealistic(props?: Partial): DatasetVersion { return this.create({ + id: 1, + title: 'Dataset Title', + publishingStatus: DatasetPublishingStatus.RELEASED, + isLatest: true, + isInReview: false, + latestVersionStatus: DatasetPublishingStatus.RELEASED, + citation: + 'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', + majorNumber: 1, + minorNumber: 0, + ...props + }) + } + + static createAnonymized(): DatasetVersion { + return this.createRealistic({ citation: `Author name(s) withheld, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1` }) } @@ -235,7 +252,6 @@ export class DatasetMother { static create(props?: Partial): Dataset { const dataset = { persistentId: faker.datatype.uuid(), - title: faker.lorem.sentence(), version: DatasetVersionMother.create(), license: { name: 'CC0 1.0', @@ -396,16 +412,7 @@ export class DatasetMother { static createRealistic(props?: Partial): Dataset { return this.create({ persistentId: 'doi:10.5072/FK2/ABC123', - version: new DatasetVersion( - 1, - DatasetPublishingStatus.RELEASED, - false, - false, - DatasetPublishingStatus.RELEASED, - `Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1`, - 1, - 0 - ), + version: DatasetVersionMother.createRealistic(), labels: [ { value: 'Version 1.0', semanticMeaning: DatasetLabelSemanticMeaning.FILE }, { value: DatasetLabelValue.DRAFT, semanticMeaning: DatasetLabelSemanticMeaning.DATASET } diff --git a/tests/component/sections/dataset/Dataset.spec.tsx b/tests/component/sections/dataset/Dataset.spec.tsx index 70b899057..6ffc3fe9e 100644 --- a/tests/component/sections/dataset/Dataset.spec.tsx +++ b/tests/component/sections/dataset/Dataset.spec.tsx @@ -41,7 +41,7 @@ describe('Dataset', () => { mountWithDataset(, testDataset) cy.findByTestId('dataset-skeleton').should('exist') - cy.findByText(testDataset.getTitle()).should('not.exist') + cy.findByText(testDataset.version.title).should('not.exist') }) it('renders page not found when dataset is null', () => { @@ -57,7 +57,7 @@ describe('Dataset', () => { mountWithDataset(, testDataset) - cy.findAllByText(testDataset.getTitle()).should('exist') + cy.findAllByText(testDataset.version.title).should('exist') testDataset.labels.forEach((label) => { cy.findAllByText(label.value).should('exist') @@ -69,7 +69,7 @@ describe('Dataset', () => { mountWithDataset(, testDataset) - cy.findAllByText(testDataset.getTitle()).should('exist') + cy.findAllByText(testDataset.version.title).should('exist') const metadataTab = cy.findByRole('tab', { name: 'Metadata' }) metadataTab.should('exist') diff --git a/tests/component/sections/dataset/DatasetProvider.spec.tsx b/tests/component/sections/dataset/DatasetProvider.spec.tsx index 03684cf44..2e2cf2420 100644 --- a/tests/component/sections/dataset/DatasetProvider.spec.tsx +++ b/tests/component/sections/dataset/DatasetProvider.spec.tsx @@ -9,7 +9,7 @@ function TestComponent() { return (
- {dataset ? {dataset.getTitle()} : Dataset Not Found} + {dataset ? {dataset.version.title} : Dataset Not Found} {isLoading &&
Loading...
}
) @@ -39,7 +39,7 @@ describe('DatasetProvider', () => { cy.findByText('Loading...').should('exist') cy.wrap(datasetRepository.getByPersistentId).should('be.calledOnceWith', dataset.persistentId) - cy.findByText(dataset.getTitle()).should('exist') + cy.findByText(dataset.version.title).should('exist') cy.findByText('Loading...').should('not.exist') }) @@ -60,7 +60,7 @@ describe('DatasetProvider', () => { dataset.persistentId, 'draft' ) - cy.findByText(dataset.getTitle()).should('exist') + cy.findByText(dataset.version.title).should('exist') cy.findByText('Loading...').should('not.exist') }) @@ -80,7 +80,7 @@ describe('DatasetProvider', () => { 'be.calledOnce', 'some-private-url-token' ) - cy.findByText(dataset.getTitle()).should('exist') + cy.findByText(dataset.version.title).should('exist') cy.findByText('Loading...').should('not.exist') }) diff --git a/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx b/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx index d628fa278..d695e40cd 100644 --- a/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx +++ b/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx @@ -1,10 +1,10 @@ import { DatasetCitation } from '../../../../../src/sections/dataset/dataset-citation/DatasetCitation' -import { DatasetMother, DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' +import { DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' describe('DatasetCitation', () => { it('renders the DatasetCitation fields of released Dataset', () => { - const dataset = DatasetMother.create() - cy.customMount() + const version = DatasetVersionMother.createRealistic() + cy.customMount() cy.findByText('Data Citation Standards.').should('exist') cy.findByText(/Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title"/).should('exist') @@ -20,10 +20,8 @@ describe('DatasetCitation', () => { }) it('shows the draft tooltip when version is draft', () => { - const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDraft() - }) - cy.customMount() + const version = DatasetVersionMother.createDraft() + cy.customMount() cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover') cy.findByText( @@ -32,10 +30,8 @@ describe('DatasetCitation', () => { }) it('shows the deaccessioned tooltip when version is deaccessioned', () => { - const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDeaccessioned() - }) - cy.customMount() + const version = DatasetVersionMother.createDeaccessioned() + cy.customMount() cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover') cy.findByText( diff --git a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx index 8a0cb0378..2a463ab30 100644 --- a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx @@ -17,6 +17,7 @@ const filesCountInfo = FilesCountInfoMother.create({ total: 100 }) const fileRepository: FileRepository = {} as FileRepository const datasetVersion = new DatasetVersion( 1, + '', DatasetPublishingStatus.RELEASED, true, false, diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 0bb66adc4..e6c00b833 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -84,7 +84,8 @@ const datasetData = (persistentId: string, versionId: number) => { latestVersionStatus: 'draft', isLatest: true, isInReview: false, - citation: `Finch, Fiona, 2023, "Darwin's Finches", ${persistentIdUrl}, Root, DRAFT VERSION` + citation: `Finch, Fiona, 2023, "Darwin's Finches", ${persistentIdUrl}, Root, DRAFT VERSION`, + title: "Darwin's Finches" }, permissions: { canDownloadFiles: true, @@ -112,7 +113,7 @@ describe('Dataset JSDataverse Repository', () => { } const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.labels).to.deep.equal(datasetExpected.labels) expect(dataset.license).to.deep.equal(datasetExpected.license) expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks) @@ -142,6 +143,7 @@ describe('Dataset JSDataverse Repository', () => { const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) const newVersion = new DatasetVersion( dataset.version.id, + "Darwin's Finches", DatasetPublishingStatus.RELEASED, true, false, @@ -153,7 +155,7 @@ describe('Dataset JSDataverse Repository', () => { 0 ) const expectedPublicationDate = getCurrentDateInYYYYMMDDFormat() - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.version).to.deep.equal(newVersion) expect(dataset.metadataBlocks[0].fields.publicationDate).to.deep.equal( expectedPublicationDate @@ -183,6 +185,7 @@ describe('Dataset JSDataverse Repository', () => { const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) const newVersion = new DatasetVersion( dataset.version.id, + "Darwin's Finches", DatasetPublishingStatus.RELEASED, true, false, @@ -194,7 +197,7 @@ describe('Dataset JSDataverse Repository', () => { 0 ) const expectedPublicationDate = getCurrentDateInYYYYMMDDFormat() - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.version).to.deep.equal(newVersion) expect(dataset.metadataBlocks[0].fields.publicationDate).to.deep.equal( expectedPublicationDate @@ -215,7 +218,7 @@ describe('Dataset JSDataverse Repository', () => { } const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.version).to.deep.equal(datasetExpected.version) }) }) @@ -230,7 +233,7 @@ describe('Dataset JSDataverse Repository', () => { } const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.version).to.deep.equal(datasetExpected.version) expect(dataset.permissions).to.deep.equal(datasetExpected.permissions) }) @@ -272,7 +275,7 @@ describe('Dataset JSDataverse Repository', () => { } const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) }) }) it('gets the dataset by persistentId when is locked', async () => { @@ -285,7 +288,7 @@ describe('Dataset JSDataverse Repository', () => { } const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) - expect(dataset.getTitle()).to.deep.equal(datasetExpected.title) + expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.locks).to.deep.equal([ { userPersistentId: 'dataverseAdmin', diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index de359b7de..78e4bebfb 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -146,6 +146,7 @@ describe('File JSDataverse Repository', () => { dataset.persistentId, new DatasetVersion( dataset.version.id, + '', DatasetPublishingStatus.RELEASED, true, false, @@ -183,6 +184,7 @@ describe('File JSDataverse Repository', () => { dataset.persistentId, new DatasetVersion( dataset.version.id, + '', DatasetPublishingStatus.DEACCESSIONED, true, false, From 030b794be80b05837319253c75d877e8df9f9e67 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 18 Dec 2023 16:48:37 +0100 Subject: [PATCH 07/15] refactor: move labels to DatasetVersion --- src/dataset/domain/models/Dataset.ts | 172 +++++++++++------- .../infrastructure/mappers/JSDatasetMapper.ts | 43 +++-- src/sections/dataset/Dataset.tsx | 2 +- .../DeaccessionDatasetButton.tsx | 5 +- .../edit-dataset-menu/DeleteDatasetButton.tsx | 4 +- .../link-dataset-button/LinkDatasetButton.tsx | 2 +- .../DatasetActionButtons.stories.tsx | 15 +- .../LinkDatasetButton.stories.tsx | 11 +- .../dataset-alerts/DatasetAlert.stories.tsx | 66 +------ .../dataset/domain/models/DatasetMother.ts | 87 +++++---- .../mappers/JSDatasetMapper.spec.ts | 50 ++--- .../sections/dataset/Dataset.spec.tsx | 2 +- .../DatasetActionButtons.spec.tsx | 10 +- .../DeaccessionDatasetButton.spec.tsx | 9 +- .../DeleteDatasetButton.spec.tsx | 10 +- .../EditDatasetMenu.spec.tsx | 6 +- .../LinkDatasetButton.spec.tsx | 12 +- .../dataset/dataset-files/useFiles.spec.tsx | 5 +- .../DatasetJSDataverseRepository.spec.ts | 55 +++--- .../files/FileJSDataverseRepository.spec.ts | 10 +- 20 files changed, 297 insertions(+), 279 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 841ea4a79..a85bed30f 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -213,26 +213,107 @@ export enum DatasetNonNumericVersion { DRAFT = ':draft' } +export class DatasetVersionNumber { + constructor(public readonly majorNumber?: number, public readonly minorNumber?: number) {} + + toString(): string | DatasetNonNumericVersion { + if (this.majorNumber === undefined || this.minorNumber === undefined) { + return DatasetNonNumericVersion.DRAFT + } + return `${this.majorNumber}.${this.minorNumber}` + } +} + export class DatasetVersion { constructor( public readonly id: number, public readonly title: string, + public readonly number: DatasetVersionNumber, public readonly publishingStatus: DatasetPublishingStatus, + public readonly citation: string, + public readonly labels: DatasetLabel[], public readonly isLatest: boolean, public readonly isInReview: boolean, - public readonly latestVersionStatus: DatasetPublishingStatus, - public readonly citation: string, - // requestedVersion will be set if the user requested a version that did not exist. - public readonly majorNumber?: number, - public readonly minorNumber?: number, - public readonly requestedVersion?: string + public readonly latestVersionPublishingStatus: DatasetPublishingStatus, + public readonly someDatasetVersionHasBeenReleased: boolean ) {} - toString(): string | DatasetNonNumericVersion { - if (this.majorNumber === undefined || this.minorNumber === undefined) { - return DatasetNonNumericVersion.DRAFT + static Builder = class { + public readonly labels: DatasetLabel[] = [] + + constructor( + public readonly id: number, + public readonly title: string, + public readonly number: DatasetVersionNumber, + public readonly publishingStatus: DatasetPublishingStatus, + public readonly citation: string, + public readonly isLatest: boolean, + public readonly isInReview: boolean, + public readonly latestVersionPublishingStatus: DatasetPublishingStatus, + public readonly someDatasetVersionHasBeenReleased: boolean + ) { + this.withLabels() + } + + withLabels() { + this.withStatusLabel() + this.withVersionLabel() + } + + private withStatusLabel(): void { + if (this.publishingStatus === DatasetPublishingStatus.DRAFT) { + this.labels.push( + new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT) + ) + } + + if (!this.someDatasetVersionHasBeenReleased) { + this.labels.push( + new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED) + ) + } + + if (this.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) { + this.labels.push( + new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED) + ) + } + + if (this.publishingStatus === DatasetPublishingStatus.EMBARGOED) { + this.labels.push( + new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED) + ) + } + + if (this.isInReview) { + this.labels.push( + new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW) + ) + } + } + + private withVersionLabel(): void { + if (this.publishingStatus === DatasetPublishingStatus.RELEASED) { + this.labels.push( + new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.number.toString()}`) + ) + } + } + + build(): DatasetVersion { + return new DatasetVersion( + this.id, + this.title, + this.number, + this.publishingStatus, + this.citation, + this.labels, + this.isLatest, + this.isInReview, + this.latestVersionPublishingStatus, + this.someDatasetVersionHasBeenReleased + ) } - return `${this.majorNumber}.${this.minorNumber}` } } @@ -275,7 +356,6 @@ export class Dataset { constructor( public readonly persistentId: string, public readonly version: DatasetVersion, - public readonly labels: DatasetLabel[], public readonly alerts: Alert[], public readonly summaryFields: DatasetMetadataBlock[], public readonly license: DatasetLicense, @@ -285,11 +365,11 @@ export class Dataset { public readonly hasValidTermsOfAccess: boolean, public readonly hasOneTabularFileAtLeast: boolean, public readonly isValid: boolean, - public readonly isReleased: boolean, public readonly downloadUrls: DatasetDownloadUrls, public readonly thumbnail?: string, public readonly privateUrl?: PrivateUrl, - public readonly fileDownloadSizes?: FileDownloadSize[] + public readonly fileDownloadSizes?: FileDownloadSize[], + public readonly requestedVersion?: string // will be set if the user requested a version that did not exist ) {} public checkIsLockedFromPublishing(userPersistentId: string): boolean { @@ -352,7 +432,6 @@ export class Dataset { } static Builder = class { - public readonly labels: DatasetLabel[] = [] public readonly alerts: Alert[] = [] constructor( @@ -366,61 +445,15 @@ export class Dataset { public readonly hasValidTermsOfAccess: boolean, public readonly hasOneTabularFileAtLeast: boolean, public readonly isValid: boolean, - public readonly isReleased: boolean, public readonly downloadUrls: DatasetDownloadUrls, public readonly thumbnail?: string, public readonly privateUrl?: PrivateUrl, - public readonly fileDownloadSizes?: FileDownloadSize[] + public readonly fileDownloadSizes?: FileDownloadSize[], + public readonly requestedVersion?: string // will be set if the user requested a version that did not exist ) { - this.withLabels() this.withAlerts() } - withLabels() { - this.withStatusLabel() - this.withVersionLabel() - } - - private withStatusLabel(): void { - if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT) - ) - } - - if (!this.isReleased) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED) - ) - } - - if (this.version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED) - ) - } - - if (this.version.publishingStatus === DatasetPublishingStatus.EMBARGOED) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED) - ) - } - - if (this.version.isInReview) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW) - ) - } - } - - private withVersionLabel(): void { - if (this.version.publishingStatus === DatasetPublishingStatus.RELEASED) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.version.toString()}`) - ) - } - } - private withAlerts(): void { if ( this.version.publishingStatus === DatasetPublishingStatus.DRAFT && @@ -428,18 +461,18 @@ export class Dataset { ) { this.alerts.push(new Alert('warning', AlertMessageKey.DRAFT_VERSION)) } - if (this.version.requestedVersion) { - if (this.version.latestVersionStatus == DatasetPublishingStatus.RELEASED) { + if (this.requestedVersion) { + if (this.version.latestVersionPublishingStatus == DatasetPublishingStatus.RELEASED) { const dynamicFields = { - requestedVersion: this.version.requestedVersion, - returnedVersion: `${this.version.toString()}` + requestedVersion: this.requestedVersion, + returnedVersion: `${this.version.number.toString()}` } this.alerts.push( new Alert('warning', AlertMessageKey.REQUESTED_VERSION_NOT_FOUND, dynamicFields) ) } else { const dynamicFields = { - requestedVersion: this.version.requestedVersion + requestedVersion: this.requestedVersion } this.alerts.push( new Alert( @@ -466,7 +499,6 @@ export class Dataset { return new Dataset( this.persistentId, this.version, - this.labels, this.alerts, this.summaryFields, this.license, @@ -476,11 +508,11 @@ export class Dataset { this.hasValidTermsOfAccess, this.hasOneTabularFileAtLeast, this.isValid, - this.isReleased, this.downloadUrls, this.thumbnail, this.privateUrl, - this.fileDownloadSizes + this.fileDownloadSizes, + this.requestedVersion ) } } diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index efda41029..60adc8be0 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -20,7 +20,8 @@ import { DatasetDownloadUrls, DatasetPermissions, DatasetLock, - DatasetLockReason + DatasetLockReason, + DatasetVersionNumber } from '../../domain/models/Dataset' export class JSDatasetMapper { @@ -37,8 +38,7 @@ export class JSDatasetMapper { jsDataset.versionId, jsDataset.versionInfo, jsDataset.metadataBlocks, - jsDatasetCitation, - requestedVersion + jsDatasetCitation ) return new Dataset.Builder( jsDataset.persistentId, @@ -56,11 +56,11 @@ export class JSDatasetMapper { true, // TODO Connect with dataset hasValidTermsOfAccess true, // TODO Connect with dataset hasOneTabularFileAtLeast true, // TODO Connect with dataset isValid - JSDatasetMapper.toIsReleased(jsDataset.versionInfo), JSDatasetMapper.toDownloadUrls(jsDataset.persistentId, version), undefined, // TODO: get dataset thumbnail from Dataverse https://github.com/IQSS/dataverse-frontend/issues/203 privateUrl, - [] // TODO: Connect with file download use case + [], // TODO: Connect with file download use case, + requestedVersion ).build() } @@ -68,20 +68,29 @@ export class JSDatasetMapper { jDatasetVersionId: number, jsDatasetVersionInfo: JSDatasetVersionInfo, jsDatasetMetadataBlocks: JSDatasetMetadataBlocks, - jsDatasetCitation: string, - requestedVersion?: string + jsDatasetCitation: string ): DatasetVersion { - return new DatasetVersion( + return new DatasetVersion.Builder( jDatasetVersionId, - jsDatasetMetadataBlocks[0].fields.title, - JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), - true, - false, + JSDatasetMapper.toDatasetTitle(jsDatasetMetadataBlocks), + JSDatasetMapper.toVersionNumber(jsDatasetVersionInfo), JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), jsDatasetCitation, + true, // TODO Connect with dataset version isLatest + false, // TODO Connect with dataset version isInReview + JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), + JSDatasetMapper.toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo) + ) + } + + static toDatasetTitle(jsDatasetMetadataBlocks: JSDatasetMetadataBlocks): string { + return jsDatasetMetadataBlocks[0].fields.title + } + + static toVersionNumber(jsDatasetVersionInfo: JSDatasetVersionInfo): DatasetVersionNumber { + return new DatasetVersionNumber( jsDatasetVersionInfo.majorNumber, - jsDatasetVersionInfo.minorNumber, - requestedVersion + jsDatasetVersionInfo.minorNumber ) } @@ -204,11 +213,11 @@ export class JSDatasetMapper { version: DatasetVersion ): DatasetDownloadUrls { return { - original: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}&format=original`, - archival: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}` + original: `/api/access/dataset/:persistentId/versions/${version.number.toString()}?persistentId=${jsDatasetPersistentId}&format=original`, + archival: `/api/access/dataset/:persistentId/versions/${version.number.toString()}?persistentId=${jsDatasetPersistentId}` } } - static toIsReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean { + static toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean { return ( jsDatasetVersionInfo.releaseTime !== undefined && !isNaN(jsDatasetVersionInfo.releaseTime.getTime()) diff --git a/src/sections/dataset/Dataset.tsx b/src/sections/dataset/Dataset.tsx index 5daefed86..e05b86f1e 100644 --- a/src/sections/dataset/Dataset.tsx +++ b/src/sections/dataset/Dataset.tsx @@ -52,7 +52,7 @@ export function Dataset({ fileRepository }: DatasetProps) {

{dataset.version.title}

- +
diff --git a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx index 98c25d869..18527ffb5 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx @@ -6,7 +6,10 @@ interface DeaccessionDatasetButtonProps { dataset: Dataset } export function DeaccessionDatasetButton({ dataset }: DeaccessionDatasetButtonProps) { - if (!dataset.isReleased || !dataset.permissions.canPublishDataset) { + if ( + !dataset.version.someDatasetVersionHasBeenReleased || + !dataset.permissions.canPublishDataset + ) { return <> } diff --git a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx index c7f4c25fe..9a1eaf9f7 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.tsx @@ -8,7 +8,7 @@ interface DeleteDatasetButtonProps { export function DeleteDatasetButton({ dataset }: DeleteDatasetButtonProps) { if ( !dataset.permissions.canDeleteDataset || - dataset.version.latestVersionStatus !== DatasetPublishingStatus.DRAFT + dataset.version.latestVersionPublishingStatus !== DatasetPublishingStatus.DRAFT ) { return <> } @@ -18,7 +18,7 @@ export function DeleteDatasetButton({ dataset }: DeleteDatasetButtonProps) { <> - {dataset.isReleased + {dataset.version.someDatasetVersionHasBeenReleased ? t('datasetActionButtons.editDataset.delete.draft') : t('datasetActionButtons.editDataset.delete.released')} 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 index ed613dfbb..3d0ef983a 100644 --- a/src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.tsx @@ -19,7 +19,7 @@ export function LinkDatasetButton({ dataset }: LinkDatasetButtonProps) { if ( !user || - !dataset.isReleased || + !dataset.version.someDatasetVersionHasBeenReleased || dataset.version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED ) { return <> diff --git a/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx b/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx index 87570d5de..d6845f7ac 100644 --- a/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx @@ -27,15 +27,14 @@ export const WithPublishPermissions: Story = { ) @@ -46,14 +45,13 @@ export const WithNoDatasetPermissions: Story = { ) @@ -68,14 +66,13 @@ export const WithUpdateAndNoPublishDatasetPermissions: Story = { canPublishDataset: false, canUpdateDataset: true }), - version: DatasetVersionMother.createDraftAsLatestVersion(), + version: DatasetVersionMother.createDraftAsLatestVersionWithSomeVersionHasBeenReleased(), hasValidTermsOfAccess: true, fileDownloadSizes: [ DatasetFileDownloadSizeMother.createOriginal(), DatasetFileDownloadSizeMother.createArchival() ], - isValid: true, - isReleased: true + isValid: true })} /> ) diff --git a/src/stories/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.stories.tsx b/src/stories/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.stories.tsx index 18c2140e3..fff6753f9 100644 --- a/src/stories/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.stories.tsx @@ -1,7 +1,10 @@ import { Meta, StoryObj } from '@storybook/react' import { WithI18next } from '../../../WithI18next' import { WithSettings } from '../../../WithSettings' -import { DatasetMother } from '../../../../../tests/component/dataset/domain/models/DatasetMother' +import { + DatasetMother, + DatasetVersionMother +} from '../../../../../tests/component/dataset/domain/models/DatasetMother' import { LinkDatasetButton } from '../../../../sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton' const meta: Meta = { @@ -18,5 +21,9 @@ export default meta type Story = StoryObj export const ReleasedDataset: Story = { - render: () => + render: () => ( + + ) } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 733bcb1fd..9f43ae771 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -1,12 +1,12 @@ import type { Meta, StoryObj } from '@storybook/react' -import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset' import { DatasetAlerts } from '../../../sections/dataset/dataset-alerts/DatasetAlerts' import { WithI18next } from '../../WithI18next' import { DatasetMother, - DatasetPermissionsMother + DatasetPermissionsMother, + DatasetVersionMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' import { useAlertContext } from '../../../sections/alerts/AlertContext' import { WithAlerts } from '../../WithAlerts' @@ -57,15 +57,7 @@ export const PublishInProgress: Story = { export const DraftVersion: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - version: new DatasetVersion( - 1, - '', - DatasetPublishingStatus.DRAFT, - true, - false, - DatasetPublishingStatus.DRAFT, - '' - ), + version: DatasetVersionMother.createDraft(), permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed() }) return ( @@ -79,18 +71,8 @@ export const DraftVersion: Story = { export const VersionNotFound: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - version: new DatasetVersion( - 1, - '', - DatasetPublishingStatus.RELEASED, - true, - false, - DatasetPublishingStatus.RELEASED, - '', - 1, - 0, - '3.0' - ) + version: DatasetVersionMother.createReleased(), + requestedVersion: '3.0' }) return ( @@ -103,18 +85,8 @@ export const VersionNotFound: Story = { export const VersionNotFoundShowDraft: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - version: new DatasetVersion( - 1, - '', - DatasetPublishingStatus.DRAFT, - true, - false, - DatasetPublishingStatus.DRAFT, - '', - 1, - 0, - '3.0' - ) + version: DatasetVersionMother.createDraft(), + requestedVersion: '3.0' }) return ( @@ -127,17 +99,7 @@ export const VersionNotFoundShowDraft: Story = { export const SharePrivateUrl: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - version: new DatasetVersion( - 1, - '', - DatasetPublishingStatus.RELEASED, - true, - false, - DatasetPublishingStatus.DRAFT, - '', - 1, - 0 - ), + version: DatasetVersionMother.createDraft(), permissions: DatasetPermissionsMother.createWithAllAllowed(), privateUrl: { urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', @@ -155,17 +117,7 @@ export const SharePrivateUrl: Story = { export const UsePrivateUrl: Story = { render: () => { const dataset = DatasetMother.createRealistic({ - version: new DatasetVersion( - 1, - '', - DatasetPublishingStatus.RELEASED, - true, - false, - DatasetPublishingStatus.DRAFT, - '', - 1, - 0 - ), + version: DatasetVersionMother.createDraft(), permissions: DatasetPermissionsMother.createWithNoneAllowed(), privateUrl: { urlSnippet: 'http://localhost:8080/privateurl.xhtml?token=', diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 2b4cd81d5..1e0b9a338 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -10,6 +10,7 @@ import { DatasetPermissions, DatasetPublishingStatus, DatasetVersion, + DatasetVersionNumber, MetadataBlockName } from '../../../../../src/dataset/domain/models/Dataset' import { @@ -20,72 +21,87 @@ import { export class DatasetVersionMother { static create(props?: Partial): DatasetVersion { - return new DatasetVersion( + return new DatasetVersion.Builder( props?.id ?? faker.datatype.number(), props?.title ?? faker.lorem.sentence(), + props?.number ?? new DatasetVersionNumber(1, 0), props?.publishingStatus ?? DatasetPublishingStatus.RELEASED, - props?.isLatest ?? false, - props?.isInReview ?? false, - props?.latestVersionStatus ?? DatasetPublishingStatus.RELEASED, props?.citation ?? 'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', - props?.majorNumber ?? 1, - props?.minorNumber ?? 0 + props?.isLatest ?? false, + props?.isInReview ?? false, + props?.latestVersionPublishingStatus ?? DatasetPublishingStatus.RELEASED, + props?.someDatasetVersionHasBeenReleased ?? faker.datatype.boolean() ) } - static createReleased(): DatasetVersion { - return this.create({ publishingStatus: DatasetPublishingStatus.RELEASED }) - } - static createDeaccessioned(): DatasetVersion { return this.create({ publishingStatus: DatasetPublishingStatus.DEACCESSIONED, + isLatest: false, citation: - 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1 DEACCESSIONED VERSION' + 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1 DEACCESSIONED VERSION', + someDatasetVersionHasBeenReleased: true }) } static createDraft(props?: Partial): DatasetVersion { return this.create({ publishingStatus: DatasetPublishingStatus.DRAFT, + isLatest: false, + number: new DatasetVersionNumber(undefined, undefined), citation: 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, DRAFT VERSION', ...props }) } - static createDraftAsLatestVersion(): DatasetVersion { - return this.createDraft({ publishingStatus: DatasetPublishingStatus.DRAFT, isLatest: true }) + static createDraftAsLatestVersion(props?: Partial): DatasetVersion { + return this.createDraft({ + latestVersionPublishingStatus: DatasetPublishingStatus.DRAFT, + isLatest: true, + ...props + }) + } + + static createDraftAsLatestVersionWithSomeVersionHasBeenReleased(): DatasetVersion { + return this.createDraftAsLatestVersion({ + someDatasetVersionHasBeenReleased: true + }) } static createDraftAsLatestVersionInReview(): DatasetVersion { - return this.createDraft({ - isLatest: true, + return this.createDraftAsLatestVersion({ isInReview: true }) } - static createReleasedWithLatestVersionIsADraft(): DatasetVersion { - return this.create({ - publishingStatus: DatasetPublishingStatus.RELEASED, - isLatest: true, - latestVersionStatus: DatasetPublishingStatus.DRAFT + static createDraftWithLatestVersionIsReleased(): DatasetVersion { + return this.createDraft({ + latestVersionPublishingStatus: DatasetPublishingStatus.RELEASED, + someDatasetVersionHasBeenReleased: true }) } - static createDraftWithLatestVersionIsADraft(): DatasetVersion { + static createNotReleased(): DatasetVersion { return this.createDraft({ - isLatest: true, - latestVersionStatus: DatasetPublishingStatus.DRAFT + someDatasetVersionHasBeenReleased: false, + latestVersionPublishingStatus: DatasetPublishingStatus.DRAFT }) } - static createWithLatestVersionIsNotADraft(): DatasetVersion { + static createReleased(props?: Partial): DatasetVersion { return this.create({ - publishingStatus: DatasetPublishingStatus.DRAFT, - isLatest: true, - latestVersionStatus: DatasetPublishingStatus.RELEASED + publishingStatus: DatasetPublishingStatus.RELEASED, + someDatasetVersionHasBeenReleased: true, + isLatest: false, + ...props + }) + } + + static createReleasedWithLatestVersionIsADraft(): DatasetVersion { + return this.createReleased({ + latestVersionPublishingStatus: DatasetPublishingStatus.DRAFT }) } @@ -96,11 +112,11 @@ export class DatasetVersionMother { publishingStatus: DatasetPublishingStatus.RELEASED, isLatest: true, isInReview: false, - latestVersionStatus: DatasetPublishingStatus.RELEASED, + latestVersionPublishingStatus: DatasetPublishingStatus.RELEASED, citation: 'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', - majorNumber: 1, - minorNumber: 0, + number: new DatasetVersionNumber(1, 0), + someDatasetVersionHasBeenReleased: true, ...props }) } @@ -343,7 +359,6 @@ export class DatasetMother { hasValidTermsOfAccess: faker.datatype.boolean(), hasOneTabularFileAtLeast: faker.datatype.boolean(), isValid: faker.datatype.boolean(), - isReleased: faker.datatype.boolean(), downloadUrls: { original: this.createDownloadUrl(), archival: this.createDownloadUrl() @@ -351,6 +366,7 @@ export class DatasetMother { thumbnail: undefined, privateUrl: undefined, fileDownloadSizes: undefined, + requestedVersion: undefined, ...props } @@ -365,11 +381,11 @@ export class DatasetMother { dataset.hasValidTermsOfAccess, dataset.hasOneTabularFileAtLeast, dataset.isValid, - dataset.isReleased, dataset.downloadUrls, dataset.thumbnail, dataset.privateUrl, - dataset.fileDownloadSizes + dataset.fileDownloadSizes, + dataset.requestedVersion ).build() } @@ -413,10 +429,6 @@ export class DatasetMother { return this.create({ persistentId: 'doi:10.5072/FK2/ABC123', version: DatasetVersionMother.createRealistic(), - labels: [ - { value: 'Version 1.0', semanticMeaning: DatasetLabelSemanticMeaning.FILE }, - { value: DatasetLabelValue.DRAFT, semanticMeaning: DatasetLabelSemanticMeaning.DATASET } - ], license: { name: 'CC0 1.0', uri: 'https://creativecommons.org/publicdomain/zero/1.0/', @@ -496,7 +508,6 @@ export class DatasetMother { canDeleteDataset: false }, locks: [], - isReleased: true, hasValidTermsOfAccess: true, hasOneTabularFileAtLeast: true, fileDownloadSizes: [ diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index 8af60a399..b95faad86 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -74,20 +74,24 @@ const expectedDataset = { persistentId: 'doi:10.5072/FK2/B4B2MJ', version: { id: 101, + title: "Darwin's Finches", + labels: [ + { semanticMeaning: 'dataset', value: 'Draft' }, + { semanticMeaning: 'warning', value: 'Unpublished' } + ], publishingStatus: 'draft', isLatest: true, isInReview: false, - latestVersionStatus: 'draft', - majorNumber: 0, - minorNumber: 0, - requestedVersion: undefined + latestVersionPublishingStatus: 'draft', + number: { + minorNumber: 0, + majorNumber: 0 + }, + someDatasetVersionHasBeenReleased: false, + citation: + 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION' }, - citation: - 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', - labels: [ - { semanticMeaning: 'dataset', value: 'Draft' }, - { semanticMeaning: 'warning', value: 'Unpublished' } - ], + requestedVersion: undefined, alerts: [{ variant: 'warning', messageKey: 'draftVersion', dynamicFields: undefined }], summaryFields: [ { @@ -144,7 +148,6 @@ const expectedDataset = { hasValidTermsOfAccess: true, hasOneTabularFileAtLeast: true, isValid: true, - isReleased: false, thumbnail: undefined, privateUrl: undefined, downloadUrls: { @@ -157,26 +160,29 @@ const expectedDatasetAlternateVersion = { persistentId: 'doi:10.5072/FK2/B4B2MJ', version: { id: 101, + title: "Darwin's Finches", + labels: [ + { semanticMeaning: 'dataset', value: 'Draft' }, + { semanticMeaning: 'warning', value: 'Unpublished' } + ], publishingStatus: 'draft', isLatest: true, isInReview: false, - latestVersionStatus: 'draft', - minorNumber: 0, - majorNumber: 0, - requestedVersion: '4.0' + latestVersionPublishingStatus: 'draft', + number: { + minorNumber: 0, + majorNumber: 0 + }, + someDatasetVersionHasBeenReleased: false, + citation: + 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION' }, - citation: - 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', + requestedVersion: '4.0', hasValidTermsOfAccess: true, hasOneTabularFileAtLeast: true, - isReleased: false, isValid: true, privateUrl: undefined, fileDownloadSizes: [], - labels: [ - { semanticMeaning: 'dataset', value: 'Draft' }, - { semanticMeaning: 'warning', value: 'Unpublished' } - ], alerts: [ { variant: 'warning', diff --git a/tests/component/sections/dataset/Dataset.spec.tsx b/tests/component/sections/dataset/Dataset.spec.tsx index 6ffc3fe9e..e3af5257d 100644 --- a/tests/component/sections/dataset/Dataset.spec.tsx +++ b/tests/component/sections/dataset/Dataset.spec.tsx @@ -59,7 +59,7 @@ describe('Dataset', () => { cy.findAllByText(testDataset.version.title).should('exist') - testDataset.labels.forEach((label) => { + testDataset.version.labels.forEach((label) => { cy.findAllByText(label.value).should('exist') }) }) 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 493613a7c..64c20869b 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx @@ -8,9 +8,8 @@ import { describe('DatasetActionButtons', () => { it('renders the DatasetActionButtons with the Publish button', () => { const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDraftAsLatestVersion(), - permissions: DatasetPermissionsMother.createWithAllAllowed(), - isReleased: true + version: DatasetVersionMother.createDraftAsLatestVersionWithSomeVersionHasBeenReleased(), + permissions: DatasetPermissionsMother.createWithAllAllowed() }) cy.mountAuthenticated() @@ -24,13 +23,12 @@ describe('DatasetActionButtons', () => { it('renders the DatasetActionButtons with the Submit for Review button', () => { const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDraftAsLatestVersion(), + version: DatasetVersionMother.createDraftAsLatestVersionWithSomeVersionHasBeenReleased(), permissions: DatasetPermissionsMother.create({ canDownloadFiles: true, canUpdateDataset: true, canPublishDataset: false - }), - isReleased: true + }) }) cy.mountAuthenticated() diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx index 2730a2432..387ddecca 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx @@ -1,6 +1,7 @@ import { DatasetMother, - DatasetPermissionsMother + DatasetPermissionsMother, + DatasetVersionMother } from '../../../../dataset/domain/models/DatasetMother' import { DeaccessionDatasetButton } from '../../../../../../src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton' @@ -8,7 +9,7 @@ describe('DeaccessionDatasetButton', () => { it('renders the DeaccessionDatasetButton if the user has publish dataset permissions and the dataset is released', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed(), - isReleased: true + version: DatasetVersionMother.createReleased() }) cy.customMount() @@ -20,7 +21,7 @@ describe('DeaccessionDatasetButton', () => { it('does not render the DeaccessionDatasetButton if the user does not have publish dataset permissions', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithPublishingDatasetNotAllowed(), - isReleased: true + version: DatasetVersionMother.createReleased() }) cy.customMount() @@ -31,7 +32,7 @@ describe('DeaccessionDatasetButton', () => { it('does not render the DeaccessionDatasetButton if the dataset is not released', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed(), - isReleased: false + version: DatasetVersionMother.createNotReleased() }) cy.customMount() diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.spec.tsx index 7f353c19b..eb71524ec 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.spec.tsx @@ -23,8 +23,7 @@ describe('DeleteDatasetButton', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithDeleteDatasetAllowed(), locks: [], - version: DatasetVersionMother.createDraftWithLatestVersionIsADraft(), - isReleased: false + version: DatasetVersionMother.createNotReleased() }) cy.customMount() @@ -32,12 +31,11 @@ describe('DeleteDatasetButton', () => { cy.findByRole('button', { name: 'Delete Dataset' }).should('exist') }) - it('renders the Delete Draft Version if the dataset is released', () => { + it('renders the Delete Draft Version if the dataset is released and the latest version is a draft', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithDeleteDatasetAllowed(), locks: [], - version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft(), - isReleased: true + version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft() }) cy.customMount() @@ -61,7 +59,7 @@ describe('DeleteDatasetButton', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithDeleteDatasetAllowed(), locks: [], - version: DatasetVersionMother.createWithLatestVersionIsNotADraft() + version: DatasetVersionMother.createDraftWithLatestVersionIsReleased() }) cy.customMount() diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx index aae0fa697..59b75f0d6 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx @@ -12,8 +12,7 @@ describe('EditDatasetMenu', () => { permissions: DatasetPermissionsMother.createWithAllAllowed(), locks: [], hasValidTermsOfAccess: true, - version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft(), - isReleased: true + version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft() }) cy.mountAuthenticated() @@ -35,8 +34,7 @@ describe('EditDatasetMenu', () => { permissions: DatasetPermissionsMother.createWithAllAllowed(), locks: [], hasValidTermsOfAccess: true, - version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft(), - isReleased: true + version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft() }) cy.customMount() 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 index f6318c4d1..bb3f6c609 100644 --- 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 @@ -7,8 +7,7 @@ import { LinkDatasetButton } from '../../../../../../src/sections/dataset/datase 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 + version: DatasetVersionMother.createReleased() }) cy.mountAuthenticated() @@ -18,8 +17,7 @@ describe('LinkDatasetButton', () => { it('does not render the LinkDatasetButton if the user is not authenticated', () => { const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDraft(), - isReleased: true + version: DatasetVersionMother.createReleased() }) cy.customMount() @@ -29,8 +27,7 @@ describe('LinkDatasetButton', () => { it('does not render the LinkDatasetButton if the dataset version is deaccessioned', () => { const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDeaccessioned(), - isReleased: true + version: DatasetVersionMother.createDeaccessioned() }) cy.mountAuthenticated() @@ -40,8 +37,7 @@ describe('LinkDatasetButton', () => { it('does not render the LinkDatasetButton if the dataset is not released', () => { const dataset = DatasetMother.create({ - version: DatasetVersionMother.createDraft(), - isReleased: false + version: DatasetVersionMother.createNotReleased() }) cy.mountAuthenticated() diff --git a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx index 2a463ab30..b0e21302d 100644 --- a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx @@ -18,13 +18,14 @@ const fileRepository: FileRepository = {} as FileRepository const datasetVersion = new DatasetVersion( 1, '', - DatasetPublishingStatus.RELEASED, + [], true, false, DatasetPublishingStatus.RELEASED, '', 1, - 0 + 0, + false ) const FilesTableTestComponent = ({ datasetPersistentId }: { datasetPersistentId: string }) => { diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index e6c00b833..bdb0e1df9 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -3,6 +3,8 @@ import chaiAsPromised from 'chai-as-promised' import { DatasetJSDataverseRepository } from '../../../../src/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { TestsUtils } from '../../shared/TestsUtils' import { + DatasetLabel, + DatasetLabelSemanticMeaning, DatasetLockReason, DatasetPublishingStatus, DatasetVersion @@ -26,10 +28,6 @@ function getPersistentIdUrl(persistentId: string) { const datasetData = (persistentId: string, versionId: number) => { const persistentIdUrl = getPersistentIdUrl(persistentId) return { - labels: [ - { semanticMeaning: 'dataset', value: 'Draft' }, - { semanticMeaning: 'warning', value: 'Unpublished' } - ], license: { name: 'CC0 1.0', uri: 'http://creativecommons.org/publicdomain/zero/1.0', @@ -77,15 +75,21 @@ const datasetData = (persistentId: string, versionId: number) => { title: "Darwin's Finches", version: { id: versionId, - majorNumber: undefined, - minorNumber: undefined, + number: { + majorNumber: undefined, + minorNumber: undefined + }, publishingStatus: 'draft', - requestedVersion: undefined, - latestVersionStatus: 'draft', + latestVersionPublishingStatus: 'draft', isLatest: true, isInReview: false, citation: `Finch, Fiona, 2023, "Darwin's Finches", ${persistentIdUrl}, Root, DRAFT VERSION`, - title: "Darwin's Finches" + title: "Darwin's Finches", + labels: [ + { semanticMeaning: 'dataset', value: 'Draft' }, + { semanticMeaning: 'warning', value: 'Unpublished' } + ], + someDatasetVersionHasBeenReleased: false }, permissions: { canDownloadFiles: true, @@ -113,8 +117,6 @@ describe('Dataset JSDataverse Repository', () => { } const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) - expect(dataset.version.title).to.deep.equal(datasetExpected.title) - expect(dataset.labels).to.deep.equal(datasetExpected.labels) expect(dataset.license).to.deep.equal(datasetExpected.license) expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks) expect(dataset.summaryFields).to.deep.equal(datasetExpected.summaryFields) @@ -140,22 +142,24 @@ describe('Dataset JSDataverse Repository', () => { if (!dataset) { throw new Error('Dataset not found') } - const datasetExpected = datasetData(dataset.persistentId, dataset.version.id) const newVersion = new DatasetVersion( dataset.version.id, "Darwin's Finches", - DatasetPublishingStatus.RELEASED, - true, - false, + { + majorNumber: 1, + minorNumber: 0 + }, DatasetPublishingStatus.RELEASED, `Finch, Fiona, 2023, "Darwin's Finches", ${getPersistentIdUrl(dataset.persistentId)}, Root, V1`, - 1, - 0 + [new DatasetLabel(DatasetLabelSemanticMeaning.FILE, 'Version 1.0')], + true, + false, + DatasetPublishingStatus.RELEASED, + true ) const expectedPublicationDate = getCurrentDateInYYYYMMDDFormat() - expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.version).to.deep.equal(newVersion) expect(dataset.metadataBlocks[0].fields.publicationDate).to.deep.equal( expectedPublicationDate @@ -186,18 +190,21 @@ describe('Dataset JSDataverse Repository', () => { const newVersion = new DatasetVersion( dataset.version.id, "Darwin's Finches", - DatasetPublishingStatus.RELEASED, - true, - false, + { + majorNumber: 1, + minorNumber: 0 + }, DatasetPublishingStatus.RELEASED, `Finch, Fiona, 2023, "Darwin's Finches", ${getPersistentIdUrl(dataset.persistentId)}, Root, V1`, - 1, - 0 + [new DatasetLabel(DatasetLabelSemanticMeaning.FILE, 'Version 1.0')], + true, + false, + DatasetPublishingStatus.RELEASED, + true ) const expectedPublicationDate = getCurrentDateInYYYYMMDDFormat() - expect(dataset.version.title).to.deep.equal(datasetExpected.title) expect(dataset.version).to.deep.equal(newVersion) expect(dataset.metadataBlocks[0].fields.publicationDate).to.deep.equal( expectedPublicationDate diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 78e4bebfb..ea7d3107f 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -147,13 +147,14 @@ describe('File JSDataverse Repository', () => { new DatasetVersion( dataset.version.id, '', - DatasetPublishingStatus.RELEASED, + [], true, false, DatasetPublishingStatus.RELEASED, '', 1, - 0 + 0, + false ) ) .then((files) => { @@ -185,13 +186,14 @@ describe('File JSDataverse Repository', () => { new DatasetVersion( dataset.version.id, '', - DatasetPublishingStatus.DEACCESSIONED, + [], true, false, DatasetPublishingStatus.DEACCESSIONED, '', 1, - 0 + 0, + false ) ) .then((files) => { From 3d4c78a2bc6a58541a044c93bbc8f702cf18434e Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 18 Dec 2023 16:57:30 +0100 Subject: [PATCH 08/15] feat(FilePage): add datasetVersion property to File model --- src/files/domain/models/File.ts | 4 +++- src/sections/file/File.tsx | 2 +- tests/component/files/domain/models/FileMother.ts | 5 +++-- tests/component/sections/file/File.spec.tsx | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/files/domain/models/File.ts b/src/files/domain/models/File.ts index 3ee029df4..d348f4df8 100644 --- a/src/files/domain/models/File.ts +++ b/src/files/domain/models/File.ts @@ -1,4 +1,6 @@ +import { DatasetVersion } from '../../../dataset/domain/models/Dataset' + export interface File { name: string - datasetTitle: string + datasetVersion: DatasetVersion } diff --git a/src/sections/file/File.tsx b/src/sections/file/File.tsx index 3fcb882b3..176eee903 100644 --- a/src/sections/file/File.tsx +++ b/src/sections/file/File.tsx @@ -34,7 +34,7 @@ export function File({ repository, id }: FileProps) {

{file.name}

- {t('subtext', { datasetTitle: file.datasetTitle })} + {t('subtext', { datasetTitle: file.datasetVersion.title })}
diff --git a/tests/component/files/domain/models/FileMother.ts b/tests/component/files/domain/models/FileMother.ts index f1b97fbd5..28b245c94 100644 --- a/tests/component/files/domain/models/FileMother.ts +++ b/tests/component/files/domain/models/FileMother.ts @@ -1,11 +1,12 @@ import { File } from '../../../../../src/files/domain/models/File' import { faker } from '@faker-js/faker' +import { DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' export class FileMother { static create(props?: Partial): File { return { name: faker.system.fileName(), - datasetTitle: faker.lorem.words(3), + datasetVersion: DatasetVersionMother.create(), ...props } } @@ -13,7 +14,7 @@ export class FileMother { static createRealistic(props?: Partial): File { return this.create({ name: 'file.csv', - datasetTitle: 'Dataset title', + datasetVersion: DatasetVersionMother.createRealistic(), ...props }) } diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx index cfc07956e..1377c092a 100644 --- a/tests/component/sections/file/File.spec.tsx +++ b/tests/component/sections/file/File.spec.tsx @@ -14,7 +14,7 @@ describe('File', () => { cy.wrap(fileRepository.getById).should('be.calledWith', 19) cy.findAllByText(testFile.name).should('exist') - cy.findByText(`This file is part of "${testFile.datasetTitle}".`).should('exist') + cy.findByText(`This file is part of "${testFile.datasetVersion.title}".`).should('exist') }) it('renders skeleton while loading', () => { From e1ed09aaf118192fbf26e21b933b1ead2c98da92 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Tue, 19 Dec 2023 15:36:52 +0100 Subject: [PATCH 09/15] refactor: pass datasetVersionNumber as files use cases argument --- .../domain/repositories/FileRepository.ts | 6 +-- .../getFilesCountInfoByDatasetPersistentId.ts | 6 +-- .../useCases/getFilesTotalDownloadSize.ts | 10 +++-- .../FileJSDataverseRepository.ts | 12 +++--- .../dataset/dataset-files/useFiles.tsx | 4 +- .../files/FileMockLoadingRepository.ts | 4 +- src/stories/files/FileMockNoDataRepository.ts | 6 +-- .../files/FileMockNoFiltersRepository.ts | 4 +- src/stories/files/FileMockRepository.ts | 6 +-- .../dataset/domain/models/DatasetMother.ts | 5 ++- .../dataset-files/DatasetFiles.spec.tsx | 4 +- .../dataset/dataset-files/useFiles.spec.tsx | 22 ++-------- .../files/FileJSDataverseRepository.spec.ts | 42 +++++-------------- 13 files changed, 50 insertions(+), 81 deletions(-) diff --git a/src/files/domain/repositories/FileRepository.ts b/src/files/domain/repositories/FileRepository.ts index 8e69a0713..765b1c2d3 100644 --- a/src/files/domain/repositories/FileRepository.ts +++ b/src/files/domain/repositories/FileRepository.ts @@ -4,7 +4,7 @@ import { FileCriteria } from '../models/FileCriteria' import { FilesCountInfo } from '../models/FilesCountInfo' import { FilePaginationInfo } from '../models/FilePaginationInfo' import { FileUserPermissions } from '../models/FileUserPermissions' -import { DatasetVersion } from '../../../dataset/domain/models/Dataset' +import { DatasetVersion, DatasetVersionNumber } from '../../../dataset/domain/models/Dataset' export interface FileRepository { getAllByDatasetPersistentId: ( @@ -15,12 +15,12 @@ export interface FileRepository { ) => Promise getFilesCountInfoByDatasetPersistentId: ( datasetPersistentId: string, - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, criteria: FileCriteria ) => Promise getFilesTotalDownloadSizeByDatasetPersistentId: ( datasetPersistentId: string, - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, criteria?: FileCriteria ) => Promise getUserPermissionsById: (id: number) => Promise diff --git a/src/files/domain/useCases/getFilesCountInfoByDatasetPersistentId.ts b/src/files/domain/useCases/getFilesCountInfoByDatasetPersistentId.ts index 13b5dfda7..897c3030b 100644 --- a/src/files/domain/useCases/getFilesCountInfoByDatasetPersistentId.ts +++ b/src/files/domain/useCases/getFilesCountInfoByDatasetPersistentId.ts @@ -1,16 +1,16 @@ import { FileRepository } from '../repositories/FileRepository' import { FilesCountInfo } from '../models/FilesCountInfo' -import { DatasetVersion } from '../../../dataset/domain/models/Dataset' +import { DatasetVersionNumber } from '../../../dataset/domain/models/Dataset' import { FileCriteria } from '../models/FileCriteria' export async function getFilesCountInfoByDatasetPersistentId( fileRepository: FileRepository, datasetPersistentId: string, - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, criteria: FileCriteria = new FileCriteria() ): Promise { return fileRepository - .getFilesCountInfoByDatasetPersistentId(datasetPersistentId, datasetVersion, criteria) + .getFilesCountInfoByDatasetPersistentId(datasetPersistentId, datasetVersionNumber, criteria) .catch((error: Error) => { throw new Error(error.message) }) diff --git a/src/files/domain/useCases/getFilesTotalDownloadSize.ts b/src/files/domain/useCases/getFilesTotalDownloadSize.ts index c95bb93ba..b69479f09 100644 --- a/src/files/domain/useCases/getFilesTotalDownloadSize.ts +++ b/src/files/domain/useCases/getFilesTotalDownloadSize.ts @@ -1,15 +1,19 @@ import { FileRepository } from '../repositories/FileRepository' -import { DatasetVersion } from '../../../dataset/domain/models/Dataset' +import { DatasetVersionNumber } from '../../../dataset/domain/models/Dataset' import { FileCriteria } from '../models/FileCriteria' export async function getFilesTotalDownloadSize( fileRepository: FileRepository, datasetPersistentId: string, - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, criteria?: FileCriteria ): Promise { return fileRepository - .getFilesTotalDownloadSizeByDatasetPersistentId(datasetPersistentId, datasetVersion, criteria) + .getFilesTotalDownloadSizeByDatasetPersistentId( + datasetPersistentId, + datasetVersionNumber, + criteria + ) .catch((error: Error) => { throw new Error(error.message) }) diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index 3177801a9..ac2e797ba 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -18,7 +18,7 @@ import { import { FileCriteria } from '../domain/models/FileCriteria' import { DomainFileMapper } from './mappers/DomainFileMapper' import { JSFileMapper } from './mappers/JSFileMapper' -import { DatasetVersion } from '../../dataset/domain/models/Dataset' +import { DatasetVersion, DatasetVersionNumber } from '../../dataset/domain/models/Dataset' import { File } from '../domain/models/File' import { FileMother } from '../../../tests/component/files/domain/models/FileMother' @@ -38,7 +38,7 @@ export class FileJSDataverseRepository implements FileRepository { return getDatasetFiles .execute( datasetPersistentId, - datasetVersion.toString(), + datasetVersion.number.toString(), includeDeaccessioned, jsPagination.limit, jsPagination.offset, @@ -111,13 +111,13 @@ export class FileJSDataverseRepository implements FileRepository { getFilesCountInfoByDatasetPersistentId( datasetPersistentId: string, - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, criteria: FileCriteria ): Promise { return getDatasetFileCounts .execute( datasetPersistentId, - datasetVersion.toString(), + datasetVersionNumber.toString(), includeDeaccessioned, DomainFileMapper.toJSFileSearchCriteria(criteria) ) @@ -131,13 +131,13 @@ export class FileJSDataverseRepository implements FileRepository { getFilesTotalDownloadSizeByDatasetPersistentId( datasetPersistentId: string, - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, criteria: FileCriteria = new FileCriteria() ): Promise { return getDatasetFilesTotalDownloadSize .execute( datasetPersistentId, - datasetVersion.toString(), + datasetVersionNumber.toString(), FileDownloadSizeMode.ARCHIVAL, DomainFileMapper.toJSFileSearchCriteria(criteria), includeDeaccessioned diff --git a/src/sections/dataset/dataset-files/useFiles.tsx b/src/sections/dataset/dataset-files/useFiles.tsx index a013be21b..40208a177 100644 --- a/src/sections/dataset/dataset-files/useFiles.tsx +++ b/src/sections/dataset/dataset-files/useFiles.tsx @@ -28,7 +28,7 @@ export function useFiles( return getFilesCountInfoByDatasetPersistentId( filesRepository, datasetPersistentId, - datasetVersion, + datasetVersion.number, criteria ) .then((filesCountInfo: FilesCountInfo) => { @@ -88,7 +88,7 @@ export function useFiles( ]) useEffect(() => { - getFilesTotalDownloadSize(filesRepository, datasetPersistentId, datasetVersion, criteria) + getFilesTotalDownloadSize(filesRepository, datasetPersistentId, datasetVersion.number, criteria) .then((filesTotalDownloadSize: number) => { setFilesTotalDownloadSize(filesTotalDownloadSize) }) diff --git a/src/stories/files/FileMockLoadingRepository.ts b/src/stories/files/FileMockLoadingRepository.ts index e7eaf02bb..b57bd0305 100644 --- a/src/stories/files/FileMockLoadingRepository.ts +++ b/src/stories/files/FileMockLoadingRepository.ts @@ -1,7 +1,7 @@ import { FileRepository } from '../../files/domain/repositories/FileRepository' import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' -import { DatasetVersion } from '../../dataset/domain/models/Dataset' +import { DatasetVersion, DatasetVersionNumber } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' import { FileMockRepository } from './FileMockRepository' import { File } from '../../files/domain/models/File' @@ -24,7 +24,7 @@ export class FileMockLoadingRepository extends FileMockRepository implements Fil // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, // eslint-disable-next-line unused-imports/no-unused-vars criteria?: FileCriteria ): Promise { diff --git a/src/stories/files/FileMockNoDataRepository.ts b/src/stories/files/FileMockNoDataRepository.ts index 0db3ae4e3..bfd993666 100644 --- a/src/stories/files/FileMockNoDataRepository.ts +++ b/src/stories/files/FileMockNoDataRepository.ts @@ -2,7 +2,7 @@ import { FileRepository } from '../../files/domain/repositories/FileRepository' import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' import { FilesCountInfoMother } from '../../../tests/component/files/domain/models/FilesCountInfoMother' -import { DatasetVersion } from '../../dataset/domain/models/Dataset' +import { DatasetVersion, DatasetVersionNumber } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' import { FileMockRepository } from './FileMockRepository' import { File } from '../../files/domain/models/File' @@ -25,7 +25,7 @@ export class FileMockNoDataRepository extends FileMockRepository implements File // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion + datasetVersionNumber: DatasetVersionNumber ): Promise { return new Promise((resolve) => { setTimeout(() => { @@ -38,7 +38,7 @@ export class FileMockNoDataRepository extends FileMockRepository implements File // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, // eslint-disable-next-line unused-imports/no-unused-vars criteria?: FileCriteria ): Promise { diff --git a/src/stories/files/FileMockNoFiltersRepository.ts b/src/stories/files/FileMockNoFiltersRepository.ts index cdddea3ef..845aa45d8 100644 --- a/src/stories/files/FileMockNoFiltersRepository.ts +++ b/src/stories/files/FileMockNoFiltersRepository.ts @@ -3,7 +3,7 @@ import { FilePreview } from '../../files/domain/models/FilePreview' import { FilesCountInfo } from '../../files/domain/models/FilesCountInfo' import { FilesCountInfoMother } from '../../../tests/component/files/domain/models/FilesCountInfoMother' import { FilesMockData } from './FileMockData' -import { DatasetVersion } from '../../dataset/domain/models/Dataset' +import { DatasetVersion, DatasetVersionNumber } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' import { FileMockRepository } from './FileMockRepository' @@ -25,7 +25,7 @@ export class FileMockNoFiltersRepository extends FileMockRepository implements F // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, // eslint-disable-next-line unused-imports/no-unused-vars criteria?: FileCriteria ): Promise { diff --git a/src/stories/files/FileMockRepository.ts b/src/stories/files/FileMockRepository.ts index 853c47d46..fb03cfc96 100644 --- a/src/stories/files/FileMockRepository.ts +++ b/src/stories/files/FileMockRepository.ts @@ -6,7 +6,7 @@ import { FilesCountInfoMother } from '../../../tests/component/files/domain/mode import { FilePaginationInfo } from '../../files/domain/models/FilePaginationInfo' import { FileUserPermissionsMother } from '../../../tests/component/files/domain/models/FileUserPermissionsMother' import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions' -import { DatasetVersion } from '../../dataset/domain/models/Dataset' +import { DatasetVersion, DatasetVersionNumber } from '../../dataset/domain/models/Dataset' import { FileCriteria } from '../../files/domain/models/FileCriteria' import { FilePreviewMother } from '../../../tests/component/files/domain/models/FilePreviewMother' import { FileMother } from '../../../tests/component/files/domain/models/FileMother' @@ -30,7 +30,7 @@ export class FileMockRepository implements FileRepository { // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion + datasetVersionNumber: DatasetVersionNumber ): Promise { return new Promise((resolve) => { setTimeout(() => { @@ -43,7 +43,7 @@ export class FileMockRepository implements FileRepository { // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, // eslint-disable-next-line unused-imports/no-unused-vars - datasetVersion: DatasetVersion, + datasetVersionNumber: DatasetVersionNumber, // eslint-disable-next-line unused-imports/no-unused-vars criteria?: FileCriteria ): Promise { diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 1e0b9a338..1ff9a88c8 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -35,13 +35,14 @@ export class DatasetVersionMother { ) } - static createDeaccessioned(): DatasetVersion { + static createDeaccessioned(props?: Partial): DatasetVersion { return this.create({ publishingStatus: DatasetPublishingStatus.DEACCESSIONED, isLatest: false, citation: 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1 DEACCESSIONED VERSION', - someDatasetVersionHasBeenReleased: true + someDatasetVersionHasBeenReleased: true, + ...props }) } diff --git a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx index 5da621756..238fde4c4 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx @@ -402,7 +402,7 @@ describe('DatasetFiles', () => { cy.wrap(fileRepository.getFilesCountInfoByDatasetPersistentId).should( 'be.calledWith', datasetPersistentId, - datasetVersion + datasetVersion.number ) }) @@ -545,7 +545,7 @@ describe('DatasetFiles', () => { cy.wrap(fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId).should( 'be.calledWith', datasetPersistentId, - datasetVersion, + datasetVersion.number, new FileCriteria().withFilterByType('image/png') ) }) diff --git a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx index b0e21302d..498f1fa44 100644 --- a/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/useFiles.spec.tsx @@ -6,27 +6,13 @@ import { FileUserPermissionsMother } from '../../../files/domain/models/FileUser import { FilePermissionsProvider } from '../../../../../src/sections/file/file-permissions/FilePermissionsProvider' import { useState } from 'react' import { FilePaginationInfo } from '../../../../../src/files/domain/models/FilePaginationInfo' -import { - DatasetPublishingStatus, - DatasetVersion -} from '../../../../../src/dataset/domain/models/Dataset' import { FileCriteria, FileSortByOption } from '../../../../../src/files/domain/models/FileCriteria' +import { DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' const files = FilePreviewMother.createMany(100) const filesCountInfo = FilesCountInfoMother.create({ total: 100 }) const fileRepository: FileRepository = {} as FileRepository -const datasetVersion = new DatasetVersion( - 1, - '', - [], - true, - false, - DatasetPublishingStatus.RELEASED, - '', - 1, - 0, - false -) +const datasetVersion = DatasetVersionMother.createReleased() const FilesTableTestComponent = ({ datasetPersistentId }: { datasetPersistentId: string }) => { const [paginationInfo, setPaginationInfo] = useState(new FilePaginationInfo()) @@ -169,7 +155,7 @@ describe('useFiles', () => { cy.wrap(fileRepository.getFilesCountInfoByDatasetPersistentId).should( 'be.calledOnceWith', 'persistentId', - datasetVersion, + datasetVersion.number, new FileCriteria() ) @@ -179,7 +165,7 @@ describe('useFiles', () => { cy.wrap(fileRepository.getFilesCountInfoByDatasetPersistentId).should( 'be.calledWith', 'persistentId', - datasetVersion, + datasetVersion.number, new FileCriteria().withSortBy(FileSortByOption.NAME_ZA) ) }) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index ea7d3107f..774bea907 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -14,10 +14,6 @@ import { import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import { DatasetJSDataverseRepository } from '../../../../src/dataset/infrastructure/repositories/DatasetJSDataverseRepository' -import { - DatasetPublishingStatus, - DatasetVersion -} from '../../../../src/dataset/domain/models/Dataset' import { FilePaginationInfo } from '../../../../src/files/domain/models/FilePaginationInfo' import { FileAccessOption, @@ -28,6 +24,7 @@ import { import { DatasetHelper } from '../../shared/datasets/DatasetHelper' import { FileData, FileHelper } from '../../shared/files/FileHelper' import { FilesCountInfo } from '../../../../src/files/domain/models/FilesCountInfo' +import { DatasetVersionMother } from '../../../component/dataset/domain/models/DatasetMother' chai.use(chaiAsPromised) const expect = chai.expect @@ -144,18 +141,7 @@ describe('File JSDataverse Repository', () => { await fileRepository .getAllByDatasetPersistentId( dataset.persistentId, - new DatasetVersion( - dataset.version.id, - '', - [], - true, - false, - DatasetPublishingStatus.RELEASED, - '', - 1, - 0, - false - ) + DatasetVersionMother.createReleased({ id: dataset.version.id }) ) .then((files) => { const expectedPublishedFile = fileData(files[0].id) @@ -183,18 +169,7 @@ describe('File JSDataverse Repository', () => { await fileRepository .getAllByDatasetPersistentId( dataset.persistentId, - new DatasetVersion( - dataset.version.id, - '', - [], - true, - false, - DatasetPublishingStatus.DEACCESSIONED, - '', - 1, - 0, - false - ) + DatasetVersionMother.createDeaccessioned({ id: dataset.version.id }) ) .then((files) => { const expectedDeaccessionedFile = fileData(files[0].id) @@ -578,7 +553,7 @@ describe('File JSDataverse Repository', () => { await fileRepository .getFilesCountInfoByDatasetPersistentId( dataset.persistentId, - dataset.version, + dataset.version.number, new FileCriteria() ) .then((filesCountInfo) => { @@ -651,7 +626,7 @@ describe('File JSDataverse Repository', () => { await fileRepository .getFilesCountInfoByDatasetPersistentId( dataset.persistentId, - dataset.version, + dataset.version.number, new FileCriteria().withFilterByType('text/csv') ) .then((filesCountInfo) => { @@ -721,7 +696,10 @@ describe('File JSDataverse Repository', () => { }, 0) }) await fileRepository - .getFilesTotalDownloadSizeByDatasetPersistentId(dataset.persistentId, dataset.version) + .getFilesTotalDownloadSizeByDatasetPersistentId( + dataset.persistentId, + dataset.version.number + ) .then((totalDownloadSize) => { expect(totalDownloadSize).to.deep.equal(expectedTotalDownloadSize) }) @@ -766,7 +744,7 @@ describe('File JSDataverse Repository', () => { await fileRepository .getFilesTotalDownloadSizeByDatasetPersistentId( dataset.persistentId, - dataset.version, + dataset.version.number, new FileCriteria().withFilterByType('csv') ) .then((totalDownloadSize) => { From 86654908bd342c000657d5abb2e4289023d29f7b Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 21 Dec 2023 15:04:11 +0100 Subject: [PATCH 10/15] feat(DatsetCard): refactor with the new DatasetVersion --- src/dataset/domain/models/DatasetPreview.ts | 6 +---- .../dataset-card/DatasetCard.tsx | 14 +++++++--- .../dataset-card/DatasetCardHeader.tsx | 13 +++++----- .../dataset-card/DatasetCardInfo.tsx | 22 +++++++++++----- .../dataset-card/DatasetCardThumbnail.tsx | 22 +++++++++++----- .../dataset/domain/models/DatasetMother.ts | 2 +- .../domain/models/DatasetPreviewMother.ts | 26 +++++-------------- tests/component/sections/home/Home.spec.tsx | 2 +- .../home/datasets-list/DatasetsList.spec.tsx | 4 +-- .../dataset-card/DatasetCard.spec.tsx | 6 ++--- .../dataset-card/DatasetCardHeader.spec.tsx | 8 +++--- .../dataset-card/DatasetCardInfo.spec.tsx | 20 +++++++++++--- .../DatasetCardThumbnail.spec.tsx | 18 ++++++++++--- 13 files changed, 99 insertions(+), 64 deletions(-) diff --git a/src/dataset/domain/models/DatasetPreview.ts b/src/dataset/domain/models/DatasetPreview.ts index 849ba4691..e7688499d 100644 --- a/src/dataset/domain/models/DatasetPreview.ts +++ b/src/dataset/domain/models/DatasetPreview.ts @@ -1,13 +1,9 @@ -import { DatasetLabel, DatasetVersion } from './Dataset' +import { DatasetVersion } from './Dataset' export class DatasetPreview { constructor( public persistentId: string, - public title: string, public version: DatasetVersion, - public citation: string, - public labels: DatasetLabel[], - public isDeaccessioned: boolean, public releaseOrCreateDate: Date, public description: string, public thumbnail?: string diff --git a/src/sections/home/datasets-list/dataset-card/DatasetCard.tsx b/src/sections/home/datasets-list/dataset-card/DatasetCard.tsx index 6fe1f807e..5e8712da2 100644 --- a/src/sections/home/datasets-list/dataset-card/DatasetCard.tsx +++ b/src/sections/home/datasets-list/dataset-card/DatasetCard.tsx @@ -11,10 +11,18 @@ interface DatasetCardProps { export function DatasetCard({ dataset }: DatasetCardProps) { return (
- +
- - + +
) diff --git a/src/sections/home/datasets-list/dataset-card/DatasetCardHeader.tsx b/src/sections/home/datasets-list/dataset-card/DatasetCardHeader.tsx index 9e927b2fc..30acd8f62 100644 --- a/src/sections/home/datasets-list/dataset-card/DatasetCardHeader.tsx +++ b/src/sections/home/datasets-list/dataset-card/DatasetCardHeader.tsx @@ -2,20 +2,21 @@ import styles from './DatasetCard.module.scss' import { LinkToPage } from '../../../shared/link-to-page/LinkToPage' import { Route } from '../../../Route.enum' import { DatasetLabels } from '../../../dataset/dataset-labels/DatasetLabels' -import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview' import { DatasetIcon } from '../../../dataset/dataset-icon/DatasetIcon' +import { DatasetVersion } from '../../../../dataset/domain/models/Dataset' interface DatasetCardHeaderProps { - dataset: DatasetPreview + persistentId: string + version: DatasetVersion } -export function DatasetCardHeader({ dataset }: DatasetCardHeaderProps) { +export function DatasetCardHeader({ persistentId, version }: DatasetCardHeaderProps) { return (
- - {dataset.title} + + {version.title} - +
diff --git a/src/sections/home/datasets-list/dataset-card/DatasetCardInfo.tsx b/src/sections/home/datasets-list/dataset-card/DatasetCardInfo.tsx index 76a03a645..b8b80a1c5 100644 --- a/src/sections/home/datasets-list/dataset-card/DatasetCardInfo.tsx +++ b/src/sections/home/datasets-list/dataset-card/DatasetCardInfo.tsx @@ -1,23 +1,31 @@ import styles from './DatasetCard.module.scss' import { DateHelper } from '../../../../shared/domain/helpers/DateHelper' -import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview' import { CitationDescription } from '../../../shared/citation/CitationDescription' +import { DatasetPublishingStatus, DatasetVersion } from '../../../../dataset/domain/models/Dataset' interface DatasetCardInfoProps { - dataset: DatasetPreview + version: DatasetVersion + releaseOrCreateDate: Date + abbreviatedDescription: string } -export function DatasetCardInfo({ dataset }: DatasetCardInfoProps) { +export function DatasetCardInfo({ + version, + releaseOrCreateDate, + abbreviatedDescription +}: DatasetCardInfoProps) { return (
- {DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)} + {DateHelper.toDisplayFormat(releaseOrCreateDate)} - + - {dataset.abbreviatedDescription} + {abbreviatedDescription}
) } diff --git a/src/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.tsx b/src/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.tsx index cba65b215..d8065b0fa 100644 --- a/src/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.tsx +++ b/src/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.tsx @@ -1,21 +1,29 @@ import styles from './DatasetCard.module.scss' -import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview' import { LinkToPage } from '../../../shared/link-to-page/LinkToPage' import { Route } from '../../../Route.enum' import { DatasetThumbnail } from '../../../dataset/dataset-thumbnail/DatasetThumbnail' +import { DatasetPublishingStatus, DatasetVersion } from '../../../../dataset/domain/models/Dataset' interface DatasetCardThumbnailProps { - dataset: DatasetPreview + persistentId: string + version: DatasetVersion + thumbnail?: string } -export function DatasetCardThumbnail({ dataset }: DatasetCardThumbnailProps) { +export function DatasetCardThumbnail({ + persistentId, + version, + thumbnail +}: DatasetCardThumbnailProps) { return (
- +
diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 81a4f0628..64bd805d7 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -29,7 +29,7 @@ export class DatasetVersionMother { props?.number ?? new DatasetVersionNumber(1, 0), props?.publishingStatus ?? DatasetPublishingStatus.RELEASED, props?.citation ?? - 'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', + 'Admin, Dataverse, 2023, "Dataset Title", https://doi.org/10.5072/FK2/BUDNRV, Root, V1', props?.isLatest ?? false, props?.isInReview ?? false, props?.latestVersionPublishingStatus ?? DatasetPublishingStatus.RELEASED, diff --git a/tests/component/dataset/domain/models/DatasetPreviewMother.ts b/tests/component/dataset/domain/models/DatasetPreviewMother.ts index 83e080ff9..f46387170 100644 --- a/tests/component/dataset/domain/models/DatasetPreviewMother.ts +++ b/tests/component/dataset/domain/models/DatasetPreviewMother.ts @@ -1,6 +1,6 @@ import { faker } from '@faker-js/faker' import { DatasetPreview } from '../../../../../src/dataset/domain/models/DatasetPreview' -import { DatasetCitationMother, DatasetLabelsMother, DatasetVersionMother } from './DatasetMother' +import { DatasetVersionMother } from './DatasetMother' export class DatasetPreviewMother { static createMany(count: number): DatasetPreview[] { @@ -14,24 +14,16 @@ export class DatasetPreviewMother { static create(props?: Partial): DatasetPreview { const datasetPreview = { persistentId: faker.datatype.uuid(), - title: faker.lorem.sentence(), - labels: DatasetLabelsMother.create(), - isDeaccessioned: faker.datatype.boolean(), - thumbnail: faker.datatype.boolean() ? faker.image.imageUrl() : undefined, - releaseOrCreateDate: faker.date.past(), version: DatasetVersionMother.create(), - citation: DatasetCitationMother.create(), + releaseOrCreateDate: faker.date.past(), description: faker.lorem.paragraph(), + thumbnail: faker.datatype.boolean() ? faker.image.imageUrl() : undefined, ...props } return new DatasetPreview( datasetPreview.persistentId, - datasetPreview.title, datasetPreview.version, - datasetPreview.citation, - datasetPreview.labels, - datasetPreview.isDeaccessioned, datasetPreview.releaseOrCreateDate, datasetPreview.description, datasetPreview.thumbnail @@ -44,25 +36,21 @@ export class DatasetPreviewMother { static createDraft(): DatasetPreview { return this.create({ - isDeaccessioned: false, - labels: DatasetLabelsMother.createDraft(), - citation: DatasetCitationMother.createDraft() + version: DatasetVersionMother.createDraft() }) } static createWithThumbnail(): DatasetPreview { - return this.create({ thumbnail: faker.image.imageUrl(), isDeaccessioned: false }) + return this.create({ thumbnail: faker.image.imageUrl() }) } static createWithNoThumbnail(): DatasetPreview { - return this.create({ thumbnail: undefined, isDeaccessioned: false }) + return this.create({ thumbnail: undefined }) } static createDeaccessioned(): DatasetPreview { return this.create({ - isDeaccessioned: true, - labels: DatasetLabelsMother.createDeaccessioned(), - citation: DatasetCitationMother.createDeaccessioned() + version: DatasetVersionMother.createDeaccessioned() }) } } diff --git a/tests/component/sections/home/Home.spec.tsx b/tests/component/sections/home/Home.spec.tsx index 52fe1d34a..fb3146917 100644 --- a/tests/component/sections/home/Home.spec.tsx +++ b/tests/component/sections/home/Home.spec.tsx @@ -22,7 +22,7 @@ describe('Home page', () => { cy.wrap(datasetRepository.getAll).should('be.calledOnce') datasets.forEach((dataset) => { - cy.findByText(dataset.title).should('exist') + cy.findByText(dataset.version.title).should('exist') }) }) }) diff --git a/tests/component/sections/home/datasets-list/DatasetsList.spec.tsx b/tests/component/sections/home/datasets-list/DatasetsList.spec.tsx index e126ce245..e5e2f79f0 100644 --- a/tests/component/sections/home/datasets-list/DatasetsList.spec.tsx +++ b/tests/component/sections/home/datasets-list/DatasetsList.spec.tsx @@ -17,7 +17,7 @@ describe('Datasets List', () => { cy.findByTestId('datasets-list-skeleton').should('exist') datasets.forEach((dataset) => { - cy.findByRole('link', { name: dataset.title }).should('not.exist') + cy.findByRole('link', { name: dataset.version.title }).should('not.exist') }) }) @@ -38,7 +38,7 @@ describe('Datasets List', () => { cy.findByText('1 to 10 of 200 Datasets').should('exist') datasets.forEach((dataset) => { - cy.findByText(dataset.title) + cy.findByText(dataset.version.title) .should('exist') .should('have.attr', 'href', `/datasets?persistentId=${dataset.persistentId}`) }) diff --git a/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx b/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx index 8b66c37d1..ad6bb084a 100644 --- a/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx +++ b/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx @@ -8,11 +8,11 @@ describe('DatasetCard', () => { const dataset = DatasetPreviewMother.createWithThumbnail() cy.customMount() - cy.findByText(dataset.title).should('exist') + cy.findByText(dataset.version.title).should('exist') - cy.findByRole('img', { name: dataset.title }).should('exist') + cy.findByRole('img', { name: dataset.version.title }).should('exist') cy.findByText(DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)).should('exist') - cy.findByText(/Finch, Fiona, 2023, "Darwin's Finches"/) + cy.findByText(/Admin, Dataverse, 2023, "Dataset Title",/) .should('exist') .parent() .should('have.class', styles['citation-box']) diff --git a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardHeader.spec.tsx b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardHeader.spec.tsx index 1e7773dfc..e428583cb 100644 --- a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardHeader.spec.tsx +++ b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardHeader.spec.tsx @@ -4,12 +4,14 @@ import { DatasetPreviewMother } from '../../../../dataset/domain/models/DatasetP describe('DatasetCardHeader', () => { it('should render the header', () => { const dataset = DatasetPreviewMother.create() - cy.customMount() + cy.customMount( + + ) - cy.findByText(dataset.title) + cy.findByText(dataset.version.title) .should('exist') .should('have.attr', 'href', `/datasets?persistentId=${dataset.persistentId}`) - dataset.labels.forEach((label) => { + dataset.version.labels.forEach((label) => { cy.findByText(label.value).should('exist') }) cy.findByLabelText('icon-dataset').should('exist') diff --git a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx index 5563fe412..f44e90ced 100644 --- a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx +++ b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx @@ -6,10 +6,16 @@ import { DatasetCardInfo } from '../../../../../../src/sections/home/datasets-li describe('DatasetCardInfo', () => { it('should render the dataset info', () => { const dataset = DatasetPreviewMother.createDraft() - cy.customMount() + cy.customMount( + + ) cy.findByText(DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)).should('exist') - cy.findByText(/Finch, Fiona, 2023, "Darwin's Finches"/) + cy.findByText(/Admin, Dataverse, 2023, "Dataset Title",/) .should('exist') .parent() .should('have.class', styles['citation-box']) @@ -18,9 +24,15 @@ describe('DatasetCardInfo', () => { it('should render the citation with the deaccessioned background if the dataset is deaccessioned', () => { const dataset = DatasetPreviewMother.createDeaccessioned() - cy.customMount() + cy.customMount( + + ) - cy.findByText(/Finch, Fiona, 2023, "Darwin's Finches"/) + cy.findByText(/Admin, Dataverse, 2023, "Dataset Title",/) .should('exist') .parent() .should('have.class', styles['citation-box-deaccessioned']) diff --git a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.spec.tsx b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.spec.tsx index e261e32db..b66e98a14 100644 --- a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.spec.tsx +++ b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardThumbnail.spec.tsx @@ -4,9 +4,15 @@ import { DatasetCardThumbnail } from '../../../../../../src/sections/home/datase describe('DatasetCardThumbnail', () => { it('should render the thumbnail', () => { const dataset = DatasetPreviewMother.createWithThumbnail() - cy.customMount() + cy.customMount( + + ) - cy.findByRole('img', { name: dataset.title }) + cy.findByRole('img', { name: dataset.version.title }) .should('exist') .parent('a') .should('have.attr', 'href', `/datasets?persistentId=${dataset.persistentId}`) @@ -14,7 +20,13 @@ describe('DatasetCardThumbnail', () => { it('should render the placeholder if the dataset has no thumbnail', () => { const dataset = DatasetPreviewMother.createWithNoThumbnail() - cy.customMount() + cy.customMount( + + ) cy.findByRole('img', { name: 'icon-dataset' }) .should('exist') From 3cbbd40a2f24d91cacc57663e10acc71070702e7 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 21 Dec 2023 16:12:32 +0100 Subject: [PATCH 11/15] feat(FileLabels): add DatasetLabels to File Page --- src/sections/file/File.module.scss | 1 + src/sections/file/File.tsx | 6 ++++-- src/sections/file/FileSkeleton.tsx | 7 +++++-- src/sections/file/file-labels/FileLabels.tsx | 9 +++++++++ tests/component/sections/file/File.spec.tsx | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/sections/file/file-labels/FileLabels.tsx diff --git a/src/sections/file/File.module.scss b/src/sections/file/File.module.scss index 2c924a81a..695d4f586 100644 --- a/src/sections/file/File.module.scss +++ b/src/sections/file/File.module.scss @@ -6,6 +6,7 @@ .subtext { color: $dv-subtext-color; + margin-bottom: 10px; } .container { diff --git a/src/sections/file/File.tsx b/src/sections/file/File.tsx index 176eee903..42bcd48c2 100644 --- a/src/sections/file/File.tsx +++ b/src/sections/file/File.tsx @@ -7,6 +7,7 @@ import { useFile } from './useFile' import { useEffect } from 'react' import { useLoading } from '../loading/LoadingContext' import { FileSkeleton } from './FileSkeleton' +import { DatasetLabels } from '../dataset/dataset-labels/DatasetLabels' interface FileProps { repository: FileRepository @@ -33,9 +34,10 @@ export function File({ repository, id }: FileProps) {

{file.name}

- +

{t('subtext', { datasetTitle: file.datasetVersion.title })} - +

+
diff --git a/src/sections/file/FileSkeleton.tsx b/src/sections/file/FileSkeleton.tsx index c92f46c0b..e2c8f30de 100644 --- a/src/sections/file/FileSkeleton.tsx +++ b/src/sections/file/FileSkeleton.tsx @@ -1,4 +1,4 @@ -import styles from '../dataset/Dataset.module.scss' +import styles from './File.module.scss' import Skeleton, { SkeletonTheme } from 'react-loading-skeleton' import { Tabs } from '@iqss/dataverse-design-system' @@ -8,8 +8,11 @@ export function FileSkeleton() {

- +

+

+ +

diff --git a/src/sections/file/file-labels/FileLabels.tsx b/src/sections/file/file-labels/FileLabels.tsx new file mode 100644 index 000000000..2b71e350f --- /dev/null +++ b/src/sections/file/file-labels/FileLabels.tsx @@ -0,0 +1,9 @@ +import { DatasetLabel } from '../../../dataset/domain/models/Dataset' + +interface FileLabelsProps { + labels: DatasetLabel[] +} + +export function FileLabels({ labels }: FileLabelsProps) { + return
Not implemented
+} diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx index 1377c092a..9f571aaac 100644 --- a/tests/component/sections/file/File.spec.tsx +++ b/tests/component/sections/file/File.spec.tsx @@ -15,6 +15,7 @@ describe('File', () => { cy.findAllByText(testFile.name).should('exist') cy.findByText(`This file is part of "${testFile.datasetVersion.title}".`).should('exist') + cy.findByText('Version 1.0').should('exist') }) it('renders skeleton while loading', () => { From b7bc8ce5e94d664fe6ca1e6a1d9b54ee1744dad1 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 21 Dec 2023 16:46:11 +0100 Subject: [PATCH 12/15] refactor: FileFileAccessRestrictedIcon move to file folder --- public/locales/en/file.json | 20 ++++++++- public/locales/en/files.json | 18 -------- .../access-file-menu/AccessStatus.tsx | 4 +- .../file-thumbnail/FileThumbnail.module.scss | 20 --------- .../file-thumbnail/FileThumbnail.tsx | 7 +++- .../FileThumbnailRestrictedIcon.tsx | 39 ------------------ .../FileAccessInfoIcon.module.scss | 21 ++++++++++ .../file-access/FileAccessRestrictedIcon.tsx | 41 +++++++++++++++++++ src/sections/file/file-labels/FileLabels.tsx | 9 ---- .../FileAccessRestrictedIcon.spec.tsx | 28 +++++++++++++ 10 files changed, 116 insertions(+), 91 deletions(-) delete mode 100644 src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx create mode 100644 src/sections/file/file-access/FileAccessInfoIcon.module.scss create mode 100644 src/sections/file/file-access/FileAccessRestrictedIcon.tsx delete mode 100644 src/sections/file/file-labels/FileLabels.tsx create mode 100644 tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx diff --git a/public/locales/en/file.json b/public/locales/en/file.json index 9e3bd1b68..56ee0fdac 100644 --- a/public/locales/en/file.json +++ b/public/locales/en/file.json @@ -2,5 +2,23 @@ "tabs": { "metadata": "Metadata" }, - "subtext": "This file is part of \"{{datasetTitle}}\"." + "subtext": "This file is part of \"{{datasetTitle}}\".", + "fileAccess": { + "title": "File Access", + "restricted": { + "name": "Restricted", + "icon": "Restricted File Icon" + }, + "restrictedWithAccess": { + "name": "Restricted with Access Granted", + "icon": "Restricted with access Icon" + }, + "embargoed": { + "name": "Embargoed" + }, + "public": { + "name": "Public", + "icon": "Public File Icon" + } + } } diff --git a/public/locales/en/files.json b/public/locales/en/files.json index bbae885f1..1f74f36ca 100644 --- a/public/locales/en/files.json +++ b/public/locales/en/files.json @@ -24,24 +24,6 @@ "published": "Published", "deposited": "Deposited" }, - "fileAccess": { - "title": "File Access", - "restricted": { - "name": "Restricted", - "icon": "Restricted File Icon" - }, - "restrictedWithAccess": { - "name": "Restricted with Access Granted", - "icon": "Restricted with access Icon" - }, - "embargoed": { - "name": "Embargoed" - }, - "public": { - "name": "Public", - "icon": "Public File Icon" - } - }, "copyToClipboard": { "clickToCopy": "Click to copy", "correctlyCopiedIcon": "Correctly copied to clipboard icon", diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx index ea4a67a8d..a7dfd03a0 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx @@ -35,7 +35,7 @@ function AccessStatusIcon({ sessionUserHasFileDownloadPermission: boolean restricted: boolean }) { - const { t } = useTranslation('files') + const { t } = useTranslation('file') if (restricted) { if (sessionUserHasFileDownloadPermission) { return ( @@ -63,7 +63,7 @@ function AccessStatusText({ file: FilePreview sessionUserHasFileDownloadPermission: boolean }) { - const { t } = useTranslation('files') + const { t } = useTranslation('file') const getAccessStatus = () => { if (file.isActivelyEmbargoed) { return 'embargoed' diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss index aaaafe437..3e9b6a559 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss @@ -37,23 +37,3 @@ .tooltip-preview-image { max-width: 390px; } - -%restricted-icon { - position: absolute; - right: -14px; - bottom: -5px; - font-size: 20px; -} - -.restricted-icon-restricted { - @extend %restricted-icon; - - color: $dv-danger-color; -} - -.restricted-icon-restrictedWithAccess { - @extend %restricted-icon; - - right: -16px; - color: $dv-success-color; -} diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx index ed343cf42..ad61432b3 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx @@ -1,7 +1,7 @@ import { FileThumbnailIcon } from './FileThumbnailIcon' import { FileThumbnailPreviewImage } from './FileThumbnailPreviewImage' import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' -import { FileThumbnailRestrictedIcon } from './FileThumbnailRestrictedIcon' +import { FileAccessRestrictedIcon } from '../../../../../../../file/file-access/FileAccessRestrictedIcon' import styles from './FileThumbnail.module.scss' import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' @@ -24,7 +24,10 @@ export function FileThumbnail({ file }: FileThumbnailProps) { ) : ( )} - +
) } diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx deleted file mode 100644 index 23f620942..000000000 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnailRestrictedIcon.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { LockFill, UnlockFill } from 'react-bootstrap-icons' -import styles from './FileThumbnail.module.scss' -import { useTranslation } from 'react-i18next' -import { Tooltip } from '@iqss/dataverse-design-system' -import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview' -import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' - -export function FileThumbnailRestrictedIcon({ file }: { file: FilePreview }) { - if (!file.access.restricted) { - return <> - } - - const { t } = useTranslation('files') - const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file) - return ( - - - {sessionUserHasFileDownloadPermission ? ( - - ) : ( - - )} - - - ) -} diff --git a/src/sections/file/file-access/FileAccessInfoIcon.module.scss b/src/sections/file/file-access/FileAccessInfoIcon.module.scss new file mode 100644 index 000000000..025907f94 --- /dev/null +++ b/src/sections/file/file-access/FileAccessInfoIcon.module.scss @@ -0,0 +1,21 @@ +@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module"; + +%restricted-icon { + position: absolute; + right: -14px; + bottom: -5px; + font-size: 20px; +} + +.restricted-icon-restricted { + @extend %restricted-icon; + + color: $dv-danger-color; +} + +.restricted-icon-restrictedWithAccess { + @extend %restricted-icon; + + right: -16px; + color: $dv-success-color; +} \ No newline at end of file diff --git a/src/sections/file/file-access/FileAccessRestrictedIcon.tsx b/src/sections/file/file-access/FileAccessRestrictedIcon.tsx new file mode 100644 index 000000000..349edc9a8 --- /dev/null +++ b/src/sections/file/file-access/FileAccessRestrictedIcon.tsx @@ -0,0 +1,41 @@ +import { LockFill, UnlockFill } from 'react-bootstrap-icons' +import styles from './FileAccessInfoIcon.module.scss' +import { useTranslation } from 'react-i18next' +import { Tooltip } from '@iqss/dataverse-design-system' + +interface FileAccessInfoIconProps { + isRestricted: boolean + canDownloadFile: boolean +} +export function FileAccessRestrictedIcon({ + isRestricted, + canDownloadFile +}: FileAccessInfoIconProps) { + const { t } = useTranslation('file') + + if (!isRestricted) { + return <> + } + + if (canDownloadFile) { + return ( + + + + + + ) + } + + return ( + + + + + + ) +} diff --git a/src/sections/file/file-labels/FileLabels.tsx b/src/sections/file/file-labels/FileLabels.tsx deleted file mode 100644 index 2b71e350f..000000000 --- a/src/sections/file/file-labels/FileLabels.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { DatasetLabel } from '../../../dataset/domain/models/Dataset' - -interface FileLabelsProps { - labels: DatasetLabel[] -} - -export function FileLabels({ labels }: FileLabelsProps) { - return
Not implemented
-} diff --git a/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx b/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx new file mode 100644 index 000000000..42a1c5fbf --- /dev/null +++ b/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx @@ -0,0 +1,28 @@ +import { FileAccessRestrictedIcon } from '../../../../../src/sections/file/file-access/FileAccessRestrictedIcon' + +describe('FileAccessRestrictedIcon', () => { + it('should render the restricted icon if the file is restricted and the user cannot download the file', () => { + cy.customMount() + + cy.findByTitle('Restricted File Icon').should('exist').parent().trigger('mouseover') + cy.findByText('File Access: Restricted').should('exist') + + cy.findByTitle('Restricted with access Icon').should('not.exist') + }) + + it('should render the restricted with access icon if the file is restricted and the user can download the file', () => { + cy.customMount() + + cy.findByTitle('Restricted with access Icon').should('exist').parent().trigger('mouseover') + cy.findByText('File Access: Restricted with Access Granted').should('exist') + + cy.findByTitle('Restricted File Icon').should('not.exist') + }) + + it('should not render any icon if the file is not restricted', () => { + cy.customMount() + + cy.findByTitle('Restricted with access Icon').should('not.exist') + cy.findByTitle('Restricted File Icon').should('not.exist') + }) +}) From 9b1c321065396cf92d2d486a85bbed61c6eb2647 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Fri, 22 Dec 2023 18:06:08 +0100 Subject: [PATCH 13/15] feat(FileLabels): add Restricted icon to File Labels --- src/files/domain/models/File.ts | 6 +++++ .../access-file-menu/AccessStatus.tsx | 17 +++--------- .../file-thumbnail/FileThumbnail.module.scss | 6 +++++ .../file-thumbnail/FileThumbnail.tsx | 10 ++++--- src/sections/file/File.module.scss | 11 +++++++- src/sections/file/File.tsx | 13 ++++++++- .../FileAccessInfoIcon.module.scss | 3 --- .../file-access/FileAccessRestrictedIcon.tsx | 9 +++---- src/stories/files/File.stories.tsx | 14 ++++++++++ src/stories/files/FileMockRepository.ts | 4 ++- .../files/domain/models/FileMother.ts | 27 +++++++++++++++++++ tests/component/sections/file/File.spec.tsx | 9 +++++++ .../FileAccessRestrictedIcon.spec.tsx | 6 ++--- 13 files changed, 103 insertions(+), 32 deletions(-) diff --git a/src/files/domain/models/File.ts b/src/files/domain/models/File.ts index d348f4df8..6f1eb29db 100644 --- a/src/files/domain/models/File.ts +++ b/src/files/domain/models/File.ts @@ -1,6 +1,12 @@ import { DatasetVersion } from '../../../dataset/domain/models/Dataset' +export interface FilePermissions { + canDownloadFile: boolean +} + export interface File { name: string datasetVersion: DatasetVersion + restricted: boolean + permissions: FilePermissions } diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx index a7dfd03a0..02509ec3c 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx @@ -39,21 +39,12 @@ function AccessStatusIcon({ if (restricted) { if (sessionUserHasFileDownloadPermission) { return ( - + ) } - return ( - - ) + return } - return + return } function AccessStatusText({ @@ -89,7 +80,7 @@ function AccessStatusText({ : 'danger' ] }> - {t(`table.fileAccess.${getAccessStatus()}.name`)} + {t(`fileAccess.${getAccessStatus()}.name`)} ) } diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss index 3e9b6a559..b30949ecb 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.module.scss @@ -37,3 +37,9 @@ .tooltip-preview-image { max-width: 390px; } + +.restricted-icon { + position: absolute; + right: -14px; + bottom: -5px; +} diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx index ad61432b3..7642d03a0 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/file-thumbnail/FileThumbnail.tsx @@ -24,10 +24,12 @@ export function FileThumbnail({ file }: FileThumbnailProps) { ) : ( )} - +
+ +
) } diff --git a/src/sections/file/File.module.scss b/src/sections/file/File.module.scss index 695d4f586..d05c34a83 100644 --- a/src/sections/file/File.module.scss +++ b/src/sections/file/File.module.scss @@ -5,8 +5,8 @@ } .subtext { - color: $dv-subtext-color; margin-bottom: 10px; + color: $dv-subtext-color; } .container { @@ -16,4 +16,13 @@ .separation-line { margin: 1em 0; border-bottom: 1px solid #dee2e6; +} + +.labels { + display: flex; + align-items: center; +} + +.restricted-icon { + margin-right: 6px; } \ No newline at end of file diff --git a/src/sections/file/File.tsx b/src/sections/file/File.tsx index 42bcd48c2..399431c14 100644 --- a/src/sections/file/File.tsx +++ b/src/sections/file/File.tsx @@ -8,6 +8,7 @@ import { useEffect } from 'react' import { useLoading } from '../loading/LoadingContext' import { FileSkeleton } from './FileSkeleton' import { DatasetLabels } from '../dataset/dataset-labels/DatasetLabels' +import { FileAccessRestrictedIcon } from './file-access/FileAccessRestrictedIcon' interface FileProps { repository: FileRepository @@ -37,7 +38,17 @@ export function File({ repository, id }: FileProps) {

{t('subtext', { datasetTitle: file.datasetVersion.title })}

- +
+ {file.restricted && ( +
+ +
+ )} + +
diff --git a/src/sections/file/file-access/FileAccessInfoIcon.module.scss b/src/sections/file/file-access/FileAccessInfoIcon.module.scss index 025907f94..7f750214c 100644 --- a/src/sections/file/file-access/FileAccessInfoIcon.module.scss +++ b/src/sections/file/file-access/FileAccessInfoIcon.module.scss @@ -1,9 +1,6 @@ @import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module"; %restricted-icon { - position: absolute; - right: -14px; - bottom: -5px; font-size: 20px; } diff --git a/src/sections/file/file-access/FileAccessRestrictedIcon.tsx b/src/sections/file/file-access/FileAccessRestrictedIcon.tsx index 349edc9a8..426278ac7 100644 --- a/src/sections/file/file-access/FileAccessRestrictedIcon.tsx +++ b/src/sections/file/file-access/FileAccessRestrictedIcon.tsx @@ -4,16 +4,13 @@ import { useTranslation } from 'react-i18next' import { Tooltip } from '@iqss/dataverse-design-system' interface FileAccessInfoIconProps { - isRestricted: boolean + restricted: boolean canDownloadFile: boolean } -export function FileAccessRestrictedIcon({ - isRestricted, - canDownloadFile -}: FileAccessInfoIconProps) { +export function FileAccessRestrictedIcon({ restricted, canDownloadFile }: FileAccessInfoIconProps) { const { t } = useTranslation('file') - if (!isRestricted) { + if (!restricted) { return <> } diff --git a/src/stories/files/File.stories.tsx b/src/stories/files/File.stories.tsx index 060fe8dfc..1f72a8c7d 100644 --- a/src/stories/files/File.stories.tsx +++ b/src/stories/files/File.stories.tsx @@ -5,6 +5,7 @@ import { File } from '../../sections/file/File' import { WithLayout } from '../WithLayout' import { FileMockLoadingRepository } from './FileMockLoadingRepository' import { FileMockNoDataRepository } from './FileMockNoDataRepository' +import { FileMother } from '../../../tests/component/files/domain/models/FileMother' const meta: Meta = { title: 'Pages/File', @@ -19,6 +20,19 @@ export const Default: Story = { render: () => } +export const Restricted: Story = { + render: () => +} + +export const RestrictedWithAccessGranted: Story = { + render: () => ( + + ) +} + export const Loading: Story = { render: () => } diff --git a/src/stories/files/FileMockRepository.ts b/src/stories/files/FileMockRepository.ts index cbb518ecf..73a089ccd 100644 --- a/src/stories/files/FileMockRepository.ts +++ b/src/stories/files/FileMockRepository.ts @@ -13,6 +13,8 @@ import { FileMother } from '../../../tests/component/files/domain/models/FileMot import { File } from '../../files/domain/models/File' export class FileMockRepository implements FileRepository { + constructor(public readonly fileMock?: File) {} + // eslint-disable-next-line unused-imports/no-unused-vars getAllByDatasetPersistentId( datasetPersistentId: string, @@ -67,7 +69,7 @@ export class FileMockRepository implements FileRepository { getById(id: number): Promise { return new Promise((resolve) => { setTimeout(() => { - resolve(FileMother.createRealistic()) + resolve(this.fileMock ?? FileMother.createRealistic()) }, 1000) }) } diff --git a/tests/component/files/domain/models/FileMother.ts b/tests/component/files/domain/models/FileMother.ts index 28b245c94..8b63476fa 100644 --- a/tests/component/files/domain/models/FileMother.ts +++ b/tests/component/files/domain/models/FileMother.ts @@ -7,6 +7,10 @@ export class FileMother { return { name: faker.system.fileName(), datasetVersion: DatasetVersionMother.create(), + restricted: faker.datatype.boolean(), + permissions: { + canDownloadFile: faker.datatype.boolean() + }, ...props } } @@ -15,6 +19,29 @@ export class FileMother { return this.create({ name: 'file.csv', datasetVersion: DatasetVersionMother.createRealistic(), + restricted: false, + permissions: { + canDownloadFile: true + }, + ...props + }) + } + + static createRestricted(props?: Partial): File { + return this.createRealistic({ + restricted: true, + permissions: { + canDownloadFile: false + }, + ...props + }) + } + + static createRestrictedWithAccessGranted(props?: Partial): File { + return this.createRestricted({ + permissions: { + canDownloadFile: true + }, ...props }) } diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx index 9f571aaac..3049c4b91 100644 --- a/tests/component/sections/file/File.spec.tsx +++ b/tests/component/sections/file/File.spec.tsx @@ -36,4 +36,13 @@ describe('File', () => { cy.findByText('Page Not Found').should('exist') }) + + it('renders the restricted icon if the file is restricted', () => { + const testFile = FileMother.createRestricted() + fileRepository.getById = cy.stub().resolves(testFile) + + cy.customMount() + + cy.findByText('Restricted File Icon').should('exist') + }) }) diff --git a/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx b/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx index 42a1c5fbf..5d918e82a 100644 --- a/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx +++ b/tests/component/sections/file/file-access/FileAccessRestrictedIcon.spec.tsx @@ -2,7 +2,7 @@ import { FileAccessRestrictedIcon } from '../../../../../src/sections/file/file- describe('FileAccessRestrictedIcon', () => { it('should render the restricted icon if the file is restricted and the user cannot download the file', () => { - cy.customMount() + cy.customMount() cy.findByTitle('Restricted File Icon').should('exist').parent().trigger('mouseover') cy.findByText('File Access: Restricted').should('exist') @@ -11,7 +11,7 @@ describe('FileAccessRestrictedIcon', () => { }) it('should render the restricted with access icon if the file is restricted and the user can download the file', () => { - cy.customMount() + cy.customMount() cy.findByTitle('Restricted with access Icon').should('exist').parent().trigger('mouseover') cy.findByText('File Access: Restricted with Access Granted').should('exist') @@ -20,7 +20,7 @@ describe('FileAccessRestrictedIcon', () => { }) it('should not render any icon if the file is not restricted', () => { - cy.customMount() + cy.customMount() cy.findByTitle('Restricted with access Icon').should('not.exist') cy.findByTitle('Restricted File Icon').should('not.exist') From 95fd1a3ddb01bbf9fdd47fafcddf2cf6a53918c6 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 8 Jan 2024 10:38:38 +0100 Subject: [PATCH 14/15] fix: remove demo dataverse reference in page not found message --- public/locales/en/pageNotFound.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/locales/en/pageNotFound.json b/public/locales/en/pageNotFound.json index 1fb88259b..19d0dcf7e 100644 --- a/public/locales/en/pageNotFound.json +++ b/public/locales/en/pageNotFound.json @@ -1,4 +1,4 @@ { "heading": "Page Not Found", - "message": "The page you are looking for was not found. If you believe this is an error, please contact Demo Dataverse Support for assistance." + "message": "The page you are looking for was not found." } From 4f9728e52656d9b8be273ffd70f7b018621fde52 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 8 Jan 2024 12:17:04 +0100 Subject: [PATCH 15/15] fix: e2e test year dependence --- .../DatasetJSDataverseRepository.spec.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index be2e91bce..dcd078695 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -30,8 +30,14 @@ function getPersistentIdUrl(persistentId: string) { return `https://doi.org/${persistentId.replace('doi:', '')}` } +function getCitationString(persistentId: string, version: 'DRAFT VERSION' | 'V1') { + const year = new Date().getFullYear() + return `Finch, Fiona, ${year}, "Darwin's Finches", ${getPersistentIdUrl(persistentId)}, Root, ${version}` +} + const datasetData = (persistentId: string, versionId: number) => { - const persistentIdUrl = getPersistentIdUrl(persistentId) return { license: { name: 'CC0 1.0', @@ -88,7 +94,7 @@ const datasetData = (persistentId: string, versionId: number) => { latestVersionPublishingStatus: 'draft', isLatest: true, isInReview: false, - citation: `Finch, Fiona, 2023, "Darwin's Finches", ${persistentIdUrl}, Root, DRAFT VERSION`, + citation: getCitationString(persistentId, 'DRAFT VERSION'), title: "Darwin's Finches", labels: [ { semanticMeaning: 'dataset', value: 'Draft' }, @@ -165,9 +171,7 @@ describe('Dataset JSDataverse Repository', () => { minorNumber: 0 }, DatasetPublishingStatus.RELEASED, - `Finch, Fiona, 2023, "Darwin's Finches", ${getPersistentIdUrl(dataset.persistentId)}, Root, V1`, + getCitationString(dataset.persistentId, 'V1'), [new DatasetLabel(DatasetLabelSemanticMeaning.FILE, 'Version 1.0')], true, false, @@ -210,9 +214,7 @@ describe('Dataset JSDataverse Repository', () => { minorNumber: 0 }, DatasetPublishingStatus.RELEASED, - `Finch, Fiona, 2023, "Darwin's Finches", ${getPersistentIdUrl(dataset.persistentId)}, Root, V1`, + getCitationString(dataset.persistentId, 'V1'), [new DatasetLabel(DatasetLabelSemanticMeaning.FILE, 'Version 1.0')], true, false,