Added alerting ui mock for jest test (#92604)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Shahzad 2021-03-01 12:55:41 +01:00 committed by GitHub
parent 99929433a4
commit b3499f0849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 126 additions and 48 deletions

View file

@ -26,16 +26,12 @@ import {
Aggregators,
METRIC_THRESHOLD_ALERT_TYPE_ID,
} from '../../../../common/alerting/metrics';
import {
ForLastExpression,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../triggers_actions_ui/public/common';
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
import {
IErrorObject,
AlertTypeParams,
AlertTypeParamsExpressionProps,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../triggers_actions_ui/public/types';
} from '../../../../../triggers_actions_ui/public';
import { MetricsExplorerKueryBar } from '../../../pages/metrics/metrics_explorer/components/kuery_bar';
import { MetricsExplorerOptions } from '../../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options';
import { MetricsExplorerGroupBy } from '../../../pages/metrics/metrics_explorer/components/group_by';

View file

@ -63,7 +63,8 @@ describe('ExpressionRow', () => {
timeUnit: 'm',
aggType: 'avg',
};
const { wrapper } = await setup(expression as MetricExpression);
const { wrapper, update } = await setup(expression as MetricExpression);
await update();
const [valueMatch] = wrapper.html().match('<span class="euiExpression__value">50</span>') ?? [];
expect(valueMatch).toBeTruthy();
});
@ -95,7 +96,7 @@ describe('ExpressionRow', () => {
const { wrapper } = await setup(expression as MetricExpression);
const helpText = wrapper.find('[data-test-subj="ofExpression"]').prop('helpText');
const helpText = wrapper.find('[data-test-subj="ofExpression"]').at(0).prop('helpText');
expect(helpText).toMatchSnapshot();
});

View file

@ -24,18 +24,15 @@ import {
WhenExpression,
OfExpression,
ThresholdExpression,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../triggers_actions_ui/public/common';
} from '../../../../../triggers_actions_ui/public';
import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { IErrorObject } from '../../../../../triggers_actions_ui/public/types';
import { IErrorObject } from '../../../../../triggers_actions_ui/public';
import { MetricExpression, AGGREGATION_TYPES } from '../types';
import {
Comparator,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../server/lib/alerting/metric_threshold/types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { builtInComparators } from '../../../../../triggers_actions_ui/public/common/constants';
import { builtInComparators } from '../../../../../triggers_actions_ui/public';
const customComparators = {
...builtInComparators,

View file

@ -7,7 +7,7 @@
import { HttpSetup } from 'kibana/public';
import { BASE_ACTION_API_PATH } from '../constants';
import { ActionConnector, ActionConnectorWithoutId, ActionType } from '../../types';
import type { ActionConnector, ActionConnectorWithoutId, ActionType } from '../../types';
import { ActionTypeExecutorResult } from '../../../../../plugins/actions/common';
export async function loadActionTypes({ http }: { http: HttpSetup }): Promise<ActionType[]> {

View file

@ -124,3 +124,6 @@ export const AlertConditions = <ConditionProps extends any, ActionGroupIds exten
</EuiFlexGroup>
);
};
// eslint-disable-next-line import/no-default-export
export { AlertConditions as default };

View file

@ -60,3 +60,6 @@ export const AlertConditionsGroup = <ConditionProps extends unknown>({
</EuiFormRow>
);
};
// eslint-disable-next-line import/no-default-export
export { AlertConditionsGroup as default };

View file

@ -7,12 +7,6 @@
import { lazy } from 'react';
import { suspendedComponentWithProps } from '../../lib/suspended_component_with_props';
export {
AlertConditions,
ActionGroupWithCondition,
AlertConditionsProps,
} from './alert_conditions';
export { AlertConditionsGroup } from './alert_conditions_group';
export const AlertAdd = suspendedComponentWithProps(lazy(() => import('./alert_add')));
export const AlertEdit = suspendedComponentWithProps(lazy(() => import('./alert_edit')));

View file

@ -7,12 +7,11 @@
import { lazy } from 'react';
import { suspendedComponentWithProps } from '../lib/suspended_component_with_props';
export {
ActionGroupWithCondition,
AlertConditionsProps,
AlertConditions,
AlertConditionsGroup,
} from './alert_form';
export type { ActionGroupWithCondition, AlertConditionsProps } from './alert_form/alert_conditions';
export const AlertConditions = lazy(() => import('./alert_form/alert_conditions'));
export const AlertConditionsGroup = lazy(() => import('./alert_form/alert_conditions_group'));
export const AlertAdd = suspendedComponentWithProps(lazy(() => import('./alert_form/alert_add')));
export const AlertEdit = suspendedComponentWithProps(lazy(() => import('./alert_form/alert_edit')));

View file

@ -23,7 +23,7 @@ import { getTimeOptions } from '../lib/get_time_options';
import { ClosablePopoverTitle } from './components';
import { IErrorObject } from '../../types';
interface ForLastExpressionProps {
export interface ForLastExpressionProps {
timeWindowSize?: number;
timeWindowUnit?: string;
errors: IErrorObject;
@ -129,3 +129,6 @@ export const ForLastExpression = ({
</EuiPopover>
);
};
// eslint-disable-next-line import/no-default-export
export { ForLastExpression as default };

View file

@ -22,7 +22,7 @@ import { GroupByType } from '../types';
import { ClosablePopoverTitle } from './components';
import { IErrorObject } from '../../types';
interface GroupByExpressionProps {
export interface GroupByExpressionProps {
groupBy: string;
errors: IErrorObject;
onChangeSelectedTermSize: (selectedTermSize?: number) => void;
@ -208,3 +208,6 @@ export const GroupByExpression = ({
</EuiPopover>
);
};
// eslint-disable-next-line import/no-default-export
export { GroupByExpression as default };

View file

@ -5,9 +5,13 @@
* 2.0.
*/
export { WhenExpression } from './when';
export { OfExpression } from './of';
export { GroupByExpression } from './group_by_over';
export { ThresholdExpression } from './threshold';
export { ForLastExpression } from './for_the_last';
export { ValueExpression } from './value';
import { lazy } from 'react';
import { suspendedComponentWithProps } from '../../application/lib/suspended_component_with_props';
export const GroupByExpression = suspendedComponentWithProps(lazy(() => import('./group_by_over')));
export const ForLastExpression = suspendedComponentWithProps(lazy(() => import('./for_the_last')));
export const ValueExpression = suspendedComponentWithProps(lazy(() => import('./value')));
export const WhenExpression = suspendedComponentWithProps(lazy(() => import('./when')));
export const OfExpression = suspendedComponentWithProps(lazy(() => import('./of')));
export const ThresholdExpression = suspendedComponentWithProps(lazy(() => import('./threshold')));

View file

@ -22,7 +22,7 @@ import { IErrorObject } from '../../types';
import { ClosablePopoverTitle } from './components';
import './of.scss';
interface OfExpressionProps {
export interface OfExpressionProps {
aggType: string;
aggField?: string;
errors: IErrorObject;
@ -152,3 +152,6 @@ export const OfExpression = ({
</EuiPopover>
);
};
// eslint-disable-next-line import/no-default-export
export { OfExpression as default };

View file

@ -22,7 +22,7 @@ import { Comparator } from '../types';
import { IErrorObject } from '../../types';
import { ClosablePopoverTitle } from './components';
interface ThresholdExpressionProps {
export interface ThresholdExpressionProps {
thresholdComparator: string;
errors: IErrorObject;
onChangeSelectedThresholdComparator: (selectedThresholdComparator?: string) => void;
@ -175,3 +175,6 @@ export const ThresholdExpression = ({
</EuiPopover>
);
};
// eslint-disable-next-line import/no-default-export
export { ThresholdExpression as default };

View file

@ -17,7 +17,7 @@ import {
import { ClosablePopoverTitle } from './components';
import { IErrorObject } from '../../types';
interface ValueExpressionProps {
export interface ValueExpressionProps {
description: string;
value: number;
onChangeSelectedValue: (updatedValue: number) => void;
@ -100,3 +100,6 @@ export const ValueExpression = ({
</EuiPopover>
);
};
// eslint-disable-next-line import/no-default-export
export { ValueExpression as default };

View file

@ -13,7 +13,7 @@ import { builtInAggregationTypes } from '../constants';
import { AggregationType } from '../types';
import { ClosablePopoverTitle } from './components';
interface WhenExpressionProps {
export interface WhenExpressionProps {
aggType: string;
customAggTypesOptions?: { [key: string]: AggregationType };
onChangeSelectedAggType: (selectedAggType: string) => void;
@ -97,3 +97,6 @@ export const WhenExpression = ({
</EuiPopover>
);
};
// eslint-disable-next-line import/no-default-export
export { WhenExpression as default };

View file

@ -14,8 +14,8 @@ export {
AlertConditionsGroup,
ActionGroupWithCondition,
} from './application/sections';
export { ActionForm } from './application/sections/action_connector_form';
export {
export type {
AlertAction,
Alert,
AlertTypeModel,
@ -29,11 +29,15 @@ export {
ActionConnector,
IErrorObject,
AlertFlyoutCloseReason,
AlertTypeParams,
} from './types';
export {
ActionForm,
ConnectorAddFlyout,
ConnectorEditFlyout,
} from './application/sections/action_connector_form';
export { loadActionTypes } from './application/lib/action_connector_api';
export * from './common';
@ -46,5 +50,4 @@ export * from './plugin';
export { TIME_UNITS } from './application/constants';
export { getTimeUnitLabel } from './common/lib/get_time_unit_label';
export { ForLastExpression } from './common/expression_items/for_the_last';
export { TriggersAndActionsUiServices } from '../public/application/app';
export type { TriggersAndActionsUiServices } from '../public/application/app';

View file

@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { ConnectorAddFlyoutProps } from './application/sections/action_connector_form/connector_add_flyout';
import type { ConnectorEditFlyoutProps } from './application/sections/action_connector_form/connector_edit_flyout';
import type { AlertAddProps } from './application/sections/alert_form/alert_add';
import type { AlertEditProps } from './application/sections/alert_form/alert_edit';
import type { TriggersAndActionsUIPublicPluginStart } from './plugin';
import { getAddConnectorFlyoutLazy } from './common/get_add_connector_flyout';
import { getEditConnectorFlyoutLazy } from './common/get_edit_connector_flyout';
import { getAddAlertFlyoutLazy } from './common/get_add_alert_flyout';
import { getEditAlertFlyoutLazy } from './common/get_edit_alert_flyout';
import { TypeRegistry } from './application/type_registry';
import { ActionTypeModel, AlertTypeModel } from './types';
function createStartMock(): TriggersAndActionsUIPublicPluginStart {
const actionTypeRegistry = new TypeRegistry<ActionTypeModel>();
const alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
return {
actionTypeRegistry,
alertTypeRegistry,
getAddConnectorFlyout: (props: Omit<ConnectorAddFlyoutProps, 'actionTypeRegistry'>) => {
return getAddConnectorFlyoutLazy({ ...props, actionTypeRegistry });
},
getEditConnectorFlyout: (props: Omit<ConnectorEditFlyoutProps, 'actionTypeRegistry'>) => {
return getEditConnectorFlyoutLazy({
...props,
actionTypeRegistry,
});
},
getAddAlertFlyout: (props: Omit<AlertAddProps, 'actionTypeRegistry' | 'alertTypeRegistry'>) => {
return getAddAlertFlyoutLazy({
...props,
actionTypeRegistry,
alertTypeRegistry,
});
},
getEditAlertFlyout: (
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'alertTypeRegistry'>
) => {
return getEditAlertFlyoutLazy({
...props,
actionTypeRegistry,
alertTypeRegistry,
});
},
};
}
export const triggersActionsUiMock = {
createStart: createStartMock,
};

View file

@ -12,7 +12,6 @@ import { ReactElement } from 'react';
import { FeaturesPluginStart } from '../../features/public';
import { KibanaFeature } from '../../features/common';
import { registerBuiltInActionTypes } from './application/components/builtin_action_types';
import { ActionTypeModel, AlertTypeModel } from './types';
import { TypeRegistry } from './application/type_registry';
import {
ManagementAppMountParams,
@ -26,14 +25,17 @@ import { ChartsPluginStart } from '../../../../src/plugins/charts/public';
import { PluginStartContract as AlertingStart } from '../../alerts/public';
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';
import { Storage } from '../../../../src/plugins/kibana_utils/public';
import type { ConnectorAddFlyoutProps } from './application/sections/action_connector_form/connector_add_flyout';
import type { ConnectorEditFlyoutProps } from './application/sections/action_connector_form/connector_edit_flyout';
import { getAddConnectorFlyoutLazy } from './common/get_add_connector_flyout';
import { getEditConnectorFlyoutLazy } from './common/get_edit_connector_flyout';
import { getAddAlertFlyoutLazy } from './common/get_add_alert_flyout';
import { getEditAlertFlyoutLazy } from './common/get_edit_alert_flyout';
import { AlertAddProps } from './application/sections/alert_form/alert_add';
import { AlertEditProps } from './application/sections/alert_form/alert_edit';
import type { ActionTypeModel, AlertTypeModel } from './types';
import type { ConnectorAddFlyoutProps } from './application/sections/action_connector_form/connector_add_flyout';
import type { ConnectorEditFlyoutProps } from './application/sections/action_connector_form/connector_edit_flyout';
import type { AlertAddProps } from './application/sections/alert_form/alert_add';
import type { AlertEditProps } from './application/sections/alert_form/alert_edit';
export interface TriggersAndActionsUIPublicPluginSetup {
actionTypeRegistry: TypeRegistry<ActionTypeModel>;