Fix anomaly alert selection text (#80746)

Was using the incorrect value. Add a case to leave out "and above" when on "critical."

Add a test and rename files to snake case.

Fixes #80441.
This commit is contained in:
Nathan L Smith 2020-10-15 17:21:33 -05:00 committed by GitHub
parent 10271c50ee
commit 29491ac3e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 4 deletions

View file

@ -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,

View file

@ -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',
]);
});
});

View file

@ -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>