[WATCHER] Allow user to set a threshold value of 0 (#44810)

This commit is contained in:
Alison Goryachev 2019-09-05 15:03:24 -04:00 committed by GitHub
parent 8c44e89b47
commit e383069066
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 1 deletions

View file

@ -92,6 +92,8 @@ export type TestSubjects =
| 'watchActionAccordion'
| 'watchActionAccordion.mockComboBox'
| 'watchActionsPanel'
| 'watchThresholdButton'
| 'watchThresholdInput'
| 'watchConditionTitle'
| 'watchTimeFieldSelect'
| 'watchVisualizationChart'

View file

@ -190,6 +190,45 @@ describe.skip('<ThresholdWatchEdit /> create route', () => {
expect(exists('watchVisualizationChart')).toBe(true);
expect(exists('watchActionsPanel')).toBe(true);
});
describe('watch conditions', () => {
beforeEach(async () => {
const { form, find, component } = testBed;
// Name, index and time fields are required before the watch condition expression renders
form.setInputValue('nameInput', 'my_test_watch');
find('mockComboBox').simulate('change', [{ label: 'index1', value: 'index1' }]); // Using mocked EuiComboBox
form.setInputValue('watchTimeFieldSelect', '@timestamp');
// @ts-ignore (remove when react 16.9.0 is released)
await act(async () => {
await nextTick();
component.update();
});
});
test('should require a threshold value', async () => {
const { form, find, component } = testBed;
find('watchThresholdButton').simulate('click');
// Provide invalid value
form.setInputValue('watchThresholdInput', '');
expect(form.getErrorsMessages()).toContain('A value is required.');
// Provide valid value
form.setInputValue('watchThresholdInput', '0');
// @ts-ignore (remove when react 16.9.0 is released)
await act(async () => {
await nextTick();
component.update();
});
expect(form.getErrorsMessages().length).toEqual(0);
});
});
});
describe('actions', () => {

View file

@ -206,7 +206,7 @@ export class ThresholdWatch extends BaseWatch {
Array.from(Array(comparators[this.thresholdComparator].requiredValues)).forEach((value, i) => {
const key = `threshold${i}`;
errors[key] = [];
if (!this.threshold[i]) {
if (this.threshold[i] == null || this.threshold[i] === '') {
errors[key].push(i18n.translate(
'xpack.watcher.thresholdWatchExpression.thresholdLevel.valueIsRequiredValidationMessage',
{

View file

@ -698,6 +698,7 @@ export const ThresholdWatchEdit = ({ pageTitle }: { pageTitle: string }) => {
id="watchThresholdPopover"
button={
<EuiExpression
data-test-subj="watchThresholdButton"
description={comparators[watch.thresholdComparator].text}
value={watch.threshold
.slice(0, comparators[watch.thresholdComparator].requiredValues)
@ -759,6 +760,7 @@ export const ThresholdWatchEdit = ({ pageTitle }: { pageTitle: string }) => {
errors={errors}
>
<EuiFieldNumber
data-test-subj="watchThresholdInput"
value={watch.threshold[i] == null ? '' : watch.threshold[i]}
min={0}
step={0.1}