Skip to content

Commit

Permalink
Add test IDs to components for integ tests (#183)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler authored Mar 1, 2022
1 parent 811263a commit 53a0f4f
Show file tree
Hide file tree
Showing 57 changed files with 339 additions and 131 deletions.
175 changes: 94 additions & 81 deletions public/components/ContentPanel/ContentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
EuiTitle,
EuiSpacer,
} from '@elastic/eui';
import { isEmpty } from 'lodash';
import { isEmpty, get } from 'lodash';

type ContentPanelProps = {
// keep title string part for backwards compatibility
Expand All @@ -39,96 +39,109 @@ type ContentPanelProps = {
children: React.ReactNode | React.ReactNode[];
contentPanelClassName?: string;
hideBody?: boolean;
titleDataTestSubj?: string;
};

const ContentPanel = (props: ContentPanelProps) => (
<EuiPanel
style={{ padding: '20px', ...props.panelStyles }}
className={props.contentPanelClassName}
betaBadgeLabel={props.badgeLabel}
>
<EuiFlexGroup
style={{ padding: '0px', ...props.titleContainerStyles }}
justifyContent="spaceBetween"
alignItems="center"
const ContentPanel = (props: ContentPanelProps) => {
const titleDataTestSubj = get(
props,
'titleDataTestSubj',
'contentPanelTitle'
);
return (
<EuiPanel
style={{ padding: '20px', ...props.panelStyles }}
className={props.contentPanelClassName}
betaBadgeLabel={props.badgeLabel}
>
<EuiFlexItem>
{typeof props.title === 'string' ? (
<EuiTitle
size={props.titleSize || 's'}
className={props.titleClassName}
>
<h3>{props.title}</h3>
</EuiTitle>
) : (
<EuiFlexGroup justifyContent="flexStart" alignItems="center">
{Array.isArray(props.title) ? (
props.title.map(
(titleComponent: React.ReactNode, idx: number) => (
<EuiFlexItem grow={false} key={idx}>
{titleComponent}
<EuiFlexGroup
style={{ padding: '0px', ...props.titleContainerStyles }}
justifyContent="spaceBetween"
alignItems="center"
>
<EuiFlexItem>
{typeof props.title === 'string' ? (
<EuiTitle
data-test-subj={titleDataTestSubj}
size={props.titleSize || 's'}
className={props.titleClassName}
>
<h3>{props.title}</h3>
</EuiTitle>
) : (
<EuiFlexGroup
data-test-subj={titleDataTestSubj}
justifyContent="flexStart"
alignItems="center"
>
{Array.isArray(props.title) ? (
props.title.map(
(titleComponent: React.ReactNode, idx: number) => (
<EuiFlexItem grow={false} key={idx}>
{titleComponent}
</EuiFlexItem>
)
)
) : (
<EuiFlexItem>{props.title}</EuiFlexItem>
)}
</EuiFlexGroup>
)}
<EuiFlexGroup>
{Array.isArray(props.subTitle) ? (
props.subTitle.map(
(subTitleComponent: React.ReactNode, idx: number) => (
<EuiFlexItem
grow={false}
key={idx}
className="content-panel-subTitle"
style={{ lineHeight: 'normal', maxWidth: '75%' }}
>
{subTitleComponent}
</EuiFlexItem>
)
)
) : (
<EuiFlexItem>{props.title}</EuiFlexItem>
<EuiFlexItem
className="content-panel-subTitle"
style={{ lineHeight: 'normal', maxWidth: '75%' }}
>
{props.subTitle}
</EuiFlexItem>
)}
</EuiFlexGroup>
)}
<EuiFlexGroup>
{Array.isArray(props.subTitle) ? (
props.subTitle.map(
(subTitleComponent: React.ReactNode, idx: number) => (
<EuiFlexItem
grow={false}
key={idx}
className="content-panel-subTitle"
style={{ lineHeight: 'normal', maxWidth: '75%' }}
>
{subTitleComponent}
</EuiFlexItem>
)
)
) : (
<EuiFlexItem
className="content-panel-subTitle"
style={{ lineHeight: 'normal', maxWidth: '75%' }}
>
{props.subTitle}
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiFlexGroup
justifyContent="spaceBetween"
alignItems="center"
gutterSize="m"
>
{Array.isArray(props.actions) ? (
props.actions.map((action: React.ReactNode, idx: number) => (
<EuiFlexItem key={idx}>{action}</EuiFlexItem>
))
) : (
<EuiFlexItem>{props.actions}</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
{!isEmpty(props.actions) ? <EuiSpacer size="s" /> : null}
{props.title != '' && props.hideBody !== true ? (
<div>
<EuiHorizontalRule
margin="s"
className={props.horizontalRuleClassName}
/>
<div style={{ padding: '10px 0px', ...props.bodyStyles }}>
{props.children}
<EuiFlexItem grow={false}>
<EuiFlexGroup
justifyContent="spaceBetween"
alignItems="center"
gutterSize="m"
>
{Array.isArray(props.actions) ? (
props.actions.map((action: React.ReactNode, idx: number) => (
<EuiFlexItem key={idx}>{action}</EuiFlexItem>
))
) : (
<EuiFlexItem>{props.actions}</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
{!isEmpty(props.actions) ? <EuiSpacer size="s" /> : null}
{props.title != '' && props.hideBody !== true ? (
<div>
<EuiHorizontalRule
margin="s"
className={props.horizontalRuleClassName}
/>
<div style={{ padding: '10px 0px', ...props.bodyStyles }}>
{props.children}
</div>
</div>
</div>
) : null}
</EuiPanel>
);
) : null}
</EuiPanel>
);
};

export default ContentPanel;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`<ContentPanel /> spec renders the component 1`] = `
>
<h3
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Testing
</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const FeatureChart = (props: FeatureChartProps) => {
? props.feature.featureName
: `${props.feature.featureName} (disabled)`
}
titleDataTestSubj="featureNameHeader"
bodyStyles={
!props.feature.featureEnabled
? { backgroundColor: getDisabledChartBackground() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export const AnomalyDetailsChart = React.memo(
<EuiFlexGroup style={{ padding: '20px' }}>
<EuiFlexItem>
<EuiStat
data-test-subj="anomalyOccurrenceStat"
title={isLoading ? '-' : anomalySummary.anomalyOccurrence}
description={getAnomalyOccurrenceWording(props.isNotSample)}
titleSize="s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const AggregationSelector = (props: AggregationSelectorProps) => {
error={getError(field.name, form)}
>
<EuiComboBox
data-test-subj={`featureFieldTextInput-${props.index}`}
placeholder="Select field"
singleSelection={{ asPlainText: true }}
selectedOptions={field.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ exports[`<AggregationSelector /> spec Empty results renders component with aggre
aria-expanded="false"
aria-haspopup="listbox"
class="euiComboBox"
data-test-subj="featureFieldTextInput-undefined"
name="featureList.undefined.aggregationOf"
role="combobox"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`<CategoryField /> spec renders the component when disabled 1`] = `
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="contentPanelTitle"
>
<div
class="euiFlexItem"
Expand Down Expand Up @@ -135,6 +136,7 @@ exports[`<CategoryField /> spec renders the component when enabled 1`] = `
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="contentPanelTitle"
>
<div
class="euiFlexItem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const FeatureAccordion = (props: FeatureAccordionProps) => {
error={getError(field.name, form)}
>
<EuiFieldText
data-test-subj={`featureNameTextInput-${props.index}`}
name={`featureList.${props.index}.featureName`}
placeholder="Enter feature name"
value={field.value ? field.value : props.feature.featureName}
Expand Down
5 changes: 4 additions & 1 deletion public/pages/ConfigureModel/containers/ConfigureModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ export function ConfigureModel(props: ConfigureModelProps) {
<EuiPageBody>
<EuiPageHeader>
<EuiPageHeaderSection>
<EuiTitle size="l">
<EuiTitle
size="l"
data-test-subj="configureOrEditModelConfigurationTitle"
>
<h1>
{props.isEdit
? 'Edit model configuration'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
>
<h1
class="euiTitle euiTitle--large"
data-test-subj="configureOrEditModelConfigurationTitle"
>
Configure model
Expand Down Expand Up @@ -65,6 +66,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
>
<h3
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Features
</h3>
Expand Down Expand Up @@ -229,6 +231,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
<input
aria-describedby="random_html_id-help"
class="euiFieldText"
data-test-subj="featureNameTextInput-0"
id="random_html_id"
name="featureList.0.featureName"
placeholder="Enter feature name"
Expand Down Expand Up @@ -455,6 +458,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
aria-expanded="false"
aria-haspopup="listbox"
class="euiComboBox"
data-test-subj="featureFieldTextInput-0"
name="featureList.0.aggregationOf"
role="combobox"
>
Expand Down Expand Up @@ -576,6 +580,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="contentPanelTitle"
>
<div
class="euiFlexItem"
Expand Down Expand Up @@ -715,6 +720,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="contentPanelTitle"
>
<div
class="euiFlexItem"
Expand Down Expand Up @@ -780,6 +786,7 @@ exports[`<ConfigureModel /> spec creating model configuration renders the compon
>
<h3
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Sample anomalies
</h3>
Expand Down Expand Up @@ -919,6 +926,7 @@ exports[`<ConfigureModel /> spec editing model configuration renders the compone
>
<h1
class="euiTitle euiTitle--large"
data-test-subj="configureOrEditModelConfigurationTitle"
>
Edit model configuration
Expand Down Expand Up @@ -972,6 +980,7 @@ exports[`<ConfigureModel /> spec editing model configuration renders the compone
>
<h3
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Features
</h3>
Expand Down Expand Up @@ -1145,6 +1154,7 @@ exports[`<ConfigureModel /> spec editing model configuration renders the compone
<input
aria-describedby="random_html_id-help"
class="euiFieldText"
data-test-subj="featureNameTextInput-0"
id="random_html_id"
name="featureList.0.featureName"
placeholder="Enter feature name"
Expand Down Expand Up @@ -1381,6 +1391,7 @@ exports[`<ConfigureModel /> spec editing model configuration renders the compone
aria-expanded="false"
aria-haspopup="listbox"
class="euiComboBox"
data-test-subj="featureFieldTextInput-0"
name="featureList.0.aggregationOf"
role="combobox"
>
Expand Down Expand Up @@ -1507,6 +1518,7 @@ exports[`<ConfigureModel /> spec editing model configuration renders the compone
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="contentPanelTitle"
>
<div
class="euiFlexItem"
Expand Down Expand Up @@ -1682,6 +1694,7 @@ exports[`<ConfigureModel /> spec editing model configuration renders the compone
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
data-test-subj="contentPanelTitle"
>
<div
class="euiFlexItem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const AnomaliesDistributionChart = (

return (
<ContentPanel
titleDataTestSubj="dashboardSunburstChartHeader"
title="Anomalies by index and detector"
titleSize="s"
subTitle={`The inner circle shows anomaly distribution by index.
Expand Down
Loading

0 comments on commit 53a0f4f

Please sign in to comment.