From 2f65c6e61e2a73483ac620da8c9b3279d95fed43 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Fri, 13 Dec 2024 17:16:17 -0500 Subject: [PATCH] fix: show strings for creationDate and publicationDate --- src/files/domain/models/FileMetadata.ts | 6 +++--- .../mappers/JSFileMetadataMapper.ts | 15 ++++++++------- .../file-info-cell/file-info-data/FileDate.tsx | 6 +----- .../file/file-metadata/FileMetadata.tsx | 13 +++---------- src/shared/helpers/DateHelper.ts | 12 ------------ .../files/domain/models/FileMetadataMother.ts | 11 +++++++---- .../file-info-data/FileDate.spec.tsx | 6 ++---- .../file/file-metadata/FileMetadata.spec.tsx | 17 ++++++----------- .../files/FileJSDataverseRepository.spec.ts | 10 +++++----- 9 files changed, 35 insertions(+), 61 deletions(-) diff --git a/src/files/domain/models/FileMetadata.ts b/src/files/domain/models/FileMetadata.ts index dadf7856d..1d4629e6d 100644 --- a/src/files/domain/models/FileMetadata.ts +++ b/src/files/domain/models/FileMetadata.ts @@ -87,7 +87,7 @@ export enum FileDateType { export interface FileDate { type: FileDateType - date: Date + date: string } export class FileEmbargo { @@ -150,8 +150,8 @@ export class FileMetadata { readonly labels: FileLabel[], public readonly isDeleted: boolean, public readonly downloadUrls: FileDownloadUrls, - readonly depositDate: Date, - readonly publicationDate?: Date, + readonly depositDate?: string, + readonly publicationDate?: string, public thumbnail?: string, readonly directory?: string, readonly embargo?: FileEmbargo, diff --git a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts index 9e97ad774..c43b6e8f6 100644 --- a/src/files/infrastructure/mappers/JSFileMetadataMapper.ts +++ b/src/files/infrastructure/mappers/JSFileMetadataMapper.ts @@ -29,13 +29,13 @@ export class JSFileMetadataMapper { return new FileMetadata( this.toFileType(jsFile.contentType, jsFile.originalFormatLabel), this.toFileSize(jsFile.sizeBytes), - this.toFileDate(jsFile.creationDate ?? '', jsFile.publicationDate, jsFile.embargo), + this.toFileDate(jsFile.creationDate, jsFile.publicationDate, jsFile.embargo), this.toFileDownloads(downloadsCount), this.toFileLabels(jsFile.categories, jsFile.tabularTags), this.toFileIsDeleted(jsFile.deleted), this.toFileOriginalFileDownloadUrl(jsFile.id), - jsFile.creationDate ? new Date(jsFile.creationDate) : new Date(), - jsFile.publicationDate ? new Date(jsFile.publicationDate) : new Date(), + jsFile.creationDate, + jsFile.publicationDate, this.toFileThumbnail(thumbnail), this.toFileDirectory(jsFile.directoryLabel), this.toFileEmbargo(jsFile.embargo), @@ -55,7 +55,7 @@ export class JSFileMetadataMapper { } static toFileDate( - jsFileCreationDate: string, + jsFileCreationDate?: string, jsFilePublicationDate?: string, jsFileEmbargo?: JSFileEmbargo ): FileDate { @@ -63,13 +63,14 @@ export class JSFileMetadataMapper { if (jsFileEmbargo) { return { type: FileDateType.METADATA_RELEASED, - date: new Date(jsFilePublicationDate) + date: jsFilePublicationDate } } - return { type: FileDateType.PUBLISHED, date: new Date(jsFilePublicationDate) } + return { type: FileDateType.PUBLISHED, date: jsFilePublicationDate } } + if (jsFileCreationDate) { - return { type: FileDateType.DEPOSITED, date: new Date(jsFileCreationDate) } + return { type: FileDateType.DEPOSITED, date: jsFileCreationDate } } throw new Error('File date not found') } 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 68256a4ac..4e9ca1ded 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,6 +1,5 @@ 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') @@ -8,10 +7,7 @@ export function FileDate({ date }: { date: FileDateModel }) { return (
- {t(`table.date.${date.type}`)}{' '} - + {t(`table.date.${date.type}`)}
) diff --git a/src/sections/file/file-metadata/FileMetadata.tsx b/src/sections/file/file-metadata/FileMetadata.tsx index ab49dbe8a..1c95782f8 100644 --- a/src/sections/file/file-metadata/FileMetadata.tsx +++ b/src/sections/file/file-metadata/FileMetadata.tsx @@ -2,7 +2,6 @@ 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 { DateHelper } from '../../../shared/helpers/DateHelper' import { FileEmbargoDate } from '../file-embargo/FileEmbargoDate' import { BASE_URL } from '../../../config' import { FileMetadata as FileMetadataModel } from '../../../files/domain/models/FileMetadata' @@ -99,9 +98,7 @@ export function FileMetadata({ {t('metadata.fields.depositDate')} - + {metadata.publicationDate && ( @@ -110,9 +107,7 @@ export function FileMetadata({ {t('metadata.fields.metadataReleaseDate')} - + )} @@ -130,9 +125,7 @@ export function FileMetadata({ /> ) : ( metadata.publicationDate && ( - + ) )} diff --git a/src/shared/helpers/DateHelper.ts b/src/shared/helpers/DateHelper.ts index 35c053c2c..1f179563a 100644 --- a/src/shared/helpers/DateHelper.ts +++ b/src/shared/helpers/DateHelper.ts @@ -1,16 +1,4 @@ export class DateHelper { - static toDisplayFileFormat(date: Date): string { - if (!date) { - return '' - } - return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { - year: 'numeric', - month: 'short', - day: 'numeric', - timeZone: 'UTC' - }) - } - static toDisplayFormat(date: Date): string { if (!date) { return '' diff --git a/tests/component/files/domain/models/FileMetadataMother.ts b/tests/component/files/domain/models/FileMetadataMother.ts index 96752b016..82db049d3 100644 --- a/tests/component/files/domain/models/FileMetadataMother.ts +++ b/tests/component/files/domain/models/FileMetadataMother.ts @@ -12,6 +12,7 @@ import { } from '../../../../../src/files/domain/models/FileMetadata' import FileTypeToFriendlyTypeMap from '../../../../../src/files/domain/models/FileTypeToFriendlyTypeMap' import { FakerHelper } from '../../../shared/FakerHelper' +import { DateHelper } from '@/shared/helpers/DateHelper' const valueOrUndefined: (value: T) => T | undefined = (value) => { const shouldShowValue = faker.datatype.boolean() @@ -143,7 +144,7 @@ export class FileMetadataMother { size: FileSizeMother.create(), date: { type: FakerHelper.fileDateType(), - date: FakerHelper.recentDate() + date: DateHelper.toISO8601Format(FakerHelper.recentDate()) }, downloadCount: FakerHelper.smallNumber(40), labels: faker.datatype.boolean() ? FileLabelMother.createMany(3) : [], @@ -155,8 +156,10 @@ export class FileMetadataMother { description: valueOrUndefined(faker.lorem.paragraph()), isDeleted: faker.datatype.boolean(), downloadUrls: FileDownloadUrlsMother.create(), - depositDate: FakerHelper.pastDate(), - publicationDate: faker.datatype.boolean() ? FakerHelper.pastDate() : undefined, + depositDate: DateHelper.toISO8601Format(FakerHelper.pastDate()), + publicationDate: faker.datatype.boolean() + ? DateHelper.toISO8601Format(FakerHelper.pastDate()) + : undefined, persistentId: faker.datatype.uuid(), ...props } @@ -315,7 +318,7 @@ export class FileMetadataMother { static createWithPublicationDate(props?: Partial): FileMetadata { return this.createDefault({ - publicationDate: FakerHelper.pastDate(), + publicationDate: DateHelper.toISO8601Format(FakerHelper.pastDate()), ...props }) } 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 02c1f6712..f08080c52 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 @@ -1,14 +1,12 @@ import { FileDate } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDate' import { FileDateType } from '../../../../../../../../../src/files/domain/models/FileMetadata' -import { DateHelper } from '../../../../../../../../../src/shared/helpers/DateHelper' describe('FileDate', () => { it('renders the date', () => { - const fileDate = new Date('2023-09-18') + const fileDate = '2023-09-18' const date = { type: FileDateType.PUBLISHED, date: fileDate } cy.customMount() - const dateString = DateHelper.toDisplayFileFormat(fileDate) cy.findByText(`Published`).should('exist') - cy.get('time').should('have.text', dateString) + cy.get('time').should('have.text', fileDate) }) }) diff --git a/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx b/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx index 23b4dbe9a..d845be11e 100644 --- a/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx +++ b/tests/component/sections/file/file-metadata/FileMetadata.spec.tsx @@ -11,7 +11,6 @@ import { } from '../../../files/domain/models/FileMetadataMother' import { DatasetPublishingStatus } from '../../../../../src/dataset/domain/models/Dataset' import { FilePermissionsMother } from '../../../files/domain/models/FilePermissionsMother' -import { DateHelper } from '../../../../../src/shared/helpers/DateHelper' const file = FileMother.create() describe('FileMetadata', () => { @@ -215,7 +214,9 @@ describe('FileMetadata', () => { /> ) cy.findByText('Deposit Date').should('exist') - cy.get('time').contains(DateHelper.toISO8601Format(file.metadata.depositDate)).should('exist') + if (file.metadata.depositDate) { + cy.get('time').contains(file.metadata.depositDate).should('exist') + } }) it('renders the file Metadata Release Date', () => { @@ -231,9 +232,7 @@ describe('FileMetadata', () => { cy.findByText('Metadata Release Date').should('exist') if (metadataWithPublicationDate.publicationDate) { - cy.findAllByText( - DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate) - ).should('exist') + cy.findAllByText(metadataWithPublicationDate.publicationDate).should('exist') } }) @@ -264,9 +263,7 @@ describe('FileMetadata', () => { cy.findByText('Publication Date').should('exist') if (metadataWithPublicationDate.publicationDate) { - cy.findAllByText( - DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate) - ).should('exist') + cy.findAllByText(metadataWithPublicationDate.publicationDate).should('exist') } }) @@ -284,9 +281,7 @@ describe('FileMetadata', () => { cy.findByText('Publication Date').should('exist') if (metadataWithPublicationDateEmbargoed.publicationDate) { - cy.findAllByText( - DateHelper.toISO8601Format(metadataWithPublicationDateEmbargoed.publicationDate) - ).should('exist') + cy.findAllByText(metadataWithPublicationDateEmbargoed.publicationDate).should('exist') } }) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 8a2fb0641..000e3603a 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -31,6 +31,8 @@ import { } from '../../../../src/dataset/domain/models/Dataset' import { File } from '../../../../src/files/domain/models/File' import { FileIngest, FileIngestStatus } from '../../../../src/files/domain/models/FileIngest' +import { DateHelper } from '@/shared/helpers/DateHelper' + const DRAFT_PARAM = DatasetNonNumericVersion.DRAFT chai.use(chaiAsPromised) @@ -38,8 +40,7 @@ const expect = chai.expect const fileRepository = new FileJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() -const dateNow = new Date() -dateNow.setHours(2, 0, 0, 0) +const dateNow = DateHelper.toISO8601Format(new Date()) const filePreviewExpectedData = (id: number): FilePreview => { return { id: id, @@ -161,7 +162,7 @@ describe('File JSDataverse Repository', () => { const compareMetadata = (fileMetadata: FileMetadata, expectedFileMetadata: FileMetadata) => { expect(fileMetadata.type).to.deep.equal(expectedFileMetadata.type) - cy.compareDate(fileMetadata.date.date, expectedFileMetadata.date.date) + expect(fileMetadata.date.date).to.deep.equal(expectedFileMetadata.date.date) expect(fileMetadata.downloadCount).to.deep.equal(expectedFileMetadata.downloadCount) expect(fileMetadata.labels).to.deep.equal(expectedFileMetadata.labels) expect(fileMetadata.checksum?.algorithm).to.deep.equal(expectedFileMetadata.checksum?.algorithm) @@ -249,8 +250,7 @@ describe('File JSDataverse Repository', () => { expect(file.datasetPublishingStatus).to.deep.equal( expectedPublishedFile.datasetPublishingStatus ) - cy.compareDate( - file.metadata.date.date, + expect(file.metadata.date.date).to.deep.equal( filePreviewExpectedData(file.id).metadata.date.date ) })