From 596ebddb95a2e6bfbb9e1d77aec8af76862964f1 Mon Sep 17 00:00:00 2001 From: Pranay Kothapalli Date: Tue, 23 Jun 2026 18:56:38 +0530 Subject: [PATCH] test(accordion): lazy mount and forceMount behavior Add regression tests for collapsed content lazy mounting and forceMount override on Accordion.Content. Related to #1847 --- .../tests/Accordion.lazyMount.test.tsx | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/components/ui/Accordion/tests/Accordion.lazyMount.test.tsx diff --git a/src/components/ui/Accordion/tests/Accordion.lazyMount.test.tsx b/src/components/ui/Accordion/tests/Accordion.lazyMount.test.tsx new file mode 100644 index 000000000..3d4ef3cef --- /dev/null +++ b/src/components/ui/Accordion/tests/Accordion.lazyMount.test.tsx @@ -0,0 +1,58 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import Accordion from '../Accordion'; + +describe('Accordion lazy mount behavior', () => { + test('does not mount collapsed content by default', () => { + render( + + + + Section one + + Panel one + + + ); + + expect(screen.getByText('Section one')).toBeInTheDocument(); + expect(screen.queryByText('Panel one')).not.toBeInTheDocument(); + }); + + test('mounts content after opening', async() => { + const user = userEvent.setup(); + + render( + + + + Section one + + Panel one + + + ); + + expect(screen.queryByText('Panel one')).not.toBeInTheDocument(); + await user.click(screen.getByText('Section one')); + expect(screen.getByText('Panel one')).toBeInTheDocument(); + }); + + test('forceMount keeps content mounted while closed', () => { + render( + + + + Section one + + Mounted panel + + + ); + + const panel = screen.getByText('Mounted panel'); + expect(panel).toBeInTheDocument(); + expect(panel.closest('[data-state="closed"]')).toBeTruthy(); + }); +});