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 b160cfe86..299887b4f 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,15 +1,17 @@ -import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/FileMetadata' import { useTranslation } from 'react-i18next' +import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/FileMetadata' import { DateHelper } from '../../../../../../../shared/helpers/DateHelper' -// TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time - export function FileDate({ date }: { date: FileDateModel }) { const { t } = useTranslation('files') + return (
- {t(`table.date.${date.type}`)} {DateHelper.toDisplayFormat(date.date)} + {t(`table.date.${date.type}`)}{' '} +
) diff --git a/src/sections/file/file-embargo/FileEmbargoDate.tsx b/src/sections/file/file-embargo/FileEmbargoDate.tsx index 6a238851c..f8817a128 100644 --- a/src/sections/file/file-embargo/FileEmbargoDate.tsx +++ b/src/sections/file/file-embargo/FileEmbargoDate.tsx @@ -12,7 +12,7 @@ interface FileEmbargoDateProps { export function FileEmbargoDate({ embargo, datasetPublishingStatus, - format = 'short' + format = 'YYYY-MM-DD' }: FileEmbargoDateProps) { const { t } = useTranslation('files') @@ -20,15 +20,17 @@ export function FileEmbargoDate({ return <> } - // TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time - return (
{t(embargoTypeOfDate(embargo.isActive, datasetPublishingStatus))}{' '} - {format === 'YYYY-MM-DD' - ? DateHelper.toDisplayFormatYYYYMMDD(embargo.dateAvailable) - : DateHelper.toDisplayFormat(embargo.dateAvailable)} +
) diff --git a/src/sections/file/file-metadata/FileMetadata.tsx b/src/sections/file/file-metadata/FileMetadata.tsx index 88f079926..ab49dbe8a 100644 --- a/src/sections/file/file-metadata/FileMetadata.tsx +++ b/src/sections/file/file-metadata/FileMetadata.tsx @@ -1,14 +1,14 @@ +import { Trans, useTranslation } from 'react-i18next' import { Accordion, Col, Row } from '@iqss/dataverse-design-system' import { FilePreview } from '../file-preview/FilePreview' import { FileLabels } from '../file-labels/FileLabels' -import styles from './FileMetadata.module.scss' import { DateHelper } from '../../../shared/helpers/DateHelper' import { FileEmbargoDate } from '../file-embargo/FileEmbargoDate' import { BASE_URL } from '../../../config' -import { Trans, useTranslation } from 'react-i18next' import { FileMetadata as FileMetadataModel } from '../../../files/domain/models/FileMetadata' import { FilePermissions } from '../../../files/domain/models/FilePermissions' import { DatasetPublishingStatus } from '../../../dataset/domain/models/Dataset' +import styles from './FileMetadata.module.scss' interface FileMetadataProps { name: string @@ -24,6 +24,7 @@ export function FileMetadata({ datasetPublishingStatus }: FileMetadataProps) { const { t } = useTranslation('file') + return ( @@ -97,16 +98,22 @@ export function FileMetadata({ {t('metadata.fields.depositDate')} - {/* TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time */} - {DateHelper.toDisplayFormatYYYYMMDD(metadata.depositDate)} + + + {metadata.publicationDate && ( {t('metadata.fields.metadataReleaseDate')} - {/* TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time */} - {DateHelper.toDisplayFormatYYYYMMDD(metadata.publicationDate)} + + + )} {(metadata.publicationDate || metadata.embargo) && ( @@ -114,7 +121,6 @@ export function FileMetadata({ {t('metadata.fields.publicationDate')} - {/* TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time */} {metadata.embargo ? ( ) : ( - DateHelper.toDisplayFormatYYYYMMDD(metadata.publicationDate) + metadata.publicationDate && ( + + ) )} 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 74b20f937..8bc1a95c8 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 @@ -8,6 +8,7 @@ describe('FileDate', () => { const date = { type: FileDateType.PUBLISHED, date: fileDate } cy.customMount() const dateString = DateHelper.toDisplayFormat(fileDate) - cy.findByText(`Published ` + dateString).should('exist') + cy.findByText(`Published`).should('exist') + cy.get('time').should('have.text', dateString) }) }) diff --git a/tests/component/sections/file/file-embargo/FileEmbargoDate.spec.tsx b/tests/component/sections/file/file-embargo/FileEmbargoDate.spec.tsx index 9809c32d9..d093fbe20 100644 --- a/tests/component/sections/file/file-embargo/FileEmbargoDate.spec.tsx +++ b/tests/component/sections/file/file-embargo/FileEmbargoDate.spec.tsx @@ -1,6 +1,7 @@ import { FileEmbargoDate } from '../../../../../src/sections/file/file-embargo/FileEmbargoDate' import { DatasetPublishingStatus } from '../../../../../src/dataset/domain/models/Dataset' import { FileEmbargoMother } from '../../../files/domain/models/FileMetadataMother' +import { DateHelper } from '../../../../../src/shared/helpers/DateHelper' describe('FileEmbargoDate', () => { it('renders the embargo date when embargo exists', () => { @@ -8,15 +9,9 @@ describe('FileEmbargoDate', () => { const embargo = FileEmbargoMother.create({ dateAvailable: embargoDate }) const status = DatasetPublishingStatus.RELEASED cy.customMount() - const dateString = embargoDate.toLocaleDateString( - Intl.DateTimeFormat().resolvedOptions().locale, - { - year: 'numeric', - month: 'short', - day: 'numeric' - } - ) - cy.findByText(`Embargoed until ` + dateString).should('exist') + const dateString = DateHelper.toISO8601Format(embargoDate) + cy.findByText(`Embargoed until`).should('exist') + cy.get('time').should('have.text', dateString) }) it('renders the until embargo date when embargo is not active and the file is not released', () => { @@ -25,15 +20,10 @@ describe('FileEmbargoDate', () => { const status = DatasetPublishingStatus.RELEASED cy.customMount() - const dateString = embargoDate.toLocaleDateString( - Intl.DateTimeFormat().resolvedOptions().locale, - { - year: 'numeric', - month: 'short', - day: 'numeric' - } - ) - cy.findByText(`Was embargoed until ` + dateString).should('exist') + const dateString = DateHelper.toISO8601Format(embargoDate) + + cy.findByText(`Was embargoed until`).should('exist') + cy.get('time').should('have.text', dateString) }) it('renders the draft until embargo date when embargo is active and the file is not released', () => { @@ -42,15 +32,10 @@ describe('FileEmbargoDate', () => { const status = DatasetPublishingStatus.DRAFT cy.customMount() - const dateString = embargoDate.toLocaleDateString( - Intl.DateTimeFormat().resolvedOptions().locale, - { - year: 'numeric', - month: 'short', - day: 'numeric' - } - ) - cy.findByText(`Draft: will be embargoed until ` + dateString).should('exist') + const dateString = DateHelper.toISO8601Format(embargoDate) + + cy.findByText(`Draft: will be embargoed until`).should('exist') + cy.get('time').should('have.text', dateString) }) it('renders an empty fragment when embargo is undefined', () => { @@ -58,7 +43,6 @@ describe('FileEmbargoDate', () => { const status = DatasetPublishingStatus.RELEASED cy.customMount() - cy.findByText(/Draft: will be embargoed until/).should('not.exist') cy.findByText(/Embargoed until/).should('not.exist') cy.findByText(/Was embargoed until/).should('not.exist') @@ -68,17 +52,12 @@ describe('FileEmbargoDate', () => { const embargoDate = new Date('2123-09-18') const embargo = FileEmbargoMother.create({ dateAvailable: embargoDate }) const status = DatasetPublishingStatus.RELEASED + cy.customMount( ) - const dateString = embargoDate.toLocaleDateString( - Intl.DateTimeFormat().resolvedOptions().locale, - { - year: 'numeric', - month: '2-digit', - day: '2-digit' - } - ) - cy.findByText(`Embargoed until ` + dateString).should('exist') + const dateString = DateHelper.toISO8601Format(embargoDate) + cy.findByText(`Embargoed until`).should('exist') + cy.get('time').should('have.text', dateString) }) }) diff --git a/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx b/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx index 7e2e09a1e..23b4dbe9a 100644 --- a/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx +++ b/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx @@ -214,9 +214,8 @@ describe('FileMetadata', () => { datasetPublishingStatus={file.datasetVersion.publishingStatus} /> ) - cy.findByText('Deposit Date').should('exist') - cy.findByText(DateHelper.toDisplayFormatYYYYMMDD(file.metadata.depositDate)).should('exist') + cy.get('time').contains(DateHelper.toISO8601Format(file.metadata.depositDate)).should('exist') }) it('renders the file Metadata Release Date', () => { @@ -231,9 +230,11 @@ describe('FileMetadata', () => { ) cy.findByText('Metadata Release Date').should('exist') - cy.findAllByText( - DateHelper.toDisplayFormatYYYYMMDD(metadataWithPublicationDate.publicationDate) - ).should('exist') + if (metadataWithPublicationDate.publicationDate) { + cy.findAllByText( + DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate) + ).should('exist') + } }) it('does not render the file Metadata Release Date if the publication date does not exist', () => { @@ -262,9 +263,11 @@ describe('FileMetadata', () => { ) cy.findByText('Publication Date').should('exist') - cy.findAllByText( - DateHelper.toDisplayFormatYYYYMMDD(metadataWithPublicationDate.publicationDate) - ).should('exist') + if (metadataWithPublicationDate.publicationDate) { + cy.findAllByText( + DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate) + ).should('exist') + } }) it('renders the file Publication Date with embargo', () => { @@ -280,11 +283,11 @@ describe('FileMetadata', () => { ) cy.findByText('Publication Date').should('exist') - cy.findByText( - `Embargoed until ${DateHelper.toDisplayFormatYYYYMMDD( - metadataWithPublicationDateEmbargoed.embargo?.dateAvailable - )}` - ).should('exist') + if (metadataWithPublicationDateEmbargoed.publicationDate) { + cy.findAllByText( + DateHelper.toISO8601Format(metadataWithPublicationDateEmbargoed.publicationDate) + ).should('exist') + } }) it('does not render the file Publication Date if the publication date and embargo do not exist', () => { diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index d78bcae85..dba8ef5d7 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -478,57 +478,39 @@ describe('Dataset', () => { }) it('loads the embargoed files', () => { - cy.window().then((win) => { - // Get the browser's locale from the window object - const browserLocale = win.navigator.language - - // Create a moment object in UTC and set the time to 12 AM (midnight) - const utcDate = moment.utc().startOf('day') - - // Add 100 years to the UTC date - utcDate.add(100, 'years') - const dateString = utcDate.format('YYYY-MM-DD') - - // Use the browser's locale to format the date using Intl.DateTimeFormat - const options: Intl.DateTimeFormatOptions = { - year: 'numeric', - month: 'short', - day: 'numeric' - } - const expectedDate = new Intl.DateTimeFormat(browserLocale, options).format( - utcDate.toDate() - ) + const utcDate = moment.utc().startOf('day').add(100, 'years') + const expectedDate = utcDate.toISOString().split('T')[0] - cy.wrap( - DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) => - DatasetHelper.embargoFiles( - dataset.persistentId, - [dataset.files ? dataset.files[0].id : 0], - dateString - ) + cy.wrap( + DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) => + DatasetHelper.embargoFiles( + dataset.persistentId, + [dataset.files ? dataset.files[0].id : 0], + expectedDate ) ) - .its('persistentId') - .then((persistentId: string) => { - cy.wait(1500) // Wait for the files to be embargoed + ) + .its('persistentId') + .then((persistentId: string) => { + cy.wait(1500) // Wait for the files to be embargoed - cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`) + cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`) - cy.wait(1500) // Wait for the files to be loaded + cy.wait(1500) // Wait for the files to be loaded - cy.findByText('Files').should('exist') + cy.findByText('Files').should('exist') - cy.findByText(/Deposited/).should('exist') - cy.findByText(`Draft: will be embargoed until ${expectedDate}`).should('exist') + cy.findByText(/Deposited/).should('exist') + cy.findByText(`Draft: will be embargoed until`).should('exist') + cy.findByTestId('embargo-date').should('have.text', expectedDate) - cy.get('#edit-files-menu').should('exist') + cy.get('#edit-files-menu').should('exist') - cy.findByRole('button', { name: 'Access File' }).as('accessButton') - cy.get('@accessButton').should('exist') - cy.get('@accessButton').click() - cy.findByText('Embargoed').should('exist') - }) - }) + cy.findByRole('button', { name: 'Access File' }).as('accessButton') + cy.get('@accessButton').should('exist') + cy.get('@accessButton').click() + cy.findByText('Embargoed').should('exist') + }) }) it('applies filters to the Files Table in the correct order', () => {