Skip to content

Commit 066dd28

Browse files
committed
feat(BreadcrumbsIntegration): add e2e tests
1 parent 9f8ab1a commit 066dd28

9 files changed

Lines changed: 103 additions & 11 deletions

File tree

src/sections/shared/hierarchy/BreadcrumbsGenerator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const LinkToDvObject = ({
6969
return (
7070
<LinkToPage
7171
page={dvObjectTypeToRoute[type]}
72-
searchParams={{ ...(version ? { version } : {}), ...idParam }}>
72+
searchParams={{ ...idParam, ...(version ? { version } : {}) }}>
7373
{name}
7474
</LinkToPage>
7575
)

tests/component/dataset/infrastructure/mappers/JSDatasetMapper.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ const jsDataset = {
6060
uri: 'http://creativecommons.org/publicdomain/zero/1.0',
6161
iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png'
6262
},
63-
thumbnail: undefined
63+
thumbnail: undefined,
64+
isPartOf: {
65+
type: 'DATAVERSE',
66+
identifier: 'root',
67+
displayName: 'Root'
68+
}
6469
}
6570
const citation =
6671
'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/B4B2MJ" target="_blank">https://doi.org/10.5072/FK2/B4B2MJ</a>, Root, DRAFT VERSION'
@@ -172,8 +177,8 @@ const expectedDataset = {
172177
hierarchy: new UpwardHierarchyNode(
173178
"Darwin's Finches",
174179
DvObjectType.DATASET,
175-
undefined,
176-
undefined,
180+
'doi:10.5072/FK2/B4B2MJ',
181+
'0.0',
177182
new UpwardHierarchyNode('Root', DvObjectType.COLLECTION, 'root')
178183
)
179184
}
@@ -279,8 +284,8 @@ const expectedDatasetAlternateVersion = {
279284
hierarchy: new UpwardHierarchyNode(
280285
"Darwin's Finches",
281286
DvObjectType.DATASET,
282-
undefined,
283-
undefined,
287+
'doi:10.5072/FK2/B4B2MJ',
288+
'0.0',
284289
new UpwardHierarchyNode('Root', DvObjectType.COLLECTION, 'root')
285290
)
286291
}
@@ -295,6 +300,7 @@ describe('JS Dataset Mapper', () => {
295300
jsDatasetFilesTotalOriginalDownloadSize,
296301
jsDatasetFilesTotalArchivalDownloadSize
297302
)
303+
298304
expect(expectedDataset).to.deep.equal(mapped)
299305
})
300306
it('maps jsDataset model to the domain Dataset model for alternate version', () => {

tests/component/sections/shared/hierarchy/BreadcrumbsGenerator.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('BreadcrumbsGenerator', () => {
1616
name: 'Dataset',
1717
parent: collection,
1818
version: '1.0',
19-
persistentId: 'doi:10.5072/FK2/ABC123'
19+
id: 'doi:10.5072/FK2/ABC123'
2020
})
2121
const file = UpwardHierarchyNodeMother.createFile({ name: 'File', parent: dataset })
2222

tests/component/shared/hierarchy/domain/models/UpwardHierarchyNodeMother.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export class UpwardHierarchyNodeMother {
99
return new UpwardHierarchyNode(
1010
props?.name ?? faker.lorem.word(),
1111
props?.type ?? faker.helpers.arrayElement(Object.values(DvObjectType)),
12-
props?.id ?? undefined,
13-
undefined,
12+
props?.id ?? faker.datatype.uuid(),
13+
props?.version ?? undefined,
1414
props?.parent ?? undefined
1515
)
1616
}

tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TestsUtils } from '../../../shared/TestsUtils'
33
import { DatasetHelper, DatasetResponse } from '../../../shared/datasets/DatasetHelper'
44
import { FileHelper } from '../../../shared/files/FileHelper'
55
import moment from 'moment-timezone'
6+
import { CollectionHelper } from '../../../shared/collection/CollectionHelper'
67

78
type Dataset = {
89
datasetVersion: { metadataBlocks: { citation: { fields: { value: string }[] } } }
@@ -170,6 +171,23 @@ describe('Dataset', () => {
170171
cy.findByText(DatasetLabelValue.DEACCESSIONED).should('exist')
171172
})
172173
})
174+
175+
it('loads correctly the breadcrumbs when the dataset is part of a subcollection', () => {
176+
cy.wrap(
177+
CollectionHelper.create('subcollection').then((collection) =>
178+
DatasetHelper.create(collection.id)
179+
)
180+
)
181+
.its('persistentId')
182+
.then((persistentId: string) => {
183+
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
184+
185+
cy.findByText('Root').should('exist')
186+
cy.findByRole('link', { name: 'Subcollection' }).should('exist').click()
187+
188+
cy.findAllByText('Subcollection').should('exist')
189+
})
190+
})
173191
})
174192

