Skip to content

Commit dcde48d

Browse files
mshrivercursoragent
andcommitted
chore(DualListSelector): Include OUIAProps for DualListSelector
Add OUIA attribute support to DualListSelector for better test automation. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c4086a0 commit dcde48d

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
22
import { css } from '@patternfly/react-styles';
3-
import { useSSRSafeId } from '../../helpers';
3+
import { useSSRSafeId, useOUIAProps, OUIAProps, useHasAnimations } from '../../helpers';
44
import { DualListSelectorContext } from './DualListSelectorContext';
5-
import { useHasAnimations } from '../../helpers';
65

76
/** Acts as a container for all other DualListSelector sub-components when using a
87
* composable dual list selector.
98
*/
109

11-
export interface DualListSelectorProps {
10+
export interface DualListSelectorProps extends OUIAProps {
1211
/** Additional classes applied to the dual list selector. */
1312
className?: string;
1413
/** ID of the dual list selector. */
@@ -22,6 +21,10 @@ export interface DualListSelectorProps {
2221
* the next breaking change release in favor of defaulting to always-rendered items.
2322
*/
2423
hasAnimations?: boolean;
24+
/** Value to overwrite the randomly generated data-ouia-component-id.*/
25+
ouiaId?: number | string;
26+
/** 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. */
27+
ouiaSafe?: boolean;
2528
}
2629

2730
export const DualListSelector: React.FunctionComponent<DualListSelectorProps> = ({
@@ -30,17 +33,21 @@ export const DualListSelector: React.FunctionComponent<DualListSelectorProps> =
3033
id,
3134
isTree = false,
3235
hasAnimations: hasAnimationsProp,
36+
ouiaId,
37+
ouiaSafe = true,
3338
...props
3439
}: DualListSelectorProps) => {
3540
const hasAnimations = useHasAnimations(hasAnimationsProp);
3641
const randomId = useSSRSafeId();
42+
const ouiaProps = useOUIAProps(DualListSelector.displayName, ouiaId, ouiaSafe);
3743

3844
return (
3945
<DualListSelectorContext.Provider value={{ isTree, hasAnimations }}>
4046
<div
4147
className={css(styles.dualListSelector, hasAnimations && isTree && styles.modifiers.animateExpand, className)}
4248
id={id || randomId}
4349
{...props}
50+
{...ouiaProps}
4451
>
4552
{children}
4653
</div>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ describe('Opt-in animations', () => {
5959
});
6060
});
6161

62+
test('Matches snapshot', () => {
63+
const { asFragment } = render(<DualListSelector ouiaId="ouia-id" data-testid="test-id" />);
64+
expect(asFragment()).toMatchSnapshot();
65+
});
66+
67+
test('Renders with custom ouiaId', () => {
68+
render(<DualListSelector data-testid="test-id" ouiaId="test-id" />);
69+
expect(screen.getByTestId('test-id')).toHaveAttribute('data-ouia-component-id', 'test-id');
70+
});
71+
72+
test('Renders with expected ouia component type', () => {
73+
render(<DualListSelector data-testid="test-id" ouiaId="test-id" />);
74+
expect(screen.getByTestId('test-id')).toHaveAttribute('data-ouia-component-type', 'PF6/DualListSelector');
75+
});
76+
77+
test('Renders with ouiaSafe defaulting to true', () => {
78+
render(<DualListSelector data-testid="test-id" ouiaId="test-id" />);
79+
expect(screen.getByTestId('test-id')).toHaveAttribute('data-ouia-safe', 'true');
80+
});
81+
82+
test('Renders with ouiaSafe=false when specified', () => {
83+
render(<DualListSelector data-testid="test-id" ouiaId="test-id" ouiaSafe={false} />);
84+
expect(screen.getByTestId('test-id')).toHaveAttribute('data-ouia-safe', 'false');
85+
});
86+
6287
// Following tests should be moved to a separate DualListSelectorPane test file
6388
describe('DualListSelector', () => {
6489
test('basic', () => {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,16 @@ exports[`DualListSelector with search inputs 1`] = `
120120
</div>
121121
</DocumentFragment>
122122
`;
123+
124+
exports[`Matches snapshot 1`] = `
125+
<DocumentFragment>
126+
<div
127+
class="pf-v6-c-dual-list-selector"
128+
data-ouia-component-id="ouia-id"
129+
data-ouia-component-type="PF6/DualListSelector"
130+
data-ouia-safe="true"
131+
data-testid="test-id"
132+
id="pf-:re:"
133+
/>
134+
</DocumentFragment>
135+
`;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ component.
5858
* [Content](/components/content)
5959
* [Dropdown](/components/menus/dropdown)
6060
* [DropdownItem](/components/menus/dropdown)
61+
* [DualListSelector](/components/dual-list-selector)
6162
* [ExpandableSection](/components/expandable-section)
6263
* [Form](/components/forms/form)
6364
* [FormGroup](/components/forms/form)

0 commit comments

Comments
 (0)