Skip to content

Commit 1e942d8

Browse files
chore(DescriptionList): Include OUIAProps for DescriptionList (#12595)
Add OUIA attribute support to DescriptionList for better test automation. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5822e05 commit 1e942d8

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

packages/react-core/src/components/DescriptionList/DescriptionList.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css } from '@patternfly/react-styles';
22
import styles from '@patternfly/react-styles/css/components/DescriptionList/description-list';
3-
import { formatBreakpointMods } from '../../helpers';
3+
import { formatBreakpointMods, useOUIAProps, OUIAProps } from '../../helpers';
44
import cssGridTemplateColumnsMin from '@patternfly/react-tokens/dist/esm/c_description_list_GridTemplateColumns_min';
55
import cssTermWidth from '@patternfly/react-tokens/dist/esm/c_description_list__term_width';
66
import cssHorizontalTermWidth from '@patternfly/react-tokens/dist/esm/c_description_list_m_horizontal__term_width';
@@ -13,7 +13,7 @@ export interface BreakpointModifiers {
1313
'2xl'?: string;
1414
}
1515

16-
export interface DescriptionListProps extends Omit<React.HTMLProps<HTMLDListElement>, 'type'> {
16+
export interface DescriptionListProps extends Omit<React.HTMLProps<HTMLDListElement>, 'type'>, OUIAProps {
1717
/** Anything that can be rendered inside of the list */
1818
children?: React.ReactNode;
1919
/** Additional classes added to the list */
@@ -71,6 +71,10 @@ export interface DescriptionListProps extends Omit<React.HTMLProps<HTMLDListElem
7171
xl?: string;
7272
'2xl'?: string;
7373
};
74+
/** Value to overwrite the randomly generated data-ouia-component-id.*/
75+
ouiaId?: number | string;
76+
/** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
77+
ouiaSafe?: boolean;
7478
}
7579

7680
const setBreakpointModifiers = (prefix: string, modifiers: BreakpointModifiers) => {
@@ -99,8 +103,11 @@ export const DescriptionList: React.FunctionComponent<DescriptionListProps> = ({
99103
horizontalTermWidthModifier,
100104
orientation,
101105
style,
106+
ouiaId,
107+
ouiaSafe = true,
102108
...props
103109
}: DescriptionListProps) => {
110+
const ouiaProps = useOUIAProps(DescriptionList.displayName, ouiaId, ouiaSafe);
104111
if (isAutoFit && autoFitMinModifier) {
105112
style = {
106113
...style,
@@ -139,6 +146,7 @@ export const DescriptionList: React.FunctionComponent<DescriptionListProps> = ({
139146
)}
140147
style={style}
141148
{...props}
149+
{...ouiaProps}
142150
>
143151
{children}
144152
</dl>

packages/react-core/src/components/DescriptionList/__tests__/DescriptionList.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DescriptionList } from '../DescriptionList';
44
import styles from '@patternfly/react-styles/css/components/DescriptionList/description-list';
55

66
test('Renders to match snapshot', () => {
7-
const { asFragment } = render(<DescriptionList />);
7+
const { asFragment } = render(<DescriptionList ouiaId="ouia-id" />);
88
expect(asFragment()).toMatchSnapshot();
99
});
1010

@@ -155,3 +155,23 @@ test(`Renders style when isAutoFit and horizontalTermWidthModifier is set`, () =
155155
`--${styles.descriptionList}--GridTemplateColumns--min: 50px; --${styles.descriptionList}--GridTemplateColumns--min-on-sm: 50px; --${styles.descriptionList}--GridTemplateColumns--min-on-md: 100px; --${styles.descriptionList}--GridTemplateColumns--min-on-lg: 150px; --${styles.descriptionList}--GridTemplateColumns--min-on-xl: 200px; --${styles.descriptionList}--GridTemplateColumns--min-on-2xl: 300px;`
156156
);
157157
});
158+
159+
test('Renders with custom ouiaId', () => {
160+
render(<DescriptionList aria-label="list" ouiaId="test-id" />);
161+
expect(screen.getByLabelText('list')).toHaveAttribute('data-ouia-component-id', 'test-id');
162+
});
163+
164+
test('Renders with expected ouia component type', () => {
165+
render(<DescriptionList aria-label="list" ouiaId="test-id" />);
166+
expect(screen.getByLabelText('list')).toHaveAttribute('data-ouia-component-type', 'PF6/DescriptionList');
167+
});
168+
169+
test('Renders with ouiaSafe defaulting to true', () => {
170+
render(<DescriptionList aria-label="list" ouiaId="test-id" />);
171+
expect(screen.getByLabelText('list')).toHaveAttribute('data-ouia-safe', 'true');
172+
});
173+
174+
test('Renders with ouiaSafe=false when specified', () => {
175+
render(<DescriptionList aria-label="list" ouiaId="test-id" ouiaSafe={false} />);
176+
expect(screen.getByLabelText('list')).toHaveAttribute('data-ouia-safe', 'false');
177+
});

packages/react-core/src/components/DescriptionList/__tests__/__snapshots__/DescriptionList.test.tsx.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ exports[`Renders to match snapshot 1`] = `
44
<DocumentFragment>
55
<dl
66
class="pf-v6-c-description-list"
7+
data-ouia-component-id="ouia-id"
8+
data-ouia-component-type="PF6/DescriptionList"
9+
data-ouia-safe="true"
710
/>
811
</DocumentFragment>
912
`;

packages/react-core/src/helpers/OUIA/OUIA.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ component.
5656
* [Chip](/components/chip)
5757
* [ClipboardCopy](/components/clipboard-copy)
5858
* [Content](/components/content)
59+
* [DescriptionList](/components/description-list)
5960
* [Dropdown](/components/menus/dropdown)
6061
* [DropdownItem](/components/menus/dropdown)
6162
* [ExpandableSection](/components/expandable-section)

0 commit comments

Comments
 (0)