Skip to content

Commit 8809d7c

Browse files
committed
Add Expression enzyme test for prefill
1 parent d6200a1 commit 8809d7c

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.test.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ import { actionTypeRegistryMock } from '../../../../../triggers_actions_ui/publi
99
import { alertTypeRegistryMock } from '../../../../../triggers_actions_ui/public/application/alert_type_registry.mock';
1010
import { coreMock } from '../../../../../../../src/core/public/mocks';
1111
import { AlertsContextValue } from '../../../../../triggers_actions_ui/public/application/context/alerts_context';
12-
import { AlertContextMeta, MetricExpression } from '../types';
12+
import { AlertContextMeta } from '../types';
1313
import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer';
1414
import React from 'react';
1515
import { Expressions, defaultExpression } from './expression';
1616
import { act } from 'react-dom/test-utils';
1717
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1818
import { 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

2227
describe('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
});

x-pack/plugins/infra/public/containers/with_kuery_autocompletion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class WithKueryAutocompletionComponent extends React.Component<
5959
) => {
6060
const { indexPattern } = this.props;
6161
const language = 'kuery';
62-
const hasQuerySuggestions = this.props.kibana.services.data.autocomplete.hasQuerySuggestions(
62+
const hasQuerySuggestions = this.props.kibana.services.data?.autocomplete.hasQuerySuggestions(
6363
language
6464
);
6565

0 commit comments

Comments
 (0)