From 4879ae8b1f7e6998a97a566c9cb930ee8994247a Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 19 Dec 2024 08:44:46 -0500 Subject: [PATCH] Add component test code coverage --- .../ItemsSortBy.spec.tsx | 70 ++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/tests/component/sections/collection/collection-items-panel/ItemsSortBy.spec.tsx b/tests/component/sections/collection/collection-items-panel/ItemsSortBy.spec.tsx index c6727794e..2980f1ba8 100644 --- a/tests/component/sections/collection/collection-items-panel/ItemsSortBy.spec.tsx +++ b/tests/component/sections/collection/collection-items-panel/ItemsSortBy.spec.tsx @@ -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( @@ -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( + + ) + 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( + + ) + 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( + + ) + 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( + + ) + 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( { ) 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') }) })