+
+
+ {t('metrics.title')}{' '}
+
+
+
+
+
+
+ {t('metrics.downloads.count.default', {
+ count: downloadCount,
+ formattedCount: formatNumber(downloadCount)
+ })}{' '}
+
+
+
+
+ )
+}
diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx
index 1f9cf81bd..d73aecbb0 100644
--- a/tests/component/sections/file/File.spec.tsx
+++ b/tests/component/sections/file/File.spec.tsx
@@ -10,12 +10,15 @@ import { DataverseInfoMockRepository } from '@/stories/shared-mock-repositories/
import { ContactMockRepository } from '@/stories/shared-mock-repositories/contact/ContactMockRepository'
import { DatasetVersionMother } from '@tests/component/dataset/domain/models/DatasetMother'
import { WithRepositories } from '@tests/component/WithRepositories'
+import { FileMetadataMother } from '@tests/component/files/domain/models/FileMetadataMother'
const fileRepository: FileRepository = {} as FileRepository
describe('File', () => {
- it('renders the File page title and details', () => {
- const testFile = FileMother.createRealistic()
+ it('renders the File page title, details and metrics', () => {
+ const testFile = FileMother.createRealistic({
+ metadata: FileMetadataMother.createDefault({ downloadCount: 8 })
+ })
fileRepository.getById = cy.stub().resolves(testFile)
cy.customMount(
@@ -47,6 +50,8 @@ describe('File', () => {
cy.findByRole('tab', { name: 'Versions' }).should('exist')
cy.findByRole('button', { name: 'File Metadata' }).should('exist')
cy.findByRole('group', { name: 'File Action Buttons' }).should('exist')
+ cy.findByText('File Metrics').should('exist')
+ cy.findByTestId('file-download-count').should('contain.text', '8 Downloads')
})
it('renders skeleton while loading', () => {
diff --git a/tests/e2e-integration/e2e/sections/file/File.spec.tsx b/tests/e2e-integration/e2e/sections/file/File.spec.tsx
index 1c965c7a4..03f21382e 100644
--- a/tests/e2e-integration/e2e/sections/file/File.spec.tsx
+++ b/tests/e2e-integration/e2e/sections/file/File.spec.tsx
@@ -60,6 +60,52 @@ describe('File', () => {
)
})
+ it('shows the file metrics download count on the file page', () => {
+ cy.wrap(DatasetHelper.createWithFileAndPublish(FileHelper.create()), { timeout: 6000 }).then(
+ (datasetResponse) => {
+ if (!datasetResponse.file) {
+ throw new Error('Expected created dataset to include a file')
+ }
+
+ cy.visit(`${FRONTEND_BASE_PATH}/files?id=${datasetResponse.file.id}`)
+
+ cy.findByText('File Metrics').should('exist')
+ cy.findByTestId('file-download-count').should('contain.text', '0 Downloads')
+ }
+ )
+ })
+
+ it('updates the file metrics download count after downloading the file', () => {
+ cy.wrap(DatasetHelper.createWithFileAndPublish(FileHelper.create()), { timeout: 6000 }).then(
+ (datasetResponse) => {
+ if (!datasetResponse.file) {
+ throw new Error('Expected created dataset to include a file')
+ }
+
+ const fileId = datasetResponse.file.id
+
+ cy.visit(`${FRONTEND_BASE_PATH}/files?id=${fileId}`)
+ cy.findByTestId('file-download-count').should('contain.text', '0 Downloads')
+
+ cy.window().then((window) => {
+ cy.stub(window.HTMLAnchorElement.prototype, 'click').as('anchorClick')
+ })
+
+ cy.findByRole('button', { name: 'Access File' }).as('accessButton')
+ cy.get('@accessButton').should('be.visible')
+ cy.wait(500)
+ cy.get('@accessButton').click()
+ cy.findByTestId('download-original-file').should('exist').click({ force: true })
+
+ cy.get('@anchorClick').should('have.been.calledOnce')
+ cy.findByText('Your download has started.').should('exist')
+
+ cy.visit(`${FRONTEND_BASE_PATH}/files?id=${fileId}`)
+ cy.findByTestId('file-download-count').should('contain.text', '1 Download')
+ }
+ )
+ })
+
it('loads version summaries when clicking on the version tab', () => {
cy.wrap(
DatasetHelper.createWithFileAndPublish(FileHelper.create()).then(
diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts
index bf0f418a7..6936cb362 100644
--- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts
+++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts
@@ -932,6 +932,7 @@ describe('File JSDataverse Repository', () => {
})
})
})
+
describe('edit file metadata', () => {
it('edits file metadata', async () => {
const datasetResponse = await DatasetHelper.createWithFile(FileHelper.create())