From cab425cf645b92d10e74b12d219fd2d1fc940c30 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 2 Oct 2023 21:45:53 -0400 Subject: [PATCH 1/9] Fix: date tests for local time zones --- .../file-info-data/FileDate.spec.tsx | 12 ++++-- .../file-info-data/FileEmbargoDate.spec.tsx | 42 +++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) 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 040a5758c..851029fa5 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,10 +1,16 @@ 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/File' + describe('FileDate', () => { it('renders the date', () => { - const date = { type: FileDateType.PUBLISHED, date: new Date('2023-09-18') } + const fileDate = new Date('2023-09-18') + const date = { type: FileDateType.PUBLISHED, date: fileDate } cy.customMount() - - cy.findByText(`Published Sep 18, 2023`).should('exist') + const dateString = fileDate.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { + year: 'numeric', + month: 'short', + day: 'numeric' + }) + cy.findByText(`Published ` + dateString).should('exist') }) }) diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx index 4ef4fe87b..0e72039f8 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileEmbargoDate.spec.tsx @@ -4,29 +4,53 @@ import { FileEmbargoMother } from '../../../../../../../files/domain/models/File describe('FileEmbargoDate', () => { it('renders the embargo date when embargo exists', () => { - const embargo = FileEmbargoMother.create(new Date('2123-09-18')) + const embargoDate = new Date('2123-09-18') + const embargo = FileEmbargoMother.create(embargoDate) const status = FilePublishingStatus.RELEASED cy.customMount() - - cy.findByText(`Embargoed until Sep 18, 2123`).should('exist') + const dateString = embargoDate.toLocaleDateString( + Intl.DateTimeFormat().resolvedOptions().locale, + { + year: 'numeric', + month: 'short', + day: 'numeric' + } + ) + cy.findByText(`Embargoed until ` + dateString).should('exist') }) it('renders the until embargo date when embargo is not active and the file is not released', () => { - const embargo = FileEmbargoMother.create(new Date('2023-09-15')) + const embargoDate = new Date('2023-09-15') + const embargo = FileEmbargoMother.create(embargoDate) const status = FilePublishingStatus.RELEASED cy.customMount() - - cy.findByText(`Was embargoed until Sep 15, 2023`).should('exist') + const dateString = embargoDate.toLocaleDateString( + Intl.DateTimeFormat().resolvedOptions().locale, + { + year: 'numeric', + month: 'short', + day: 'numeric' + } + ) + cy.findByText(`Was embargoed until ` + dateString).should('exist') }) it('renders the draft until embargo date when embargo is active and the file is not released', () => { - const embargo = FileEmbargoMother.create(new Date('2123-09-18')) + const embargoDate = new Date('2123-09-18') + const embargo = FileEmbargoMother.create(embargoDate) const status = FilePublishingStatus.DRAFT cy.customMount() - - cy.findByText(`Draft: will be embargoed until Sep 18, 2123`).should('exist') + const dateString = embargoDate.toLocaleDateString( + Intl.DateTimeFormat().resolvedOptions().locale, + { + year: 'numeric', + month: 'short', + day: 'numeric' + } + ) + cy.findByText(`Draft: will be embargoed until ` + dateString).should('exist') }) it('renders an empty fragment when embargo is undefined', () => { From cfb4e2816c64ed947a847f1b0678bd2a3e7354ff Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 2 Oct 2023 21:48:46 -0400 Subject: [PATCH 2/9] Add isAlternateVersion to Dataset.js --- public/locales/en/dataset.json | 5 ++- src/dataset/domain/models/Dataset.ts | 37 ++++++++++++++++++- .../infrastructure/mappers/JSDatasetMapper.ts | 19 ++++++++-- .../DatasetJSDataverseRepository.ts | 10 +++-- .../mappers/JSDatasetMapper.spec.ts | 9 ++++- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index ba62759a4..2f87a7e68 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -18,8 +18,11 @@ "learnAbout": "Learn About", "standards": "Data Citation Standards" }, - "actions": { "uploadFiles": "Upload Files" + }, + "alerts": { + "draftVersion": "This is a draft version", + "requestedVersionNotFound": "Requested version not found" } } diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index f42bc6819..0bfb4886f 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -1,3 +1,5 @@ +import { AlertVariant } from '@iqss/dataverse-design-system/dist/components/alert/AlertVariant' + export enum DatasetLabelSemanticMeaning { DATASET = 'dataset', FILE = 'file', @@ -22,6 +24,20 @@ export class DatasetLabel { ) {} } +export enum DatasetAlertMessageKey { + DRAFT_VERSION = 'draftVersion', + REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound' + //TODO: add more +} + +export class DatasetAlert { + constructor( + public readonly variant: AlertVariant, + public readonly message: DatasetAlertMessageKey, + public readonly customHeading?: string + ) {} +} + export enum MetadataBlockName { CITATION = 'citation', GEOSPATIAL = 'geospatial', @@ -191,6 +207,7 @@ export interface DatasetLicense { uri: string iconUri?: string } + const defaultLicense: DatasetLicense = { name: 'CC0 1.0', uri: 'https://creativecommons.org/publicdomain/zero/1.0', @@ -215,7 +232,10 @@ export class DatasetVersion { public readonly id: number, public readonly publishingStatus: DatasetPublishingStatus, public readonly majorNumber?: number, - public readonly minorNumber?: number + public readonly minorNumber?: number, + // isAlternateVersion will be set to true if the requested version did not exist, + // in this case the latest version will be sent instead + public readonly isAlternateVersion?: boolean ) {} toString(): string | DatasetNonNumericVersion { @@ -232,6 +252,7 @@ export class Dataset { public readonly version: DatasetVersion, public readonly citation: string, public readonly labels: DatasetLabel[], + public readonly alerts: DatasetAlert[], public readonly summaryFields: DatasetMetadataBlock[], public readonly license: DatasetLicense, public readonly metadataBlocks: DatasetMetadataBlocks @@ -243,6 +264,7 @@ export class Dataset { static Builder = class { public readonly labels: DatasetLabel[] = [] + public readonly alerts: DatasetAlert[] = [] constructor( public readonly persistentId: string, @@ -253,6 +275,7 @@ export class Dataset { public readonly metadataBlocks: DatasetMetadataBlocks ) { this.withLabels() + this.withAlerts() } withLabels() { @@ -300,12 +323,24 @@ export class Dataset { } } + private withAlerts(): void { + if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) { + this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, 'Info')) + } + if (this.version.isAlternateVersion) { + this.alerts.push( + new DatasetAlert('info', DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND) + ) + } + } + build(): Dataset { return new Dataset( this.persistentId, this.version, this.citation, this.labels, + this.alerts, this.summaryFields, this.license, this.metadataBlocks diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index 0207de851..0237f05d1 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -17,10 +17,19 @@ import { } from '../../domain/models/Dataset' export class JSDatasetMapper { - static toDataset(jsDataset: JSDataset, citation: string, summaryFieldsNames: string[]): Dataset { + static toDataset( + jsDataset: JSDataset, + citation: string, + summaryFieldsNames: string[], + isAlternateVersion?: boolean + ): Dataset { + let isAlternate = false + if (isAlternateVersion) { + isAlternate = true + } return new Dataset.Builder( jsDataset.persistentId, - JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo), + JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, isAlternate), citation, JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames), jsDataset.license, @@ -35,13 +44,15 @@ export class JSDatasetMapper { static toVersion( jDatasetVersionId: number, - jsDatasetVersionInfo: JSDatasetVersionInfo + jsDatasetVersionInfo: JSDatasetVersionInfo, + isAlternateVersion?: boolean ): DatasetVersion { return new DatasetVersion( jDatasetVersionId, JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), jsDatasetVersionInfo.majorNumber, - jsDatasetVersionInfo.minorNumber + jsDatasetVersionInfo.minorNumber, + isAlternateVersion ) } diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index ea25c0aa2..89eb5180a 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -12,7 +12,11 @@ import { import { JSDatasetMapper } from '../mappers/JSDatasetMapper' export class DatasetJSDataverseRepository implements DatasetRepository { - getByPersistentId(persistentId: string, version?: string): Promise { + getByPersistentId( + persistentId: string, + version?: string, + isAlternateVersion?: boolean + ): Promise { return getDataset .execute(persistentId, this.versionToVersionId(version)) .then((jsDataset) => @@ -23,13 +27,13 @@ export class DatasetJSDataverseRepository implements DatasetRepository { ]) ) .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames) + JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, isAlternateVersion) ) .catch((error: WriteError) => { if (!version) { throw new Error(error.message) } - return this.getByPersistentId(persistentId) + return this.getByPersistentId(persistentId, undefined, (isAlternateVersion = true)) }) } diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index 60ecfe7d7..5ae759116 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -52,13 +52,20 @@ const citation = const datasetSummaryFields = ['dsDescription', 'subject', 'keyword', 'publication', 'notesText'] const expectedDataset = { persistentId: 'doi:10.5072/FK2/B4B2MJ', - version: { id: 101, minorNumber: 0, majorNumber: 0, publishingStatus: 'draft' }, + version: { + id: 101, + publishingStatus: 'draft', + minorNumber: 0, + majorNumber: 0, + isAlternateVersion: false + }, citation: 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', labels: [ { semanticMeaning: 'dataset', value: 'Draft' }, { semanticMeaning: 'warning', value: 'Unpublished' } ], + alerts: [{ variant: 'warning', message: 'draftVersion', customHeading: 'Info' }], summaryFields: [ { name: 'citation', From b26093f5c67bd243f282d6fd935a251a705147da Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Tue, 3 Oct 2023 08:03:52 -0400 Subject: [PATCH 3/9] use undefined for isAlternateVersion instead of false --- .../infrastructure/mappers/JSDatasetMapper.ts | 6 +- .../mappers/JSDatasetMapper.spec.ts | 77 ++++++++++++++++++- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index 0237f05d1..c84b2124b 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -23,13 +23,9 @@ export class JSDatasetMapper { summaryFieldsNames: string[], isAlternateVersion?: boolean ): Dataset { - let isAlternate = false - if (isAlternateVersion) { - isAlternate = true - } return new Dataset.Builder( jsDataset.persistentId, - JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, isAlternate), + JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, isAlternateVersion), citation, JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames), jsDataset.license, diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index 5ae759116..9e908945a 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -57,7 +57,7 @@ const expectedDataset = { publishingStatus: 'draft', minorNumber: 0, majorNumber: 0, - isAlternateVersion: false + isAlternateVersion: undefined }, citation: 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', @@ -105,13 +105,86 @@ const expectedDataset = { } ] } - +const expectedDatasetAlternateVersion = { + persistentId: 'doi:10.5072/FK2/B4B2MJ', + version: { + id: 101, + publishingStatus: 'draft', + minorNumber: 0, + majorNumber: 0, + isAlternateVersion: true + }, + citation: + 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', + labels: [ + { semanticMeaning: 'dataset', value: 'Draft' }, + { semanticMeaning: 'warning', value: 'Unpublished' } + ], + alerts: [ + { variant: 'warning', message: 'draftVersion', customHeading: 'Info' }, + { + message: 'requestedVersionNotFound', + variant: 'info', + customHeading: undefined + } + ], + summaryFields: [ + { + name: 'citation', + fields: { + dsDescription: [ + { + dsDescriptionValue: + "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds." + } + ], + subject: ['Medicine, Health and Life Sciences'] + } + } + ], + license: { + name: 'CC0 1.0', + uri: 'http://creativecommons.org/publicdomain/zero/1.0', + iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png' + }, + metadataBlocks: [ + { + name: 'citation', + fields: { + title: "Darwin's Finches", + author: [{ authorName: 'Finch, Fiona', authorAffiliation: 'Birds Inc.' }], + datasetContact: [ + { datasetContactName: 'Finch, Fiona', datasetContactEmail: 'finch@mailinator.com' } + ], + dsDescription: [ + { + dsDescriptionValue: + "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds." + } + ], + subject: ['Medicine, Health and Life Sciences'] + } + } + ] +} describe('JS Dataset Mapper', () => { it('maps jsDataset model to the domain Dataset model', () => { expect(expectedDataset).to.deep.equal( JSDatasetMapper.toDataset(jsDataset, citation, datasetSummaryFields) ) }) + it('maps jsDataset model to the domain Dataset model for alternate version', () => { + const mappedWithAlternate = JSDatasetMapper.toDataset( + jsDataset, + citation, + datasetSummaryFields, + true + ) + expect(expectedDatasetAlternateVersion.version).to.deep.equal(mappedWithAlternate.version) + console.log(`expected ` + JSON.stringify(expectedDatasetAlternateVersion.alerts)) + console.log(`mapped ` + JSON.stringify(mappedWithAlternate.alerts)) + expect(expectedDatasetAlternateVersion.alerts).to.deep.equal(mappedWithAlternate.alerts) + }) it('maps jsDataset model to the domain Dataset model when alternativePersistentId is provided', () => { const jsDatasetWithAlternativePersistentId = { From 6ad836aadc42809b4ab9d643813df5ed03a8ce9c Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Tue, 3 Oct 2023 08:58:31 -0400 Subject: [PATCH 4/9] use dynamic fields in DatasetAlert, save requestedVersion in JSDatasetMapper. --- public/locales/en/dataset.json | 4 +-- src/dataset/domain/models/Dataset.ts | 21 +++++++++----- .../infrastructure/mappers/JSDatasetMapper.ts | 8 +++--- .../DatasetJSDataverseRepository.ts | 6 ++-- .../mappers/JSDatasetMapper.spec.ts | 28 +++++++++++-------- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index 2f87a7e68..c52bc9493 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -22,7 +22,7 @@ "uploadFiles": "Upload Files" }, "alerts": { - "draftVersion": "This is a draft version", - "requestedVersionNotFound": "Requested version not found" + "draftVersion": "This draft version needs to be published. When ready for sharing, please publish it so that others can see these changes", + "requestedVersionNotFound": "Info – Version {0} was not found. This is version {1}" } } diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 0bfb4886f..c25adc0fc 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -27,13 +27,13 @@ export class DatasetLabel { export enum DatasetAlertMessageKey { DRAFT_VERSION = 'draftVersion', REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound' - //TODO: add more } export class DatasetAlert { constructor( public readonly variant: AlertVariant, public readonly message: DatasetAlertMessageKey, + public readonly dynamicFields?: string[], public readonly customHeading?: string ) {} } @@ -233,9 +233,8 @@ export class DatasetVersion { public readonly publishingStatus: DatasetPublishingStatus, public readonly majorNumber?: number, public readonly minorNumber?: number, - // isAlternateVersion will be set to true if the requested version did not exist, - // in this case the latest version will be sent instead - public readonly isAlternateVersion?: boolean + // requestedVersion will be set if the user requested a version that did not exist. + public readonly requestedVersion?: string ) {} toString(): string | DatasetNonNumericVersion { @@ -325,11 +324,19 @@ export class Dataset { private withAlerts(): void { if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) { - this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, 'Info')) + this.alerts.push( + new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, undefined, 'Info') + ) } - if (this.version.isAlternateVersion) { + if (this.version.requestedVersion) { + const dynamicFields = [this.version.requestedVersion, `${this.version.toString()}`] + this.alerts.push( - new DatasetAlert('info', DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND) + new DatasetAlert( + 'info', + DatasetAlertMessageKey.REQUESTED_VERSION_NOT_FOUND, + dynamicFields + ) ) } } diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index c84b2124b..ea2347281 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -21,11 +21,11 @@ export class JSDatasetMapper { jsDataset: JSDataset, citation: string, summaryFieldsNames: string[], - isAlternateVersion?: boolean + requestedVersion?: string ): Dataset { return new Dataset.Builder( jsDataset.persistentId, - JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, isAlternateVersion), + JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo, requestedVersion), citation, JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames), jsDataset.license, @@ -41,14 +41,14 @@ export class JSDatasetMapper { static toVersion( jDatasetVersionId: number, jsDatasetVersionInfo: JSDatasetVersionInfo, - isAlternateVersion?: boolean + requestedVersion?: string ): DatasetVersion { return new DatasetVersion( jDatasetVersionId, JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), jsDatasetVersionInfo.majorNumber, jsDatasetVersionInfo.minorNumber, - isAlternateVersion + requestedVersion ) } diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index 89eb5180a..a1409b317 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -15,7 +15,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { getByPersistentId( persistentId: string, version?: string, - isAlternateVersion?: boolean + requestedVersion?: string ): Promise { return getDataset .execute(persistentId, this.versionToVersionId(version)) @@ -27,13 +27,13 @@ export class DatasetJSDataverseRepository implements DatasetRepository { ]) ) .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, isAlternateVersion) + JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, requestedVersion) ) .catch((error: WriteError) => { if (!version) { throw new Error(error.message) } - return this.getByPersistentId(persistentId, undefined, (isAlternateVersion = true)) + return this.getByPersistentId(persistentId, undefined, (requestedVersion = version)) }) } diff --git a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts index 9e908945a..5abd258f7 100644 --- a/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts +++ b/tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts @@ -57,7 +57,7 @@ const expectedDataset = { publishingStatus: 'draft', minorNumber: 0, majorNumber: 0, - isAlternateVersion: undefined + requestedVersion: undefined }, citation: 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', @@ -65,7 +65,9 @@ const expectedDataset = { { semanticMeaning: 'dataset', value: 'Draft' }, { semanticMeaning: 'warning', value: 'Unpublished' } ], - alerts: [{ variant: 'warning', message: 'draftVersion', customHeading: 'Info' }], + alerts: [ + { variant: 'warning', message: 'draftVersion', dynamicFields: undefined, customHeading: 'Info' } + ], summaryFields: [ { name: 'citation', @@ -112,7 +114,7 @@ const expectedDatasetAlternateVersion = { publishingStatus: 'draft', minorNumber: 0, majorNumber: 0, - isAlternateVersion: true + requestedVersion: '4.0' }, citation: 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/B4B2MJ, Root, DRAFT VERSION', @@ -121,10 +123,16 @@ const expectedDatasetAlternateVersion = { { semanticMeaning: 'warning', value: 'Unpublished' } ], alerts: [ - { variant: 'warning', message: 'draftVersion', customHeading: 'Info' }, + { + variant: 'warning', + message: 'draftVersion', + dynamicFields: undefined, + customHeading: 'Info' + }, { message: 'requestedVersionNotFound', variant: 'info', + dynamicFields: ['4.0', '0.0'], customHeading: undefined } ], @@ -169,21 +177,17 @@ const expectedDatasetAlternateVersion = { } describe('JS Dataset Mapper', () => { it('maps jsDataset model to the domain Dataset model', () => { - expect(expectedDataset).to.deep.equal( - JSDatasetMapper.toDataset(jsDataset, citation, datasetSummaryFields) - ) + const mapped = JSDatasetMapper.toDataset(jsDataset, citation, datasetSummaryFields) + expect(expectedDataset).to.deep.equal(mapped) }) it('maps jsDataset model to the domain Dataset model for alternate version', () => { const mappedWithAlternate = JSDatasetMapper.toDataset( jsDataset, citation, datasetSummaryFields, - true + '4.0' ) - expect(expectedDatasetAlternateVersion.version).to.deep.equal(mappedWithAlternate.version) - console.log(`expected ` + JSON.stringify(expectedDatasetAlternateVersion.alerts)) - console.log(`mapped ` + JSON.stringify(mappedWithAlternate.alerts)) - expect(expectedDatasetAlternateVersion.alerts).to.deep.equal(mappedWithAlternate.alerts) + expect(expectedDatasetAlternateVersion).to.deep.equal(mappedWithAlternate) }) it('maps jsDataset model to the domain Dataset model when alternativePersistentId is provided', () => { From f903022ebe1ac1f690dcc58ad3abaf79afd6b534 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Tue, 3 Oct 2023 09:21:56 -0400 Subject: [PATCH 5/9] Add privateURL DatasetAlert --- public/locales/en/dataset.json | 3 ++- src/dataset/domain/models/Dataset.ts | 21 +++++++++++++++---- .../infrastructure/mappers/JSDatasetMapper.ts | 6 ++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/public/locales/en/dataset.json b/public/locales/en/dataset.json index c52bc9493..09d4687b8 100644 --- a/public/locales/en/dataset.json +++ b/public/locales/en/dataset.json @@ -23,6 +23,7 @@ }, "alerts": { "draftVersion": "This draft version needs to be published. When ready for sharing, please publish it so that others can see these changes", - "requestedVersionNotFound": "Info – Version {0} was not found. This is version {1}" + "requestedVersionNotFound": "Info – Version {0} was not found. This is version {1}", + "unpublishedDataset": "Privately share this dataset before it is published: {0}" } } diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index c25adc0fc..9bff2f11d 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -26,7 +26,8 @@ export class DatasetLabel { export enum DatasetAlertMessageKey { DRAFT_VERSION = 'draftVersion', - REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound' + REQUESTED_VERSION_NOT_FOUND = 'requestedVersionNotFound', + UNPUBLISHED_DATASET = 'unpublishedDataset' } export class DatasetAlert { @@ -271,10 +272,11 @@ export class Dataset { public readonly citation: string, public readonly summaryFields: DatasetMetadataBlock[], public readonly license: DatasetLicense = defaultLicense, - public readonly metadataBlocks: DatasetMetadataBlocks + public readonly metadataBlocks: DatasetMetadataBlocks, + public readonly privateUrl?: string ) { this.withLabels() - this.withAlerts() + this.withAlerts(privateUrl) } withLabels() { @@ -322,7 +324,7 @@ export class Dataset { } } - private withAlerts(): void { + private withAlerts(privateUrl?: string): void { if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) { this.alerts.push( new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, undefined, 'Info') @@ -339,6 +341,17 @@ export class Dataset { ) ) } + if (privateUrl) { + const dynamicFields = [privateUrl] + this.alerts.push( + new DatasetAlert( + 'info', + DatasetAlertMessageKey.UNPUBLISHED_DATASET, + dynamicFields, + 'Unpublished Dataset Private URL' + ) + ) + } } build(): Dataset { diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index ea2347281..78f3ee188 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -21,7 +21,8 @@ export class JSDatasetMapper { jsDataset: JSDataset, citation: string, summaryFieldsNames: string[], - requestedVersion?: string + requestedVersion?: string, + privateUrl?: string ): Dataset { return new Dataset.Builder( jsDataset.persistentId, @@ -34,7 +35,8 @@ export class JSDatasetMapper { jsDataset.alternativePersistentId, jsDataset.publicationDate, jsDataset.citationDate - ) + ), + privateUrl ).build() } From 82a5b404a1dcd4325e76073e44c5512d83cdd3f6 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 4 Oct 2023 18:45:16 -0400 Subject: [PATCH 6/9] Fix: Date comparisons in tests --- package-lock.json | 15 ++++++++++++++- packages/design-system/package.json | 18 +++++++++--------- .../file-info-cell/file-info-data/FileDate.tsx | 2 +- .../files/FileJSDataverseRepository.spec.ts | 4 ++-- tests/support/commands.tsx | 6 ++++++ tests/support/component.ts | 4 ++++ 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1284be569..8d445f32d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43627,7 +43627,6 @@ "react-bootstrap": "2.7.2", "react-bootstrap-icons": "1.10.3", "sass": "1.58.1", - "typescript": "4.9.5", "vite-plugin-istanbul": "4.0.1" }, "devDependencies": { @@ -43639,6 +43638,7 @@ "chromatic": "6.17.4", "cypress": "12.5.1", "react": "18.2.0", + "typescript": "^5.2.2", "vite": "4.1.5", "vite-plugin-dts": "2.3.0", "vite-plugin-libcss": "1.0.6" @@ -43755,6 +43755,19 @@ "funding": { "url": "https://github.com/chalk/supports-color?sponsor=1" } + }, + "packages/design-system/node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } } } } diff --git a/packages/design-system/package.json b/packages/design-system/package.json index b3502cb41..5ff03ee7b 100644 --- a/packages/design-system/package.json +++ b/packages/design-system/package.json @@ -32,25 +32,25 @@ }, "dependencies": { "@types/react": "18.0.27", - "typescript": "4.9.5", - "vite-plugin-istanbul": "4.0.1", "bootstrap": "5.2.3", "react-bootstrap": "2.7.2", "react-bootstrap-icons": "1.10.3", - "sass": "1.58.1" + "sass": "1.58.1", + "vite-plugin-istanbul": "4.0.1" }, "devDependencies": { - "@vitejs/plugin-react": "3.1.0", - "@testing-library/cypress": "9.0.0", "@storybook/react": "7.0.2", "@storybook/test-runner": "0.10.0", + "@testing-library/cypress": "9.0.0", + "@vitejs/plugin-react": "3.1.0", + "axe-playwright": "1.2.3", + "chromatic": "6.17.4", "cypress": "12.5.1", + "react": "18.2.0", + "typescript": "^5.2.2", "vite": "4.1.5", "vite-plugin-dts": "2.3.0", - "vite-plugin-libcss": "1.0.6", - "react": "18.2.0", - "axe-playwright": "1.2.3", - "chromatic": "6.17.4" + "vite-plugin-libcss": "1.0.6" }, "files": [ "dist", 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 a219b5017..61ddb0c44 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 @@ -7,7 +7,7 @@ export function FileDate({ date }: { date: FileDateModel }) {
{t(`table.date.${date.type}`)}{' '} - {date.date.toLocaleDateString('en-US', { + {date.date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { year: 'numeric', month: 'short', day: 'numeric' diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 844b61ed1..e97999204 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -91,7 +91,7 @@ describe('File JSDataverse Repository', () => { expect(file.version).to.deep.equal(expectedFile.version) expect(file.access).to.deep.equal(expectedFile.access) expect(file.type).to.deep.equal(expectedFile.type) - expect(file.date).to.deep.equal(expectedFile.date) + cy.compareDate(file.date.date, expectedFile.date.date) expect(file.downloadCount).to.deep.equal(expectedFile.downloadCount) expect(file.labels).to.deep.equal(expectedFile.labels) expect(file.checksum?.algorithm).to.deep.equal(expectedFile.checksum?.algorithm) @@ -143,7 +143,7 @@ describe('File JSDataverse Repository', () => { files.forEach((file) => { expect(file.version).to.deep.equal(expectedPublishedFile.version) - expect(file.date).to.deep.equal(expectedFile.date) + cy.compareDate(file.date.date, expectedFile.date.date) }) }) }) diff --git a/tests/support/commands.tsx b/tests/support/commands.tsx index c0da8c8fd..51d4922ea 100644 --- a/tests/support/commands.tsx +++ b/tests/support/commands.tsx @@ -72,3 +72,9 @@ Cypress.Commands.add('getApiToken', () => { cy.loginAsAdmin('/dataverseuser.xhtml?selectTab=dataRelatedToMe') return cy.findByRole('link', { name: 'API Token' }).click().get('#apiToken code').invoke('text') }) + +Cypress.Commands.add('compareDate', (date, expectedDate) => { + expect(date.getUTCDate()).to.deep.equal(expectedDate.getUTCDate()) + expect(date.getUTCMonth()).to.deep.equal(expectedDate.getUTCMonth()) + expect(date.getUTCFullYear()).to.deep.equal(expectedDate.getUTCFullYear()) +}) diff --git a/tests/support/component.ts b/tests/support/component.ts index a2a7d1b06..4b23b3cc2 100644 --- a/tests/support/component.ts +++ b/tests/support/component.ts @@ -33,8 +33,12 @@ declare global { interface Chainable { mount: typeof mount customMount: typeof mount + loginAsAdmin(go?: string): Chainable> + getApiToken(): Chainable + + compareDate(date: Date, expectedDate: Date): Chainable } } } From 7679af950d9a62902338807065787976094d3bdb Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 4 Oct 2023 19:00:53 -0400 Subject: [PATCH 7/9] fix: remove priveUrl from withAlerts() --- src/dataset/domain/models/Dataset.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 9bff2f11d..901bf5aa5 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -276,7 +276,7 @@ export class Dataset { public readonly privateUrl?: string ) { this.withLabels() - this.withAlerts(privateUrl) + this.withAlerts() } withLabels() { @@ -324,7 +324,7 @@ export class Dataset { } } - private withAlerts(privateUrl?: string): void { + private withAlerts(): void { if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) { this.alerts.push( new DatasetAlert('warning', DatasetAlertMessageKey.DRAFT_VERSION, undefined, 'Info') @@ -341,8 +341,8 @@ export class Dataset { ) ) } - if (privateUrl) { - const dynamicFields = [privateUrl] + if (this.privateUrl) { + const dynamicFields = [this.privateUrl] this.alerts.push( new DatasetAlert( 'info', From d9e465cd16803e17a9ab21beef4c7bc5528ca6b2 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 4 Oct 2023 19:26:37 -0400 Subject: [PATCH 8/9] fix: add requestedVersion to dataset data --- .../integration/datasets/DatasetJSDataverseRepository.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index a548c5e4b..3b2139087 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -75,7 +75,8 @@ const datasetData = (persistentId: string, versionId: number) => { id: versionId, majorNumber: undefined, minorNumber: undefined, - publishingStatus: 'draft' + publishingStatus: 'draft', + requestedVersion: undefined } } } From 77876210c1626e9c8d87bbaa7679eb54ff6dc342 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 5 Oct 2023 08:01:53 -0400 Subject: [PATCH 9/9] fix: locale of embargo date string --- .../file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx index e7e5358ba..4c61171b9 100644 --- a/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate.tsx @@ -17,7 +17,7 @@ export function FileEmbargoDate({ embargo, publishingStatus }: FileEmbargoDatePr
{t(embargoTypeOfDate(embargo.isActive, publishingStatus))}{' '} - {embargo.dateAvailable.toLocaleDateString('en-US', { + {embargo.dateAvailable.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, { year: 'numeric', month: 'short', day: 'numeric'