From 56b406c97184208bcf5727dfc755acbe167b0a1d Mon Sep 17 00:00:00 2001 From: Georgii Karataev Date: Thu, 22 Feb 2024 14:02:46 +0100 Subject: [PATCH] chore: Enhance OUIA IDs for ConditionalFilter (#1972) * chore: Enhance OUIA IDs for ConditionalFilter * chore: Cover more bulk select components with OUIA ID * chore: Add more OUIA IDs to primary toolbar actions * chore: Add OUIA ID for bulk select dropdown * chore: Update remaining snapshots * chore: Update cypress tests --- .../components/src/BulkSelect/BulkSelect.tsx | 23 ++++++------ .../__snapshots__/BulkSelect.test.js.snap | 18 ++++----- .../ConditionalFilter.test.js | 10 ++--- .../ConditionalFilter/ConditionalFilter.tsx | 13 +++++-- .../ConditionalFilter.test.js.snap | 37 ++++++++++++++----- .../components/src/PrimaryToolbar/Actions.tsx | 4 +- .../PrimaryToolbar/PrimaryToolbar.spec.ct.js | 2 +- .../src/PrimaryToolbar/PrimaryToolbar.tsx | 4 +- .../__snapshots__/Actions.test.js.snap | 9 ++++- .../__snapshots__/PrimaryToolbar.test.js.snap | 3 -- 10 files changed, 76 insertions(+), 47 deletions(-) diff --git a/packages/components/src/BulkSelect/BulkSelect.tsx b/packages/components/src/BulkSelect/BulkSelect.tsx index d29521919..af4f0c064 100644 --- a/packages/components/src/BulkSelect/BulkSelect.tsx +++ b/packages/components/src/BulkSelect/BulkSelect.tsx @@ -1,5 +1,6 @@ import React, { Fragment, useRef, useState } from 'react'; import classnames from 'classnames'; +// eslint-disable-next-line rulesdir/forbid-pf-relative-imports import { Checkbox, Dropdown, @@ -10,7 +11,6 @@ import { MenuToggleCheckbox, MenuToggleCheckboxProps, MenuToggleProps, - getDefaultOUIAId, } from '@patternfly/react-core'; import './bulk-select.scss'; @@ -35,8 +35,10 @@ export interface BulkSelectProps { onSelect?: MenuToggleCheckboxProps['onChange']; toggleProps?: MenuToggleProps; isDisabled?: boolean; - ouiaId?: string; ouiaSafe?: boolean; + dropdownOuiaId?: string; + checkboxOuiaId?: string; + listOuiaId?: string; } const BulkSelect: React.FunctionComponent = ({ @@ -48,17 +50,15 @@ const BulkSelect: React.FunctionComponent = ({ toggleProps, count, className, - ouiaId, ouiaSafe = true, ...props }) => { const [isOpen, setIsOpen] = useState(false); const { current: hasError } = useRef(false); - const { current: ouiaStateId } = useRef(getDefaultOUIAId('RHI/BulkSelect')); const onToggle = (isOpen: boolean) => setIsOpen(isOpen); - const ouiaFinalId = ouiaId !== undefined ? ouiaId : ouiaStateId; + const { dropdownOuiaId, checkboxOuiaId, listOuiaId } = props; return ( @@ -66,18 +66,18 @@ const BulkSelect: React.FunctionComponent = ({ onToggle(false)} onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)} + data-ouia-component-id={dropdownOuiaId ?? 'BulkSelect'} {...props} className={classnames(className, 'ins-c-bulk-select')} - ouiaId={ouiaFinalId} ouiaSafe={ouiaSafe} toggle={(toggleRef) => ( setIsOpen((prev) => !prev)} + data-ouia-component-id={dropdownOuiaId ?? 'BulkSelect'} > {hasError ? ( @@ -86,7 +86,7 @@ const BulkSelect: React.FunctionComponent = ({ aria-label="Select all" onChange={onSelect} isChecked={checked} - ouiaId={ouiaFinalId} + ouiaId={checkboxOuiaId ?? 'BulkSelectCheckbox'} /> ) : ( = ({ aria-label="Select all" onChange={onSelect} isChecked={checked} - ouiaId={ouiaFinalId} + ouiaId={checkboxOuiaId ?? 'BulkSelectCheckbox'} > {count ? `${count} selected` : ''} @@ -104,7 +104,7 @@ const BulkSelect: React.FunctionComponent = ({ )} isOpen={isOpen} > - + {count !== undefined && count > 0 && ( = ({ oneItem.onClick && oneItem.onClick(event, oneItem, key)} {...oneItem?.props} > @@ -137,6 +137,7 @@ const BulkSelect: React.FunctionComponent = ({ id={`${id}-checkbox`} isChecked={checked} onChange={(e, checked) => onSelect?.(checked, e)} + ouiaId={dropdownOuiaId ?? 'BulkSelect'} /> )} diff --git a/packages/components/src/BulkSelect/__snapshots__/BulkSelect.test.js.snap b/packages/components/src/BulkSelect/__snapshots__/BulkSelect.test.js.snap index 7b811d75a..c7f02038e 100644 --- a/packages/components/src/BulkSelect/__snapshots__/BulkSelect.test.js.snap +++ b/packages/components/src/BulkSelect/__snapshots__/BulkSelect.test.js.snap @@ -9,7 +9,7 @@ exports[`BulkSelect should render correctly - no data 1`] = ` aria-invalid="false" aria-label="Select all" class="pf-v5-c-check__input" - data-ouia-component-id="OUIA-Generated-Checkbox-1" + data-ouia-component-id="BulkSelect" data-ouia-component-type="PF5/Checkbox" data-ouia-safe="true" id="undefined-checkbox" @@ -23,8 +23,8 @@ exports[`BulkSelect should render correctly - null checked 1`] = `