Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix anomaly alert selection text #80746

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression';
import {
AnomalySeverity,
SelectAnomalySeverity,
} from './SelectAnomalySeverity';
} from './select_anomaly_severity';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
import {
EnvironmentField,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { render } from '@testing-library/react';
import React, { ReactNode } from 'react';
import { IntlProvider } from 'react-intl';
import { ANOMALY_SEVERITY } from '../../../../../ml/common';
import { SelectAnomalySeverity } from './select_anomaly_severity';

function Wrapper({ children }: { children?: ReactNode }) {
return <IntlProvider locale="en">{children}</IntlProvider>;
}

describe('SelectAnomalySeverity', () => {
it('shows the correct text for each item', async () => {
const result = render(
<SelectAnomalySeverity
onChange={() => {}}
value={ANOMALY_SEVERITY.CRITICAL}
/>,
{ wrapper: Wrapper }
);
const button = (await result.findAllByText('critical'))[1];

button.click();

const options = await result.findAllByTestId(
'SelectAnomalySeverity option text'
);

expect(
options.map((option) => (option.firstChild as HTMLElement)?.innerHTML)
).toEqual([
'score critical ', // Trailing space is intentional here, to keep the i18n simple
'score major and above',
'score minor and above',
'score warning and above',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export function SelectAnomalySeverity({ onChange, value }: Props) {
<AnomalySeverity type={option.type} />
<EuiSpacer size="xs" />
<EuiText size="xs" color="subdued">
<p className="euiTextColor--subdued">
<p
className="euiTextColor--subdued"
data-test-subj="SelectAnomalySeverity option text"
>
<FormattedMessage
id="xpack.apm.alerts.anomalySeverity.scoreDetailsDescription"
defaultMessage="score {value} and above"
values={{ value }}
defaultMessage="score {value} {value, select, critical {} other {and above}}"
values={{ value: option.type }}
/>
</p>
</EuiText>
Expand Down