+
+
+ {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 34b7cf25f..85da7d224 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(
@@ -48,6 +51,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 4feb4044c..1c6870104 100644
--- a/tests/e2e-integration/e2e/sections/file/File.spec.tsx
+++ b/tests/e2e-integration/e2e/sections/file/File.spec.tsx
@@ -77,53 +77,50 @@ describe('File', () => {
)
})
- it('shows export metadata on the file page for admin draft, admin latest published, and guest latest published views', () => {
- cy.wrap(DatasetHelper.createWithFile(FileHelper.create())).then((draftDataset) => {
- if (!draftDataset.file) {
- throw new Error('Expected created dataset to include a file')
- }
-
- visitFileMetadataTabAndAssertExportMetadata(draftDataset.file.id, true)
- })
-
+ it('shows the file metrics download count on the file page', () => {
cy.wrap(DatasetHelper.createWithFileAndPublish(FileHelper.create()), { timeout: 6000 }).then(
- (publishedDataset) => {
- if (!publishedDataset.file) {
+ (datasetResponse) => {
+ if (!datasetResponse.file) {
throw new Error('Expected created dataset to include a file')
}
- visitFileMetadataTabAndAssertExportMetadata(publishedDataset.file.id, true)
+ cy.visit(`${FRONTEND_BASE_PATH}/files?id=${datasetResponse.file.id}`)
- TestsUtils.logout()
- visitFileMetadataTabAndAssertExportMetadata(publishedDataset.file.id, true)
+ cy.findByText('File Metrics').should('exist')
+ cy.findByTestId('file-download-count').should('contain.text', '0 Downloads')
}
)
})
- it('hides export metadata on the file page for older published versions', () => {
- cy.wrap(DatasetHelper.createWithFileAndPublish(FileHelper.create()), { timeout: 6000 })
- .then((dataset) => {
- if (!dataset.file) {
+ 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')
}
- return cy.wrap(
- FileHelper.addLabel(dataset.file.id, []).then(async () => {
- await DatasetHelper.publish(dataset.persistentId)
- return dataset.file?.id
- })
- )
- })
- .then((fileId) => {
- if (!fileId) {
- throw new Error('Expected created dataset to include a file')
- }
+ const fileId = datasetResponse.file.id
- visitFileMetadataTabAndAssertExportMetadata(fileId, false, '1.0')
+ cy.visit(`${FRONTEND_BASE_PATH}/files?id=${fileId}`)
+ cy.findByTestId('file-download-count').should('contain.text', '0 Downloads')
- TestsUtils.logout()
- visitFileMetadataTabAndAssertExportMetadata(fileId, false, '1.0')
- })
+ 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', () => {
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())