Skip to content

Commit

Permalink
cleanup usage of test providers and mocks
Browse files Browse the repository at this point in the history
- removed `kibanaMock` from the timelines plugin
- removed security solution imports of test providers that come from the timelines plugin
  • Loading branch information
janmonschke committed Jan 31, 2024
1 parent f2ff44a commit 523080c
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '../../../common/mock';
import { TimelineId } from '../../../../common/types/timeline';
import { createStore } from '../../../common/store';
import { kibanaMock } from '@kbn/timelines-plugin/public/mock';
import { kibanaMock } from '../../../common/mock/test_providers';
import { sourcererPaths } from '../../../common/containers/sourcerer';

jest.mock('react-router-dom', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useTourContext } from './tour';
import { mockGlobalState, SUB_PLUGINS_REDUCER, TestProviders } from '../../mock';
import { TimelineId } from '../../../../common/types';
import { createStore } from '../../store';
import { kibanaMock } from '@kbn/timelines-plugin/public/mock';
import { kibanaMock } from '../../mock/test_providers';
import { createSecuritySolutionStorageMock } from '@kbn/timelines-plugin/public/mock/mock_local_storage';

jest.mock('./tour');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import { ALERT_WORKFLOW_ASSIGNEE_IDS } from '@kbn/rule-data-utils';
import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import type { BulkActionsConfig } from '@kbn/triggers-actions-ui-plugin/public/types';
import type { TimelineItem } from '@kbn/triggers-actions-ui-plugin/public/application/sections/alerts_table/bulk_actions/components/toolbar';
import { act, fireEvent, render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';

import { TestProviders } from '../../../mock';
import type {
UseBulkAlertAssigneesItemsProps,
UseBulkAlertAssigneesPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import { ALERT_WORKFLOW_TAGS } from '@kbn/rule-data-utils';
import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { act, fireEvent, render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import { TestProviders } from '../../../mock';
import type {
UseBulkAlertTagsItemsProps,
UseBulkAlertTagsPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { act, renderHook } from '@testing-library/react-hooks';
import React from 'react';
import { TestProviders } from '../../../../common/mock';
import { useGroupTakeActionsItems } from '.';

jest.mock('../../../../common/store', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { renderHook } from '@testing-library/react-hooks';
import type { UseAlertAssigneesActionsProps } from './use_alert_assignees_actions';
import { useAlertAssigneesActions } from './use_alert_assignees_actions';
Expand All @@ -15,6 +14,7 @@ import { render } from '@testing-library/react';
import React from 'react';
import type { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { EuiPopover, EuiContextMenu } from '@elastic/eui';
import { TestProviders } from '../../../../common/mock';
import { useSetAlertAssignees } from '../../../../common/components/toolbar/bulk_actions/use_set_alert_assignees';
import { useGetCurrentUserProfile } from '../../../../common/components/user_profiles/use_get_current_user_profile';
import { useBulkGetUserProfiles } from '../../../../common/components/user_profiles/use_bulk_get_user_profiles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { renderHook } from '@testing-library/react-hooks';
import type { UseAlertTagsActionsProps } from './use_alert_tags_actions';
import { useAlertTagsActions } from './use_alert_tags_actions';
Expand All @@ -15,6 +14,7 @@ import { render } from '@testing-library/react';
import React from 'react';
import type { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { EuiPopover, EuiContextMenu } from '@elastic/eui';
import { TestProviders } from '../../../../common/mock';
import { useSetAlertTags } from '../../../../common/components/toolbar/bulk_actions/use_set_alert_tags';
import { useUiSetting$ } from '../../../../common/lib/kibana';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import React from 'react';
import { makeAction } from '../../../common/components/cell_actions/mocks';
import { VIEW_SELECTION } from '../../../../common/constants';
import { createStore } from '../../../common/store';
import { createStartServicesMock } from '@kbn/timelines-plugin/public/mock';
import { createStartServicesMock } from '../../../common/lib/kibana/kibana_react.mock';

const useCellActions = getUseCellActionsHook(TableId.test);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TestProviders,
} from '../../../common/mock';
import { createStore } from '../../../common/store';
import { kibanaMock } from '@kbn/timelines-plugin/public/mock';
import { kibanaMock } from '../../../common/mock/test_providers';
import { ALERTS_PATH, ALERT_DETAILS_REDIRECT_PATH } from '../../../../common/constants';
import { mockHistory } from '../../../common/utils/route/mocks';
import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { renderHook } from '@testing-library/react-hooks';
import { useObservedHostFields } from './use_observed_host_fields';
import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { mockObservedHostData } from '../../mocks';
import { TestProviders } from '../../../../common/mock';

describe('useManagedUserItems', () => {
it('returns managed user items for Entra user', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { renderHook } from '@testing-library/react-hooks';
import { mockObservedUser } from '../mocks';
import { TestProviders } from '../../../../common/mock';
import { useObservedUserItems } from './use_observed_user_items';

describe('useManagedUserItems', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';

import { mockTimelineData } from '../../../../../common/mock';
import { mockTimelineData, TestProviders } from '../../../../../common/mock';
import { defaultColumnHeaderType } from '../column_headers/default_headers';
import { REASON_FIELD_NAME } from './constants';
import { reasonColumnRenderer } from './reason_column_renderer';
Expand All @@ -17,7 +17,6 @@ import type { ColumnHeaderOptions, RowRenderer } from '../../../../../../common/
import { RowRendererId } from '../../../../../../common/api/timeline';

import { render } from '@testing-library/react';
import { TestProviders } from '@kbn/timelines-plugin/public/mock';
import { cloneDeep } from 'lodash';
import { TableId } from '@kbn/securitysolution-data-table';
jest.mock('./plain_column_renderer');
Expand Down
22 changes: 4 additions & 18 deletions x-pack/plugins/timelines/public/mock/kibana_react.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@

import React from 'react';

import { RecursivePartial } from '@elastic/eui/src/components/common';
import { coreMock } from '@kbn/core/public/mocks';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { EuiTheme } from '@kbn/kibana-react-plugin/common';
import { CoreStart } from '@kbn/core/public';

export const mockGetCreateCaseFlyout = jest.fn();
export const mockGetAllCasesSelectorModal = jest.fn();
export const mockNavigateToApp = jest.fn();
const mockGetCreateCaseFlyout = jest.fn();
const mockGetAllCasesSelectorModal = jest.fn();
const mockNavigateToApp = jest.fn();

export const createStartServicesMock = (): CoreStart => {
const createStartServicesMock = (): CoreStart => {
const coreServices = coreMock.createStart();
return {
...coreServices,
Expand All @@ -37,22 +35,10 @@ export const createStartServicesMock = (): CoreStart => {
} as unknown as CoreStart;
};

export const createWithKibanaMock = () => {
const services = createStartServicesMock();

// eslint-disable-next-line react/display-name
return (Component: unknown) => (props: unknown) => {
return React.createElement(Component as string, { ...(props as object), kibana: { services } });
};
};

export const createKibanaContextProviderMock = () => {
const services = createStartServicesMock();

// eslint-disable-next-line react/display-name
return ({ children }: { children: React.ReactNode }) =>
React.createElement(KibanaContextProvider, { services }, children);
};

export const getMockTheme = (partialTheme: RecursivePartial<EuiTheme>): EuiTheme =>
partialTheme as EuiTheme;
5 changes: 1 addition & 4 deletions x-pack/plugins/timelines/public/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import { Store } from 'redux';
import { ThemeProvider } from 'styled-components';

import { configureStore } from '@reduxjs/toolkit';
import { createKibanaContextProviderMock, createStartServicesMock } from './kibana_react.mock';
import { createKibanaContextProviderMock } from './kibana_react.mock';
import { timelineReducer } from '../store/timeline/reducer';

interface Props {
children: React.ReactNode;
store?: Store;
}

// TODO: can this be imported from somewhere else?
export const kibanaMock = createStartServicesMock();

interface State {
timelineById: Record<string, unknown>;
}
Expand Down

0 comments on commit 523080c

Please sign in to comment.