Skip to content

Commit

Permalink
refactor: move title to DatasetVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 15, 2023
1 parent 37180ad commit 62b69b2
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 69 deletions.
7 changes: 2 additions & 5 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,14 @@ export enum DatasetNonNumericVersion {
export class DatasetVersion {
constructor(
public readonly id: number,
public readonly title: string,
public readonly publishingStatus: DatasetPublishingStatus,
public readonly isLatest: boolean,
public readonly isInReview: boolean,
public readonly latestVersionStatus: DatasetPublishingStatus,
public readonly citation: string,
public readonly majorNumber?: number,
// requestedVersion will be set if the user requested a version that did not exist.
public readonly majorNumber?: number,
public readonly minorNumber?: number,
public readonly requestedVersion?: string
) {}
Expand Down Expand Up @@ -291,10 +292,6 @@ export class Dataset {
public readonly fileDownloadSizes?: FileDownloadSize[]
) {}

public getTitle(): string {
return this.metadataBlocks[0].fields.title
}

public checkIsLockedFromPublishing(userPersistentId: string): boolean {
return this.checkIsLockedFromEdits(userPersistentId)
}
Expand Down
3 changes: 3 additions & 0 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class JSDatasetMapper {
const version = JSDatasetMapper.toVersion(
jsDataset.versionId,
jsDataset.versionInfo,
jsDataset.metadataBlocks,
jsDatasetCitation,
requestedVersion
)
Expand Down Expand Up @@ -66,11 +67,13 @@ export class JSDatasetMapper {
static toVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo,
jsDatasetMetadataBlocks: JSDatasetMetadataBlocks,
jsDatasetCitation: string,
requestedVersion?: string
): DatasetVersion {
return new DatasetVersion(
jDatasetVersionId,
jsDatasetMetadataBlocks[0].fields.title,
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
true,
false,
Expand Down
8 changes: 2 additions & 6 deletions src/sections/dataset/Dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ export function Dataset({ fileRepository }: DatasetProps) {
</div>

<header className={styles.header}>
<h1>{dataset.getTitle()}</h1>
<h1>{dataset.version.title}</h1>
<DatasetLabels labels={dataset.labels} />
</header>
<div className={styles.container}>
<Row>
<Col sm={9}>
<DatasetCitation
title={dataset.getTitle()}
thumbnail={dataset.thumbnail}
version={dataset.version}
/>
<DatasetCitation thumbnail={dataset.thumbnail} version={dataset.version} />
</Col>
<Col sm={3}>
<DatasetActionButtons dataset={dataset} />
Expand Down
5 changes: 2 additions & 3 deletions src/sections/dataset/dataset-citation/DatasetCitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { CitationThumbnail } from './CitationThumbnail'

interface DatasetCitationProps {
thumbnail?: string
title: string
version: DatasetVersion
}

export function DatasetCitation({ thumbnail, title, version }: DatasetCitationProps) {
export function DatasetCitation({ thumbnail, version }: DatasetCitationProps) {
const { t } = useTranslation('dataset')
return (
<>
Expand All @@ -25,7 +24,7 @@ export function DatasetCitation({ thumbnail, title, version }: DatasetCitationPr
<Col sm={2}>
<CitationThumbnail
thumbnail={thumbnail}
title={title}
title={version.title}
publishingStatus={version.publishingStatus}
/>
</Col>
Expand Down
5 changes: 5 additions & 0 deletions src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const DraftVersion: Story = {
const dataset = DatasetMother.createRealistic({
version: new DatasetVersion(
1,
'',
DatasetPublishingStatus.DRAFT,
true,
false,
Expand All @@ -80,6 +81,7 @@ export const VersionNotFound: Story = {
const dataset = DatasetMother.createRealistic({
version: new DatasetVersion(
1,
'',
DatasetPublishingStatus.RELEASED,
true,
false,
Expand All @@ -103,6 +105,7 @@ export const VersionNotFoundShowDraft: Story = {
const dataset = DatasetMother.createRealistic({
version: new DatasetVersion(
1,
'',
DatasetPublishingStatus.DRAFT,
true,
false,
Expand All @@ -126,6 +129,7 @@ export const SharePrivateUrl: Story = {
const dataset = DatasetMother.createRealistic({
version: new DatasetVersion(
1,
'',
DatasetPublishingStatus.RELEASED,
true,
false,
Expand Down Expand Up @@ -153,6 +157,7 @@ export const UsePrivateUrl: Story = {
const dataset = DatasetMother.createRealistic({
version: new DatasetVersion(
1,
'',
DatasetPublishingStatus.RELEASED,
true,
false,
Expand Down
25 changes: 8 additions & 17 deletions src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type Story = StoryObj<typeof DatasetCitation>

export const Default: Story = {
render: () => {
const dataset = DatasetMother.createRealistic()
const version = DatasetVersionMother.createRealistic()
return (
<div>
<br></br>
<br></br>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
<DatasetCitation version={version} />
</div>
)
}
Expand All @@ -36,40 +36,31 @@ export const WithThumbnail: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation
title={dataset.getTitle()}
thumbnail={dataset.thumbnail}
version={dataset.version}
/>
<DatasetCitation thumbnail={dataset.thumbnail} version={dataset.version} />
</div>
)
}
}

export const DraftVersion: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({
version: DatasetVersionMother.createDraft()
})

const version = DatasetVersionMother.createDraft()
/*
Includes extra breaks, so you can see the DRAFT tooltip message
*/
return (
<div>
<br></br>
<br></br>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
<DatasetCitation version={version} />
</div>
)
}
}

export const Deaccessioned: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({
version: DatasetVersionMother.createDeaccessioned()
})
const version = DatasetVersionMother.createDeaccessioned()

/*
Includes extra breaks, so you can see the DRAFT tooltip message
Expand All @@ -78,7 +69,7 @@ export const Deaccessioned: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
<DatasetCitation version={version} />
</div>
)
}
Expand All @@ -95,7 +86,7 @@ export const Anonymized: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
<DatasetCitation version={dataset.version} />
</div>
)
}
Expand Down
31 changes: 19 additions & 12 deletions tests/component/dataset/domain/models/DatasetMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class DatasetVersionMother {
static create(props?: Partial<DatasetVersion>): DatasetVersion {
return new DatasetVersion(
props?.id ?? faker.datatype.number(),
props?.title ?? faker.lorem.sentence(),
props?.publishingStatus ?? DatasetPublishingStatus.RELEASED,
props?.isLatest ?? false,
props?.isInReview ?? false,
Expand Down Expand Up @@ -88,8 +89,24 @@ export class DatasetVersionMother {
})
}

static createAnonymized(): DatasetVersion {
static createRealistic(props?: Partial<DatasetVersion>): DatasetVersion {
return this.create({
id: 1,
title: 'Dataset Title',
publishingStatus: DatasetPublishingStatus.RELEASED,
isLatest: true,
isInReview: false,
latestVersionStatus: DatasetPublishingStatus.RELEASED,
citation:
'Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1',
majorNumber: 1,
minorNumber: 0,
...props
})
}

static createAnonymized(): DatasetVersion {
return this.createRealistic({
citation: `Author name(s) withheld, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1`
})
}
Expand Down Expand Up @@ -235,7 +252,6 @@ export class DatasetMother {
static create(props?: Partial<Dataset>): Dataset {
const dataset = {
persistentId: faker.datatype.uuid(),
title: faker.lorem.sentence(),
version: DatasetVersionMother.create(),
license: {
name: 'CC0 1.0',
Expand Down Expand Up @@ -396,16 +412,7 @@ export class DatasetMother {
static createRealistic(props?: Partial<Dataset>): Dataset {
return this.create({
persistentId: 'doi:10.5072/FK2/ABC123',
version: new DatasetVersion(
1,
DatasetPublishingStatus.RELEASED,
false,
false,
DatasetPublishingStatus.RELEASED,
`Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1`,
1,
0
),
version: DatasetVersionMother.createRealistic(),
labels: [
{ value: 'Version 1.0', semanticMeaning: DatasetLabelSemanticMeaning.FILE },
{ value: DatasetLabelValue.DRAFT, semanticMeaning: DatasetLabelSemanticMeaning.DATASET }
Expand Down
6 changes: 3 additions & 3 deletions tests/component/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Dataset', () => {
mountWithDataset(<Dataset fileRepository={fileRepository} />, testDataset)

cy.findByTestId('dataset-skeleton').should('exist')
cy.findByText(testDataset.getTitle()).should('not.exist')
cy.findByText(testDataset.version.title).should('not.exist')
})

it('renders page not found when dataset is null', () => {
Expand All @@ -57,7 +57,7 @@ describe('Dataset', () => {

mountWithDataset(<Dataset fileRepository={fileRepository} />, testDataset)

cy.findAllByText(testDataset.getTitle()).should('exist')
cy.findAllByText(testDataset.version.title).should('exist')

testDataset.labels.forEach((label) => {
cy.findAllByText(label.value).should('exist')
Expand All @@ -69,7 +69,7 @@ describe('Dataset', () => {

mountWithDataset(<Dataset fileRepository={fileRepository} />, testDataset)

cy.findAllByText(testDataset.getTitle()).should('exist')
cy.findAllByText(testDataset.version.title).should('exist')

const metadataTab = cy.findByRole('tab', { name: 'Metadata' })
metadataTab.should('exist')
Expand Down
8 changes: 4 additions & 4 deletions tests/component/sections/dataset/DatasetProvider.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function TestComponent() {

return (
<div>
{dataset ? <span>{dataset.getTitle()}</span> : <span>Dataset Not Found</span>}
{dataset ? <span>{dataset.version.title}</span> : <span>Dataset Not Found</span>}
{isLoading && <div>Loading...</div>}
</div>
)
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('DatasetProvider', () => {

cy.findByText('Loading...').should('exist')
cy.wrap(datasetRepository.getByPersistentId).should('be.calledOnceWith', dataset.persistentId)
cy.findByText(dataset.getTitle()).should('exist')
cy.findByText(dataset.version.title).should('exist')
cy.findByText('Loading...').should('not.exist')
})

Expand All @@ -60,7 +60,7 @@ describe('DatasetProvider', () => {
dataset.persistentId,
'draft'
)
cy.findByText(dataset.getTitle()).should('exist')
cy.findByText(dataset.version.title).should('exist')
cy.findByText('Loading...').should('not.exist')
})

Expand All @@ -80,7 +80,7 @@ describe('DatasetProvider', () => {
'be.calledOnce',
'some-private-url-token'
)
cy.findByText(dataset.getTitle()).should('exist')
cy.findByText(dataset.version.title).should('exist')
cy.findByText('Loading...').should('not.exist')
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DatasetCitation } from '../../../../../src/sections/dataset/dataset-citation/DatasetCitation'
import { DatasetMother, DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother'
import { DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother'

describe('DatasetCitation', () => {
it('renders the DatasetCitation fields of released Dataset', () => {
const dataset = DatasetMother.create()
cy.customMount(<DatasetCitation title="Dataset title" version={dataset.version} />)
const version = DatasetVersionMother.createRealistic()
cy.customMount(<DatasetCitation version={version} />)

cy.findByText('Data Citation Standards.').should('exist')
cy.findByText(/Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title"/).should('exist')
Expand All @@ -20,10 +20,8 @@ describe('DatasetCitation', () => {
})

it('shows the draft tooltip when version is draft', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDraft()
})
cy.customMount(<DatasetCitation title="Dataset title" version={dataset.version} />)
const version = DatasetVersionMother.createDraft()
cy.customMount(<DatasetCitation version={version} />)

cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover')
cy.findByText(
Expand All @@ -32,10 +30,8 @@ describe('DatasetCitation', () => {
})

it('shows the deaccessioned tooltip when version is deaccessioned', () => {
const dataset = DatasetMother.create({
version: DatasetVersionMother.createDeaccessioned()
})
cy.customMount(<DatasetCitation title="Dataset title" version={dataset.version} />)
const version = DatasetVersionMother.createDeaccessioned()
cy.customMount(<DatasetCitation version={version} />)

cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover')
cy.findByText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const filesCountInfo = FilesCountInfoMother.create({ total: 100 })
const fileRepository: FileRepository = {} as FileRepository
const datasetVersion = new DatasetVersion(
1,
'',
DatasetPublishingStatus.RELEASED,
true,
false,
Expand Down
Loading

0 comments on commit 62b69b2

Please sign in to comment.