From 6da0f0afffc77524447d5eab35a2b2846b496b95 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 14 Dec 2023 13:45:07 +0100 Subject: [PATCH] feat(DatasetPreviewMother): mock randomly deaccessioned of draft datasets previews --- .../DatasetJSDataverseRepository.ts | 2 +- src/stories/dataset/DatasetMockRepository.ts | 2 +- .../home/datasets-list/DatasetCard.stories.tsx | 2 +- .../dataset/domain/models/DatasetMother.ts | 8 ++++++++ .../domain/models/DatasetPreviewMother.ts | 18 +++++++++++++++++- .../dataset-card/DatasetCard.spec.tsx | 2 +- .../dataset-card/DatasetCardInfo.spec.tsx | 2 +- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index 385099768..59ea3c23a 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -23,7 +23,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { // TODO - Implement using the js-dataverse-client return new Promise((resolve) => { setTimeout(() => { - resolve(DatasetPreviewMother.createMany(10)) + resolve(DatasetPreviewMother.createManyRealistic(10)) }, 1000) }) } diff --git a/src/stories/dataset/DatasetMockRepository.ts b/src/stories/dataset/DatasetMockRepository.ts index 263d789a9..9ffa083ed 100644 --- a/src/stories/dataset/DatasetMockRepository.ts +++ b/src/stories/dataset/DatasetMockRepository.ts @@ -11,7 +11,7 @@ export class DatasetMockRepository implements DatasetRepository { getAll(paginationInfo: DatasetPaginationInfo): Promise { return new Promise((resolve) => { setTimeout(() => { - resolve(DatasetPreviewMother.createMany(paginationInfo.pageSize)) + resolve(DatasetPreviewMother.createManyRealistic(paginationInfo.pageSize)) }, 1000) }) } diff --git a/src/stories/home/datasets-list/DatasetCard.stories.tsx b/src/stories/home/datasets-list/DatasetCard.stories.tsx index 81d3c7170..26f6af0da 100644 --- a/src/stories/home/datasets-list/DatasetCard.stories.tsx +++ b/src/stories/home/datasets-list/DatasetCard.stories.tsx @@ -13,7 +13,7 @@ export default meta type Story = StoryObj export const Default: Story = { - render: () => + render: () => } export const Deaccessioned: Story = { diff --git a/tests/component/dataset/domain/models/DatasetMother.ts b/tests/component/dataset/domain/models/DatasetMother.ts index 40a07a2e6..6c2a01f28 100644 --- a/tests/component/dataset/domain/models/DatasetMother.ts +++ b/tests/component/dataset/domain/models/DatasetMother.ts @@ -192,6 +192,10 @@ export class DatasetLockMother { export class DatasetLabelsMother { static create(): DatasetLabel[] { + return [{ value: 'Version 1.0', semanticMeaning: DatasetLabelSemanticMeaning.FILE }] + } + + static createDraft(): DatasetLabel[] { return [ { value: DatasetLabelValue.UNPUBLISHED, @@ -213,6 +217,10 @@ export class DatasetLabelsMother { export class DatasetCitationMother { static create(): string { + return 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/0YFWKL, Root, V1' + } + + static createDraft(): string { return 'Finch, Fiona, 2023, "Darwin\'s Finches", https://doi.org/10.5072/FK2/0YFWKL, Root, DRAFT VERSION' } diff --git a/tests/component/dataset/domain/models/DatasetPreviewMother.ts b/tests/component/dataset/domain/models/DatasetPreviewMother.ts index 458f68bff..83e080ff9 100644 --- a/tests/component/dataset/domain/models/DatasetPreviewMother.ts +++ b/tests/component/dataset/domain/models/DatasetPreviewMother.ts @@ -7,12 +7,16 @@ export class DatasetPreviewMother { return Array.from({ length: count }, () => this.create()) } + static createManyRealistic(count: number): DatasetPreview[] { + return Array.from({ length: count }, () => this.createRealistic()) + } + static create(props?: Partial): DatasetPreview { const datasetPreview = { persistentId: faker.datatype.uuid(), title: faker.lorem.sentence(), labels: DatasetLabelsMother.create(), - isDeaccessioned: false, + isDeaccessioned: faker.datatype.boolean(), thumbnail: faker.datatype.boolean() ? faker.image.imageUrl() : undefined, releaseOrCreateDate: faker.date.past(), version: DatasetVersionMother.create(), @@ -34,6 +38,18 @@ export class DatasetPreviewMother { ) } + static createRealistic(): DatasetPreview { + return faker.datatype.boolean() ? this.createDraft() : this.createDeaccessioned() + } + + static createDraft(): DatasetPreview { + return this.create({ + isDeaccessioned: false, + labels: DatasetLabelsMother.createDraft(), + citation: DatasetCitationMother.createDraft() + }) + } + static createWithThumbnail(): DatasetPreview { return this.create({ thumbnail: faker.image.imageUrl(), isDeaccessioned: false }) } diff --git a/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx b/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx index 4bebfacca..d0b2750f6 100644 --- a/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx +++ b/tests/component/sections/home/datasets-list/dataset-card/DatasetCard.spec.tsx @@ -5,7 +5,7 @@ import styles from '../../../../../../src/sections/home/datasets-list/dataset-ca describe('DatasetCard', () => { it('should render the card', () => { - const dataset = DatasetPreviewMother.create() + const dataset = DatasetPreviewMother.createDraft() cy.customMount() cy.findByText(dataset.title).should('exist') diff --git a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx index 222c45f1e..5563fe412 100644 --- a/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx +++ b/tests/component/sections/home/datasets-list/dataset-card/DatasetCardInfo.spec.tsx @@ -5,7 +5,7 @@ import { DatasetCardInfo } from '../../../../../../src/sections/home/datasets-li describe('DatasetCardInfo', () => { it('should render the dataset info', () => { - const dataset = DatasetPreviewMother.create() + const dataset = DatasetPreviewMother.createDraft() cy.customMount() cy.findByText(DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)).should('exist')