Skip to content

Commit

Permalink
feat(DatasetPreviewMother): mock randomly deaccessioned of draft data…
Browse files Browse the repository at this point in the history
…sets previews
  • Loading branch information
MellyGray committed Dec 14, 2023
1 parent d847894 commit 6da0f0a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/stories/dataset/DatasetMockRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class DatasetMockRepository implements DatasetRepository {
getAll(paginationInfo: DatasetPaginationInfo): Promise<DatasetPreview[]> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(DatasetPreviewMother.createMany(paginationInfo.pageSize))
resolve(DatasetPreviewMother.createManyRealistic(paginationInfo.pageSize))
}, 1000)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/stories/home/datasets-list/DatasetCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default meta
type Story = StoryObj<typeof DatasetCard>

export const Default: Story = {
render: () => <DatasetCard dataset={DatasetPreviewMother.create()} />
render: () => <DatasetCard dataset={DatasetPreviewMother.createDraft()} />
}

export const Deaccessioned: Story = {
Expand Down
8 changes: 8 additions & 0 deletions tests/component/dataset/domain/models/DatasetMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -213,6 +217,10 @@ export class DatasetLabelsMother {

export class DatasetCitationMother {
static create(): string {
return 'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/0YFWKL" target="_blank">https://doi.org/10.5072/FK2/0YFWKL</a>, Root, V1'
}

static createDraft(): string {
return 'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/0YFWKL" target="_blank">https://doi.org/10.5072/FK2/0YFWKL</a>, Root, DRAFT VERSION'
}

Expand Down
18 changes: 17 additions & 1 deletion tests/component/dataset/domain/models/DatasetPreviewMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>): 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(),
Expand All @@ -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 })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<DatasetCard dataset={dataset} />)

cy.findByText(dataset.title).should('exist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<DatasetCardInfo dataset={dataset} />)

cy.findByText(DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)).should('exist')
Expand Down

0 comments on commit 6da0f0a

Please sign in to comment.