Skip to content

Commit

Permalink
Add different data-test-subj for different alert details pages based …
Browse files Browse the repository at this point in the history
…on rule type id (#163709)

Closes #163682

## 📝 Summary 

Add different data-test-subj for different alert details pages based on
rule type id, this will help us in tracking these pages more easily.


![image](https://github.com/elastic/kibana/assets/12370520/86a080f8-7a1c-4352-abab-9dcd93c93176)


![image](https://github.com/elastic/kibana/assets/12370520/195358ef-e01d-42b6-b5ab-abdb55447604)
  • Loading branch information
maryam-saeidi authored Aug 14, 2023
1 parent 7cb6e29 commit cb3d22a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Alert details', () => {

expect(alertDetails.queryByTestId('alertDetails')).toBeTruthy();
expect(alertDetails.queryByTestId('alertDetailsError')).toBeFalsy();
expect(alertDetails.queryByTestId('page-title-container')).toBeTruthy();
expect(alertDetails.queryByTestId('alertDetailsPageTitle')).toBeTruthy();
expect(alertDetails.queryByTestId('alert-summary-container')).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export function AlertDetails() {
return (
<ObservabilityPageTemplate
pageHeader={{
pageTitle: <PageTitle alert={alert} />,
pageTitle: (
<PageTitle alert={alert} dataTestSubj={rule?.ruleTypeId || 'alertDetailsPageTitle'} />
),
rightSideItems: [
<CasesContext
owner={[observabilityFeatureId]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { alert } from '../mock/alert';
describe('Page Title', () => {
const defaultProps = {
alert,
dataTestSubj: 'ruleTypeId',
};

const renderComp = (props: PageTitleProps) => {
Expand All @@ -28,7 +29,7 @@ describe('Page Title', () => {
it('should display Log threshold title', () => {
const { getByTestId } = renderComp(defaultProps);

expect(getByTestId('page-title-container').textContent).toContain('Log threshold breached');
expect(getByTestId('ruleTypeId').textContent).toContain('Log threshold breached');
});

it('should display Anomaly title', () => {
Expand All @@ -40,11 +41,12 @@ describe('Page Title', () => {
[ALERT_RULE_CATEGORY]: 'Anomaly',
},
},
dataTestSubj: defaultProps.dataTestSubj,
};

const { getByTestId } = renderComp(props);

expect(getByTestId('page-title-container').textContent).toContain('Anomaly detected');
expect(getByTestId('ruleTypeId').textContent).toContain('Anomaly detected');
});

it('should display Inventory title', () => {
Expand All @@ -56,13 +58,12 @@ describe('Page Title', () => {
[ALERT_RULE_CATEGORY]: 'Inventory',
},
},
dataTestSubj: defaultProps.dataTestSubj,
};

const { getByTestId } = renderComp(props);

expect(getByTestId('page-title-container').textContent).toContain(
'Inventory threshold breached'
);
expect(getByTestId('ruleTypeId').textContent).toContain('Inventory threshold breached');
});

it('should display an active badge when active is true', async () => {
Expand All @@ -71,7 +72,7 @@ describe('Page Title', () => {
});

it('should display an inactive badge when active is false', async () => {
const updatedProps = { alert };
const updatedProps = { alert, dataTestSubj: defaultProps.dataTestSubj };
updatedProps.alert.active = false;

const { getByText } = renderComp({ ...updatedProps });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {

export interface PageTitleProps {
alert: TopAlert | null;
dataTestSubj: string;
}

export function pageTitleContent(ruleCategory: string) {
Expand All @@ -51,7 +52,7 @@ export function pageTitleContent(ruleCategory: string) {
});
}

export function PageTitle({ alert }: PageTitleProps) {
export function PageTitle({ alert, dataTestSubj }: PageTitleProps) {
const { euiTheme } = useEuiTheme();

if (!alert) return <EuiLoadingSpinner />;
Expand All @@ -62,7 +63,7 @@ export function PageTitle({ alert }: PageTitleProps) {
alert.fields[ALERT_RULE_TYPE_ID] === METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID;

return (
<div data-test-subj="page-title-container">
<div data-test-subj={dataTestSubj}>
<EuiFlexGroup direction="row" alignItems="center" gutterSize="s">
{pageTitleContent(alert.fields[ALERT_RULE_CATEGORY])}
{showExperimentalBadge && <ExperimentalBadge />}
Expand Down

0 comments on commit cb3d22a

Please sign in to comment.