Skip to content

Commit

Permalink
Add Expression enzyme test for prefill
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Jun 23, 2020
1 parent d6200a1 commit 8809d7c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import { actionTypeRegistryMock } from '../../../../../triggers_actions_ui/publi
import { alertTypeRegistryMock } from '../../../../../triggers_actions_ui/public/application/alert_type_registry.mock';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { AlertsContextValue } from '../../../../../triggers_actions_ui/public/application/context/alerts_context';
import { AlertContextMeta, MetricExpression } from '../types';
import { AlertContextMeta } from '../types';
import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer';
import React from 'react';
import { Expressions, defaultExpression } from './expression';
import { act } from 'react-dom/test-utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { Comparator } from '../../../../server/lib/alerting/metric_threshold/types';
import { MetricsExplorerResponse } from '../../../../common/http_api';
import { validateMetricThreshold } from './validation';

jest.mock('../../../containers/source/use_source_via_http', () => ({
useSourceViaHttp: (any) => ({
source: { id: 'default' },
createDerivedIndexPattern: () => ({ fields: [], title: 'metricbeat-*' }),
}),
}));

describe('Expression', () => {
async function setup(currentOptions: {
Expand All @@ -26,7 +31,9 @@ describe('Expression', () => {
groupBy?: string;
}) {
const alertParams = {
criteria: [defaultExpression],
criteria: [],
groupBy: undefined,
filterQueryText: '',
};

const mocks = coreMock.createSetup();
Expand Down Expand Up @@ -55,14 +62,12 @@ describe('Expression', () => {
},
};

const validationResult = validateMetricThreshold([alertParams.criteria]);

const wrapper = mountWithIntl(
<Expressions
alertsContext={context}
alertInterval="1m"
alertParams={alertParams}
errors={validationResult.errors}
errors={[]}
setAlertParams={(key, value) => Reflect.set(alertParams, key, value)}
setAlertProperty={() => {}}
/>
Expand All @@ -83,7 +88,10 @@ describe('Expression', () => {
const currentOptions = {
groupBy: 'host.hostname',
filterQuery: 'foo',
metrics: [{ aggregation: 'avg', field: 'system.load.1' }],
metrics: [
{ aggregation: 'avg', field: 'system.load.1' },
{ aggregation: 'cardinality', field: 'system.cpu.user.pct' },
] as MetricsExplorerMetric[],
};
const { alertParams } = await setup(currentOptions);
expect(alertParams.groupBy).toBe('host.hostname');
Expand All @@ -93,10 +101,18 @@ describe('Expression', () => {
metric: 'system.load.1',
comparator: Comparator.GT,
threshold: [],
timeSize,
timeUnit,
timeSize: 1,
timeUnit: 'm',
aggType: 'avg',
},
{
metric: 'system.cpu.user.pct',
comparator: Comparator.GT,
threshold: [],
timeSize: 1,
timeUnit: 'm',
aggType: 'cardinality',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WithKueryAutocompletionComponent extends React.Component<
) => {
const { indexPattern } = this.props;
const language = 'kuery';
const hasQuerySuggestions = this.props.kibana.services.data.autocomplete.hasQuerySuggestions(
const hasQuerySuggestions = this.props.kibana.services.data?.autocomplete.hasQuerySuggestions(
language
);

Expand Down

0 comments on commit 8809d7c

Please sign in to comment.