Skip to content

Commit 1d5f233

Browse files
committed
Merge branch 'develop' into feature/492-publish-dataset-with-compare-versions
2 parents d91fd51 + 88d218a commit 1d5f233

File tree

7 files changed

+90
-111
lines changed

7 files changed

+90
-111
lines changed

src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/FileMetadata'
21
import { useTranslation } from 'react-i18next'
2+
import { FileDate as FileDateModel } from '../../../../../../../files/domain/models/FileMetadata'
33
import { DateHelper } from '../../../../../../../shared/helpers/DateHelper'
44

5-
// TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
6-
75
export function FileDate({ date }: { date: FileDateModel }) {
86
const { t } = useTranslation('files')
7+
98
return (
109
<div>
1110
<span>
12-
{t(`table.date.${date.type}`)} {DateHelper.toDisplayFormat(date.date)}
11+
{t(`table.date.${date.type}`)}{' '}
12+
<time dateTime={DateHelper.toISO8601Format(date.date)}>
13+
{DateHelper.toDisplayFormat(date.date)}
14+
</time>
1315
</span>
1416
</div>
1517
)

src/sections/file/file-embargo/FileEmbargoDate.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ interface FileEmbargoDateProps {
1212
export function FileEmbargoDate({
1313
embargo,
1414
datasetPublishingStatus,
15-
format = 'short'
15+
format = 'YYYY-MM-DD'
1616
}: FileEmbargoDateProps) {
1717
const { t } = useTranslation('files')
1818

1919
if (!embargo) {
2020
return <></>
2121
}
2222

23-
// TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
24-
2523
return (
2624
<div>
2725
<span>
2826
{t(embargoTypeOfDate(embargo.isActive, datasetPublishingStatus))}{' '}
29-
{format === 'YYYY-MM-DD'
30-
? DateHelper.toDisplayFormatYYYYMMDD(embargo.dateAvailable)
31-
: DateHelper.toDisplayFormat(embargo.dateAvailable)}
27+
<time
28+
dateTime={DateHelper.toISO8601Format(embargo.dateAvailable)}
29+
data-testid="embargo-date">
30+
{format === 'YYYY-MM-DD'
31+
? DateHelper.toISO8601Format(embargo.dateAvailable)
32+
: DateHelper.toDisplayFormat(embargo.dateAvailable)}
33+
</time>
3234
</span>
3335
</div>
3436
)

src/sections/file/file-metadata/FileMetadata.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { Trans, useTranslation } from 'react-i18next'
12
import { Accordion, Col, Row } from '@iqss/dataverse-design-system'
23
import { FilePreview } from '../file-preview/FilePreview'
34
import { FileLabels } from '../file-labels/FileLabels'
4-
import styles from './FileMetadata.module.scss'
55
import { DateHelper } from '../../../shared/helpers/DateHelper'
66
import { FileEmbargoDate } from '../file-embargo/FileEmbargoDate'
77
import { BASE_URL } from '../../../config'
8-
import { Trans, useTranslation } from 'react-i18next'
98
import { FileMetadata as FileMetadataModel } from '../../../files/domain/models/FileMetadata'
109
import { FilePermissions } from '../../../files/domain/models/FilePermissions'
1110
import { DatasetPublishingStatus } from '../../../dataset/domain/models/Dataset'
11+
import styles from './FileMetadata.module.scss'
1212

1313
interface FileMetadataProps {
1414
name: string
@@ -24,6 +24,7 @@ export function FileMetadata({
2424
datasetPublishingStatus
2525
}: FileMetadataProps) {
2626
const { t } = useTranslation('file')
27+
2728
return (
2829
<Accordion defaultActiveKey="0">
2930
<Accordion.Item eventKey="0">
@@ -97,24 +98,29 @@ export function FileMetadata({
9798
<Col sm={3}>
9899
<strong>{t('metadata.fields.depositDate')}</strong>
99100
</Col>
100-
{/* TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time */}
101-
<Col>{DateHelper.toDisplayFormatYYYYMMDD(metadata.depositDate)}</Col>
101+
<Col>
102+
<time dateTime={DateHelper.toISO8601Format(metadata.depositDate)}>
103+
{DateHelper.toISO8601Format(metadata.depositDate)}
104+
</time>
105+
</Col>
102106
</Row>
103107
{metadata.publicationDate && (
104108
<Row className={styles.row}>
105109
<Col sm={3}>
106110
<strong>{t('metadata.fields.metadataReleaseDate')}</strong>
107111
</Col>
108-
{/* TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time */}
109-
<Col>{DateHelper.toDisplayFormatYYYYMMDD(metadata.publicationDate)}</Col>
112+
<Col>
113+
<time dateTime={DateHelper.toISO8601Format(metadata.publicationDate)}>
114+
{DateHelper.toISO8601Format(metadata.publicationDate)}
115+
</time>
116+
</Col>
110117
</Row>
111118
)}
112119
{(metadata.publicationDate || metadata.embargo) && (
113120
<Row className={styles.row}>
114121
<Col sm={3}>
115122
<strong>{t('metadata.fields.publicationDate')}</strong>
116123
</Col>
117-
{/* TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time */}
118124
<Col>
119125
{metadata.embargo ? (
120126
<FileEmbargoDate
@@ -123,7 +129,11 @@ export function FileMetadata({
123129
format="YYYY-MM-DD"
124130
/>
125131
) : (
126-
DateHelper.toDisplayFormatYYYYMMDD(metadata.publicationDate)
132+
metadata.publicationDate && (
133+
<time dateTime={DateHelper.toISO8601Format(metadata.publicationDate)}>
134+
{DateHelper.toISO8601Format(metadata.publicationDate)}
135+
</time>
136+
)
127137
)}
128138
</Col>
129139
</Row>

tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileDate.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('FileDate', () => {
88
const date = { type: FileDateType.PUBLISHED, date: fileDate }
99
cy.customMount(<FileDate date={date} />)
1010
const dateString = DateHelper.toDisplayFormat(fileDate)
11-
cy.findByText(`Published ` + dateString).should('exist')
11+
cy.findByText(`Published`).should('exist')
12+
cy.get('time').should('have.text', dateString)
1213
})
1314
})
Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import { FileEmbargoDate } from '../../../../../src/sections/file/file-embargo/FileEmbargoDate'
22
import { DatasetPublishingStatus } from '../../../../../src/dataset/domain/models/Dataset'
33
import { FileEmbargoMother } from '../../../files/domain/models/FileMetadataMother'
4+
import { DateHelper } from '../../../../../src/shared/helpers/DateHelper'
45

56
describe('FileEmbargoDate', () => {
67
it('renders the embargo date when embargo exists', () => {
78
const embargoDate = new Date('2123-09-18')
89
const embargo = FileEmbargoMother.create({ dateAvailable: embargoDate })
910
const status = DatasetPublishingStatus.RELEASED
1011
cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
11-
const dateString = embargoDate.toLocaleDateString(
12-
Intl.DateTimeFormat().resolvedOptions().locale,
13-
{
14-
year: 'numeric',
15-
month: 'short',
16-
day: 'numeric'
17-
}
18-
)
19-
cy.findByText(`Embargoed until ` + dateString).should('exist')
12+
const dateString = DateHelper.toISO8601Format(embargoDate)
13+
cy.findByText(`Embargoed until`).should('exist')
14+
cy.get('time').should('have.text', dateString)
2015
})
2116

2217
it('renders the until embargo date when embargo is not active and the file is not released', () => {
@@ -25,15 +20,10 @@ describe('FileEmbargoDate', () => {
2520
const status = DatasetPublishingStatus.RELEASED
2621

2722
cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
28-
const dateString = embargoDate.toLocaleDateString(
29-
Intl.DateTimeFormat().resolvedOptions().locale,
30-
{
31-
year: 'numeric',
32-
month: 'short',
33-
day: 'numeric'
34-
}
35-
)
36-
cy.findByText(`Was embargoed until ` + dateString).should('exist')
23+
const dateString = DateHelper.toISO8601Format(embargoDate)
24+
25+
cy.findByText(`Was embargoed until`).should('exist')
26+
cy.get('time').should('have.text', dateString)
3727
})
3828

3929
it('renders the draft until embargo date when embargo is active and the file is not released', () => {
@@ -42,23 +32,17 @@ describe('FileEmbargoDate', () => {
4232
const status = DatasetPublishingStatus.DRAFT
4333

4434
cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
45-
const dateString = embargoDate.toLocaleDateString(
46-
Intl.DateTimeFormat().resolvedOptions().locale,
47-
{
48-
year: 'numeric',
49-
month: 'short',
50-
day: 'numeric'
51-
}
52-
)
53-
cy.findByText(`Draft: will be embargoed until ` + dateString).should('exist')
35+
const dateString = DateHelper.toISO8601Format(embargoDate)
36+
37+
cy.findByText(`Draft: will be embargoed until`).should('exist')
38+
cy.get('time').should('have.text', dateString)
5439
})
5540

5641
it('renders an empty fragment when embargo is undefined', () => {
5742
const embargo = undefined
5843
const status = DatasetPublishingStatus.RELEASED
5944

6045
cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)
61-
6246
cy.findByText(/Draft: will be embargoed until/).should('not.exist')
6347
cy.findByText(/Embargoed until/).should('not.exist')
6448
cy.findByText(/Was embargoed until/).should('not.exist')
@@ -68,17 +52,12 @@ describe('FileEmbargoDate', () => {
6852
const embargoDate = new Date('2123-09-18')
6953
const embargo = FileEmbargoMother.create({ dateAvailable: embargoDate })
7054
const status = DatasetPublishingStatus.RELEASED
55+
7156
cy.customMount(
7257
<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} format="YYYY-MM-DD" />
7358
)
74-
const dateString = embargoDate.toLocaleDateString(
75-
Intl.DateTimeFormat().resolvedOptions().locale,
76-
{
77-
year: 'numeric',
78-
month: '2-digit',
79-
day: '2-digit'
80-
}
81-
)
82-
cy.findByText(`Embargoed until ` + dateString).should('exist')
59+
const dateString = DateHelper.toISO8601Format(embargoDate)
60+
cy.findByText(`Embargoed until`).should('exist')
61+
cy.get('time').should('have.text', dateString)
8362
})
8463
})

tests/component/sections/file/file-metadata/FileMetadata.spec.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,8 @@ describe('FileMetadata', () => {
214214
datasetPublishingStatus={file.datasetVersion.publishingStatus}
215215
/>
216216
)
217-
218217
cy.findByText('Deposit Date').should('exist')
219-
cy.findByText(DateHelper.toDisplayFormatYYYYMMDD(file.metadata.depositDate)).should('exist')
218+
cy.get('time').contains(DateHelper.toISO8601Format(file.metadata.depositDate)).should('exist')
220219
})
221220

222221
it('renders the file Metadata Release Date', () => {
@@ -231,9 +230,11 @@ describe('FileMetadata', () => {
231230
)
232231

233232
cy.findByText('Metadata Release Date').should('exist')
234-
cy.findAllByText(
235-
DateHelper.toDisplayFormatYYYYMMDD(metadataWithPublicationDate.publicationDate)
236-
).should('exist')
233+
if (metadataWithPublicationDate.publicationDate) {
234+
cy.findAllByText(
235+
DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate)
236+
).should('exist')
237+
}
237238
})
238239

239240
it('does not render the file Metadata Release Date if the publication date does not exist', () => {
@@ -262,9 +263,11 @@ describe('FileMetadata', () => {
262263
)
263264

264265
cy.findByText('Publication Date').should('exist')
265-
cy.findAllByText(
266-
DateHelper.toDisplayFormatYYYYMMDD(metadataWithPublicationDate.publicationDate)
267-
).should('exist')
266+
if (metadataWithPublicationDate.publicationDate) {
267+
cy.findAllByText(
268+
DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate)
269+
).should('exist')
270+
}
268271
})
269272

270273
it('renders the file Publication Date with embargo', () => {
@@ -280,11 +283,11 @@ describe('FileMetadata', () => {
280283
)
281284

282285
cy.findByText('Publication Date').should('exist')
283-
cy.findByText(
284-
`Embargoed until ${DateHelper.toDisplayFormatYYYYMMDD(
285-
metadataWithPublicationDateEmbargoed.embargo?.dateAvailable
286-
)}`
287-
).should('exist')
286+
if (metadataWithPublicationDateEmbargoed.publicationDate) {
287+
cy.findAllByText(
288+
DateHelper.toISO8601Format(metadataWithPublicationDateEmbargoed.publicationDate)
289+
).should('exist')
290+
}
288291
})
289292

290293
it('does not render the file Publication Date if the publication date and embargo do not exist', () => {

tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -478,57 +478,39 @@ describe('Dataset', () => {
478478
})
479479

480480
it('loads the embargoed files', () => {
481-
cy.window().then((win) => {
482-
// Get the browser's locale from the window object
483-
const browserLocale = win.navigator.language
484-
485-
// Create a moment object in UTC and set the time to 12 AM (midnight)
486-
const utcDate = moment.utc().startOf('day')
487-
488-
// Add 100 years to the UTC date
489-
utcDate.add(100, 'years')
490-
const dateString = utcDate.format('YYYY-MM-DD')
491-
492-
// Use the browser's locale to format the date using Intl.DateTimeFormat
493-
const options: Intl.DateTimeFormatOptions = {
494-
year: 'numeric',
495-
month: 'short',
496-
day: 'numeric'
497-
}
498-
const expectedDate = new Intl.DateTimeFormat(browserLocale, options).format(
499-
utcDate.toDate()
500-
)
481+
const utcDate = moment.utc().startOf('day').add(100, 'years')
482+
const expectedDate = utcDate.toISOString().split('T')[0]
501483

502-
cy.wrap(
503-
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
504-
DatasetHelper.embargoFiles(
505-
dataset.persistentId,
506-
[dataset.files ? dataset.files[0].id : 0],
507-
dateString
508-
)
484+
cy.wrap(
485+
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
486+
DatasetHelper.embargoFiles(
487+
dataset.persistentId,
488+
[dataset.files ? dataset.files[0].id : 0],
489+
expectedDate
509490
)
510491
)
511-
.its('persistentId')
512-
.then((persistentId: string) => {
513-
cy.wait(1500) // Wait for the files to be embargoed
492+
)
493+
.its('persistentId')
494+
.then((persistentId: string) => {
495+
cy.wait(1500) // Wait for the files to be embargoed
514496

515-
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)
497+
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)
516498

517-
cy.wait(1500) // Wait for the files to be loaded
499+
cy.wait(1500) // Wait for the files to be loaded
518500

519-
cy.findByText('Files').should('exist')
501+
cy.findByText('Files').should('exist')
520502

521-
cy.findByText(/Deposited/).should('exist')
522-
cy.findByText(`Draft: will be embargoed until ${expectedDate}`).should('exist')
503+
cy.findByText(/Deposited/).should('exist')
504+
cy.findByText(`Draft: will be embargoed until`).should('exist')
505+
cy.findByTestId('embargo-date').should('have.text', expectedDate)
523506

524-
cy.get('#edit-files-menu').should('exist')
507+
cy.get('#edit-files-menu').should('exist')
525508

526-
cy.findByRole('button', { name: 'Access File' }).as('accessButton')
527-
cy.get('@accessButton').should('exist')
528-
cy.get('@accessButton').click()
529-
cy.findByText('Embargoed').should('exist')
530-
})
531-
})
509+
cy.findByRole('button', { name: 'Access File' }).as('accessButton')
510+
cy.get('@accessButton').should('exist')
511+
cy.get('@accessButton').click()
512+
cy.findByText('Embargoed').should('exist')
513+
})
532514
})
533515

534516
it('applies filters to the Files Table in the correct order', () => {

0 commit comments

Comments
 (0)