diff --git a/packages/design-system/src/lib/components/dropdown-button/dropdown-button-item/DropdownButtonItem.tsx b/packages/design-system/src/lib/components/dropdown-button/dropdown-button-item/DropdownButtonItem.tsx index f820d33dd..61425e7ef 100644 --- a/packages/design-system/src/lib/components/dropdown-button/dropdown-button-item/DropdownButtonItem.tsx +++ b/packages/design-system/src/lib/components/dropdown-button/dropdown-button-item/DropdownButtonItem.tsx @@ -5,6 +5,7 @@ interface DropdownItemProps extends React.HTMLAttributes { href?: string eventKey?: string disabled?: boolean + download?: string children: ReactNode } @@ -12,11 +13,17 @@ export function DropdownButtonItem({ href, eventKey, disabled, + download, children, ...props }: DropdownItemProps) { return ( - + {children} ) diff --git a/src/files/domain/models/File.ts b/src/files/domain/models/File.ts index a2000775d..bb24317aa 100644 --- a/src/files/domain/models/File.ts +++ b/src/files/domain/models/File.ts @@ -145,6 +145,12 @@ export interface FileIngest { reportMessage?: string } +export interface FileDownloadUrls { + original: string + tabular?: string + rData?: string +} + export class File { constructor( readonly id: number, @@ -158,12 +164,13 @@ export class File { readonly labels: FileLabel[], public readonly isDeleted: boolean, public readonly ingest: FileIngest, - readonly checksum?: FileChecksum, - readonly thumbnail?: string, + public readonly downloadUrls: FileDownloadUrls, + public thumbnail?: string, readonly directory?: string, readonly embargo?: FileEmbargo, readonly tabularData?: FileTabularData, - readonly description?: string + readonly description?: string, + readonly checksum?: FileChecksum ) {} getLink(): string { diff --git a/src/files/infrastructure/mappers/JSFileMapper.ts b/src/files/infrastructure/mappers/JSFileMapper.ts index aa5ec32ed..d16f872b9 100644 --- a/src/files/infrastructure/mappers/JSFileMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMapper.ts @@ -4,6 +4,7 @@ import { FileChecksum, FileDate, FileDateType, + FileDownloadUrls, FileEmbargo, FileIngestStatus, FileLabel, @@ -56,12 +57,13 @@ export class JSFileMapper { this.toFileLabels(jsFile.categories, jsFile.tabularTags), this.toFileIsDeleted(jsFile.deleted), { status: FileIngestStatus.NONE }, // TODO - Implement this when it is added to js-dataverse - this.toFileChecksum(jsFile.checksum), + this.toFileOriginalFileDownloadUrl(jsFile.id), this.toFileThumbnail(thumbnail), this.toFileDirectory(jsFile.directoryLabel), this.toFileEmbargo(jsFile.embargo), this.toFileTabularData(jsTabularData), - this.toFileDescription(jsFile.description) + this.toFileDescription(jsFile.description), + this.toFileChecksum(jsFile.checksum) ) } @@ -167,6 +169,14 @@ export class JSFileMapper { return undefined } + static toFileOriginalFileDownloadUrl(id: number): FileDownloadUrls { + return { + original: `/api/access/datafile/${id}?format=original`, + tabular: `/api/access/datafile/${id}`, + rData: `/api/access/datafile/${id}?format=RData` + } + } + static toFileThumbnail(thumbnail?: string): string | undefined { return thumbnail } 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 61f0e8400..a1b98acf9 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 @@ -4,6 +4,7 @@ import { File } from '../../../../../../../../files/domain/models/File' import { FileTabularDownloadOptions } from './FileTabularDownloadOptions' import { FileNonTabularDownloadOptions } from './FileNonTabularDownloadOptions' import { useTranslation } from 'react-i18next' +import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission' interface FileDownloadOptionsProps { file: File @@ -11,6 +12,12 @@ interface FileDownloadOptionsProps { export function FileDownloadOptions({ file }: FileDownloadOptionsProps) { const { t } = useTranslation('files') + const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file) + + if (!sessionUserHasFileDownloadPermission) { + return <> + } + return ( <> 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 e7306abb0..eb64a832d 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 @@ -20,6 +20,7 @@ export function FileNonTabularDownloadOptions({ file }: FileNonTabularDownloadOp return ( {originalFileFormatIsKnown && ( - {`${file.type.original} (${t( - 'actions.accessFileMenu.downloadOptions.options.original' - )})`} + {`${ + file.type.original + } (${t('actions.accessFileMenu.downloadOptions.options.original')})`} )} - + {t('actions.accessFileMenu.downloadOptions.options.tabular')} {file.type.original !== 'R Data' && ( - + {t('actions.accessFileMenu.downloadOptions.options.RData')} )} 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 a3a80a32d..b016c7722 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 @@ -25,7 +25,7 @@ export const NonTabularFiles: Story = { } export const TabularFiles: Story = { - render: () => + render: () => } export const Restricted: Story = { 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 6f4d8c401..7cd2f550d 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 @@ -29,7 +29,7 @@ export const WithEmbargo: Story = { } export const WithTabularData: Story = { - render: () => + render: () => } export const WithDescription: Story = { diff --git a/tests/component/files/domain/models/FileMother.ts b/tests/component/files/domain/models/FileMother.ts index 99dc36332..880cbb459 100644 --- a/tests/component/files/domain/models/FileMother.ts +++ b/tests/component/files/domain/models/FileMother.ts @@ -124,6 +124,11 @@ export class FileMother { description: valueOrUndefined(faker.lorem.paragraph()), isDeleted: faker.datatype.boolean(), ingest: { status: FileIngestStatus.NONE }, + downloadUrls: { + original: this.createDownloadUrl(), + tabular: this.createDownloadUrl(), + rData: this.createDownloadUrl() + }, ...props } @@ -139,15 +144,23 @@ export class FileMother { fileMockedData.labels, fileMockedData.isDeleted, fileMockedData.ingest, - fileMockedData.checksum, + fileMockedData.downloadUrls, fileMockedData.thumbnail, fileMockedData.directory, fileMockedData.embargo, fileMockedData.tabularData, - fileMockedData.description + 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)) } @@ -212,7 +225,7 @@ export class FileMother { }) } - static createWithTabularData(props?: Partial): File { + static createTabular(props?: Partial): File { return this.createDefault({ type: new FileType('text/tab-separated-values', 'Comma Separated Values'), tabularData: { @@ -224,6 +237,14 @@ export class FileMother { }) } + static createNonTabular(props?: Partial): File { + return this.createDefault({ + type: new FileType('text/plain'), + tabularData: undefined, + ...props + }) + } + static createWithDescription(): File { return this.createDefault({ description: faker.lorem.paragraph() 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 b25c43a4e..460cfab8d 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,9 +1,21 @@ 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 { 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 fileRepository = {} as FileRepository describe('AccessFileMenu', () => { + beforeEach(() => { + fileRepository.getUserPermissionsById = cy.stub().resolves( + FileUserPermissionsMother.create({ + canDownloadFile: true + }) + ) + }) it('renders the access file menu', () => { cy.customMount() @@ -53,10 +65,11 @@ describe('AccessFileMenu', () => { }) it('renders the download options header', () => { + const filePublic = FileMother.createWithPublicAccess() cy.customMount( - - - + + + ) cy.findByRole('button', { name: 'Access File' }).click() 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 0c8d299cb..912c63a18 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,30 +1,64 @@ 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 { FileType } from '../../../../../../../../../../src/files/domain/models/File' +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.create({ - tabularData: undefined, - type: new FileType('text/plain') -}) -const fileTabular = FileMother.createWithTabularData() +const fileNonTabular = FileMother.createNonTabular() +const fileTabular = FileMother.createTabular() +const fileRepository = {} as FileRepository describe('FileDownloadOptions', () => { + beforeEach(() => { + fileRepository.getUserPermissionsById = cy.stub().resolves( + FileUserPermissionsMother.create({ + canDownloadFile: true + }) + ) + }) + it('renders the download options header', () => { - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('heading', { name: 'Download Options' }).should('exist') }) + it('does not render the download options if the user does not have permissions', () => { + fileRepository.getUserPermissionsById = cy.stub().resolves( + FileUserPermissionsMother.create({ + canDownloadFile: false + }) + ) + + cy.customMount( + + + + ) + + cy.findByRole('heading', { name: 'Download Options' }).should('not.exist') + }) + it('renders the download options for a non-tabular file', () => { - cy.customMount() + cy.customMount( + + {' '} + + ) - cy.findByRole('button', { name: 'Plain Text' }).should('exist') + cy.findByRole('link', { name: 'Plain Text' }).should('exist') }) it('renders the download options for a tabular file', () => { - cy.customMount() - - cy.findByRole('button', { name: 'Comma Separated Values (Original File Format)' }).should( - 'exist' + cy.customMount( + + + ) + + cy.findByRole('link', { name: 'Comma Separated Values (Original File Format)' }).should('exist') }) }) 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 da32a5321..2d9cf8c17 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 @@ -23,25 +23,27 @@ describe('FileNonTabularDownloadOptions', () => { }) cy.customMount() - cy.findByRole('button', { name: 'Original File Format' }) + cy.findByRole('link', { name: 'Original File Format' }) .should('exist') .should('not.have.class', 'disabled') + .should('have.attr', 'href', fileNonTabularUnknown.downloadUrls.original) }) it('renders the download options for a non-tabular file', () => { cy.customMount() - cy.findByRole('button', { name: 'Plain Text' }) + cy.findByRole('link', { name: 'Plain Text' }) .should('exist') .should('not.have.class', 'disabled') + .should('have.attr', 'href', fileNonTabular.downloadUrls.original) }) it('does not render the download options for a tabular file', () => { - const fileTabular = FileMother.createWithTabularData() + const fileTabular = FileMother.createTabular() cy.customMount() - cy.findByRole('button', { name: 'Original File Format' }).should('not.exist') - cy.findByRole('button', { name: 'Tab-Delimited' }).should('not.exist') + cy.findByRole('link', { name: 'Original File Format' }).should('not.exist') + cy.findByRole('link', { name: 'Tab-Delimited' }).should('not.exist') }) it('renders the options as disabled when the file ingest is in progress', () => { @@ -54,7 +56,7 @@ describe('FileNonTabularDownloadOptions', () => { }) cy.customMount() - cy.findByRole('button', { name: 'Plain Text' }).should('have.class', 'disabled') + cy.findByRole('link', { name: 'Plain Text' }).should('have.class', 'disabled') }) it('renders the options as disabled when the dataset is locked from file download', () => { @@ -72,6 +74,6 @@ describe('FileNonTabularDownloadOptions', () => { ) - cy.findByRole('button', { name: 'Plain Text' }).should('have.class', 'disabled') + cy.findByRole('link', { name: 'Plain Text' }).should('have.class', 'disabled') }) }) 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 d54605ab2..8dad61fb6 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,4 +1,3 @@ -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 { FileIngestStatus, @@ -16,56 +15,60 @@ const fileNonTabular = FileMother.create({ tabularData: undefined, type: new FileType('text/plain') }) -const fileTabular = FileMother.createWithTabularData() -const fileTabularUnknown = FileMother.createWithTabularData({ +const fileTabular = FileMother.createTabular() +const fileTabularUnknown = FileMother.createTabular({ type: new FileType('text/tab-separated-values', 'Unknown') }) describe('FileTabularDownloadOptions', () => { it('renders the download options for a tabular file', () => { cy.customMount() - cy.findByRole('button', { name: 'Comma Separated Values (Original File Format)' }).should( - 'exist' - ) - cy.findByRole('button', { name: 'Tab-Delimited' }) + cy.findByRole('link', { name: 'Comma Separated Values (Original File Format)' }) + .should('exist') + .should('have.attr', 'href', fileTabular.downloadUrls.original) + cy.findByRole('link', { name: 'Tab-Delimited' }) + .should('exist') + .should('have.attr', 'href', fileTabular.downloadUrls.tabular) + .should('not.have.class', 'disabled') + cy.findByRole('link', { name: 'R Data' }) .should('exist') .should('not.have.class', 'disabled') - cy.findByRole('button', { name: 'R Data' }).should('exist').should('not.have.class', 'disabled') + .should('have.attr', 'href', fileTabular.downloadUrls.rData) }) it('renders the download options for a tabular file of unknown original type', () => { - cy.customMount() + cy.customMount() - cy.findByRole('button', { name: /(Original File Format)/ }).should('not.exist') - cy.findByRole('button', { name: 'Tab-Delimited' }) + cy.findByRole('link', { name: /(Original File Format)/ }).should('not.exist') + cy.findByRole('link', { name: 'Tab-Delimited' }) .should('exist') .should('not.have.class', 'disabled') - cy.findByRole('button', { name: 'R Data' }).should('exist').should('not.have.class', 'disabled') + cy.findByRole('link', { name: 'R Data' }).should('exist').should('not.have.class', 'disabled') }) it('does not render the download options for a non-tabular file', () => { cy.customMount() - cy.findByRole('button', { name: /(Original File Format)/ }).should('not.exist') - cy.findByRole('button', { name: 'Tab-Delimited' }).should('not.exist') - cy.findByRole('button', { name: 'R Data' }).should('not.exist') + cy.findByRole('link', { name: /(Original File Format)/ }).should('not.exist') + cy.findByRole('link', { name: 'Tab-Delimited' }).should('not.exist') + cy.findByRole('link', { name: 'R Data' }).should('not.exist') }) it('renders the options as disabled when the file ingest is in progress', () => { - const fileTabularInProgress = FileMother.createWithTabularData({ + const fileTabularInProgress = FileMother.createTabular({ ingest: { status: FileIngestStatus.IN_PROGRESS } }) cy.customMount() - cy.findByRole('button', { name: 'Comma Separated Values (Original File Format)' }) + cy.findByRole('link', { name: 'Comma Separated Values (Original File Format)' }) .should('exist') .should('have.class', 'disabled') - cy.findByRole('button', { name: 'Tab-Delimited' }) + cy.findByRole('link', { name: 'Tab-Delimited' }) .should('exist') .should('have.class', 'disabled') - cy.findByRole('button', { name: 'R Data' }).should('exist').should('have.class', 'disabled') + cy.findByRole('link', { name: 'R Data' }).should('exist').should('have.class', 'disabled') }) it('renders the options as disabled when the dataset is locked from file download', () => { @@ -83,27 +86,27 @@ describe('FileTabularDownloadOptions', () => { ) - cy.findByRole('button', { name: 'Comma Separated Values (Original File Format)' }) + cy.findByRole('link', { name: 'Comma Separated Values (Original File Format)' }) .should('exist') .should('have.class', 'disabled') - cy.findByRole('button', { name: 'Tab-Delimited' }) + cy.findByRole('link', { name: 'Tab-Delimited' }) .should('exist') .should('have.class', 'disabled') - cy.findByRole('button', { name: 'R Data' }).should('exist').should('have.class', 'disabled') + cy.findByRole('link', { name: 'R Data' }).should('exist').should('have.class', 'disabled') }) it('does not render the RData option if the file type is already R Data', () => { - const fileTabularRData = FileMother.createWithTabularData({ + const fileTabularRData = FileMother.createTabular({ type: new FileType('text/tab-separated-values', 'R Data') }) cy.customMount() - cy.findByRole('button', { name: 'R Data (Original File Format)' }) + cy.findByRole('link', { name: 'R Data (Original File Format)' }) .should('exist') .should('not.have.class', 'disabled') - cy.findByRole('button', { name: 'Tab-Delimited' }) + cy.findByRole('link', { name: 'Tab-Delimited' }) .should('exist') .should('not.have.class', 'disabled') - cy.findByRole('button', { name: 'R Data' }).should('not.exist') + cy.findByRole('link', { name: 'R Data' }).should('not.exist') }) }) 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 db176f339..e68ae02c7 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 @@ -28,7 +28,7 @@ describe('FileType', () => { }) it('renders the type correctly when is a tabular file', () => { - const file = FileMother.createWithTabularData({ + const file = FileMother.createTabular({ size: new FileSize(123.03932894722, FileSizeUnit.BYTES) }) diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index 46d3f9a3d..562eb9996 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -504,4 +504,36 @@ describe('Dataset', () => { }) }) }) + + it('downloads a file', () => { + cy.wrap( + DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) => + DatasetHelper.publish(dataset.persistentId) + ) + ) + .its('persistentId') + .then((persistentId: string) => { + cy.wait(1500) // Wait for the dataset to be published + cy.visit(`/spa/datasets?persistentId=${persistentId}`) + cy.wait(1500) // Wait for the page to load + + cy.findByText('Files').should('exist') + + cy.findByRole('button', { name: 'Access File' }).should('exist').click() + + // Workaround for issue where Cypress gets stuck on the download + cy.window() + .document() + .then(function (doc) { + doc.addEventListener('click', () => { + setTimeout(function () { + doc.location.reload() + }, 5000) + }) + cy.findByText('Plain Text').should('exist').click() + }) + + cy.findByText('1 Downloads').should('exist') + }) + }) }) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index d96da59e1..df8d92afe 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -36,36 +36,43 @@ const fileRepository = new FileJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() const dateNow = new Date() dateNow.setHours(2, 0, 0, 0) -const expectedFile = new File( - 1, - { number: 1, publishingStatus: FilePublishingStatus.DRAFT }, - 'blob', - { - restricted: false, - latestVersionRestricted: false, - canBeRequested: false, - requested: false - }, - new FileType('text/plain'), - new FileSize(25, FileSizeUnit.BYTES), - { - type: FileDateType.DEPOSITED, - date: dateNow - }, - 0, - [], - false, - { status: FileIngestStatus.NONE }, - { - algorithm: 'MD5', - value: '0187a54071542738aa47939e8218e5f2' - }, - undefined, - undefined, - undefined, - undefined, - 'This is an example file' -) +const fileData = (id: number) => { + return new File( + id, + { number: 1, publishingStatus: FilePublishingStatus.DRAFT }, + 'blob', + { + restricted: false, + latestVersionRestricted: false, + canBeRequested: false, + requested: false + }, + new FileType('text/plain'), + new FileSize(25, FileSizeUnit.BYTES), + { + type: FileDateType.DEPOSITED, + date: dateNow + }, + 0, + [], + false, + { status: FileIngestStatus.NONE }, + { + original: `/api/access/datafile/${id}?format=original`, + tabular: `/api/access/datafile/${id}`, + rData: `/api/access/datafile/${id}?format=RData` + }, + undefined, + undefined, + undefined, + undefined, + 'This is an example file', + { + algorithm: 'MD5', + value: '0187a54071542738aa47939e8218e5f2' + } + ) +} describe('File JSDataverse Repository', () => { before(() => { @@ -87,6 +94,7 @@ describe('File JSDataverse Repository', () => { .then((files) => { files.forEach((file, index) => { const expectedFileNames = ['blob', 'blob-1', 'blob-2'] + const expectedFile = fileData(file.id) expect(file.name).to.deep.equal(expectedFileNames[index]) expect(file.version).to.deep.equal(expectedFile.version) expect(file.access).to.deep.equal(expectedFile.access) @@ -100,6 +108,7 @@ describe('File JSDataverse Repository', () => { expect(file.embargo).to.deep.equal(expectedFile.embargo) expect(file.tabularData).to.deep.equal(expectedFile.tabularData) expect(file.description).to.deep.equal(expectedFile.description) + expect(file.downloadUrls).to.deep.equal(expectedFile.downloadUrls) expect(file.isDeleted).to.deep.equal(expectedFile.isDeleted) }) }) @@ -146,13 +155,13 @@ describe('File JSDataverse Repository', () => { ) ) .then((files) => { - const expectedPublishedFile = expectedFile + const expectedPublishedFile = fileData(files[0].id) expectedPublishedFile.version.publishingStatus = FilePublishingStatus.RELEASED expectedPublishedFile.date.type = FileDateType.PUBLISHED files.forEach((file) => { expect(file.version).to.deep.equal(expectedPublishedFile.version) - cy.compareDate(file.date.date, expectedFile.date.date) + cy.compareDate(file.date.date, fileData(file.id).date.date) }) }) }) @@ -182,7 +191,7 @@ describe('File JSDataverse Repository', () => { ) ) .then((files) => { - const expectedDeaccessionedFile = expectedFile + const expectedDeaccessionedFile = fileData(files[0].id) expectedDeaccessionedFile.version.publishingStatus = FilePublishingStatus.DEACCESSIONED files.forEach((file) => {