diff --git a/package-lock.json b/package-lock.json index a73e91aca..ba0c0c1ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr99.c36f1db", + "@iqss/dataverse-client-javascript": "2.0.0-pr107.228a37e", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3589,9 +3589,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-pr99.c36f1db", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr99.c36f1db/3f49037b14e53295c39ce787cce53f20b2558ba6", - "integrity": "sha512-KzMVzB420eKKaOuwDEpvAB/k1RrW3Le/ZJcVtjxFk/Wvxov2Jl1npbwy4SXQWasEXaJWslohn2KRkBfBDoTHTQ==", + "version": "2.0.0-pr107.228a37e", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr107.228a37e/e3abc35bae153cce761c0297c7c59c4df0d3e0a9", + "integrity": "sha512-mqx7vvRObgdLZz/fZYscQ9AQzhxd2xGUcnLLMQFL8boQldakNIwQXSX2wTZXC5Ht+BKigejNhC8L8/UpL92fxQ==", "license": "MIT", "dependencies": { "@types/node": "^18.15.11", diff --git a/package.json b/package.json index af7cf0bdb..6c97e6688 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr99.c36f1db", + "@iqss/dataverse-client-javascript": "2.0.0-pr107.228a37e", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 96c56d448..b0f465d6b 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -252,52 +252,57 @@ export class DatasetVersion { public readonly latestVersionPublishingStatus: DatasetPublishingStatus, public readonly someDatasetVersionHasBeenReleased: boolean ) { - this.withLabels() + this.createLabels() } - withLabels() { - this.withStatusLabel() - this.withVersionLabel() + createLabels() { + const statusLabels = this.createStatusLabels() + const versionLabels = this.createVersionNumberLabel() + this.labels.push(...statusLabels, ...versionLabels) } - private withStatusLabel(): void { + createStatusLabels(): DatasetLabel[] { + const labels: DatasetLabel[] = [] + if (this.publishingStatus === DatasetPublishingStatus.DRAFT) { - this.labels.push( - new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT) - ) + labels.push(new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT)) } if (!this.someDatasetVersionHasBeenReleased) { - this.labels.push( + labels.push( new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED) ) } if (this.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) { - this.labels.push( + labels.push( new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED) ) } if (this.publishingStatus === DatasetPublishingStatus.EMBARGOED) { - this.labels.push( + labels.push( new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED) ) } if (this.isInReview) { - this.labels.push( + labels.push( new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW) ) } + + return labels } - private withVersionLabel(): void { + createVersionNumberLabel(): DatasetLabel[] { + const labels: DatasetLabel[] = [] if (this.publishingStatus === DatasetPublishingStatus.RELEASED) { - this.labels.push( + labels.push( new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.number.toString()}`) ) } + return labels } build(): DatasetVersion { diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index bd7d8dbdb..817ec6ff1 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -4,10 +4,8 @@ import { DatasetMetadataBlock as JSDatasetMetadataBlock, DatasetMetadataBlocks as JSDatasetMetadataBlocks, DatasetMetadataFields as JSDatasetMetadataFields, - DatasetUserPermissions as JSDatasetPermissions, - DatasetVersionInfo as JSDatasetVersionInfo + DatasetUserPermissions as JSDatasetPermissions } from '@iqss/dataverse-client-javascript' -import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset' import { Dataset, DatasetDownloadUrls, @@ -17,17 +15,16 @@ import { DatasetMetadataBlocks, DatasetMetadataFields, DatasetPermissions, - DatasetPublishingStatus, DatasetVersion, MetadataBlockName, - PrivateUrl, - DatasetVersionNumber + PrivateUrl } from '../../domain/models/Dataset' import { FileDownloadMode, FileDownloadSize, FileSizeUnit } from '../../../files/domain/models/FilePreview' +import { JSDatasetVersionMapper } from './JSDatasetVersionMapper' export class JSDatasetMapper { static toDataset( @@ -41,10 +38,10 @@ export class JSDatasetMapper { requestedVersion?: string, privateUrl?: PrivateUrl ): Dataset { - const version = JSDatasetMapper.toVersion( + const version = JSDatasetVersionMapper.toVersion( jsDataset.versionId, jsDataset.versionInfo, - jsDataset.metadataBlocks, + JSDatasetMapper.toDatasetTitle(jsDataset.metadataBlocks), jsDatasetCitation ) return new Dataset.Builder( @@ -74,49 +71,10 @@ export class JSDatasetMapper { ).build() } - static toVersion( - jDatasetVersionId: number, - jsDatasetVersionInfo: JSDatasetVersionInfo, - jsDatasetMetadataBlocks: JSDatasetMetadataBlocks, - jsDatasetCitation: string - ): DatasetVersion { - return new DatasetVersion.Builder( - jDatasetVersionId, - JSDatasetMapper.toDatasetTitle(jsDatasetMetadataBlocks), - JSDatasetMapper.toVersionNumber(jsDatasetVersionInfo), - JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), - jsDatasetCitation, - true, // TODO Connect with dataset version isLatest - false, // TODO Connect with dataset version isInReview - JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), - JSDatasetMapper.toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo) - ) - } - static toDatasetTitle(jsDatasetMetadataBlocks: JSDatasetMetadataBlocks): string { return jsDatasetMetadataBlocks[0].fields.title } - static toVersionNumber(jsDatasetVersionInfo: JSDatasetVersionInfo): DatasetVersionNumber { - return new DatasetVersionNumber( - jsDatasetVersionInfo.majorNumber, - jsDatasetVersionInfo.minorNumber - ) - } - - static toStatus(jsDatasetVersionState: JSDatasetVersionState): DatasetPublishingStatus { - switch (jsDatasetVersionState) { - case JSDatasetVersionState.DRAFT: - return DatasetPublishingStatus.DRAFT - case JSDatasetVersionState.DEACCESSIONED: - return DatasetPublishingStatus.DEACCESSIONED - case JSDatasetVersionState.RELEASED: - return DatasetPublishingStatus.RELEASED - default: - return DatasetPublishingStatus.DRAFT - } - } - static toSummaryFields( jsDatasetMetadataBlocks: JSDatasetMetadataBlocks, summaryFieldsNames: string[] @@ -228,13 +186,6 @@ export class JSDatasetMapper { } } - static toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean { - return ( - jsDatasetVersionInfo.releaseTime !== undefined && - !isNaN(jsDatasetVersionInfo.releaseTime.getTime()) - ) - } - static toDatasetPermissions(jsDatasetPermissions: JSDatasetPermissions): DatasetPermissions { return { canDownloadFiles: true, // TODO: connect with js-dataverse @@ -245,6 +196,7 @@ export class JSDatasetMapper { canDeleteDataset: jsDatasetPermissions.canManageDatasetPermissions } } + static toLocks(jsDatasetLocks: JSDatasetLock[]): DatasetLock[] { return jsDatasetLocks.map((jsDatasetLock) => { return { diff --git a/src/dataset/infrastructure/mappers/JSDatasetPreviewMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetPreviewMapper.ts new file mode 100644 index 000000000..e6e69b930 --- /dev/null +++ b/src/dataset/infrastructure/mappers/JSDatasetPreviewMapper.ts @@ -0,0 +1,25 @@ +import { DatasetPreview as JSDatasetPreview } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/DatasetPreview' +import { DatasetPreview } from '../../domain/models/DatasetPreview' +import { DatasetVersionInfo as JSDatasetVersionInfo } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset' +import { JSDatasetVersionMapper } from './JSDatasetVersionMapper' + +export class JSDatasetPreviewMapper { + static toDatasetPreview(jsDatasetPreview: JSDatasetPreview): DatasetPreview { + return new DatasetPreview( + jsDatasetPreview.persistentId, + JSDatasetVersionMapper.toVersion( + jsDatasetPreview.versionId, + jsDatasetPreview.versionInfo, + jsDatasetPreview.title, + jsDatasetPreview.citation + ), + JSDatasetPreviewMapper.toPreviewDate(jsDatasetPreview.versionInfo), + jsDatasetPreview.description, + undefined // TODO: get dataset thumbnail from Dataverse https://github.com/IQSS/dataverse-frontend/issues/203 + ) + } + + static toPreviewDate(jsVersionInfo: JSDatasetVersionInfo): Date { + return jsVersionInfo.releaseTime ? jsVersionInfo.releaseTime : jsVersionInfo.createTime + } +} diff --git a/src/dataset/infrastructure/mappers/JSDatasetVersionMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetVersionMapper.ts new file mode 100644 index 000000000..946ef0e70 --- /dev/null +++ b/src/dataset/infrastructure/mappers/JSDatasetVersionMapper.ts @@ -0,0 +1,56 @@ +import { + DatasetVersionInfo as JSDatasetVersionInfo, + DatasetVersionState as JSDatasetVersionState +} from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset' +import { + DatasetPublishingStatus, + DatasetVersion, + DatasetVersionNumber +} from '../../domain/models/Dataset' +export class JSDatasetVersionMapper { + static toVersion( + jDatasetVersionId: number, + jsDatasetVersionInfo: JSDatasetVersionInfo, + jsDatasetTitle: string, + jsDatasetCitation: string + ): DatasetVersion { + return new DatasetVersion.Builder( + jDatasetVersionId, + jsDatasetTitle, + this.toVersionNumber(jsDatasetVersionInfo), + this.toStatus(jsDatasetVersionInfo.state), + jsDatasetCitation, + true, // TODO Connect with dataset version isLatest + false, // TODO Connect with dataset version isInReview + this.toStatus(jsDatasetVersionInfo.state), + this.toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo) + ) + } + + static toVersionNumber(jsDatasetVersionInfo: JSDatasetVersionInfo): DatasetVersionNumber { + return new DatasetVersionNumber( + jsDatasetVersionInfo.majorNumber, + jsDatasetVersionInfo.minorNumber + ) + } + + static toStatus(jsDatasetVersionState: JSDatasetVersionState): DatasetPublishingStatus { + switch (jsDatasetVersionState) { + case JSDatasetVersionState.DRAFT: + return DatasetPublishingStatus.DRAFT + case JSDatasetVersionState.DEACCESSIONED: + return DatasetPublishingStatus.DEACCESSIONED + case JSDatasetVersionState.RELEASED: + return DatasetPublishingStatus.RELEASED + default: + return DatasetPublishingStatus.DRAFT + } + } + + static toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean { + return ( + jsDatasetVersionInfo.releaseTime !== undefined && + !isNaN(jsDatasetVersionInfo.releaseTime.getTime()) + ) + } +} diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index b5ddf718c..ca5794a6b 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -2,9 +2,11 @@ import { DatasetRepository } from '../../domain/repositories/DatasetRepository' import { Dataset } from '../../domain/models/Dataset' import { getDataset, + getAllDatasetPreviews, getDatasetCitation, getDatasetSummaryFieldNames, Dataset as JSDataset, + DatasetPreview as JSDatasetPreview, DatasetUserPermissions as JSDatasetPermissions, getPrivateUrlDataset, getPrivateUrlDatasetCitation, @@ -13,32 +15,32 @@ import { getDatasetLocks, DatasetLock as JSDatasetLock, getDatasetFilesTotalDownloadSize, - FileDownloadSizeMode + FileDownloadSizeMode, + DatasetPreviewSubset } from '@iqss/dataverse-client-javascript' import { JSDatasetMapper } from '../mappers/JSDatasetMapper' import { TotalDatasetsCount } from '../../domain/models/TotalDatasetsCount' import { DatasetPaginationInfo } from '../../domain/models/DatasetPaginationInfo' import { DatasetPreview } from '../../domain/models/DatasetPreview' -import { DatasetPreviewMother } from '../../../../tests/component/dataset/domain/models/DatasetPreviewMother' +import { JSDatasetPreviewMapper } from '../mappers/JSDatasetPreviewMapper' const includeDeaccessioned = true + export class DatasetJSDataverseRepository implements DatasetRepository { - // eslint-disable-next-line unused-imports/no-unused-vars getAll(paginationInfo: DatasetPaginationInfo): Promise { - // TODO - Implement using the js-dataverse-client - return new Promise((resolve) => { - setTimeout(() => { - resolve(DatasetPreviewMother.createManyRealistic(10)) - }, 1000) - }) + return getAllDatasetPreviews + .execute(paginationInfo.pageSize, paginationInfo.offset) + .then((subset: DatasetPreviewSubset) => { + return subset.datasetPreviews.map((datasetPreview: JSDatasetPreview) => + JSDatasetPreviewMapper.toDatasetPreview(datasetPreview) + ) + }) } getTotalDatasetsCount(): Promise { - // TODO - Implement using the js-dataverse-client - return new Promise((resolve) => { - setTimeout(() => { - resolve(200) - }, 1000) + // TODO: refactor this so we don't make the same call twice? + return getAllDatasetPreviews.execute(10, 0).then((subset: DatasetPreviewSubset) => { + return subset.totalDatasetCount }) } @@ -53,7 +55,11 @@ export class DatasetJSDataverseRepository implements DatasetRepository { Promise.all([ jsDataset, getDatasetSummaryFieldNames.execute(), - getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)), + getDatasetCitation.execute( + jsDataset.id, + this.versionToVersionId(version), + includeDeaccessioned + ), getDatasetUserPermissions.execute(jsDataset.id), getDatasetLocks.execute(jsDataset.id), getDatasetFilesTotalDownloadSize.execute( diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index b64bbb683..1e4053c36 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -34,14 +34,13 @@ export class FileJSDataverseRepository implements FileRepository { paginationInfo: FilePaginationInfo = new FilePaginationInfo(), criteria: FileCriteria = new FileCriteria() ): Promise { - const jsPagination = DomainFileMapper.toJSPagination(paginationInfo) return getDatasetFiles .execute( datasetPersistentId, datasetVersion.number.toString(), includeDeaccessioned, - jsPagination.limit, - jsPagination.offset, + paginationInfo.pageSize, + paginationInfo.offset, DomainFileMapper.toJSFileSearchCriteria(criteria), DomainFileMapper.toJSFileOrderCriteria(criteria.sortBy) ) diff --git a/src/files/infrastructure/mappers/DomainFileMapper.ts b/src/files/infrastructure/mappers/DomainFileMapper.ts index ce4eca2be..e87c38b40 100644 --- a/src/files/infrastructure/mappers/DomainFileMapper.ts +++ b/src/files/infrastructure/mappers/DomainFileMapper.ts @@ -10,19 +10,8 @@ import { FileOrderCriteria as JSFileOrderCriteria } from '@iqss/dataverse-client-javascript' import { FileType } from '../../domain/models/FilePreview' -import { FilePaginationInfo } from '../../domain/models/FilePaginationInfo' export class DomainFileMapper { - static toJSPagination(paginationInfo: FilePaginationInfo): { - limit?: number - offset?: number - } { - return { - limit: paginationInfo.pageSize, - offset: (paginationInfo.page - 1) * paginationInfo.pageSize - } - } - static toJSFileSearchCriteria(criteria: FileCriteria): JSFileSearchCriteria { return new JSFileSearchCriteria( this.toJSContentType(criteria.filterByType), diff --git a/src/stories/dataset/Dataset.stories.tsx b/src/stories/dataset/Dataset.stories.tsx index 85fe96332..e28279c4d 100644 --- a/src/stories/dataset/Dataset.stories.tsx +++ b/src/stories/dataset/Dataset.stories.tsx @@ -16,6 +16,7 @@ import { WithDatasetNotFound } from './WithDatasetNotFound' import { WithDatasetLoading } from './WithDatasetLoading' import { WithLoggedInUser } from '../WithLoggedInUser' import { WithAlerts } from '../WithAlerts' +import { WithDeaccessionedDataset } from './WithDeaccessionedDataset' import { WithNotImplementedModal } from '../WithNotImplementedModal' const meta: Meta = { @@ -46,6 +47,10 @@ export const DraftWithAllDatasetPermissions: Story = { ], render: () => } +export const Deaccessioned: Story = { + decorators: [WithLayout, WithDeaccessionedDataset, WithLoggedInUser, WithFilePermissionsGranted], + render: () => +} export const LoggedInAsOwner: Story = { decorators: [ WithDataset, diff --git a/src/stories/dataset/WithDeaccessionedDataset.tsx b/src/stories/dataset/WithDeaccessionedDataset.tsx new file mode 100644 index 000000000..0f8235cd2 --- /dev/null +++ b/src/stories/dataset/WithDeaccessionedDataset.tsx @@ -0,0 +1,35 @@ +import { StoryFn } from '@storybook/react' +import { DatasetProvider } from '../../sections/dataset/DatasetProvider' +import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository' +import { Dataset } from '../../dataset/domain/models/Dataset' +import { + DatasetMother, + DatasetVersionMother +} from '../../../tests/component/dataset/domain/models/DatasetMother' + +export const WithDeaccessionedDataset = (Story: StoryFn) => { + const datasetRepository = {} as DatasetRepository + datasetRepository.getByPersistentId = ( + // eslint-disable-next-line unused-imports/no-unused-vars + persistentId: string, + // eslint-disable-next-line unused-imports/no-unused-vars + version?: string | undefined + ): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + resolve( + DatasetMother.createRealistic({ + version: DatasetVersionMother.createDeaccessioned() + }) + ) + }, 1000) + }) + } + return ( + + + + ) +} diff --git a/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx b/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx index d6845f7ac..1daec9754 100644 --- a/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx @@ -8,11 +8,12 @@ import { DatasetPermissionsMother, DatasetVersionMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' +import { WithLoggedInUser } from '../../WithLoggedInUser' const meta: Meta = { title: 'Sections/Dataset Page/DatasetActionButtons', component: DatasetActionButtons, - decorators: [WithI18next, WithSettings], + decorators: [WithI18next, WithSettings, WithLoggedInUser], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } diff --git a/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx b/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx index cbc01d0d3..143a1ea9a 100644 --- a/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx @@ -7,11 +7,12 @@ import { DatasetVersionMother } from '../../../../../tests/component/dataset/domain/models/DatasetMother' import { PublishDatasetMenu } from '../../../../sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu' +import { WithLoggedInUser } from '../../../WithLoggedInUser' const meta: Meta = { title: 'Sections/Dataset Page/DatasetActionButtons/PublishDatasetMenu', component: PublishDatasetMenu, - decorators: [WithI18next, WithSettings], + decorators: [WithI18next, WithSettings, WithLoggedInUser], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index d79142ed1..8c584cf87 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -155,8 +155,7 @@ describe('Dataset', () => { }) }) - it.skip('successfully loads a dataset deaccessioned', () => { - // TODO - Implement once the getDatasetCitation includes deaccessioned datasets + it('successfully loads a dataset deaccessioned', () => { cy.wrap(DatasetHelper.create()) // eslint-disable-next-line @typescript-eslint/no-unsafe-argument .then((dataset) => Promise.all([dataset, DatasetHelper.publish(dataset.persistentId)])) diff --git a/tests/e2e-integration/e2e/sections/home/Home.spec.ts b/tests/e2e-integration/e2e/sections/home/Home.spec.ts index 1f85bc181..b40e1897f 100644 --- a/tests/e2e-integration/e2e/sections/home/Home.spec.ts +++ b/tests/e2e-integration/e2e/sections/home/Home.spec.ts @@ -1,9 +1,30 @@ +import { DatasetHelper } from '../../../shared/datasets/DatasetHelper' +import { TestsUtils } from '../../../shared/TestsUtils' +import { faker } from '@faker-js/faker' + describe('Home Page', () => { + const title = faker.lorem.sentence() + before(() => { + TestsUtils.setup() + }) + + beforeEach(() => {}) it('successfully loads', () => { cy.visit('/spa') cy.findAllByText(/Root/i).should('exist') }) + it('goes to dataset page from list', () => { + void DatasetHelper.destroyAll() + void DatasetHelper.createWithTitle(title) + TestsUtils.login() + cy.findByText(/Dataverse Admin/i).should('exist') + cy.findByText(title).should('be.visible') + cy.findByText(title).click({ force: true }) + cy.url().should('include', 'persistentId') + cy.findAllByText(title).should('be.visible') + }) + it('log in Dataverse Admin user', () => { cy.loginAsAdmin('/spa') diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index dcd078695..dcdbcefd6 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -15,6 +15,7 @@ import { FileDownloadSize, FileSizeUnit } from '../../../../src/files/domain/models/FilePreview' +import { DatasetPaginationInfo } from '../../../../src/dataset/domain/models/DatasetPaginationInfo' chai.use(chaiAsPromised) const expect = chai.expect @@ -125,7 +126,9 @@ const datasetData = (persistentId: string, versionId: number) => { const datasetRepository = new DatasetJSDataverseRepository() describe('Dataset JSDataverse Repository', () => { before(() => TestsUtils.setup()) - beforeEach(() => TestsUtils.login()) + beforeEach(() => { + TestsUtils.login() + }) it('gets the dataset by persistentId', async () => { const datasetResponse = await DatasetHelper.create() @@ -284,6 +287,29 @@ describe('Dataset JSDataverse Repository', () => { expect(dataset.metadataBlocks[0].fields.citationDate).not.to.exist }) }) + it('gets the total dataset count', async () => { + await DatasetHelper.destroyAll() + await datasetRepository.getTotalDatasetsCount().then((count) => { + expect(count).to.equal(0) + }) + await DatasetHelper.createAndPublish() + + await datasetRepository.getTotalDatasetsCount().then((count) => { + expect(count).to.equal(1) + }) + }) + it('gets the DatasetPreview', async () => { + await DatasetHelper.destroyAll() + + const datasetResponse = await DatasetHelper.createAndPublish() + const paginationInfo = new DatasetPaginationInfo(1, 20) + + await datasetRepository.getAll(paginationInfo).then((datasetPreview) => { + expect(datasetPreview.length).to.equal(1) + expect(datasetPreview[0].version.title).to.equal("Darwin's Finches") + expect(datasetPreview[0].persistentId).to.equal(datasetResponse.persistentId) + }) + }) it.skip('gets the dataset by persistentId when the dataset is deaccessioned', async () => { // TODO - Implement once the getDatasetCitation includes deaccessioned datasets diff --git a/tests/e2e-integration/shared/datasets/DatasetHelper.ts b/tests/e2e-integration/shared/datasets/DatasetHelper.ts index e46519395..80a92bd88 100644 --- a/tests/e2e-integration/shared/datasets/DatasetHelper.ts +++ b/tests/e2e-integration/shared/datasets/DatasetHelper.ts @@ -2,6 +2,7 @@ import newDatasetData from '../../fixtures/dataset-finch1.json' import { DataverseApiHelper } from '../DataverseApiHelper' import { FileData } from '../files/FileHelper' import { DatasetLockReason } from '../../../../src/dataset/domain/models/Dataset' +import { TestsUtils } from '../TestsUtils' export interface DatasetResponse { persistentId: string @@ -17,6 +18,30 @@ export class DatasetHelper extends DataverseApiHelper { static async create(): Promise { return this.request(`/dataverses/root/datasets`, 'POST', newDatasetData) } + static async createWithTitle(title: string): Promise { + newDatasetData.datasetVersion.metadataBlocks.citation.fields[0].value = title + return this.request(`/dataverses/root/datasets`, 'POST', newDatasetData) + } + static async destroy(persistentId: string): Promise { + return this.request( + `/datasets/:persistentId/destroy/?persistentId=${persistentId}`, + 'DELETE' + ) + } + static async createAndPublish(): Promise { + const datasetResponse = await DatasetHelper.create() + await DatasetHelper.publish(datasetResponse.persistentId) + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) + return datasetResponse + } + static async destroyAll(): Promise { + const response = await this.request<{ + items: Array<{ global_id: string }> + }>('/search?q=*&type=dataset&sort=date&order=desc&per_page=500&start=0', 'GET') + for (const dataset of response.items as Array<{ global_id: string }>) { + await this.destroy(dataset.global_id) + } + } static async publish(persistentId: string): Promise<{ status: string