diff --git a/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx b/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx index ed4e612982c..b045532b71d 100644 --- a/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx +++ b/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx @@ -6,7 +6,7 @@ import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-mi import { PickOptional } from '../../helpers/typeUtils'; import { debounce } from '../../helpers/util'; import { getResizeObserver } from '../../helpers/resizeObserver'; -import { GenerateId } from '../../helpers'; +import { GenerateId, getOUIAProps, OUIAProps } from '../../helpers'; import { Button } from '../Button'; export enum ExpandableSectionVariant { @@ -16,7 +16,7 @@ export enum ExpandableSectionVariant { /** The main expandable section component. */ -export interface ExpandableSectionProps extends Omit, 'onToggle'> { +export interface ExpandableSectionProps extends Omit, 'onToggle'>, OUIAProps { /** Content rendered inside the expandable section. */ children?: React.ReactNode; /** Additional classes added to the expandable section. */ @@ -84,6 +84,10 @@ export interface ExpandableSectionProps extends Omit {variant === ExpandableSectionVariant.default && expandableToggle}
{ - const { asFragment } = render(test ); + const { asFragment } = render( + + test{' '} + + ); expect(asFragment()).toMatchSnapshot(); }); @@ -306,3 +310,27 @@ test('Renders toggle icon by default when hasToggleIcon is true', () => { const button = screen.getByRole('button'); expect(button.querySelector('.pf-v6-c-expandable-section__toggle-icon')).toBeInTheDocument(); }); + +test('Renders with custom ouiaId', () => { + const { container } = render(Test content); + expect(container.firstChild).toHaveAttribute('data-ouia-component-id', 'test-id'); +}); + +test('Renders with expected ouia component type', () => { + const { container } = render(Test content); + expect(container.firstChild).toHaveAttribute('data-ouia-component-type', 'PF6/ExpandableSection'); +}); + +test('Renders with ouiaSafe defaulting to true', () => { + const { container } = render(Test content); + expect(container.firstChild).toHaveAttribute('data-ouia-safe', 'true'); +}); + +test('Renders with ouiaSafe=false when specified', () => { + const { container } = render( + + Test content + + ); + expect(container.firstChild).toHaveAttribute('data-ouia-safe', 'false'); +}); diff --git a/packages/react-core/src/components/ExpandableSection/__tests__/__snapshots__/ExpandableSection.test.tsx.snap b/packages/react-core/src/components/ExpandableSection/__tests__/__snapshots__/ExpandableSection.test.tsx.snap index 9129caa2247..1225988eca1 100644 --- a/packages/react-core/src/components/ExpandableSection/__tests__/__snapshots__/ExpandableSection.test.tsx.snap +++ b/packages/react-core/src/components/ExpandableSection/__tests__/__snapshots__/ExpandableSection.test.tsx.snap @@ -4,6 +4,8 @@ exports[`Disclosure ExpandableSection 1`] = `