Skip to content

Commit

Permalink
test: finish with e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Dec 12, 2024
1 parent 3089539 commit a13a2c9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ export const CollectionItemsPanel = ({
})
} else {
// Update the URL with the search value ,keep other querys and include all item types always
setSearchParams((currentSearchParams) => ({
...currentSearchParams,
[GetCollectionItemsQueryParams.TYPES]: [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET,
CollectionItemType.FILE
].join(','),
[QueryParamKey.QUERY]: searchValue
}))
setSearchParams((currentSearchParams) => {
currentSearchParams.set(
GetCollectionItemsQueryParams.TYPES,
[CollectionItemType.COLLECTION, CollectionItemType.DATASET, CollectionItemType.FILE].join(
','
)
)

currentSearchParams.set(QueryParamKey.QUERY, searchValue)

return currentSearchParams
})
}

// WHEN SEARCHING, WE RESET THE PAGINATION INFO AND KEEP ALL ITEM TYPES!!
Expand Down Expand Up @@ -157,13 +160,11 @@ export const CollectionItemsPanel = ({
setPaginationInfo(resetPaginationInfo)

// Update the URL with the new item types, keep other querys and include the search value if exists
setSearchParams((currentSearchParams) => ({
...currentSearchParams,
[GetCollectionItemsQueryParams.TYPES]: newItemsTypes.join(','),
...(currentSearchCriteria.searchText && {
[QueryParamKey.QUERY]: currentSearchCriteria.searchText
})
}))
setSearchParams((currentSearchParams) => {
currentSearchParams.set(GetCollectionItemsQueryParams.TYPES, newItemsTypes.join(','))

return currentSearchParams
})

const newCollectionSearchCriteria = new CollectionSearchCriteria(
currentSearchCriteria.searchText,
Expand Down Expand Up @@ -203,16 +204,12 @@ export const CollectionItemsPanel = ({

// Update the URL with the new facets, keep other querys and include the search value if exists
setSearchParams((currentSearchParams) => {
return {
...currentSearchParams,
...(newFilterQueries.length > 0 && {
[GetCollectionItemsQueryParams.FILTER_QUERIES]:
newFilterQueriesWithFacetValueEncoded.join(',')
}),
...(currentSearchCriteria.searchText && {
[QueryParamKey.QUERY]: currentSearchCriteria.searchText
})
}
currentSearchParams.set(
GetCollectionItemsQueryParams.FILTER_QUERIES,
newFilterQueriesWithFacetValueEncoded.join(',')
)

return currentSearchParams
})

const newCollectionSearchCriteria = new CollectionSearchCriteria(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('Collection Items Panel', () => {
})

beforeEach(async () => {
cy.viewport(1280, 720)

cy.intercept(SEARCH_ENDPOINT_REGEX).as('getCollectionItems')

// Creates 8 datasets with 1 file each
Expand Down Expand Up @@ -109,7 +111,7 @@ describe('Collection Items Panel', () => {
})

// 2 - Now perform a search in the input
cy.findByPlaceholderText('Search this collection...').type('Darwin{enter}')
cy.findByPlaceholderText('Search this collection...').type('Darwin{enter}', { force: true })

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

// 3 - Clear the search and assert that the search is performed correctly and the url is updated correctly
cy.findByPlaceholderText('Search this collection...').clear()
cy.findByRole('button', { name: /Search submit/ }).click()
cy.findByRole('button', { name: /Search submit/ }).click({ force: true })

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

// 4 - Uncheck the Collections checkbox

cy.findByRole('checkbox', { name: /Collections/ }).click()
cy.findByRole('checkbox', { name: /Collections/ }).click({ force: true })

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

// 5 - Uncheck the Dataset checkbox
cy.findByRole('checkbox', { name: /Datasets/ }).click()
cy.findByRole('checkbox', { name: /Datasets/ }).click({ force: true })

cy.wait('@getCollectionItems').then((interception) => {
const { totalItemsInResponse, collectionsInResponse, datasetsInResponse, filesInResponse } =
Expand All @@ -234,7 +236,7 @@ describe('Collection Items Panel', () => {
cy.url().should('include', `/collections?${fifthExpectedURL}`)
})

//6 - Navigate back with the browser and assert that the url is updated correctly and the items are displayed correctly as in step 4
// 6 - Navigate back with the browser and assert that the url is updated correctly and the items are displayed correctly as in step 4
cy.go('back')

cy.wait('@getCollectionItems').then((interception) => {
Expand Down Expand Up @@ -264,5 +266,46 @@ describe('Collection Items Panel', () => {

cy.url().should('include', `/collections?${fourthExpectedURL}`)
})

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

cy.wait('@getCollectionItems').then((interception) => {
const { totalItemsInResponse, collectionsInResponse, datasetsInResponse, filesInResponse } =
extractInfoFromInterceptedResponse(interception)

cy.findByTestId('items-list')
.should('exist')
.children()
.should('have.length', totalItemsInResponse)

collectionsInResponse.length > 0 &&
cy.findAllByTestId('collection-card').should('have.length', collectionsInResponse.length)

datasetsInResponse.length > 0 &&
cy.findAllByTestId('dataset-card').should('have.length', datasetsInResponse.length)

filesInResponse.length > 0 &&
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const expectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
CollectionItemType.DATASET,
CollectionItemType.FILE
].join(','),
[GetCollectionItemsQueryParams.FILTER_QUERIES]: [
`authorName_ss:${encodeURIComponent('Finch, Fiona')}`
].join(',')
}).toString()

console.log({ expectedURL })

cy.url().should('include', `/collections?${expectedURL}`)

// Assert that the selected facet filter is displayed
cy.findAllByRole('button', { name: /Finch, Fiona/ })
.should('exist')
.should('have.length', 2)
})
})
})

0 comments on commit a13a2c9

Please sign in to comment.