Skip to content

Commit

Permalink
Add component test code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Dec 19, 2024
1 parent cf17f67 commit 4879ae8
Showing 1 changed file with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ItemsSortBy } from '@/sections/collection/collection-items-panel/items-
import { OrderType, SortType } from '@/collection/domain/models/CollectionSearchCriteria'

describe('ItemsSortBy', () => {
it.only('should render Relevance option when search text is present', () => {
it('should render Relevance option when search text is present', () => {
const onSortChange = cy.stub().as('onSortChange')

cy.customMount(
Expand All @@ -20,6 +20,71 @@ describe('ItemsSortBy', () => {
it('should not render Relevance option when search text is undefined', () => {
const onSortChange = cy.stub().as('onSortChange')

cy.customMount(
<ItemsSortBy
isLoadingCollectionItems={false}
currentSortType={SortType.NAME}
currentSortOrder={OrderType.ASC}
onSortChange={onSortChange}></ItemsSortBy>
)
cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Name \(Z-A\)/ }).should('exist')
cy.findByText(/Relevance/).should('not.exist')
cy.findByRole('button', { name: /Name \(Z-A\)/ }).click({ force: true })
cy.wrap(onSortChange).should('be.calledWith', 'name', 'desc')
})
it('should set sort type and order to undefined when Relevance is selected', () => {
const onSortChange = cy.stub().as('onSortChange')

cy.customMount(
<ItemsSortBy
isLoadingCollectionItems={false}
currentSortType={SortType.NAME}
currentSortOrder={OrderType.DESC}
currentSearchText={'test'}
onSortChange={onSortChange}></ItemsSortBy>
)
cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Relevance/ }).should('exist')

cy.findByText(/Relevance/).click()
cy.wrap(onSortChange).should('be.calledWith', undefined, undefined)
})
it('should set sort type and order correctly when Newest is selected', () => {
const onSortChange = cy.stub().as('onSortChange')

cy.customMount(
<ItemsSortBy
isLoadingCollectionItems={false}
currentSortType={SortType.NAME}
currentSortOrder={OrderType.DESC}
onSortChange={onSortChange}></ItemsSortBy>
)
cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Newest/ }).should('exist')
cy.findByRole('button', { name: /Newest/ }).click({ force: true })

cy.wrap(onSortChange).should('be.calledWith', 'date', 'desc')
})
it('should set sort type and order correctly when Oldest is selected', () => {
const onSortChange = cy.stub().as('onSortChange')

cy.customMount(
<ItemsSortBy
isLoadingCollectionItems={false}
currentSortType={SortType.NAME}
currentSortOrder={OrderType.DESC}
onSortChange={onSortChange}></ItemsSortBy>
)
cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Oldest/ }).should('exist')
cy.findByRole('button', { name: /Oldest/ }).click({ force: true })

cy.wrap(onSortChange).should('be.calledWith', 'date', 'asc')
})
it('should set sort type and order correctly when Name_ASC is selected', () => {
const onSortChange = cy.stub().as('onSortChange')

cy.customMount(
<ItemsSortBy
isLoadingCollectionItems={false}
Expand All @@ -29,9 +94,8 @@ describe('ItemsSortBy', () => {
)
cy.findByRole('button', { name: /Sort/ }).click()
cy.findByRole('button', { name: /Name \(A-Z\)/ }).should('exist')
cy.findByText(/Relevance/).should('not.exist')
cy.findByRole('button', { name: /Name \(A-Z\)/ }).click({ force: true })

cy.findByText(/Name \(A-Z\)/).click()
cy.wrap(onSortChange).should('be.calledWith', 'name', 'asc')
})
})

0 comments on commit 4879ae8

Please sign in to comment.