Skip to content

Commit

Permalink
update stories and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Apr 17, 2024
1 parent ae1fb60 commit 74e329a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/stories/collection/CollectionInfo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const WithAffiliation: Story = {
render: () => <CollectionInfo collection={CollectionMother.createWithAffiliation()} />
}

export const Unpublished: Story = {
render: () => <CollectionInfo collection={CollectionMother.createUnpublished()} />
}
export const WithDescription: Story = {
render: () => <CollectionInfo collection={CollectionMother.createWithDescription()} />
}
11 changes: 10 additions & 1 deletion tests/component/collection/domain/models/CollectionMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class CollectionMother {
return {
id: faker.datatype.uuid(),
name: faker.lorem.words(3),
isReleased: faker.datatype.boolean(),
description: faker.datatype.boolean()
? `${faker.lorem.paragraph()} **${faker.lorem.sentence()}** ${faker.lorem.paragraph()}`
: undefined,
Expand All @@ -20,6 +21,7 @@ export class CollectionMother {
static createRealistic(): Collection {
return CollectionMother.create({
id: 'science',
isReleased: true,
name: 'Collection Name',
description: 'We do all the science.',
affiliation: 'Scientific Research University'
Expand All @@ -30,6 +32,7 @@ export class CollectionMother {
return CollectionMother.create({
id: faker.datatype.uuid(),
name: FakerHelper.collectionName(),
isReleased: faker.datatype.boolean(),
affiliation: undefined,
description: undefined,
...props
Expand All @@ -39,12 +42,18 @@ export class CollectionMother {
static createComplete(): Collection {
return CollectionMother.create({
id: faker.datatype.uuid(),
isReleased: faker.datatype.boolean(),
name: FakerHelper.collectionName(),
description: FakerHelper.paragraph(),
affiliation: FakerHelper.affiliation()
})
}

static createUnpublished(): Collection {
return CollectionMother.createWithOnlyRequiredFields({
isReleased: false,
affiliation: FakerHelper.affiliation()
})
}
static createWithDescription(): Collection {
return CollectionMother.createWithOnlyRequiredFields({
description: FakerHelper.paragraph()
Expand Down
8 changes: 8 additions & 0 deletions tests/component/sections/collection/CollectionInfo.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('CollectionInfo', () => {
const collection = CollectionMother.create({
name: 'Collection Name',
affiliation: 'Affiliation',
isReleased: true,
description: 'Here is a description with [a link](https://dataverse.org)'
})
cy.customMount(<CollectionInfo collection={collection} />)
Expand All @@ -14,6 +15,7 @@ describe('CollectionInfo', () => {
cy.findByText('(Affiliation)').should('exist')
cy.findByText(/Here is a description with/).should('exist')
cy.findByRole('link', { name: 'a link' }).should('exist')
cy.findByText('Unpublished').should('not.exist')
})

it('does not render affiliation when it is not present', () => {
Expand All @@ -33,4 +35,10 @@ describe('CollectionInfo', () => {

cy.findByText('Description').should('not.exist')
})
it('renders unpublished label when isReleased is false', () => {
const collection = CollectionMother.createUnpublished()
cy.customMount(<CollectionInfo collection={collection} />)

cy.findByText('Unpublished').should('exist')
})
})

0 comments on commit 74e329a

Please sign in to comment.