Skip to content

Commit 31ebb0d

Browse files
committed
test: add more cases
1 parent 98b673e commit 31ebb0d

4 files changed

Lines changed: 86 additions & 1 deletion

File tree

src/sections/file/file-labels/FileLabels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const VARIANT_BY_LABEL_TYPE: Record<FileLabelType, 'secondary' | 'info'> = {
99

1010
export function FileLabels({ labels }: { labels: FileLabel[] }) {
1111
return (
12-
<div className={styles.container}>
12+
<div className={styles.container} data-testid="file-labels">
1313
{labels.map((label, index) => (
1414
<Badge key={`${label.value}-${index}`} variant={VARIANT_BY_LABEL_TYPE[label.type]}>
1515
{label.value}

tests/component/sections/collection/collection-items-panel/dataset-card/DatasetCard.spec.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { DatasetCard } from '@/sections/collection/collection-items-panel/items-
22
import { DatasetItemTypePreviewMother } from '@tests/component/dataset/domain/models/DatasetItemTypePreviewMother'
33
import { DateHelper } from '@/shared/helpers/DateHelper'
44
import styles from '@/sections/collection/collection-items-panel/items-list/dataset-card/DatasetCard.module.scss'
5+
import { Route } from '@/sections/Route.enum'
56

67
describe('DatasetCard', () => {
78
it('should render the card', () => {
@@ -55,4 +56,32 @@ describe('DatasetCard', () => {
5556
.parent()
5657
.should('have.class', styles['deaccesioned'])
5758
})
59+
60+
describe('Parent Collection Link', () => {
61+
it('should render it if parentCollectionAlias is not the one where the dataset card is being shown', () => {
62+
const dataset = DatasetItemTypePreviewMother.create({
63+
parentCollectionAlias: 'parent-collection-alias',
64+
parentCollectionName: 'Parent Collection Name'
65+
})
66+
cy.customMount(
67+
<DatasetCard datasetPreview={dataset} parentCollectionAlias="another-collection-alias" />
68+
)
69+
70+
cy.findByText('Parent Collection Name')
71+
.should('exist')
72+
.should('have.attr', 'href', `${Route.COLLECTIONS_BASE}/parent-collection-alias`)
73+
})
74+
75+
it('should not render it if parentCollectionAlias is the same as the one where the dataset card is being shown', () => {
76+
const dataset = DatasetItemTypePreviewMother.create({
77+
parentCollectionAlias: 'parent-collection-alias',
78+
parentCollectionName: 'Parent Collection Name'
79+
})
80+
cy.customMount(
81+
<DatasetCard datasetPreview={dataset} parentCollectionAlias="parent-collection-alias" />
82+
)
83+
84+
cy.findByText('Parent Collection Name').should('not.exist')
85+
})
86+
})
5887
})

tests/component/sections/collection/collection-items-panel/dataset-card/DatasetCardHeader.spec.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,44 @@ describe('DatasetCardHeader', () => {
3939
.should('exist')
4040
.should('have.attr', 'href', `/datasets?persistentId=${dataset.persistentId}&version=DRAFT`)
4141
})
42+
43+
it('should sort the publication statuses by name', () => {
44+
const dataset = DatasetItemTypePreviewMother.create({
45+
publicationStatuses: [
46+
PublicationStatus.Unpublished,
47+
PublicationStatus.Draft,
48+
PublicationStatus.InReview
49+
]
50+
})
51+
cy.customMount(
52+
<DatasetCardHeader
53+
persistentId={dataset.persistentId}
54+
version={dataset.version}
55+
publicationStatuses={dataset.publicationStatuses}
56+
/>
57+
)
58+
59+
cy.findAllByText(PublicationStatus.Draft).should('exist')
60+
cy.findAllByText(PublicationStatus.InReview).should('exist')
61+
cy.findAllByText(PublicationStatus.Unpublished).should('exist')
62+
63+
cy.get('.badge').then((badges) => {
64+
expect(badges[0].textContent).to.equal(PublicationStatus.Draft)
65+
expect(badges[1].textContent).to.equal(PublicationStatus.InReview)
66+
expect(badges[2].textContent).to.equal(PublicationStatus.Unpublished)
67+
})
68+
})
69+
70+
it('should filter out and dont render the Published status badge', () => {
71+
const dataset = DatasetItemTypePreviewMother.create()
72+
cy.customMount(
73+
<DatasetCardHeader
74+
persistentId={dataset.persistentId}
75+
version={dataset.version}
76+
publicationStatuses={[PublicationStatus.Published]}
77+
/>
78+
)
79+
80+
cy.findByText(PublicationStatus.Published).should('not.exist')
81+
})
4282
})

tests/component/sections/collection/collection-items-panel/file-card/FileCard.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,20 @@ describe('FileCard', () => {
6767
.should('have.attr', 'href')
6868
.and('include', 'version=DRAFT')
6969
})
70+
71+
it('should not show any tag if the file has no tags', () => {
72+
const filePreview = FileItemTypePreviewMother.create({ tags: [] })
73+
cy.customMount(<FileCard filePreview={filePreview} />)
74+
cy.findByTestId('file-labels').children().should('have.length', 0)
75+
})
76+
77+
it('should default to 0 variables and 0 observations if file is tabular and they are not present', () => {
78+
const filePreview = FileItemTypePreviewMother.create({
79+
fileType: 'Tab-Delimited',
80+
variables: undefined,
81+
observations: undefined
82+
})
83+
cy.customMount(<FileCard filePreview={filePreview} />)
84+
cy.contains('0 variables, 0 observations').should('exist')
85+
})
7086
})

0 commit comments

Comments
 (0)