Skip to content

Commit

Permalink
Added alerting ui mock for jest test (elastic#92604) (elastic#93020)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Shahzad <shahzad.muhammad@elastic.co>
  • Loading branch information
kibanamachine and shahzad31 authored Mar 1, 2021
1 parent c8c4f90 commit 9a97394
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ export const AlertConditionsGroup = <ConditionProps extends unknown>({
</EuiFormRow>
);
};

// eslint-disable-next-line import/no-default-export
export { AlertConditionsGroup as default };
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,3 +129,6 @@ export const ForLastExpression = ({
</EuiPopover>
);
};

// eslint-disable-next-line import/no-default-export
export { ForLastExpression as default };
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,3 +208,6 @@ export const GroupByExpression = ({
</EuiPopover>
);
};

// eslint-disable-next-line import/no-default-export
export { GroupByExpression as default };
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,3 +152,6 @@ export const OfExpression = ({
</EuiPopover>
);
};

// eslint-disable-next-line import/no-default-export
export { OfExpression as default };
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,3 +175,6 @@ export const ThresholdExpression = ({
</EuiPopover>
);
};

// eslint-disable-next-line import/no-default-export
export { ThresholdExpression as default };
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,3 +100,6 @@ export const ValueExpression = ({
</EuiPopover>
);
};

// eslint-disable-next-line import/no-default-export
export { ValueExpression as default };
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,3 +97,6 @@ export const WhenExpression = ({
</EuiPopover>
);
};

// eslint-disable-next-line import/no-default-export
export { WhenExpression as default };
11 changes: 7 additions & 4 deletions x-pack/plugins/triggers_actions_ui/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export {
AlertConditionsGroup,
ActionGroupWithCondition,
} from './application/sections';
export { ActionForm } from './application/sections/action_connector_form';
export {

export type {
AlertAction,
Alert,
AlertTypeModel,
Expand All @@ -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';

Expand All @@ -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';
58 changes: 58 additions & 0 deletions x-pack/plugins/triggers_actions_ui/public/mocks.ts
Original file line number Diff line number Diff line change
@@ -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,
};
12 changes: 7 additions & 5 deletions x-pack/plugins/triggers_actions_ui/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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>;
Expand Down

0 comments on commit 9a97394

Please sign in to comment.