@@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event';
33
44import { ExpandableSection , ExpandableSectionVariant } from '../ExpandableSection' ;
55import styles from '@patternfly/react-styles/css/components/ExpandableSection/expandable-section' ;
6+ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon' ;
67
78const props = { contentId : 'content-id' , toggleId : 'toggle-id' } ;
89
@@ -191,3 +192,33 @@ test('Renders with class pf-m-detached when isDetached is true and direction is
191192
192193 expect ( screen . getByText ( 'Test content' ) . parentElement ) . toHaveClass ( 'pf-m-detached' ) ;
193194} ) ;
195+
196+ test ( 'Can render custom toggle icon' , ( ) => {
197+ render ( < ExpandableSection toggleIcon = { < BellIcon data-testid = "bell-icon" /> } > Test content</ ExpandableSection > ) ;
198+
199+ expect ( screen . getByTestId ( 'bell-icon' ) ) . toBeInTheDocument ( ) ;
200+ } ) ;
201+
202+ test ( 'Does not render toggle icon when hasToggleIcon is false' , ( ) => {
203+ render ( < ExpandableSection hasToggleIcon = { false } > Test content</ ExpandableSection > ) ;
204+
205+ const button = screen . getByRole ( 'button' ) ;
206+ expect ( button . querySelector ( '.pf-v6-c-expandable-section__toggle-icon' ) ) . not . toBeInTheDocument ( ) ;
207+ } ) ;
208+
209+ test ( 'Does not render custom toggle icon when hasToggleIcon is false' , ( ) => {
210+ render (
211+ < ExpandableSection toggleIcon = { < BellIcon data-testid = "bell-icon" /> } hasToggleIcon = { false } >
212+ Test content
213+ </ ExpandableSection >
214+ ) ;
215+
216+ expect ( screen . queryByTestId ( 'bell-icon' ) ) . not . toBeInTheDocument ( ) ;
217+ } ) ;
218+
219+ test ( 'Renders toggle icon by default when hasToggleIcon is true' , ( ) => {
220+ render ( < ExpandableSection > Test content</ ExpandableSection > ) ;
221+
222+ const button = screen . getByRole ( 'button' ) ;
223+ expect ( button . querySelector ( '.pf-v6-c-expandable-section__toggle-icon' ) ) . toBeInTheDocument ( ) ;
224+ } ) ;
0 commit comments