mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
parent
a7ef033e5b
commit
93c61fcb4e
4 changed files with 44 additions and 1 deletions
|
@ -92,6 +92,8 @@ export type TestSubjects =
|
|||
| 'watchActionAccordion'
|
||||
| 'watchActionAccordion.mockComboBox'
|
||||
| 'watchActionsPanel'
|
||||
| 'watchThresholdButton'
|
||||
| 'watchThresholdInput'
|
||||
| 'watchConditionTitle'
|
||||
| 'watchTimeFieldSelect'
|
||||
| 'watchVisualizationChart'
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -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',
|
||||
{
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue