Skip to content

Commit

Permalink
fix: add dateTime attribute, and apply dateHelper to some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengShi-1 committed Nov 8, 2024
1 parent 21e7f0a commit 1946b1c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +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'

export function FileDate({ date }: { date: FileDateModel }) {
const { t } = useTranslation('files')

return (
<div>
<span>
{t(`table.date.${date.type}`)} <time>{DateHelper.toDisplayFormat(date.date)}</time>
{t(`table.date.${date.type}`)}{' '}
<time dateTime={DateHelper.toDisplayFormat(date.date)}>
{DateHelper.toDisplayFormat(date.date)}
</time>
</span>
</div>
)
Expand Down
8 changes: 7 additions & 1 deletion src/sections/file/file-embargo/FileEmbargoDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ export function FileEmbargoDate({
<div>
<span>
{t(embargoTypeOfDate(embargo.isActive, datasetPublishingStatus))}{' '}
<time data-testid="embargo-date">
<time
dateTime={
format === 'YYYY-MM-DD'
? DateHelper.toISO8601Format(embargo.dateAvailable)
: DateHelper.toDisplayFormat(embargo.dateAvailable)
}
data-testid="embargo-date">
{format === 'YYYY-MM-DD'
? DateHelper.toISO8601Format(embargo.dateAvailable)
: DateHelper.toDisplayFormat(embargo.dateAvailable)}
Expand Down
22 changes: 14 additions & 8 deletions src/sections/file/file-metadata/FileMetadata.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,6 +24,7 @@ export function FileMetadata({
datasetPublishingStatus
}: FileMetadataProps) {
const { t } = useTranslation('file')

return (
<Accordion defaultActiveKey="0">
<Accordion.Item eventKey="0">
Expand Down Expand Up @@ -98,7 +99,9 @@ export function FileMetadata({
<strong>{t('metadata.fields.depositDate')}</strong>
</Col>
<Col>
<time>{DateHelper.toISO8601Format(metadata.depositDate)}</time>
<time dateTime={DateHelper.toISO8601Format(metadata.depositDate)}>
{DateHelper.toISO8601Format(metadata.depositDate)}
</time>
</Col>
</Row>
{metadata.publicationDate && (
Expand All @@ -107,7 +110,9 @@ export function FileMetadata({
<strong>{t('metadata.fields.metadataReleaseDate')}</strong>
</Col>
<Col>
<time>{DateHelper.toISO8601Format(metadata.publicationDate)}</time>
<time dateTime={DateHelper.toISO8601Format(metadata.publicationDate)}>
{DateHelper.toISO8601Format(metadata.publicationDate)}
</time>
</Col>
</Row>
)}
Expand All @@ -124,10 +129,11 @@ export function FileMetadata({
format="YYYY-MM-DD"
/>
) : (
<time>
{metadata.publicationDate &&
DateHelper.toISO8601Format(metadata.publicationDate)}
</time>
metadata.publicationDate && (
<time dateTime={DateHelper.toISO8601Format(metadata.publicationDate)}>
{DateHelper.toISO8601Format(metadata.publicationDate)}
</time>
)
)}
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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', () => {
const embargoDate = new Date('2123-09-18')
const embargo = FileEmbargoMother.create({ dateAvailable: embargoDate })
const status = DatasetPublishingStatus.RELEASED
cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
const dateString = embargoDate.toISOString().split('T')[0]
const dateString = DateHelper.toISO8601Format(embargoDate)
cy.findByText(`Embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
})
Expand All @@ -19,7 +20,7 @@ describe('FileEmbargoDate', () => {
const status = DatasetPublishingStatus.RELEASED

cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
const dateString = embargoDate.toISOString().split('T')[0]
const dateString = DateHelper.toISO8601Format(embargoDate)

cy.findByText(`Was embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
Expand All @@ -31,7 +32,7 @@ describe('FileEmbargoDate', () => {
const status = DatasetPublishingStatus.DRAFT

cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
const dateString = embargoDate.toISOString().split('T')[0]
const dateString = DateHelper.toISO8601Format(embargoDate)

cy.findByText(`Draft: will be embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
Expand All @@ -55,7 +56,7 @@ describe('FileEmbargoDate', () => {
cy.customMount(
<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} format="YYYY-MM-DD" />
)
const dateString = embargoDate.toISOString().split('T')[0]
const dateString = DateHelper.toISO8601Format(embargoDate)
cy.findByText(`Embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
})
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FileHelper } from '../../../shared/files/FileHelper'
import moment from 'moment-timezone'
import { CollectionHelper } from '../../../shared/collection/CollectionHelper'
import { FILES_TAB_INFINITE_SCROLL_ENABLED } from '../../../../../src/sections/dataset/config'
import { DateHelper } from '../../../../../src/shared/helpers/DateHelper'

type Dataset = {
datasetVersion: { metadataBlocks: { citation: { fields: { value: string }[] } } }
Expand Down Expand Up @@ -478,8 +479,8 @@ describe('Dataset', () => {
})

it('loads the embargoed files', () => {
const utcDate = moment.utc().startOf('day').add(100, 'years')
const expectedDate = utcDate.toISOString().split('T')[0]
const utcDate = moment.utc().startOf('day').add(100, 'years').toDate()
const expectedDate = DateHelper.toDisplayFormat(utcDate)

cy.wrap(
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
Expand Down

0 comments on commit 1946b1c

Please sign in to comment.