Skip to content

Commit

Permalink
feat: add e2e test for sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Dec 17, 2024
1 parent 16f10f6 commit a11a2d7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import { TestsUtils } from '@tests/e2e-integration/shared/TestsUtils'
import { Interception } from 'cypress/types/net-stubbing'

const numbersOfDatasetsToCreate = [1, 2, 3, 4, 5, 6, 7, 8]

const datasetTitles = [
'Darwin',
'Einstein',
'Galileo',
'Newton',
'Tesla',
'Curie',
'Hawking',
'Sagan'
]
const SEARCH_ENDPOINT_REGEX = /^\/api\/v1\/search(\?.*)?$/

function extractInfoFromInterceptedResponse(interception: Interception) {
Expand Down Expand Up @@ -46,7 +55,7 @@ describe('Collection Items Panel', () => {

// Creates 8 datasets with 1 file each
for (const _number of numbersOfDatasetsToCreate) {
await DatasetHelper.createWithFile(FileHelper.create())
await DatasetHelper.createWithFileAndTitle(FileHelper.create(), datasetTitles[_number - 1])
}
})

Expand Down Expand Up @@ -79,7 +88,7 @@ describe('Collection Items Panel', () => {
})

// 1 - Now select the Files checkbox
cy.findByRole('checkbox', { name: /Files/ }).click()
cy.findByRole('checkbox', { name: /Files/ }).click({ force: true })

cy.wait('@getCollectionItems').then((interception) => {
const { totalItemsInResponse, collectionsInResponse, datasetsInResponse, filesInResponse } =
Expand Down Expand Up @@ -268,7 +277,7 @@ describe('Collection Items Panel', () => {
})

// 7 - Selects a facet filter
cy.findByRole('button', { name: /Finch, Fiona/ }).click()
cy.findByRole('button', { name: /Finch, Fiona/ }).click({ force: true })

cy.wait('@getCollectionItems').then((interception) => {
const { totalItemsInResponse, collectionsInResponse, datasetsInResponse, filesInResponse } =
Expand Down Expand Up @@ -307,5 +316,16 @@ describe('Collection Items Panel', () => {
.should('exist')
.should('have.length', 2)
})
// 8 Sort by Name (Z-A)
cy.visit(`/spa/collections`)
cy.findByRole('button', { name: /Sort/ }).click({ force: true })
cy.contains('Name (Z-A)').click({ force: true })

cy.findAllByTestId('dataset-card').first().contains('Tesla')
const sortExpectedUrl = new URLSearchParams({
[CollectionItemsQueryParams.SORT]: 'name',
[CollectionItemsQueryParams.ORDER]: 'desc'
}).toString()
cy.url().should('include', `/collections?${sortExpectedUrl}`)
})
})
20 changes: 18 additions & 2 deletions tests/e2e-integration/shared/datasets/DatasetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ export class DatasetHelper extends DataverseApiHelper {
)
}

static async createWithTitle(title: string): Promise<DatasetResponse> {
static async createWithTitle(
title: string,
collectionId = ROOT_COLLECTION_ALIAS
): Promise<DatasetResponse> {
newDatasetData.datasetVersion.metadataBlocks.citation.fields[0].value = title
return this.request<DatasetResponse>(`/dataverses/root/datasets`, 'POST', newDatasetData)
return this.request<DatasetResponse>(
`/dataverses/${collectionId}/datasets`,
'POST',
newDatasetData
)
}

static async destroy(persistentId: string): Promise<DatasetResponse | undefined> {
Expand Down Expand Up @@ -157,6 +164,15 @@ export class DatasetHelper extends DataverseApiHelper {
return { ...datasetResponse, file: file }
}

static async createWithFileAndTitle(
fileData: FileData,
title: string,
collectionId = ROOT_COLLECTION_ALIAS
): Promise<DatasetResponse> {
const datasetResponse = await this.createWithTitle(title, collectionId)
const file = await this.uploadFile(datasetResponse.persistentId, fileData)
return { ...datasetResponse, file: file }
}
static async createWithFileAndPublish(
fileData: FileData,
collectionId = ROOT_COLLECTION_ALIAS
Expand Down

0 comments on commit a11a2d7

Please sign in to comment.