175193
describe('Visualizing the Files Tab', () => {

tests/e2e-integration/e2e/sections/file/File.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,22 @@ describe('File', () => {
9595
cy.visit(`/spa/files?id=wrong-id`)
9696
cy.findByText('Page Not Found').should('exist')
9797
})
98+
99+
it('loads correctly the breadcrumbs', () => {
100+
cy.wrap(
101+
DatasetHelper.createWithFile(FileHelper.create()).then(
102+
(datasetResponse) => datasetResponse.file
103+
)
104+
)
105+
.its('id')
106+
.then((id: string) => {
107+
cy.visit(`/spa/files?id=${id}`)
108+
109+
cy.findByText('Root').should('exist')
110+
cy.findByRole('link', { name: "Darwin's Finches" }).should('exist').click({ force: true })
111+
112+
cy.findByRole('heading', { name: "Darwin's Finches" }).should('exist')
113+
})
114+
})
98115
})
99116
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Subcollection",
3+
"alias": "science",
4+
"dataverseContacts": [
5+
{
6+
"contactEmail": "pi@example.edu"
7+
},
8+
{
9+
"contactEmail": "student@example.edu"
10+
}
11+
],
12+
"affiliation": "Scientific Research University",
13+
"description": "We do all the science.",
14+
"dataverseType": "LABORATORY"
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { DataverseApiHelper } from '../DataverseApiHelper'
2+
import newCollectionData from '../../fixtures/new-collection-data.json'
3+
4+
export interface CollectionResponse {
5+
id: string
6+
}
7+
8+
interface CollectionPayload {
9+
alias: string
10+
}
11+
12+
export class CollectionHelper extends DataverseApiHelper {
13+
static async create(id = 'subcollection'): Promise<CollectionResponse> {
14+
const collection: CollectionPayload | undefined = await this.request<CollectionPayload>(
15+
`/dataverses/${id}`,
16+
'GET'
17+
).catch(() => undefined)
18+
if (collection) {
19+
return { id: collection.alias }
20+
}
21+
22+
const newCollection: CollectionPayload = await this.request<CollectionPayload>(
23+
`/dataverses/root`,
24+
'POST',
25+
{
26+
...newCollectionData,
27+
alias: id
28+
}
29+
)
30+
return { id: newCollection.alias }
31+
}
32+
}

tests/e2e-integration/shared/datasets/DatasetHelper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export interface DatasetFileResponse {
1616
}
1717

1818
export class DatasetHelper extends DataverseApiHelper {
19-
static async create(): Promise<DatasetResponse> {
20-
return this.request<DatasetResponse>(`/dataverses/root/datasets`, 'POST', newDatasetData)
19+
static async create(collectionId = 'root'): Promise<DatasetResponse> {
20+
return this.request<DatasetResponse>(
21+
`/dataverses/${collectionId}/datasets`,
22+
'POST',
23+
newDatasetData
24+
)
2125
}
2226

2327
static async createWithTitle(title: string): Promise<DatasetResponse> {

0 commit comments

Comments
 (0)