Skip to content

Commit

Permalink
[RAM] Bug with custom threshold in the create rule flyout (elastic#17…
Browse files Browse the repository at this point in the history
…4982)

## Summary

We needed to add Lens dependency in triggerActionsUI plugin

FIX => elastic#174699
  • Loading branch information
XavierM authored Jan 18, 2024
1 parent 06c46ee commit 1a51e61
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import userEvent from '@testing-library/user-event';
import { useKibana } from '@kbn/triggers-actions-ui-plugin/public';
import { DEFAULT_BEDROCK_MODEL } from '../../../common/bedrock/constants';
import { useGetDashboard } from '../lib/gen_ai/use_get_dashboard';

jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana');
import { createStartServicesMock } from '@kbn/triggers-actions-ui-plugin/public/common/lib/kibana/kibana_react.mock';

const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('../lib/gen_ai/use_get_dashboard');

const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import userEvent from '@testing-library/user-event';
import { DEFAULT_OPENAI_MODEL, OpenAiProviderType } from '../../../common/openai/constants';
import { useKibana } from '@kbn/triggers-actions-ui-plugin/public';
import { useGetDashboard } from '../lib/gen_ai/use_get_dashboard';

jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana');
import { createStartServicesMock } from '@kbn/triggers-actions-ui-plugin/public/common/lib/kibana/kibana_react.mock';

const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('../lib/gen_ai/use_get_dashboard');

const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
import React from 'react';
import { act, render, screen, waitFor } from '@testing-library/react';
import { useKibana } from '@kbn/triggers-actions-ui-plugin/public';
import { createStartServicesMock } from '@kbn/triggers-actions-ui-plugin/public/common/lib/kibana/kibana_react.mock';

import { ConnectorFormTestProvider, waitForComponentToUpdate } from '../lib/test_utils';
import { SlackActionFieldsComponents as SlackActionFields } from './slack_connectors';
import { useValidChannels } from './use_valid_channels';

jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana');
const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('./use_valid_channels');

(useKibana as jest.Mock).mockImplementation(() => ({
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/triggers_actions_ui/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"actions",
"dashboard",
"licensing",
"expressions"
"expressions",
"lens"
],
"optionalPlugins": [
"cloud",
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/triggers_actions_ui/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PluginStartContract as AlertingStart } from '@kbn/alerting-plugin/publi
import type { SpacesPluginStart } from '@kbn/spaces-plugin/public';
import type { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { LensPublicStart } from '@kbn/lens-plugin/public';

import { Storage } from '@kbn/kibana-utils-plugin/public';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
Expand Down Expand Up @@ -74,6 +75,7 @@ export interface TriggersAndActionsUiServices extends CoreStart {
expressions: ExpressionsStart;
isServerless: boolean;
fieldFormats: FieldFormatsStart;
lens: LensPublicStart;
}

export const renderApp = (deps: TriggersAndActionsUiServices) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ import { getMaintenanceWindowMockMap } from '../maintenance_windows/index.mock';
import userEvent from '@testing-library/user-event';
import { AppMockRenderer, createAppMockRenderer } from '../../test_utils';
import { useCaseViewNavigation } from './use_case_view_navigation';

jest.mock('../../../../common/lib/kibana');
import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock';

const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('../../../../common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('./use_case_view_navigation');

const useCaseViewNavigationMock = useCaseViewNavigation as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ import { useKibana } from '../../../../common/lib/kibana';
import { useBulkGetMaintenanceWindows } from './use_bulk_get_maintenance_windows';
import { AppMockRenderer, createAppMockRenderer } from '../../test_utils';
import { useLicense } from '../../../hooks/use_license';

jest.mock('../../../../common/lib/kibana');
import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock';

const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('../../../../common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('../../../hooks/use_license');
jest.mock('./apis/bulk_get_maintenance_windows');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ import { useColumns, UseColumnsArgs, UseColumnsResp } from './use_columns';
import { useFetchBrowserFieldCapabilities } from '../use_fetch_browser_fields_capabilities';
import { BrowserFields } from '@kbn/rule-registry-plugin/common';
import { AlertsTableStorage } from '../../alerts_table_state';

jest.mock('../../../../../common/lib/kibana');
import { createStartServicesMock } from '../../../../../common/lib/kibana/kibana_react.mock';

const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('../../../../../common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('../use_fetch_browser_fields_capabilities');

const setItemStorageMock = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import { useKibana } from '../../../../common/lib/kibana';
import { useBulkGetMaintenanceWindows } from '../../alerts_table/hooks/use_bulk_get_maintenance_windows';
import { getMaintenanceWindowMockMap } from '../../alerts_table/maintenance_windows/index.mock';

jest.mock('../../../../common/lib/kibana');
const mockUseKibanaReturnValue = createStartServicesMock();
jest.mock('../../../../common/lib/kibana', () => ({
__esModule: true,
useKibana: jest.fn(() => ({
services: mockUseKibanaReturnValue,
})),
}));
jest.mock('../../../../common/get_experimental_features', () => ({
getIsExperimentalFeatureEnabled: jest.fn(),
}));
Expand Down Expand Up @@ -55,6 +61,7 @@ const ruleTypeRegistry = ruleTypeRegistryMock.create();

import { getIsExperimentalFeatureEnabled } from '../../../../common/get_experimental_features';
import { waitFor } from '@testing-library/react';
import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock';

const fakeNow = new Date('2020-02-09T23:15:41.941Z');
const fake2MinutesAgo = new Date('2020-02-09T23:13:41.941Z');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks'
import { coreMock, scopedHistoryMock, themeServiceMock } from '@kbn/core/public/mocks';
import { licensingMock } from '@kbn/licensing-plugin/public/mocks';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { lensPluginMock } from '@kbn/lens-plugin/public/mocks';
import { TriggersAndActionsUiServices } from '../../../application/app';
import {
RuleTypeRegistryContract,
Expand Down Expand Up @@ -78,6 +79,7 @@ export const createStartServicesMock = (): TriggersAndActionsUiServices => {
expressions: expressionsPluginMock.createStartContract(),
isServerless: false,
fieldFormats: fieldFormatsServiceMock.createStartContract(),
lens: lensPluginMock.createStartContract(),
} as TriggersAndActionsUiServices;
};

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/triggers_actions_ui/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import { ExpressionsStart } from '@kbn/expressions-plugin/public';
import { ServerlessPluginStart } from '@kbn/serverless/public';
import { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { getAlertsTableDefaultAlertActionsLazy } from './common/get_alerts_table_default_row_actions';
import type { AlertActionsProps } from './types';
import type { AlertsSearchBarProps } from './application/sections/alerts_search_bar';
Expand Down Expand Up @@ -174,6 +175,7 @@ interface PluginsStart {
licensing: LicensingPluginStart;
serverless?: ServerlessPluginStart;
fieldFormats: FieldFormatsRegistry;
lens: LensPublicStart;
}

export class Plugin
Expand Down Expand Up @@ -301,6 +303,7 @@ export class Plugin
expressions: pluginsStart.expressions,
isServerless: !!pluginsStart.serverless,
fieldFormats: pluginsStart.fieldFormats,
lens: pluginsStart.lens,
});
},
});
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/triggers_actions_ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@kbn/triggers-actions-ui-types",
"@kbn/code-editor",
"@kbn/code-editor-mock",
"@kbn/lens-plugin",
],
"exclude": ["target/**/*"]
}

0 comments on commit 1a51e61

Please sign in to comment.