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 {