diff --git a/README.md b/README.md index 6e842c00..75e40109 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ When adding/making changes to a component, always make sure your code is tested: - use React Testing Library for testing - add tests to a `[ComponentName].test.tsx` file to your component's directory - make sure all the core logic is covered +- add `ouiaId` to component props definition with a default value of the component name (for subcomponents, let's use `ComponentName-element-specification` naming convention e.g. `ouiaId="WarningModal-confirm-button"`) ### Styling: - for styling always use JSS diff --git a/packages/module/src/Ansible/Ansible.tsx b/packages/module/src/Ansible/Ansible.tsx index cea29462..0d3a6565 100644 --- a/packages/module/src/Ansible/Ansible.tsx +++ b/packages/module/src/Ansible/Ansible.tsx @@ -5,8 +5,10 @@ import { createUseStyles } from 'react-jss'; export interface AnsibleProps extends React.DetailedHTMLProps, HTMLElement> { /** Supported/unsupported variant flag */ unsupported?: boolean | number; - /** Ansible icon className*/ + /** Ansible icon className */ className?: string; + /** Custom OUIA ID */ + ouiaId?: string | number; } const useStyles = createUseStyles({ @@ -30,7 +32,7 @@ const useStyles = createUseStyles({ } }) -const Ansible: React.FunctionComponent = ({ unsupported, className, ...props }: AnsibleProps) => { +const Ansible: React.FunctionComponent = ({ unsupported, className, ouiaId = "Ansible-icon", ...props }: AnsibleProps) => { const classes = useStyles(); const ansibleLogoClass = clsx( classes.ansible, @@ -71,7 +73,7 @@ const Ansible: React.FunctionComponent = ({ unsupported, className ); return ( - + = ({ severity, label, labelHidden, className, ...props }: BatteryProps) => { +const Battery: React.FunctionComponent = ({ severity, label, labelHidden, className, ouiaId = 'Battery-icon', ...props }: BatteryProps) => { const classes = useStyles(); const batteryClasses = clsx(classes.battery, classes[String(batteryLevels(severity, true))], className); @@ -103,7 +105,7 @@ const Battery: React.FunctionComponent = ({ severity, label, label return ( {/* eslint-disable-next-line react/no-unknown-property */} - + = ({ className, dataTestID, onClick, + ouiaId="CloseButton", ...props }: CloseButtonProps) => { const classes = useStyles(); @@ -30,6 +31,7 @@ const CloseButton: React.FunctionComponent = ({ data-test-id={dataTestID} onClick={onClick} variant={ButtonVariant.plain} + ouiaId={ouiaId} {...props} > diff --git a/packages/module/src/ErrorBoundary/ErrorBoundary.tsx b/packages/module/src/ErrorBoundary/ErrorBoundary.tsx index bd0c48f5..2e4bca63 100644 --- a/packages/module/src/ErrorBoundary/ErrorBoundary.tsx +++ b/packages/module/src/ErrorBoundary/ErrorBoundary.tsx @@ -18,6 +18,8 @@ export interface ErrorPageProps { defaultErrorDescription?: React.ReactNode; /** The component that the error boundary component is wrapped around, which should be returned if there is no error */ children?: React.ReactNode; + /** Custom OUIA ID */ + ouiaId?: string | number; } export interface ErrorPageState { @@ -61,33 +63,36 @@ class ErrorBoundary extends React.Component { } render() { + const { ouiaId = 'ErrorBoundary', ...props } = this.props; + if (this.state.hasError) { if (this.props.silent) { return null; } + return ( - - {this.props.headerTitle} +
+ {props.headerTitle} - {this.props.errorDescription} + {props.errorDescription} {this.state.error && ( - - + + )} } - defaultErrorDescription={this.props.defaultErrorDescription} + defaultErrorDescription={props.defaultErrorDescription} /> - +
); } - return this.props.children; + return props.children; } -} +}; export default ErrorBoundary; \ No newline at end of file diff --git a/packages/module/src/ErrorState/ErrorState.tsx b/packages/module/src/ErrorState/ErrorState.tsx index 2b93784b..d9cdfea9 100644 --- a/packages/module/src/ErrorState/ErrorState.tsx +++ b/packages/module/src/ErrorState/ErrorState.tsx @@ -29,27 +29,29 @@ export interface ErrorStateProps extends Omit { defaultErrorDescription?: React.ReactNode; /** Custom footer content */ customFooter?: React.ReactNode; + /** ErrorState OUIA ID */ + ouiaId?: string | number; } -const ErrorState: React.FunctionComponent = ({ errorTitle = 'Something went wrong', errorDescription, defaultErrorDescription, customFooter, ...props }: ErrorStateProps) => { +const ErrorState: React.FunctionComponent = ({ errorTitle = 'Something went wrong', errorDescription, defaultErrorDescription, customFooter, ouiaId = "ErrorState", ...props }: ErrorStateProps) => { const classes = useStyles(); return ( - {errorTitle}} icon={} headingLevel="h4" /> - + {errorTitle}} icon={} headingLevel="h4" data-ouia-component-id={`${ouiaId}-header`}/> + {errorDescription ? {errorDescription} : defaultErrorDescription} - + { customFooter || (document.referrer ? ( - ) : ( - ))} diff --git a/packages/module/src/InvalidObject/InvalidObject.tsx b/packages/module/src/InvalidObject/InvalidObject.tsx index 669f156a..1b9178e9 100644 --- a/packages/module/src/InvalidObject/InvalidObject.tsx +++ b/packages/module/src/InvalidObject/InvalidObject.tsx @@ -1,32 +1,35 @@ -import { Button, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateVariant } from '@patternfly/react-core'; +import { Button, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateProps, EmptyStateVariant } from '@patternfly/react-core'; import NotFoundIcon from '../NotFoundIcon/NotFoundIcon'; import React from 'react'; -export interface InvalidObjectProps extends React.DetailedHTMLProps, HTMLElement> { - /** The URL that the landing page link points to */ - toLandingPageUrl?: string; - /** The text label for the link that points back to the landing page */ - toLandingPageText?: React.ReactNode; +export interface InvalidObjectProps extends Omit { + /** The URL that the home page link points to */ + toHomePageUrl?: string; + /** The text label for the link that points back to the home page */ + toHomePageText?: React.ReactNode; /** The title for the invalid object message */ invalidObjectTitleText?: string; /** The body text for the invalid object message */ invalidObjectBodyText?: string; + /** Custom OUIA ID */ + ouiaId?: string | number; } - const InvalidObject: React.FunctionComponent = ({ - toLandingPageUrl = window.location.origin, - toLandingPageText = 'Return to homepage', + toHomePageUrl = window.location.origin, + toHomePageText = 'Return to homepage', invalidObjectTitleText = 'We lost that page', - invalidObjectBodyText = "Let's find you a new one. Try a new search or return home." + invalidObjectBodyText = "Let's find you a new one. Try a new search or return home.", + ouiaId = "InvalidObject", + ...props }: InvalidObjectProps) => ( - - } headingLevel='h1' /> - {invalidObjectBodyText} - - diff --git a/packages/module/src/InvalidObject/__snapshots__/InvalidObject.test.tsx.snap b/packages/module/src/InvalidObject/__snapshots__/InvalidObject.test.tsx.snap index 7325579d..a467d80b 100644 --- a/packages/module/src/InvalidObject/__snapshots__/InvalidObject.test.tsx.snap +++ b/packages/module/src/InvalidObject/__snapshots__/InvalidObject.test.tsx.snap @@ -7,16 +7,19 @@ exports[`InvalidObject component should render 1`] = `
Let's find you a new one. Try a new search or return home.