Skip to content
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 @@ -158,6 +158,20 @@ describe('expression params validation', () => {
);
});

test('if size property is 0 should not return error message', () => {
const initialParams: EsQueryAlertParams<SearchType.esQuery> = {
index: ['test'],
esQuery: `{\n \"query\":{\n \"match_all\" : {}\n }\n`,
size: 0,
timeWindowSize: 1,
timeWindowUnit: 's',
threshold: [0],
timeField: '',
excludeHitsFromPreviousRun: true,
};
expect(validateExpression(initialParams).errors.size.length).toBe(0);
});

test('if size property is > 10000 should return proper error message', () => {
const initialParams: EsQueryAlertParams<SearchType.esQuery> = {
index: ['test'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { defaultsDeep } from 'lodash';
import { defaultsDeep, isNil } from 'lodash';
import { i18n } from '@kbn/i18n';
import { ValidationResult, builtInComparators } from '@kbn/triggers-actions-ui-plugin/public';
import { EsQueryAlertParams, ExpressionErrors } from './types';
Expand Down Expand Up @@ -63,7 +63,7 @@ export const validateExpression = (ruleParams: EsQueryAlertParams): ValidationRe
);
}

if (!size) {
if (isNil(size)) {
errors.size.push(
i18n.translate('xpack.stackAlerts.esQuery.ui.validation.error.requiredSizeText', {
defaultMessage: 'Size is required.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,27 @@ describe('threshold expression', () => {
wrapper.update();
expect(wrapper.find('input[data-test-subj="alertThresholdInput"]').length).toEqual(1);
});

it('is valid when the threshold value is 0', () => {
const onChangeSelectedThreshold = jest.fn();
const onChangeSelectedThresholdComparator = jest.fn();
const wrapper = shallow(
<ThresholdExpression
thresholdComparator={'>'}
threshold={[0]}
errors={{ threshold0: [], threshold1: [] }}
onChangeSelectedThreshold={onChangeSelectedThreshold}
onChangeSelectedThresholdComparator={onChangeSelectedThresholdComparator}
/>
);
expect(wrapper.find('[data-test-subj="alertThresholdInput"]')).toMatchInlineSnapshot(`
<EuiFieldNumber
data-test-subj="alertThresholdInput"
isInvalid={false}
min={0}
onChange={[Function]}
value={0}
/>
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EuiFieldNumber,
EuiText,
} from '@elastic/eui';
import { isNil } from 'lodash';
import { builtInComparators } from '../constants';
import { Comparator } from '../types';
import { IErrorObject } from '../../types';
Expand Down Expand Up @@ -145,14 +146,14 @@ export const ThresholdExpression = ({
) : null}
<EuiFlexItem grow={false}>
<EuiFormRow
isInvalid={errors[`threshold${i}`]?.length > 0 || !threshold[i]}
isInvalid={errors[`threshold${i}`]?.length > 0 || isNil(threshold[i])}
error={errors[`threshold${i}`]}
>
<EuiFieldNumber
data-test-subj="alertThresholdInput"
min={0}
value={!threshold || threshold[i] === undefined ? '' : threshold[i]}
isInvalid={errors[`threshold${i}`]?.length > 0 || !threshold[i]}
isInvalid={errors[`threshold${i}`]?.length > 0 || isNil(threshold[i])}
Comment thread
doakalexi marked this conversation as resolved.
onChange={(e) => {
const { value } = e.target;
const thresholdVal = value !== '' ? parseFloat(value) : undefined;
Expand Down