Skip to content

Commit 7b86f99

Browse files
committed
test: add max 10 items validation test and ignore untested dragging
1 parent 226cd2d commit 7b86f99

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/sections/edit-collection-featured-items/featured-items-form/FeaturedItemsForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const FeaturedItemsForm = ({
8686

8787
const handleOnRemoveField = (index: number) => remove(index)
8888

89-
const handleDragEnd = (event: DragEndEvent) => {
89+
const handleDragEnd = /* istanbul ignore next */ (event: DragEndEvent) => {
9090
const { active, over } = event
9191

9292
if (over && active.id !== over?.id) {

tests/component/sections/edit-collection-featured-items/FeaturedItemsForm.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,40 @@ describe('FeaturedItemsForm', () => {
510510
.should('be.visible')
511511
})
512512
})
513+
514+
it('should show toast error message when trying to add more than 10 featured items', () => {
515+
const testFeaturedItems = Array.from({ length: 10 }, (_, index) =>
516+
CollectionFeaturedItemMother.createFeaturedItem({
517+
id: index,
518+
displayOrder: index,
519+
content: `<h1 class="rte-heading">Featured Item ${index}</h1>`,
520+
imageFileUrl: undefined
521+
})
522+
)
523+
524+
const formDefaultValues: FeaturedItemsFormData = {
525+
featuredItems: FeaturedItemsFormHelper.defineFormDefaultFeaturedItems(testFeaturedItems)
526+
}
527+
528+
cy.mountAuthenticated(
529+
<FeaturedItemsForm
530+
collectionId={testCollection.id}
531+
collectionRepository={collectionRepository}
532+
defaultValues={formDefaultValues}
533+
collectionFeaturedItems={testFeaturedItems}
534+
/>
535+
)
536+
537+
cy.findByTestId('featured-item-9').as('last-item').should('exist').should('be.visible')
538+
539+
cy.get('@last-item').within(() => {
540+
cy.get(`[aria-label="Add Featured Item"]`).should('exist').should('be.visible').click()
541+
})
542+
543+
cy.findByText(/You can add up to 10 featured items./)
544+
.should('exist')
545+
.should('be.visible')
546+
})
513547
})
514548

515549
// TODO: This test is failing in CI sometimes, we need to investigate why and fix it

0 commit comments

Comments
 (0)