@@ -9,15 +9,20 @@ import { actionTypeRegistryMock } from '../../../../../triggers_actions_ui/publi
99import { alertTypeRegistryMock } from '../../../../../triggers_actions_ui/public/application/alert_type_registry.mock' ;
1010import { coreMock } from '../../../../../../../src/core/public/mocks' ;
1111import { AlertsContextValue } from '../../../../../triggers_actions_ui/public/application/context/alerts_context' ;
12- import { AlertContextMeta , MetricExpression } from '../types' ;
12+ import { AlertContextMeta } from '../types' ;
1313import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer' ;
1414import React from 'react' ;
1515import { Expressions , defaultExpression } from './expression' ;
1616import { act } from 'react-dom/test-utils' ;
1717// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1818import { Comparator } from '../../../../server/lib/alerting/metric_threshold/types' ;
19- import { MetricsExplorerResponse } from '../../../../common/http_api' ;
20- import { validateMetricThreshold } from './validation' ;
19+
20+ jest . mock ( '../../../containers/source/use_source_via_http' , ( ) => ( {
21+ useSourceViaHttp : ( any ) => ( {
22+ source : { id : 'default' } ,
23+ createDerivedIndexPattern : ( ) => ( { fields : [ ] , title : 'metricbeat-*' } ) ,
24+ } ) ,
25+ } ) ) ;
2126
2227describe ( 'Expression' , ( ) => {
2328 async function setup ( currentOptions : {
@@ -26,7 +31,9 @@ describe('Expression', () => {
2631 groupBy ?: string ;
2732 } ) {
2833 const alertParams = {
29- criteria : [ defaultExpression ] ,
34+ criteria : [ ] ,
35+ groupBy : undefined ,
36+ filterQueryText : '' ,
3037 } ;
3138
3239 const mocks = coreMock . createSetup ( ) ;
@@ -55,14 +62,12 @@ describe('Expression', () => {
5562 } ,
5663 } ;
5764
58- const validationResult = validateMetricThreshold ( [ alertParams . criteria ] ) ;
59-
6065 const wrapper = mountWithIntl (
6166 < Expressions
6267 alertsContext = { context }
6368 alertInterval = "1m"
6469 alertParams = { alertParams }
65- errors = { validationResult . errors }
70+ errors = { [ ] }
6671 setAlertParams = { ( key , value ) => Reflect . set ( alertParams , key , value ) }
6772 setAlertProperty = { ( ) => { } }
6873 />
@@ -83,7 +88,10 @@ describe('Expression', () => {
8388 const currentOptions = {
8489 groupBy : 'host.hostname' ,
8590 filterQuery : 'foo' ,
86- metrics : [ { aggregation : 'avg' , field : 'system.load.1' } ] ,
91+ metrics : [
92+ { aggregation : 'avg' , field : 'system.load.1' } ,
93+ { aggregation : 'cardinality' , field : 'system.cpu.user.pct' } ,
94+ ] as MetricsExplorerMetric [ ] ,
8795 } ;
8896 const { alertParams } = await setup ( currentOptions ) ;
8997 expect ( alertParams . groupBy ) . toBe ( 'host.hostname' ) ;
@@ -93,10 +101,18 @@ describe('Expression', () => {
93101 metric : 'system.load.1' ,
94102 comparator : Comparator . GT ,
95103 threshold : [ ] ,
96- timeSize,
97- timeUnit,
104+ timeSize : 1 ,
105+ timeUnit : 'm' ,
98106 aggType : 'avg' ,
99107 } ,
108+ {
109+ metric : 'system.cpu.user.pct' ,
110+ comparator : Comparator . GT ,
111+ threshold : [ ] ,
112+ timeSize : 1 ,
113+ timeUnit : 'm' ,
114+ aggType : 'cardinality' ,
115+ } ,
100116 ] ) ;
101117 } ) ;
102118} ) ;
0 commit comments