diff --git a/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_in.test.ts b/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_in.test.ts index 01650820294bd..89dad46c09ef3 100644 --- a/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_in.test.ts +++ b/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_in.test.ts @@ -6,13 +6,7 @@ */ import { createFilterManagerMock } from '@kbn/data-plugin/public/query/filter_manager/filter_manager.mock'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; +import { createMockStore, mockGlobalState } from '../../../common/mock'; import { createFilterInCellActionFactory } from './filter_in'; import type { SecurityCellActionExecutionContext } from '../../types'; import { createStartServicesMock } from '../../../common/lib/kibana/kibana_react.mock'; @@ -45,8 +39,7 @@ jest.mock('@kbn/ui-actions-plugin/public', () => ({ addFilterOut: () => {}, })); -const { storage } = createSecuritySolutionStorageMock(); -const mockStore = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const mockStore = createMockStore(mockState); describe('createFilterInCellActionFactory', () => { const createFilterInCellAction = createFilterInCellActionFactory({ store: mockStore, services }); diff --git a/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_out.test.ts b/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_out.test.ts index 088cc944cb1c7..28db39739611b 100644 --- a/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_out.test.ts +++ b/x-pack/plugins/security_solution/public/actions/filter/cell_action/filter_out.test.ts @@ -6,13 +6,7 @@ */ import { createFilterManagerMock } from '@kbn/data-plugin/public/query/filter_manager/filter_manager.mock'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; +import { createMockStore, mockGlobalState } from '../../../common/mock'; import { createFilterOutCellActionFactory } from './filter_out'; import type { SecurityCellActionExecutionContext } from '../../types'; import { createStartServicesMock } from '../../../common/lib/kibana/kibana_react.mock'; @@ -39,8 +33,7 @@ const mockState = { }, }; -const { storage } = createSecuritySolutionStorageMock(); -const mockStore = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const mockStore = createMockStore(mockState); describe('createFilterOutCellActionFactory', () => { const filterOutActionFactory = createFilterOutCellActionFactory({ store: mockStore, services }); diff --git a/x-pack/plugins/security_solution/public/actions/filter/discover/filter_in.test.ts b/x-pack/plugins/security_solution/public/actions/filter/discover/filter_in.test.ts index a221210ce63d4..c7136f87e05b9 100644 --- a/x-pack/plugins/security_solution/public/actions/filter/discover/filter_in.test.ts +++ b/x-pack/plugins/security_solution/public/actions/filter/discover/filter_in.test.ts @@ -5,13 +5,7 @@ * 2.0. */ -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; +import { createMockStore } from '../../../common/mock'; import { createFilterInDiscoverCellActionFactory } from './filter_in'; import type { SecurityCellActionExecutionContext } from '../../types'; import { createStartServicesMock } from '../../../common/lib/kibana/kibana_react.mock'; @@ -30,8 +24,7 @@ jest.mock('@kbn/ui-actions-plugin/public', () => ({ addFilterOut: () => {}, })); -const { storage } = createSecuritySolutionStorageMock(); -const mockStore = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const mockStore = createMockStore(); describe('createFilterInDiscoverCellActionFactory', () => { const createFilterInCellAction = createFilterInDiscoverCellActionFactory({ diff --git a/x-pack/plugins/security_solution/public/actions/filter/discover/filter_out.test.ts b/x-pack/plugins/security_solution/public/actions/filter/discover/filter_out.test.ts index bcbc4dcbbad39..fa028bce4ecd9 100644 --- a/x-pack/plugins/security_solution/public/actions/filter/discover/filter_out.test.ts +++ b/x-pack/plugins/security_solution/public/actions/filter/discover/filter_out.test.ts @@ -5,13 +5,7 @@ * 2.0. */ -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; +import { createMockStore } from '../../../common/mock'; import { createFilterOutDiscoverCellActionFactory } from './filter_out'; import type { SecurityCellActionExecutionContext } from '../../types'; import { createStartServicesMock } from '../../../common/lib/kibana/kibana_react.mock'; @@ -30,8 +24,7 @@ jest.mock('@kbn/ui-actions-plugin/public', () => ({ addFilterOut: () => {}, })); -const { storage } = createSecuritySolutionStorageMock(); -const mockStore = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const mockStore = createMockStore(); describe('createFilterOutDiscoverCellActionFactory', () => { const createFilterOutCellAction = createFilterOutDiscoverCellActionFactory({ diff --git a/x-pack/plugins/security_solution/public/app/home/global_header/index.test.tsx b/x-pack/plugins/security_solution/public/app/home/global_header/index.test.tsx index bfce21c47867c..378fbb6b196eb 100644 --- a/x-pack/plugins/security_solution/public/app/home/global_header/index.test.tsx +++ b/x-pack/plugins/security_solution/public/app/home/global_header/index.test.tsx @@ -16,15 +16,12 @@ import { THREAT_INTELLIGENCE_PATH, } from '../../../../common/constants'; import { - createSecuritySolutionStorageMock, + createMockStore, mockGlobalState, mockIndexPattern, - SUB_PLUGINS_REDUCER, TestProviders, } from '../../../common/mock'; import { TimelineId } from '../../../../common/types/timeline'; -import { createStore } from '../../../common/store'; -import { kibanaObservable } from '@kbn/timelines-plugin/public/mock'; import { sourcererPaths } from '../../../common/containers/sourcerer'; jest.mock('react-router-dom', () => { @@ -61,8 +58,7 @@ describe('global header', () => { }, }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); beforeEach(() => { useVariationMock.mockReset(); @@ -159,7 +155,7 @@ describe('global header', () => { }, }, }; - const mockStore = createStore(mockstate, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockstate); (useLocation as jest.Mock).mockReturnValue({ pathname: sourcererPaths[2] }); diff --git a/x-pack/plugins/security_solution/public/app/home/index.test.tsx b/x-pack/plugins/security_solution/public/app/home/index.test.tsx index 8fce33967e151..961b9128f3e5c 100644 --- a/x-pack/plugins/security_solution/public/app/home/index.test.tsx +++ b/x-pack/plugins/security_solution/public/app/home/index.test.tsx @@ -11,13 +11,7 @@ import { HomePage } from '.'; import type { SavedQuery } from '@kbn/data-plugin/public'; import { FilterManager } from '@kbn/data-plugin/public'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../common/mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../common/mock'; import { inputsActions } from '../../common/store/inputs'; import { setSearchBarFilter, @@ -26,7 +20,6 @@ import { } from '../../common/store/inputs/actions'; import { coreMock } from '@kbn/core/public/mocks'; import type { Filter } from '@kbn/es-query'; -import { createStore } from '../../common/store'; import type { TimeRange, UrlInputsModel } from '../../common/store/inputs/model'; import { SecurityPageName } from '../types'; import type { TimelineUrl } from '../../timelines/store/model'; @@ -346,7 +339,6 @@ describe('HomePage', () => { const state = null; mockUseInitializeUrlParam(URL_PARAM_KEY.filters, state); const spySetAppFilters = jest.spyOn(mockedFilterManager, 'setAppFilters'); - const { storage } = createSecuritySolutionStorageMock(); const mockstate = { ...mockGlobalState, @@ -359,7 +351,7 @@ describe('HomePage', () => { }, }; - const mockStore = createStore(mockstate, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockstate); render( @@ -512,8 +504,7 @@ describe('HomePage', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - const mockStore = createStore(mockstate, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockstate); const TestComponent = () => ( @@ -569,8 +560,7 @@ describe('HomePage', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - const mockStore = createStore(mockstate, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockstate); const TestComponent = () => ( @@ -629,16 +619,13 @@ describe('HomePage', () => { }); it('it keeps timeline visibility and selected tab state in URL', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - mockUseInitializeUrlParam(URL_PARAM_KEY.timeline, { id: 'testSavedTimelineId', isOpen: false, }); const TestComponent = () => ( - + @@ -660,8 +647,6 @@ describe('HomePage', () => { }); it('it updates URL when timeline store changes', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); const savedObjectId = 'testTimelineId'; mockUseInitializeUrlParam(URL_PARAM_KEY.timeline, { @@ -670,7 +655,7 @@ describe('HomePage', () => { }); const TestComponent = () => ( - + diff --git a/x-pack/plugins/security_solution/public/common/components/chart_settings_popover/configurations/default/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/chart_settings_popover/configurations/default/index.test.tsx index ed262ee04d9db..9155edb7d36ea 100644 --- a/x-pack/plugins/security_solution/public/common/components/chart_settings_popover/configurations/default/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/chart_settings_popover/configurations/default/index.test.tsx @@ -8,15 +8,7 @@ import { renderHook } from '@testing-library/react-hooks'; import React from 'react'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../../mock'; -import type { State } from '../../../../store'; -import { createStore } from '../../../../store'; +import { TestProviders } from '../../../../mock'; import * as i18n from './translations'; import { useChartSettingsPopoverConfiguration } from '.'; @@ -30,11 +22,8 @@ describe('useChartSettingsPopoverConfiguration', () => { const onResetStackByFields = jest.fn(); const queryId = 'abcd'; - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); const wrapper = ({ children }: { children: React.ReactNode }) => ( - {children} + {children} ); beforeEach(() => jest.clearAllMocks()); diff --git a/x-pack/plugins/security_solution/public/common/components/discover_in_timeline/use_discover_in_timeline_actions.test.tsx b/x-pack/plugins/security_solution/public/common/components/discover_in_timeline/use_discover_in_timeline_actions.test.tsx index b2d1ac052a1e0..581648acd8b7c 100644 --- a/x-pack/plugins/security_solution/public/common/components/discover_in_timeline/use_discover_in_timeline_actions.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/discover_in_timeline/use_discover_in_timeline_actions.test.tsx @@ -9,19 +9,12 @@ import { discoverPluginMock } from '@kbn/discover-plugin/public/mocks'; import { dataViewMock } from '@kbn/discover-utils/src/__mocks__'; import type { SavedSearch } from '@kbn/saved-search-plugin/common'; import { renderHook } from '@testing-library/react-hooks'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { useDiscoverInTimelineActions } from './use_discover_in_timeline_actions'; import type { Filter } from '@kbn/es-query'; import { createStartServicesMock } from '../../lib/kibana/kibana_react.mock'; import { useKibana } from '../../lib/kibana'; import type { State } from '../../store'; -import { createStore } from '../../store'; import { TimelineId } from '../../../../common/types'; import * as timelineActions from '../../../timelines/store/actions'; import type { ComponentType, FC, PropsWithChildren } from 'react'; @@ -67,10 +60,8 @@ jest.mock('./use_discover_in_timeline_actions', () => { return actual; }); -const { storage } = createSecuritySolutionStorageMock(); - const getTestProviderWithCustomState = (state: State = mockState) => { - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); const MockTestProvider: FC> = ({ children }) => ( {children} diff --git a/x-pack/plugins/security_solution/public/common/components/error_toast_dispatcher/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/error_toast_dispatcher/index.test.tsx index 51888a1a6bda8..5f70f0ce84936 100644 --- a/x-pack/plugins/security_solution/public/common/components/error_toast_dispatcher/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/error_toast_dispatcher/index.test.tsx @@ -9,30 +9,15 @@ import { shallow } from 'enzyme'; import React from 'react'; import { Provider } from 'react-redux'; -import { - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../mock'; -import { createStore } from '../../store/store'; +import { createMockStore } from '../../mock'; import { ErrorToastDispatcher } from '.'; -import type { State } from '../../store/types'; describe('Error Toast Dispatcher', () => { - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - describe('rendering', () => { test('it renders', () => { const wrapper = shallow( - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/event_details/overview/overview_card.test.tsx b/x-pack/plugins/security_solution/public/common/components/event_details/overview/overview_card.test.tsx index b0aa72c0a7b9d..4704ec7a565e3 100644 --- a/x-pack/plugins/security_solution/public/common/components/event_details/overview/overview_card.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/event_details/overview/overview_card.test.tsx @@ -8,16 +8,9 @@ import React from 'react'; import { act, render } from '@testing-library/react'; import { OverviewCardWithActions } from './overview_card'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../../mock'; import { SeverityBadge } from '../../severity_badge'; import type { State } from '../../../store'; -import { createStore } from '../../../store'; import { TimelineId } from '../../../../../common/types'; import { createAction } from '@kbn/ui-actions-plugin/public'; @@ -34,8 +27,7 @@ const state: State = { }, }; -const { storage } = createSecuritySolutionStorageMock(); -const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const store = createMockStore(state); const props = { title: 'Severity', diff --git a/x-pack/plugins/security_solution/public/common/components/filter_group/filter_group.test.tsx b/x-pack/plugins/security_solution/public/common/components/filter_group/filter_group.test.tsx index 7d3c961473fa9..1a56b6c8a28a8 100644 --- a/x-pack/plugins/security_solution/public/common/components/filter_group/filter_group.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/filter_group/filter_group.test.tsx @@ -10,13 +10,7 @@ import type { ComponentProps, FC } from 'react'; import React from 'react'; import { act, render, screen, fireEvent, waitFor } from '@testing-library/react'; import { DEFAULT_DETECTION_PAGE_FILTERS } from '../../../../common/constants'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; +import { TestProviders } from '../../mock'; import type { ControlGroupOutput, ControlGroupInput, @@ -24,7 +18,6 @@ import type { } from '@kbn/controls-plugin/public'; import { OPTIONS_LIST_CONTROL } from '@kbn/controls-plugin/common'; import { initialInputData, sampleOutputData } from './mocks/data'; -import { createStore } from '../../store'; import { useGetInitialUrlParamValue } from '../../utils/global_query_string/helpers'; import { COMMON_OPTIONS_LIST_CONTROL_INPUTS, TEST_IDS } from './constants'; import { @@ -88,19 +81,12 @@ jest.mock('@kbn/controls-plugin/public/control_group/external_api/control_group_ const onFilterChangeMock = jest.fn(); const onInitMock = jest.fn(); -const state = mockGlobalState; -const { storage } = createSecuritySolutionStorageMock(); - -const getStoreWithCustomState = (newState: typeof state = state) => { - return createStore(newState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); -}; - const TestComponent: FC< ComponentProps & { filterGroupProps?: Partial>; } > = (props) => ( - + { }, }, }; - const { storage } = createSecuritySolutionStorageMock(); - const mockStore = createStore(mockstate, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockstate); render( diff --git a/x-pack/plugins/security_solution/public/common/components/inspect/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/inspect/index.test.tsx index cc31b9a0300cf..14cb4d6f52b33 100644 --- a/x-pack/plugins/security_solution/public/common/components/inspect/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/inspect/index.test.tsx @@ -8,15 +8,8 @@ import { mount } from 'enzyme'; import React from 'react'; -import { - TestProviders, - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../mock'; +import { TestProviders, mockGlobalState, createMockStore } from '../../mock'; import type { State } from '../../store'; -import { createStore } from '../../store'; import type { UpdateQueryParams } from '../../store/inputs/helpers'; import { upsertQuery } from '../../store/inputs/helpers'; @@ -31,7 +24,6 @@ jest.mock('./modal', () => ({ describe('Inspect Button', () => { const refetch = jest.fn(); const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); const newQuery: UpdateQueryParams = { inputId: InputsModelId.global, id: 'myQuery', @@ -41,19 +33,13 @@ describe('Inspect Button', () => { state: state.inputs, }; - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(state); describe('Render', () => { beforeEach(() => { const myState = cloneDeep(state); myState.inputs = upsertQuery(newQuery); - store = createStore( - myState, - SUB_PLUGINS_REDUCER, - - kibanaObservable, - storage - ); + store = createMockStore(myState); }); test('Eui Empty Button', () => { const wrapper = mount( @@ -159,7 +145,7 @@ describe('Inspect Button', () => { const myQuery = cloneDeep(newQuery); myQuery.inspect = null; myState.inputs = upsertQuery(myQuery); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( @@ -176,7 +162,7 @@ describe('Inspect Button', () => { response: ['my response'], }; myState.inputs = upsertQuery(myQuery); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( @@ -193,7 +179,7 @@ describe('Inspect Button', () => { response: [], }; myState.inputs = upsertQuery(myQuery); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( @@ -212,7 +198,7 @@ describe('Inspect Button', () => { response: ['my response'], }; myState.inputs = upsertQuery(myQuery); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); }); test('Open Inspect Modal', () => { const wrapper = mount( @@ -257,7 +243,7 @@ describe('Inspect Button', () => { }; myState.inputs = upsertQuery(myQuery); myState.inputs.global.queries[0].isInspected = true; - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( @@ -276,7 +262,7 @@ describe('Inspect Button', () => { }; myState.inputs = upsertQuery(myQuery); myState.inputs.global.queries[0].isInspected = false; - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( @@ -295,7 +281,7 @@ describe('Inspect Button', () => { }; myState.inputs = upsertQuery(myQuery); myState.inputs.global.queries[0].isInspected = true; - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( @@ -314,7 +300,7 @@ describe('Inspect Button', () => { }; myState.inputs = upsertQuery(myQuery); myState.inputs.global.queries[0].isInspected = true; - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(myState); const wrapper = mount( diff --git a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_enable_data_feed.test.tsx b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_enable_data_feed.test.tsx index 52d955414a099..0801ec37f6ae6 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_enable_data_feed.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_enable_data_feed.test.tsx @@ -7,26 +7,14 @@ import React from 'react'; import { renderHook, act } from '@testing-library/react-hooks'; import { useEnableDataFeed } from './use_enable_data_feed'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../mock'; -import { createStore } from '../../../store'; -import type { State } from '../../../store'; +import { TestProviders } from '../../../mock'; import type { SecurityJob } from '../types'; import { createTelemetryServiceMock } from '../../../lib/telemetry/telemetry_service.mock'; import { ML_JOB_TELEMETRY_STATUS } from '../../../lib/telemetry'; -const state: State = mockGlobalState; -const { storage } = createSecuritySolutionStorageMock(); -const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - const wrapper = ({ children }: { children: React.ReactNode }) => ( - {children} + {children} ); const moduleId = 'test_module_id'; diff --git a/x-pack/plugins/security_solution/public/common/components/page/use_refetch_by_session.test.tsx b/x-pack/plugins/security_solution/public/common/components/page/use_refetch_by_session.test.tsx index a800266a8ac6d..da5610d8c9ab2 100644 --- a/x-pack/plugins/security_solution/public/common/components/page/use_refetch_by_session.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/page/use_refetch_by_session.test.tsx @@ -8,15 +8,7 @@ import type { MutableRefObject } from 'react'; import React from 'react'; import type { RenderHookResult } from '@testing-library/react-hooks'; import { renderHook } from '@testing-library/react-hooks'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import type { State } from '../../store'; -import { createStore } from '../../store'; +import { TestProviders } from '../../mock'; import { useKibana } from '../../lib/kibana'; import { InputsModelId } from '../../store/inputs/constants'; import { useRefetchByRestartingSession } from './use_refetch_by_session'; @@ -24,13 +16,8 @@ import { inputsActions } from '../../store/actions'; import type { Refetch } from '../../store/inputs/model'; import type { ISessionService } from '@kbn/data-plugin/public'; -const state: State = mockGlobalState; - -const { storage } = createSecuritySolutionStorageMock(); -const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - const wrapper = ({ children }: { children: React.ReactNode }) => ( - {children} + {children} ); jest.mock('react-redux', () => { diff --git a/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx index 915a8fef984cd..1ffb709b314fc 100644 --- a/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx @@ -6,19 +6,12 @@ */ import React from 'react'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { render, fireEvent, waitFor } from '@testing-library/react'; import { SearchBarComponent } from '.'; import type { SavedQuery } from '@kbn/data-plugin/public'; import { FilterManager } from '@kbn/data-plugin/public'; import { coreMock } from '@kbn/core/public/mocks'; -import { createStore } from '../../store'; import { inputsActions } from '../../store/inputs'; import { InputsModelId } from '../../store/inputs/constants'; @@ -137,8 +130,7 @@ describe('SearchBarComponent', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); render( @@ -174,8 +166,7 @@ describe('SearchBarComponent', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); render( @@ -189,9 +180,7 @@ describe('SearchBarComponent', () => { }); it('calls useUpdateUrlParam when query query changes', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - + const store = createMockStore(); render( @@ -214,9 +203,7 @@ describe('SearchBarComponent', () => { }); it('calls useUpdateUrlParam when filters change', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - + const store = createMockStore(); render( @@ -250,9 +237,7 @@ describe('SearchBarComponent', () => { }); it('calls useUpdateUrlParam when savedQuery changes', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - + const store = createMockStore(); render( @@ -284,9 +269,7 @@ describe('SearchBarComponent', () => { describe('Timerange', () => { it('calls useUpdateUrlParam when global timerange changes', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - + const store = createMockStore(); render( @@ -320,9 +303,7 @@ describe('SearchBarComponent', () => { }); it('calls useUpdateUrlParam when timeline timerange changes', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - + const store = createMockStore(); render( @@ -359,11 +340,9 @@ describe('SearchBarComponent', () => { }); it('initializes timerange URL param with redux date on mount', async () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); jest.clearAllMocks(); render( - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/alerts_sourcerer.test.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/alerts_sourcerer.test.tsx index da0bc5699882d..6d37aff3c804e 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/alerts_sourcerer.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/alerts_sourcerer.test.tsx @@ -9,14 +9,7 @@ import React from 'react'; import { Sourcerer } from '.'; import { sourcererModel } from '../../store/sourcerer'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; +import { TestProviders } from '../../mock'; import { useSourcererDataView } from '../../containers/sourcerer'; import { useSignalHelpers } from '../../containers/sourcerer/use_signal_helpers'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; @@ -57,14 +50,11 @@ jest.mock('../../utils/global_query_string', () => { }; }); -let store: ReturnType; const sourcererDataView = { indicesExist: true, loading: false, }; describe('sourcerer on alerts page or rules details page', () => { - const { storage } = createSecuritySolutionStorageMock(); - store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); const testProps = { scope: sourcererModel.SourcererScopeName.detections, }; @@ -85,7 +75,7 @@ describe('sourcerer on alerts page or rules details page', () => { }); render( - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx index f91ebef48d7a7..d8e84b7f774c4 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/index.test.tsx @@ -12,14 +12,7 @@ import { mount } from 'enzyme'; import { SourcererScopeName } from '../../store/sourcerer/model'; import { Sourcerer } from '.'; import { sourcererActions, sourcererModel } from '../../store/sourcerer'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import type { EuiSuperSelectOption } from '@elastic/eui/src/components/form/super_select/super_select_control'; import { fireEvent, waitFor, render } from '@testing-library/react'; import { useSourcererDataView } from '../../containers/sourcerer'; @@ -81,19 +74,16 @@ const { id, patternList, title } = mockGlobalState.sourcerer.defaultDataView; const patternListNoSignals = sortWithExcludesAtEnd( patternList.filter((p) => p !== mockGlobalState.sourcerer.signalIndexName) ); -let store: ReturnType; const sourcererDataView = { indicesExist: true, loading: false, }; describe('Sourcerer component', () => { - const { storage } = createSecuritySolutionStorageMock(); const pollForSignalIndexMock = jest.fn(); let wrapper: ReactWrapper; beforeEach(() => { jest.clearAllMocks(); - store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); (useSourcererDataView as jest.Mock).mockReturnValue(sourcererDataView); (useSignalHelpers as jest.Mock).mockReturnValue({ signalIndexNeedsInit: false }); }); @@ -104,7 +94,7 @@ describe('Sourcerer component', () => { it('renders data view title', () => { wrapper = mount( - + ); @@ -120,7 +110,7 @@ describe('Sourcerer component', () => { showAlertsOnlyCheckbox: true, }; wrapper = mount( - + ); @@ -159,7 +149,7 @@ describe('Sourcerer component', () => { // because EuiSelectable uses a virtualized list, which isn't easily testable via test subjects it('Mounts with all options selected', () => { wrapper = mount( - + ); @@ -174,40 +164,35 @@ describe('Sourcerer component', () => { ); }); it('Removes duplicate options from title', () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - defaultDataView: { + const store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + id: '1234', + title: 'filebeat-*,auditbeat-*,auditbeat-*,auditbeat-*,auditbeat-*', + patternList: ['filebeat-*', 'auditbeat-*'], + }, + kibanaDataViews: [ + { ...mockGlobalState.sourcerer.defaultDataView, id: '1234', title: 'filebeat-*,auditbeat-*,auditbeat-*,auditbeat-*,auditbeat-*', patternList: ['filebeat-*', 'auditbeat-*'], }, - kibanaDataViews: [ - { - ...mockGlobalState.sourcerer.defaultDataView, - id: '1234', - title: 'filebeat-*,auditbeat-*,auditbeat-*,auditbeat-*,auditbeat-*', - patternList: ['filebeat-*', 'auditbeat-*'], - }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.default]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], - loading: false, - selectedDataViewId: '1234', - selectedPatterns: ['filebeat-*'], - }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.default]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], + loading: false, + selectedDataViewId: '1234', + selectedPatterns: ['filebeat-*'], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); wrapper = mount( @@ -225,39 +210,34 @@ describe('Sourcerer component', () => { expect(options.length).toEqual(2); }); it('Disables options with no data', () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - defaultDataView: { + const store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + id: '1234', + title: 'filebeat-*,auditbeat-*,fakebeat-*', + patternList: ['filebeat-*', 'auditbeat-*'], + }, + kibanaDataViews: [ + { ...mockGlobalState.sourcerer.defaultDataView, id: '1234', title: 'filebeat-*,auditbeat-*,fakebeat-*', patternList: ['filebeat-*', 'auditbeat-*'], }, - kibanaDataViews: [ - { - ...mockGlobalState.sourcerer.defaultDataView, - id: '1234', - title: 'filebeat-*,auditbeat-*,fakebeat-*', - patternList: ['filebeat-*', 'auditbeat-*'], - }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.default]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], - selectedDataViewId: '1234', - selectedPatterns: ['filebeat-*'], - }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.default]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], + selectedDataViewId: '1234', + selectedPatterns: ['filebeat-*'], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); wrapper = mount( @@ -306,7 +286,7 @@ describe('Sourcerer component', () => { }, }; - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state2); wrapper = mount( @@ -351,7 +331,7 @@ describe('Sourcerer component', () => { }, }; - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state2); const { getByTestId, queryByTitle, queryAllByTestId } = render( @@ -371,34 +351,29 @@ describe('Sourcerer component', () => { }); }); it('onSave dispatches setSelectedDataView', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - kibanaDataViews: [ - mockGlobalState.sourcerer.defaultDataView, - { - ...mockGlobalState.sourcerer.defaultDataView, - id: '1234', - title: 'filebeat-*', - patternList: ['filebeat-*'], - }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.default]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], - selectedDataViewId: id, - selectedPatterns: patternListNoSignals.slice(0, 2), - }, + const store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + kibanaDataViews: [ + mockGlobalState.sourcerer.defaultDataView, + { + ...mockGlobalState.sourcerer.defaultDataView, + id: '1234', + title: 'filebeat-*', + patternList: ['filebeat-*'], + }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.default]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], + selectedDataViewId: id, + selectedPatterns: patternListNoSignals.slice(0, 2), }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); wrapper = mount( @@ -428,34 +403,29 @@ describe('Sourcerer component', () => { }); it('onSave updates the URL param', () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - kibanaDataViews: [ - mockGlobalState.sourcerer.defaultDataView, - { - ...mockGlobalState.sourcerer.defaultDataView, - id: '1234', - title: 'filebeat-*', - patternList: ['filebeat-*'], - }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.default]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], - selectedDataViewId: id, - selectedPatterns: patternListNoSignals.slice(0, 2), - }, + const store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + kibanaDataViews: [ + mockGlobalState.sourcerer.defaultDataView, + { + ...mockGlobalState.sourcerer.defaultDataView, + id: '1234', + title: 'filebeat-*', + patternList: ['filebeat-*'], + }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.default]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], + selectedDataViewId: id, + selectedPatterns: patternListNoSignals.slice(0, 2), }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); wrapper = mount( @@ -472,7 +442,7 @@ describe('Sourcerer component', () => { it('resets to default index pattern', async () => { wrapper = mount( - + ); @@ -504,26 +474,21 @@ describe('Sourcerer component', () => { }); }); it('disables saving when no index patterns are selected', () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - kibanaDataViews: [ - mockGlobalState.sourcerer.defaultDataView, - { - ...mockGlobalState.sourcerer.defaultDataView, - id: '1234', - title: 'auditbeat-*', - patternList: ['auditbeat-*'], - }, - ], - }, + const store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + kibanaDataViews: [ + mockGlobalState.sourcerer.defaultDataView, + { + ...mockGlobalState.sourcerer.defaultDataView, + id: '1234', + title: 'auditbeat-*', + patternList: ['auditbeat-*'], + }, + ], }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); wrapper = mount( @@ -572,7 +537,7 @@ describe('Sourcerer component', () => { }, }; - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state2); const el = render( @@ -620,7 +585,7 @@ describe('Sourcerer component', () => { }, }; - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state2); wrapper = mount( @@ -644,7 +609,7 @@ describe('Sourcerer component', () => { }); mount( - + ); @@ -659,7 +624,7 @@ describe('Sourcerer component', () => { }); mount( - + ); @@ -674,7 +639,7 @@ describe('Sourcerer component', () => { }); mount( - + ); @@ -688,7 +653,7 @@ describe('Sourcerer component', () => { }); mount( - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/misc.test.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/misc.test.tsx index 5acd207856619..6573dc4d8fb05 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/misc.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/misc.test.tsx @@ -13,14 +13,7 @@ import { cloneDeep } from 'lodash'; import { initialSourcererState, SourcererScopeName } from '../../store/sourcerer/model'; import { Sourcerer } from '.'; import { sourcererActions, sourcererModel } from '../../store/sourcerer'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { useSourcererDataView } from '../../containers/sourcerer'; import { useSignalHelpers } from '../../containers/sourcerer/use_signal_helpers'; import { TimelineId } from '../../../../common/types/timeline'; @@ -81,7 +74,6 @@ const { id, patternList } = mockGlobalState.sourcerer.defaultDataView; const patternListNoSignals = sortWithExcludesAtEnd( patternList.filter((p) => p !== mockGlobalState.sourcerer.signalIndexName) ); -let store: ReturnType; const sourcererDataView = { indicesExist: true, loading: false, @@ -94,8 +86,7 @@ describe('No data', () => { ...initialSourcererState, }, }; - - const { storage } = createSecuritySolutionStorageMock(); + let store = createMockStore(mockNoIndicesState); const pollForSignalIndexMock = jest.fn(); beforeEach(() => { @@ -107,7 +98,7 @@ describe('No data', () => { pollForSignalIndex: pollForSignalIndexMock, signalIndexNeedsInit: false, }); - store = createStore(mockNoIndicesState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(mockNoIndicesState); jest.clearAllMocks(); }); @@ -141,7 +132,6 @@ describe('No data', () => { }); describe('Update available', () => { - const { storage } = createSecuritySolutionStorageMock(); const state2 = { ...mockGlobalState, sourcerer: { @@ -174,7 +164,7 @@ describe('Update available', () => { }, }, }; - + let store = createMockStore(state2); const pollForSignalIndexMock = jest.fn(); beforeEach(() => { (useSignalHelpers as jest.Mock).mockReturnValue({ @@ -185,7 +175,7 @@ describe('Update available', () => { ...sourcererDataView, activePatterns: ['myFakebeat-*'], }); - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(state2); render( @@ -265,7 +255,6 @@ describe('Update available', () => { }); describe('Update available for timeline template', () => { - const { storage } = createSecuritySolutionStorageMock(); const state2 = { ...mockGlobalState, timeline: { @@ -308,13 +297,14 @@ describe('Update available for timeline template', () => { }, }, }; + let store = createMockStore(state2); beforeEach(() => { (useSourcererDataView as jest.Mock).mockReturnValue({ ...sourcererDataView, activePatterns: ['myFakebeat-*'], }); - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(state2); render( @@ -341,7 +331,6 @@ describe('Update available for timeline template', () => { }); describe('Missing index patterns', () => { - const { storage } = createSecuritySolutionStorageMock(); const state2 = { ...mockGlobalState, timeline: { @@ -384,7 +373,7 @@ describe('Missing index patterns', () => { }, }, }; - + let store = createMockStore(state2); beforeEach(() => { const pollForSignalIndexMock = jest.fn(); (useSignalHelpers as jest.Mock).mockReturnValue({ @@ -404,7 +393,7 @@ describe('Missing index patterns', () => { }); const state3 = cloneDeep(state2); state3.timeline.timelineById[TimelineId.active].timelineType = TimelineType.default; - store = createStore(state3, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(state3); render( @@ -435,7 +424,7 @@ describe('Missing index patterns', () => { ...sourcererDataView, activePatterns: ['myFakebeat-*'], }); - store = createStore(state2, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(state2); render( @@ -493,8 +482,7 @@ describe('Sourcerer integration tests', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - + let store = createMockStore(state); beforeEach(() => { const pollForSignalIndexMock = jest.fn(); (useSignalHelpers as jest.Mock).mockReturnValue({ @@ -506,7 +494,7 @@ describe('Sourcerer integration tests', () => { ...sourcererDataView, activePatterns: ['myFakebeat-*'], }); - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(state); jest.clearAllMocks(); }); diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/sourcerer_integration.test.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/sourcerer_integration.test.tsx index 33eba9dac6b95..749800194ac91 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/sourcerer_integration.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/sourcerer_integration.test.tsx @@ -13,14 +13,7 @@ import { SourcererScopeName } from '../../store/sourcerer/model'; import { Sourcerer } from '.'; import { useSignalHelpers } from '../../containers/sourcerer/use_signal_helpers'; import { sourcererActions, sourcererModel } from '../../store/sourcerer'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { sortWithExcludesAtEnd } from '../../../../common/utils/sourcerer'; import { useSourcererDataView } from '../../containers/sourcerer'; @@ -76,7 +69,6 @@ const { id, patternList } = mockGlobalState.sourcerer.defaultDataView; const patternListNoSignals = sortWithExcludesAtEnd( patternList.filter((p) => p !== mockGlobalState.sourcerer.signalIndexName) ); -let store: ReturnType; const sourcererDataView = { indicesExist: true, loading: false, @@ -108,8 +100,6 @@ describe('Sourcerer integration tests', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - beforeEach(() => { const pollForSignalIndexMock = jest.fn(); (useSignalHelpers as jest.Mock).mockReturnValue({ @@ -121,13 +111,12 @@ describe('Sourcerer integration tests', () => { ...sourcererDataView, activePatterns: ['myFakebeat-*'], }); - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); jest.clearAllMocks(); }); it('Selects a different index pattern', async () => { const wrapper = mount( - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/sourcerer/timeline_sourcerer.test.tsx b/x-pack/plugins/security_solution/public/common/components/sourcerer/timeline_sourcerer.test.tsx index 6f57f5fc2d34f..878e88c88a5fb 100644 --- a/x-pack/plugins/security_solution/public/common/components/sourcerer/timeline_sourcerer.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/sourcerer/timeline_sourcerer.test.tsx @@ -11,14 +11,7 @@ import { render, cleanup, fireEvent, screen, waitFor } from '@testing-library/re import { SourcererScopeName } from '../../store/sourcerer/model'; import { Sourcerer } from '.'; import { sourcererModel } from '../../store/sourcerer'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { useSourcererDataView } from '../../containers/sourcerer'; import { useSignalHelpers } from '../../containers/sourcerer/use_signal_helpers'; @@ -60,15 +53,12 @@ jest.mock('../../utils/global_query_string', () => { const { id } = mockGlobalState.sourcerer.defaultDataView; -let store: ReturnType; const sourcererDataView = { indicesExist: true, loading: false, }; describe('timeline sourcerer', () => { - const { storage } = createSecuritySolutionStorageMock(); - store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); const testProps = { scope: sourcererModel.SourcererScopeName.timeline, }; @@ -84,7 +74,7 @@ describe('timeline sourcerer', () => { }); render( - + ); @@ -165,16 +155,8 @@ describe('timeline sourcerer', () => { }, }; - store = createStore( - state2, - SUB_PLUGINS_REDUCER, - - kibanaObservable, - storage - ); - render( - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx index 5410a3c2b18f3..a2cbc508da56e 100644 --- a/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx @@ -11,15 +11,8 @@ import { Provider as ReduxStoreProvider } from 'react-redux'; import { DEFAULT_TIMEPICKER_QUICK_RANGES } from '../../../../common/constants'; import { useUiSetting$ } from '../../lib/kibana'; -import { - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../mock'; +import { mockGlobalState, createMockStore } from '../../mock'; import { createUseUiSetting$Mock } from '../../lib/kibana/kibana_react.mock'; -import type { State } from '../../store'; -import { createStore } from '../../store'; import { SuperDatePicker, makeMapStateToProps } from '.'; import { cloneDeep } from 'lodash/fp'; @@ -27,6 +20,7 @@ import { InputsModelId } from '../../store/inputs/constants'; jest.mock('../../lib/kibana'); const mockUseUiSetting$ = useUiSetting$ as jest.Mock; +const state = mockGlobalState; const timepickerRanges = [ { from: 'now/d', @@ -82,13 +76,11 @@ const timepickerRanges = [ describe('SIEM Super Date Picker', () => { describe('#SuperDatePicker', () => { - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); beforeEach(() => { jest.clearAllMocks(); - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); mockUseUiSetting$.mockImplementation((key, defaultValue) => { const useUiSetting$Mock = createUseUiSetting$Mock(); diff --git a/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_assignees_items.test.tsx b/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_assignees_items.test.tsx index 7a6b9c87fa27e..f3269fceb2a64 100644 --- a/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_assignees_items.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_assignees_items.test.tsx @@ -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, diff --git a/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_tags_items.test.tsx b/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_tags_items.test.tsx index c49e1cf133dd4..2c1b30b976d72 100644 --- a/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_tags_items.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/toolbar/bulk_actions/use_bulk_alert_tags_items.test.tsx @@ -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, diff --git a/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx index d7a7b28529d5a..5a8c5f3166ae7 100644 --- a/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx @@ -11,16 +11,8 @@ import React from 'react'; import { waitFor } from '@testing-library/react'; import '../../mock/match_media'; import { mockBrowserFields } from '../../containers/source/mock'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, - mockIndexPattern, -} from '../../mock'; +import { mockGlobalState, TestProviders, mockIndexPattern, createMockStore } from '../../mock'; import type { State } from '../../store'; -import { createStore } from '../../store'; import type { Props } from './top_n'; import { StatefulTopN } from '.'; @@ -149,8 +141,7 @@ const state: State = { }, }; -const { storage } = createSecuritySolutionStorageMock(); -const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const store = createMockStore(state); const testProps = { browserFields: mockBrowserFields, diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_embeddable.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_embeddable.test.tsx index 8aa39b7c08dac..a6ceb5842102e 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_embeddable.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/lens_embeddable.test.tsx @@ -7,15 +7,8 @@ import { render } from '@testing-library/react'; import type { RenderResult } from '@testing-library/react'; import React from 'react'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import type { State } from '../../store'; -import { createStore } from '../../store'; import { kpiHostMetricLensAttributes } from './lens_attributes/hosts/kpi_host_metric'; import { LensEmbeddable } from './lens_embeddable'; import { useKibana } from '../../lib/kibana'; @@ -77,8 +70,7 @@ describe('LensEmbeddable', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); const mockEmbeddableComponent = jest .fn() .mockReturnValue(
); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/mocks.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/mocks.tsx index 77fa5b02cede0..0153fc6b06c43 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/mocks.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/mocks.tsx @@ -7,15 +7,7 @@ import React from 'react'; import { cloneDeep } from 'lodash/fp'; -import { - TestProviders, - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../mock'; -import type { State } from '../../store'; -import { createStore } from '../../store'; +import { TestProviders, mockGlobalState, createMockStore } from '../../mock'; import type { LensAttributes } from './types'; export const queryFromSearchBar = { @@ -43,13 +35,8 @@ export const filterFromSearchBar = [ }, ]; -export const mockCreateStoreWithQueryFilters = () => { - const { storage } = createSecuritySolutionStorageMock(); - - const state: State = mockGlobalState; - - const myState = cloneDeep(state); - +const mockCreateStoreWithQueryFilters = () => { + const myState = cloneDeep(mockGlobalState); myState.inputs = { ...myState.inputs, global: { @@ -58,7 +45,7 @@ export const mockCreateStoreWithQueryFilters = () => { filters: filterFromSearchBar, }, }; - return createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + return createMockStore(myState); }; export const wrapper = ({ children }: { children: React.ReactElement }) => ( diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_visualization_response.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_visualization_response.test.tsx index 68adb1dd8f20a..cb13823d8512c 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_visualization_response.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_visualization_response.test.tsx @@ -5,14 +5,7 @@ * 2.0. */ -import { createStore } from '../../store'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { useVisualizationResponse } from './use_visualization_response'; import { renderHook } from '@testing-library/react-hooks'; import React from 'react'; @@ -45,8 +38,7 @@ describe('useVisualizationResponse', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - const mockStore = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockState); const visualizationId = 'testId'; beforeEach(() => { jest.clearAllMocks(); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/visualization_embeddable.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/visualization_embeddable.test.tsx index 8d5ef1a3b6e84..f6f8597ef52a7 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/visualization_embeddable.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/visualization_embeddable.test.tsx @@ -12,15 +12,7 @@ import { kpiHostMetricLensAttributes } from './lens_attributes/hosts/kpi_host_me import { VisualizationEmbeddable } from './visualization_embeddable'; import * as inputActions from '../../store/inputs/actions'; import { InputsModelId } from '../../store/inputs/constants'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; -import type { State } from '../../store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { useRefetchByRestartingSession } from '../page/use_refetch_by_session'; import { getRiskScoreDonutAttributes } from '../../../entity_analytics/lens_attributes/risk_score_donut'; @@ -36,11 +28,6 @@ const mockRefetchByRestartingSession = jest.fn(); const mockRefetchByDeletingSession = jest.fn(); const mockSetQuery = jest.spyOn(inputActions, 'setQuery'); const mockDeleteQuery = jest.spyOn(inputActions, 'deleteOneQuery'); -const state: State = { - ...mockGlobalState, -}; -const { storage } = createSecuritySolutionStorageMock(); -const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); describe('VisualizationEmbeddable', () => { describe('when isDonut = false', () => { @@ -59,7 +46,7 @@ describe('VisualizationEmbeddable', () => { refetchByDeletingSession: mockRefetchByDeletingSession, }); res = render( - + { }, }, }; - const mockStore = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const mockStore = createMockStore(mockState); beforeEach(() => { jest.clearAllMocks(); @@ -177,7 +164,7 @@ describe('VisualizationEmbeddable', () => { refetchByRestartingSession: mockRefetchByRestartingSession, }); res = render( - + ({ })); describe('Sourcerer Hooks', () => { - const { storage } = createSecuritySolutionStorageMock(); - let store: ReturnType; + let store = createMockStore(); beforeEach(() => { jest.clearAllMocks(); - store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); mockUseUserInfo.mockImplementation(() => userInfoState); }); it('initializes loading default and timeline index patterns', async () => { @@ -192,23 +183,18 @@ describe('Sourcerer Hooks', () => { }; (createSourcererDataView as jest.Mock).mockResolvedValue(mockNewDataViews); - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - signalIndexName: null, - defaultDataView: { - ...mockGlobalState.sourcerer.defaultDataView, - title: DEFAULT_INDEX_PATTERN.join(','), - patternList: DEFAULT_INDEX_PATTERN, - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + signalIndexName: null, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + title: DEFAULT_INDEX_PATTERN.join(','), + patternList: DEFAULT_INDEX_PATTERN, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { mockUseUserInfo.mockImplementation(() => ({ ...userInfoState, @@ -295,22 +281,17 @@ describe('Sourcerer Hooks', () => { }); it('calls addWarning if defaultDataView has an error', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - signalIndexName: null, - defaultDataView: { - ...mockGlobalState.sourcerer.defaultDataView, - error: true, - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + signalIndexName: null, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + error: true, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { renderHook(() => useInitSourcerer(), { wrapper: ({ children }) => {children}, @@ -330,23 +311,18 @@ describe('Sourcerer Hooks', () => { // puts us in the catch block, but the addError toast is not called (createSourcererDataView as jest.Mock).mockImplementation(mockCreateSourcererDataView); - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - signalIndexName: null, - defaultDataView: { - ...mockGlobalState.sourcerer.defaultDataView, - title: DEFAULT_INDEX_PATTERN.join(','), - patternList: DEFAULT_INDEX_PATTERN, - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + signalIndexName: null, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + title: DEFAULT_INDEX_PATTERN.join(','), + patternList: DEFAULT_INDEX_PATTERN, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { mockUseUserInfo.mockImplementation(() => ({ ...userInfoState, @@ -374,23 +350,18 @@ describe('Sourcerer Hooks', () => { throw Error('fake error'); }); - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - signalIndexName: null, - defaultDataView: { - ...mockGlobalState.sourcerer.defaultDataView, - title: DEFAULT_INDEX_PATTERN.join(','), - patternList: DEFAULT_INDEX_PATTERN, - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + signalIndexName: null, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + title: DEFAULT_INDEX_PATTERN.join(','), + patternList: DEFAULT_INDEX_PATTERN, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { mockUseUserInfo.mockImplementation(() => ({ ...userInfoState, @@ -448,24 +419,19 @@ describe('Sourcerer Hooks', () => { }); }); it('index field search called twice when default and timeline have different dataViewId', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.timeline]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], - selectedDataViewId: 'different-id', - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.timeline]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], + selectedDataViewId: 'different-id', }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { const { rerender, waitForNextUpdate } = renderHook(() => useInitSourcerer(), { wrapper: ({ children }) => {children}, @@ -505,25 +471,20 @@ describe('Sourcerer Hooks', () => { }); it('does needToBeInit if scope is default and selectedPatterns/missingPatterns are empty', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.default]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], - selectedPatterns: [], - missingPatterns: [], - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.default]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], + selectedPatterns: [], + missingPatterns: [], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { const { rerender, waitForNextUpdate } = renderHook(() => useInitSourcerer(), { wrapper: ({ children }) => {children}, @@ -541,30 +502,25 @@ describe('Sourcerer Hooks', () => { }); it('does needToBeInit and skipScopeUpdate=false if scope is timeline and selectedPatterns/missingPatterns are empty', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - kibanaDataViews: [ - ...mockGlobalState.sourcerer.kibanaDataViews, - { ...mockSourcererState.defaultDataView, id: 'something-weird', patternList: [] }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.timeline]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], - selectedDataViewId: 'something-weird', - selectedPatterns: [], - missingPatterns: [], - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + kibanaDataViews: [ + ...mockGlobalState.sourcerer.kibanaDataViews, + { ...mockSourcererState.defaultDataView, id: 'something-weird', patternList: [] }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.timeline]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], + selectedDataViewId: 'something-weird', + selectedPatterns: [], + missingPatterns: [], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { const { rerender, waitForNextUpdate } = renderHook(() => useInitSourcerer(), { wrapper: ({ children }) => {children}, @@ -583,30 +539,25 @@ describe('Sourcerer Hooks', () => { }); it('does needToBeInit and skipScopeUpdate=true if scope is timeline and selectedPatterns have value', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - kibanaDataViews: [ - ...mockGlobalState.sourcerer.kibanaDataViews, - { ...mockSourcererState.defaultDataView, id: 'something-weird', patternList: [] }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.timeline]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], - selectedDataViewId: 'something-weird', - selectedPatterns: ['ohboy'], - missingPatterns: [], - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + kibanaDataViews: [ + ...mockGlobalState.sourcerer.kibanaDataViews, + { ...mockSourcererState.defaultDataView, id: 'something-weird', patternList: [] }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.timeline]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], + selectedDataViewId: 'something-weird', + selectedPatterns: ['ohboy'], + missingPatterns: [], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { const { rerender, waitForNextUpdate } = renderHook(() => useInitSourcerer(), { wrapper: ({ children }) => {children}, @@ -625,34 +576,29 @@ describe('Sourcerer Hooks', () => { }); it('does not needToBeInit if scope is timeline and data view has patternList', async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - kibanaDataViews: [ - ...mockGlobalState.sourcerer.kibanaDataViews, - { - ...mockSourcererState.defaultDataView, - id: 'something-weird', - patternList: ['ohboy'], - }, - ], - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.timeline]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], - selectedDataViewId: 'something-weird', - selectedPatterns: [], - missingPatterns: [], - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + kibanaDataViews: [ + ...mockGlobalState.sourcerer.kibanaDataViews, + { + ...mockSourcererState.defaultDataView, + id: 'something-weird', + patternList: ['ohboy'], + }, + ], + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.timeline]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], + selectedDataViewId: 'something-weird', + selectedPatterns: [], + missingPatterns: [], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); await act(async () => { const { rerender, waitForNextUpdate } = renderHook(() => useInitSourcerer(), { wrapper: ({ children }) => {children}, @@ -673,34 +619,29 @@ describe('Sourcerer Hooks', () => { describe('useSourcererDataView', () => { it('Should put any excludes in the index pattern at the end of the pattern list, and sort both the includes and excludes', async () => { await act(async () => { - store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.default]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], - selectedPatterns: [ - '-packetbeat-*', - 'endgame-*', - 'auditbeat-*', - 'filebeat-*', - 'winlogbeat-*', - '-filebeat-*', - 'packetbeat-*', - 'traces-apm*', - 'apm-*-transaction*', - ], - }, + store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.default]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.default], + selectedPatterns: [ + '-packetbeat-*', + 'endgame-*', + 'auditbeat-*', + 'filebeat-*', + 'winlogbeat-*', + '-filebeat-*', + 'packetbeat-*', + 'traces-apm*', + 'apm-*-transaction*', + ], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { result, rerender, waitForNextUpdate } = renderHook< SourcererScopeName, SelectedDataView diff --git a/x-pack/plugins/security_solution/public/common/containers/sourcerer/use_signal_helpers.test.tsx b/x-pack/plugins/security_solution/public/common/containers/sourcerer/use_signal_helpers.test.tsx index b48d96a453aa5..771599132326d 100644 --- a/x-pack/plugins/security_solution/public/common/containers/sourcerer/use_signal_helpers.test.tsx +++ b/x-pack/plugins/security_solution/public/common/containers/sourcerer/use_signal_helpers.test.tsx @@ -6,17 +6,10 @@ */ import React from 'react'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import { act, renderHook } from '@testing-library/react-hooks'; import { useSignalHelpers } from './use_signal_helpers'; import type { State } from '../../store'; -import { createStore } from '../../store'; import { createSourcererDataView } from './create_sourcerer_data_view'; const mockCreateSourcererDataView = jest.fn(() => { @@ -76,8 +69,7 @@ describe('useSignalHelpers', () => { ], }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); await act(async () => { const { result, waitForNextUpdate } = renderHook(() => useSignalHelpers(), { wrapper: ({ children }) => {children}, @@ -106,8 +98,7 @@ describe('useSignalHelpers', () => { ], }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); await act(async () => { const { result, waitForNextUpdate } = renderHook(() => useSignalHelpers(), { wrapper: ({ children }) => {children}, @@ -138,8 +129,7 @@ describe('useSignalHelpers', () => { ], }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); await act(async () => { const { result, waitForNextUpdate } = renderHook(() => useSignalHelpers(), { wrapper: ({ children }) => {children}, @@ -173,8 +163,7 @@ describe('useSignalHelpers', () => { ], }, }; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); await act(async () => { const { result, waitForNextUpdate } = renderHook(() => useSignalHelpers(), { wrapper: ({ children }) => {children}, diff --git a/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx b/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx index c8c2b80506210..aa35c0115394e 100644 --- a/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx @@ -30,13 +30,11 @@ import type { StartPlugins, StartServices } from '../../../types'; import { depsStartMock } from './dependencies_start_mock'; import type { MiddlewareActionSpyHelper } from '../../store/test_utils'; import { createSpyMiddleware } from '../../store/test_utils'; -import { kibanaObservable } from '../test_providers'; import type { State } from '../../store'; -import { createStore } from '../../store'; import { AppRootProvider } from './app_root_provider'; import { managementMiddlewareFactory } from '../../../management/store/middleware'; import { createStartServicesMock } from '../../lib/kibana/kibana_react.mock'; -import { SUB_PLUGINS_REDUCER, mockGlobalState, createSecuritySolutionStorageMock } from '..'; +import { SUB_PLUGINS_REDUCER, mockGlobalState, createMockStore } from '..'; import type { ExperimentalFeatures } from '../../../../common/experimental_features'; import { APP_UI_ID, APP_PATH } from '../../../../common/constants'; import { KibanaServices } from '../../lib/kibana'; @@ -201,7 +199,6 @@ export const createAppRootMockRenderer = (): AppContextTestRender => { const coreStart = createCoreStartMock(history); const depsStart = depsStartMock(); const middlewareSpy = createSpyMiddleware(); - const { storage } = createSecuritySolutionStorageMock(); const startServices: StartServices = createStartServicesMock(coreStart); const storeReducer = { @@ -211,11 +208,11 @@ export const createAppRootMockRenderer = (): AppContextTestRender => { app: experimentalFeaturesReducer, }; - const store = createStore( - mockGlobalState, + const store = createMockStore( + undefined, storeReducer, - kibanaObservable, - storage, + undefined, + undefined, // @ts-expect-error ts upgrade v4.7.4 [...managementMiddlewareFactory(coreStart, depsStart), middlewareSpy.actionSpyMiddleware] ); diff --git a/x-pack/plugins/security_solution/public/common/mock/storybook_providers.tsx b/x-pack/plugins/security_solution/public/common/mock/storybook_providers.tsx index 40b9ce71419db..0fe2b8a2ecec9 100644 --- a/x-pack/plugins/security_solution/public/common/mock/storybook_providers.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/storybook_providers.tsx @@ -8,7 +8,7 @@ import { euiLightVars } from '@kbn/ui-theme'; import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; -import { BehaviorSubject, Subject } from 'rxjs'; +import { Subject } from 'rxjs'; import { ThemeProvider } from 'styled-components'; import type { CoreStart } from '@kbn/core/public'; import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public'; @@ -16,16 +16,11 @@ import { I18nProvider } from '@kbn/i18n-react'; import { CellActionsProvider } from '@kbn/cell-actions'; import { NavigationProvider } from '@kbn/security-solution-navigation'; import { CASES_FEATURE_ID } from '../../../common'; -import { createStore } from '../store'; -import { mockGlobalState } from './global_state'; -import { SUB_PLUGINS_REDUCER } from './utils'; -import { createSecuritySolutionStorageMock } from './mock_local_storage'; import type { StartServices } from '../../types'; import { ReactQueryClientProvider } from '../containers/query_client/query_client_provider'; +import { createMockStore } from './test_providers'; -export const kibanaObservable = new BehaviorSubject({} as unknown as StartServices); - -const { storage } = createSecuritySolutionStorageMock(); +export const kibanaMock = {} as unknown as StartServices; const uiSettings = { get: (setting: string) => { @@ -101,7 +96,7 @@ const KibanaReactContext = createKibanaReactContext(coreMock); * To reuse TestProvidersComponent here, we need to remove all references to jest from mocks. */ export const StorybookProviders: React.FC = ({ children }) => { - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(); return ( diff --git a/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx b/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx index 3e98c9ce346f2..17e0efa86773c 100644 --- a/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx @@ -12,8 +12,7 @@ import React from 'react'; import type { DropResult, ResponderProvided } from '@hello-pangea/dnd'; import { DragDropContext } from '@hello-pangea/dnd'; import { Provider as ReduxStoreProvider } from 'react-redux'; -import type { Store } from 'redux'; -import { BehaviorSubject } from 'rxjs'; +import type { Dispatch, Middleware, Store } from 'redux'; import { ThemeProvider } from 'styled-components'; import type { Capabilities } from '@kbn/core/public'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; @@ -38,8 +37,8 @@ import { createSecuritySolutionStorageMock, localStorageMock } from './mock_loca import { ASSISTANT_FEATURE_ID, CASES_FEATURE_ID } from '../../../common/constants'; import { UserPrivilegesProvider } from '../components/user_privileges/user_privileges_context'; import { MockDiscoverInTimelineContext } from '../components/discover_in_timeline/mocks/discover_in_timeline_provider'; - -const state: State = mockGlobalState; +import type { AppAction } from '../store/actions'; +import type { Immutable } from '../../../common/endpoint/types'; interface Props { children?: React.ReactNode; @@ -48,19 +47,29 @@ interface Props { cellActions?: Action[]; } -export const kibanaObservable = new BehaviorSubject(createStartServicesMock()); +export const kibanaMock = createStartServicesMock(); Object.defineProperty(window, 'localStorage', { value: localStorageMock(), }); window.scrollTo = jest.fn(); const MockKibanaContextProvider = createKibanaContextProviderMock(); -const { storage } = createSecuritySolutionStorageMock(); +const { storage: storageMock } = createSecuritySolutionStorageMock(); + +export const createMockStore = ( + state: State = mockGlobalState, + pluginsReducer: typeof SUB_PLUGINS_REDUCER = SUB_PLUGINS_REDUCER, + kibana: typeof kibanaMock = kibanaMock, + storage: typeof storageMock = storageMock, + additionalMiddleware?: Array>>> +) => { + return createStore(state, pluginsReducer, kibana, storage, additionalMiddleware); +}; /** A utility for wrapping children in the providers required to run most tests */ export const TestProvidersComponent: React.FC = ({ children, - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage), + store = createMockStore(), onDragEnd = jest.fn(), cellActions = [], }) => { @@ -118,7 +127,7 @@ const UpsellingProviderMock = ({ children }: React.PropsWithChildren<{}>) => { */ const TestProvidersWithPrivilegesComponent: React.FC = ({ children, - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage), + store = createMockStore(), onDragEnd = jest.fn(), cellActions = [], }) => { diff --git a/x-pack/plugins/security_solution/public/common/store/data_table/middlware_local_storage.test.ts b/x-pack/plugins/security_solution/public/common/store/data_table/middlware_local_storage.test.ts index 251d40527e79f..0e2c9b3d12ebf 100644 --- a/x-pack/plugins/security_solution/public/common/store/data_table/middlware_local_storage.test.ts +++ b/x-pack/plugins/security_solution/public/common/store/data_table/middlware_local_storage.test.ts @@ -6,17 +6,7 @@ */ import '../../mock/match_media'; -import { - mockGlobalState, - SUB_PLUGINS_REDUCER, - defaultHeaders, - createSecuritySolutionStorageMock, - kibanaObservable, -} from '../../mock'; - -import type { State } from '..'; -import { createStore } from '..'; - +import { defaultHeaders, createSecuritySolutionStorageMock, createMockStore } from '../../mock'; import { addTableInStorage } from '../../../timelines/containers/local_storage'; import { Direction } from '../../../../common/search_strategy'; import { TableId, dataTableActions } from '@kbn/securitysolution-data-table'; @@ -37,12 +27,11 @@ jest.mock('../../../timelines/containers/local_storage'); const addTableInStorageMock = addTableInStorage as jest.Mock; describe('DataTable localStorage middleware', () => { - const state: State = mockGlobalState; const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(undefined, undefined, undefined, storage); beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(undefined, undefined, undefined, storage); }); it('should call the storage method with the most recent table state', () => { diff --git a/x-pack/plugins/security_solution/public/common/store/store.ts b/x-pack/plugins/security_solution/public/common/store/store.ts index ed1b7844dec0b..4cfa008dcbb4a 100644 --- a/x-pack/plugins/security_solution/public/common/store/store.ts +++ b/x-pack/plugins/security_solution/public/common/store/store.ts @@ -17,8 +17,6 @@ import type { import { applyMiddleware, createStore as createReduxStore } from 'redux'; import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'; import type { EnhancerOptions } from 'redux-devtools-extension'; -import type { Observable } from 'rxjs'; -import { BehaviorSubject, pluck } from 'rxjs'; import type { Storage } from '@kbn/kibana-utils-plugin/public'; import type { CoreStart } from '@kbn/core/public'; import reduceReducers from 'reduce-reducers'; @@ -41,7 +39,7 @@ import type { State } from './types'; import type { TimelineState } from '../../timelines/store/types'; import type { KibanaDataView, SourcererModel, SourcererDataView } from './sourcerer/model'; import { initDataView } from './sourcerer/model'; -import type { AppObservableLibs, StartedSubPlugins, StartPlugins } from '../../types'; +import type { StartedSubPlugins, StartPlugins } from '../../types'; import type { ExperimentalFeatures } from '../../../common/experimental_features'; import { createSourcererDataView } from '../containers/sourcerer/create_sourcerer_data_view'; import type { AnalyzerState } from '../../resolver/types'; @@ -96,8 +94,6 @@ export const createStoreFactory = async ( defaultDataView = { ...initDataView, error }; kibanaDataViews = []; } - const appLibs: AppObservableLibs = { kibana: coreStart }; - const libs$ = new BehaviorSubject(appLibs); const timelineInitialState = { timeline: { @@ -161,7 +157,7 @@ export const createStoreFactory = async ( ...subPlugins.management.store.reducer, }; - return createStore(initialState, rootReducer, libs$.pipe(pluck('kibana')), storage, [ + return createStore(initialState, rootReducer, coreStart, storage, [ ...(subPlugins.management.store.middleware ?? []), ...(subPlugins.explore.store.middleware ?? []), ...[resolverMiddlewareFactory(dataAccessLayerFactory(coreStart)) ?? []], @@ -249,7 +245,7 @@ const stateSanitizer = (state: State) => { export const createStore = ( state: State, pluginsReducer: SubPluginsInitReducer, - kibana$: Observable, + kibana: CoreStart, storage: Storage, additionalMiddleware?: Array>>> ): Store => { @@ -266,16 +262,6 @@ export const createStore = ( const composeEnhancers = composeWithDevTools(enhancerOptions); - // TODO: Once `createStore` does not use redux-observable, we will not need to pass a - // kibana observable anymore. Then we can remove this `any` cast and replace kibana$ - // with a regular kibana instance. - // I'm not doing it in this PR, as this will have an impact on literally hundreds of test files. - // A separate PR will be created to clean this up. - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const kibanaObsv = kibana$ as any; - const kibana = - 'source' in kibanaObsv ? kibanaObsv.source._value.kibana : kibanaObsv._value.kibana; - const middlewareEnhancer = applyMiddleware( ...createMiddlewares(kibana, storage), telemetryMiddleware, diff --git a/x-pack/plugins/security_solution/public/common/utils/global_query_string/index.test.tsx b/x-pack/plugins/security_solution/public/common/utils/global_query_string/index.test.tsx index 24fc87bf7bf61..2685708968c78 100644 --- a/x-pack/plugins/security_solution/public/common/utils/global_query_string/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/utils/global_query_string/index.test.tsx @@ -16,14 +16,7 @@ import { import type { GlobalUrlParam } from '../../store/global_url_param'; import { globalUrlParamActions } from '../../store/global_url_param'; import { mockHistory } from '../route/mocks'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../mock'; -import { createStore } from '../../store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../mock'; import type { LinkInfo } from '../../links'; import { SecurityPageName } from '../../../app/types'; @@ -56,18 +49,11 @@ jest.mock('../../links', () => ({ })); describe('global query string', () => { - const { storage } = createSecuritySolutionStorageMock(); - const makeStore = (globalUrlParam: GlobalUrlParam) => - createStore( - { - ...mockGlobalState, - globalUrlParam, - }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + createMockStore({ + ...mockGlobalState, + globalUrlParam, + }); const makeWrapper = (globalUrlParam?: GlobalUrlParam) => { const wrapper = ({ children }: { children: React.ReactElement }) => ( @@ -181,22 +167,17 @@ describe('global query string', () => { describe('useGlobalQueryString', () => { it('returns global query string', () => { - const store = createStore( - { - ...mockGlobalState, - globalUrlParam: { - testNumber: 123, - testObject: { testKey: 321 }, - testEmptyObject: {}, - testEmptyArray: [], - testNull: null, - testEmptyString: '', - }, + const store = createMockStore({ + ...mockGlobalState, + globalUrlParam: { + testNumber: 123, + testObject: { testKey: 321 }, + testEmptyObject: {}, + testEmptyArray: [], + testNull: null, + testEmptyString: '', }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const wrapper = ({ children }: { children: React.ReactElement }) => ( {children} ); diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/components/rule_preview/preview_histogram.test.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/components/rule_preview/preview_histogram.test.tsx index 80e98a8f288d8..7a25095242945 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/components/rule_preview/preview_histogram.test.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/components/rule_preview/preview_histogram.test.tsx @@ -13,20 +13,13 @@ import { fields } from '@kbn/data-plugin/common/mocks'; import { render } from '@testing-library/react'; import { useGlobalTime } from '../../../../common/containers/use_global_time'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../../common/mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../../../common/mock'; import { VisualizationEmbeddable } from '../../../../common/components/visualization_actions/visualization_embeddable'; import { useVisualizationResponse } from '../../../../common/components/visualization_actions/use_visualization_response'; import { PreviewHistogram } from './preview_histogram'; import { useTimelineEvents } from '../../../../common/components/events_viewer/use_timelines_events'; import { TableId } from '@kbn/securitysolution-data-table'; -import { createStore } from '../../../../common/store'; import { mockEventViewerResponse } from '../../../../common/components/events_viewer/mock'; import type { UseFieldBrowserOptionsProps } from '../../../../timelines/components/fields_browser'; import type { TransformColumnsProps } from '../../../../common/components/control_columns'; @@ -87,24 +80,17 @@ describe('PreviewHistogram', () => { }); }); - const { storage } = createSecuritySolutionStorageMock(); - - const store = createStore( - { - ...mockGlobalState, - dataTable: { - ...mockGlobalState.dataTable, - tableById: { - [TableId.rulePreview]: { - ...mockGlobalState.dataTable.tableById[TableId.test], - }, + const store = createMockStore({ + ...mockGlobalState, + dataTable: { + ...mockGlobalState.dataTable, + tableById: { + [TableId.rulePreview]: { + ...mockGlobalState.dataTable.tableById[TableId.test], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); afterEach(() => { jest.clearAllMocks(); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/alerts_grouping.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/alerts_grouping.test.tsx index a0e016754a60c..b1a838ba74598 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/alerts_grouping.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/alerts_grouping.test.tsx @@ -11,19 +11,12 @@ import type { Filter } from '@kbn/es-query'; import useResizeObserver from 'use-resize-observer/polyfilled'; import '../../../common/mock/match_media'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../common/mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../../common/mock'; import type { AlertsTableComponentProps } from './alerts_grouping'; import { GroupedAlertsTable } from './alerts_grouping'; import { TableId } from '@kbn/securitysolution-data-table'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; import type { UseFieldBrowserOptionsProps } from '../../../timelines/components/fields_browser'; -import { createStore } from '../../../common/store'; import { useKibana as mockUseKibana } from '../../../common/lib/kibana/__mocks__'; import { createTelemetryServiceMock } from '../../../common/lib/telemetry/telemetry_service.mock'; import { useQueryAlerts } from '../../containers/detection_engine/alerts/use_query'; @@ -154,22 +147,16 @@ const getMockStorageState = (groups: string[] = ['none']) => }); describe('GroupedAlertsTable', () => { - const { storage } = createSecuritySolutionStorageMock(); - let store: ReturnType; + let store = createMockStore(); beforeEach(() => { jest.clearAllMocks(); - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { options: mockOptions, activeGroups: ['kibana.alert.rule.name'] }, - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { options: mockOptions, activeGroups: ['kibana.alert.rule.name'] }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); (useSourcererDataView as jest.Mock).mockReturnValue({ ...sourcererDataView, selectedPatterns: ['myFakebeat-*'], @@ -186,9 +173,8 @@ describe('GroupedAlertsTable', () => { }); it('calls the proper initial dispatch actions for groups', () => { - store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); const { getByTestId, queryByTestId } = render( - + ); @@ -260,20 +246,15 @@ describe('GroupedAlertsTable', () => { jest .spyOn(window.localStorage, 'getItem') .mockReturnValue(getMockStorageState(['kibana.alert.rule.name', 'host.name'])); - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { - options: mockOptions, - activeGroups: ['kibana.alert.rule.name', 'host.name'], - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { + options: mockOptions, + activeGroups: ['kibana.alert.rule.name', 'host.name'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { getByTestId } = render( @@ -292,20 +273,15 @@ describe('GroupedAlertsTable', () => { jest .spyOn(window.localStorage, 'getItem') .mockReturnValue(getMockStorageState(['kibana.alert.rule.name', 'host.name', 'user.name'])); - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { - options: mockOptions, - activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { + options: mockOptions, + activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { getByTestId, getAllByTestId } = render( @@ -355,20 +331,15 @@ describe('GroupedAlertsTable', () => { jest .spyOn(window.localStorage, 'getItem') .mockReturnValue(getMockStorageState(['kibana.alert.rule.name', 'host.name', 'user.name'])); - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { - options: mockOptions, - activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { + options: mockOptions, + activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { getByTestId, rerender } = render( @@ -405,20 +376,15 @@ describe('GroupedAlertsTable', () => { }); it('resets only most inner group pagination when its parent groups open/close', () => { - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { - options: mockOptions, - activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { + options: mockOptions, + activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { getByTestId } = render( @@ -468,20 +434,15 @@ describe('GroupedAlertsTable', () => { }); it(`resets innermost level's current page when that level's page size updates`, () => { - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { - options: mockOptions, - activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { + options: mockOptions, + activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { getByTestId } = render( @@ -521,20 +482,15 @@ describe('GroupedAlertsTable', () => { }); it(`resets outermost level's current page when that level's page size updates`, () => { - store = createStore( - { - ...mockGlobalState, - groups: { - [testProps.tableId]: { - options: mockOptions, - activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], - }, + store = createMockStore({ + ...mockGlobalState, + groups: { + [testProps.tableId]: { + options: mockOptions, + activeGroups: ['kibana.alert.rule.name', 'host.name', 'user.name'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); + }); const { getByTestId, getAllByTestId } = render( diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/grouping_settings/group_take_action_items.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/grouping_settings/group_take_action_items.test.tsx index 6470c9a4abc66..5518926f4ab61 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/grouping_settings/group_take_action_items.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/grouping_settings/group_take_action_items.test.tsx @@ -5,22 +5,11 @@ * 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', () => ({ - inputsSelectors: { - globalQuery: jest.fn(), - }, - inputsModel: {}, -})); - -jest.mock('../../../../common/hooks/use_selector', () => ({ - useDeepEqualSelector: () => jest.fn(), -})); - describe('useGroupTakeActionsItems', () => { const wrapperContainer: React.FC<{ children?: React.ReactNode }> = ({ children }) => ( {children} diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_assignees_actions.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_assignees_actions.test.tsx index 52c196fa729fc..a7bde416b7ca0 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_assignees_actions.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_assignees_actions.test.tsx @@ -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'; @@ -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'; diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_tags_actions.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_tags_actions.test.tsx index 17340d8ca42e7..4e037467597c9 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_tags_actions.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_alert_tags_actions.test.tsx @@ -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'; @@ -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'; diff --git a/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_cell_actions.test.tsx b/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_cell_actions.test.tsx index 16228ec498358..c58fd2c22ec2a 100644 --- a/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_cell_actions.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_cell_actions.test.tsx @@ -5,12 +5,7 @@ * 2.0. */ -import { - createSecuritySolutionStorageMock, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../common/mock'; +import { createMockStore, mockGlobalState, TestProviders } from '../../../common/mock'; import { TableId } from '@kbn/securitysolution-data-table'; import { renderHook } from '@testing-library/react-hooks'; import { getUseCellActionsHook } from './use_cell_actions'; @@ -27,9 +22,6 @@ import type { ComponentProps, JSXElementConstructor, PropsWithChildren } from 'r 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 { BehaviorSubject } from 'rxjs'; const useCellActions = getUseCellActionsHook(TableId.test); @@ -86,17 +78,10 @@ const mockedStateWithEventRenderedView: typeof mockGlobalState = { }, }, }; -export const kibanaObservable = new BehaviorSubject(createStartServicesMock()); -const { storage } = createSecuritySolutionStorageMock(); const TestProviderWithCustomStateAndActions = withCustomPropsAndCellActions({ cellActions: compatibleActions, - store: createStore( - mockedStateWithEventRenderedView, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ), + store: createMockStore(mockedStateWithEventRenderedView), }); describe('getUseCellActionsHook', () => { diff --git a/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_persistent_controls.test.tsx b/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_persistent_controls.test.tsx index 98c2d75b625e3..9ae0ef47090fb 100644 --- a/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_persistent_controls.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_persistent_controls.test.tsx @@ -10,14 +10,7 @@ import { getPersistentControlsHook } from './use_persistent_controls'; import { TableId } from '@kbn/securitysolution-data-table'; import { renderHook } from '@testing-library/react-hooks'; import { render, fireEvent } from '@testing-library/react'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; +import { createMockStore, mockGlobalState, TestProviders } from '../../../common/mock'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; import { useDeepEqualSelector, useShallowEqualSelector } from '../../../common/hooks/use_selector'; import { useKibana as mockUseKibana } from '../../../common/lib/kibana/__mocks__'; @@ -71,9 +64,6 @@ const groups = { }; describe('usePersistentControls', () => { - const { storage } = createSecuritySolutionStorageMock(); - let store: ReturnType; - beforeEach(() => { (useDeepEqualSelector as jest.Mock).mockImplementation(() => groups[tableId]); (useShallowEqualSelector as jest.Mock).mockReturnValue({ @@ -81,15 +71,6 @@ describe('usePersistentControls', () => { showBuildBlockAlerts: false, }); jest.clearAllMocks(); - store = createStore( - { - ...mockGlobalState, - groups, - }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage - ); (useSourcererDataView as jest.Mock).mockReturnValue({ ...sourcererDataView, selectedPatterns: ['myFakebeat-*'], @@ -101,6 +82,10 @@ describe('usePersistentControls', () => { }); test('Should render the group selector component and allow the user to select a grouping field', () => { + const store = createMockStore({ + ...mockGlobalState, + groups, + }); const usePersistentControls = getPersistentControlsHook(tableId); const { result } = renderHook(() => usePersistentControls(), { wrapper: ({ children }) => {children}, diff --git a/x-pack/plugins/security_solution/public/detections/pages/alerts/alert_details_redirect.test.tsx b/x-pack/plugins/security_solution/public/detections/pages/alerts/alert_details_redirect.test.tsx index 94a96a0958725..18873d9ae3ddc 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/alerts/alert_details_redirect.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/alerts/alert_details_redirect.test.tsx @@ -8,14 +8,7 @@ import React from 'react'; import { render } from '@testing-library/react'; import { Router } from '@kbn/shared-ux-router'; import { AlertDetailsRedirect } from './alert_details_redirect'; -import { - createSecuritySolutionStorageMock, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; -import { kibanaObservable } from '@kbn/timelines-plugin/public/mock'; +import { TestProviders } from '../../../common/mock'; 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'; @@ -37,8 +30,6 @@ const testTimestamp = '2023-04-20T12:00:00.000Z'; const mockPathname = `${ALERT_DETAILS_REDIRECT_PATH}/${testAlertId}`; describe('AlertDetailsRedirect', () => { - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); afterEach(() => { mockHistory.replace.mockClear(); }); @@ -56,7 +47,7 @@ describe('AlertDetailsRedirect', () => { }, }; render( - + @@ -85,7 +76,7 @@ describe('AlertDetailsRedirect', () => { }, }; render( - + @@ -113,7 +104,7 @@ describe('AlertDetailsRedirect', () => { }, }; render( - + @@ -147,7 +138,7 @@ describe('AlertDetailsRedirect', () => { }, }; render( - + diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx index aa196b174131e..473ac70f47e28 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx @@ -9,18 +9,11 @@ import React, { useEffect } from 'react'; import { render, waitFor } from '@testing-library/react'; import { useParams } from 'react-router-dom'; import '../../../common/mock/match_media'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; +import { mockGlobalState, TestProviders, createMockStore } from '../../../common/mock'; import { DetectionEnginePage } from './detection_engine'; import { useUserData } from '../../components/user_info'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; import { mockHistory, Router } from '../../../common/mock/router'; import { mockTimelines } from '../../../common/mock/mock_timelines_plugin'; import { mockBrowserFields } from '../../../common/containers/source/mock'; @@ -168,26 +161,14 @@ jest.mock('../../../timelines/components/side_panel/hooks/use_detail_panel', () }; }); -const state: State = { - ...mockGlobalState, -}; - -const { storage } = createSecuritySolutionStorageMock(); - -const getStoreWithCustomState = (newState: State = state) => { - return createStore(newState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); -}; - -const store = getStoreWithCustomState(); - const stateWithBuildingBlockAlertsEnabled: State = { - ...state, + ...mockGlobalState, dataTable: { - ...state.dataTable, + ...mockGlobalState.dataTable, tableById: { - ...state.dataTable.tableById, + ...mockGlobalState.dataTable.tableById, [TableId.test]: { - ...state.dataTable.tableById[TableId.test], + ...mockGlobalState.dataTable.tableById[TableId.test], additionalFilters: { showOnlyThreatIndicatorAlerts: false, showBuildingBlockAlerts: true, @@ -198,13 +179,13 @@ const stateWithBuildingBlockAlertsEnabled: State = { }; const stateWithThreatIndicatorsAlertEnabled: State = { - ...state, + ...mockGlobalState, dataTable: { - ...state.dataTable, + ...mockGlobalState.dataTable, tableById: { - ...state.dataTable.tableById, + ...mockGlobalState.dataTable.tableById, [TableId.test]: { - ...state.dataTable.tableById[TableId.test], + ...mockGlobalState.dataTable.tableById[TableId.test], additionalFilters: { showOnlyThreatIndicatorAlerts: true, showBuildingBlockAlerts: false, @@ -248,7 +229,7 @@ describe('DetectionEnginePageComponent', () => { }); it('renders correctly', async () => { const { getByTestId } = render( - + @@ -261,7 +242,7 @@ describe('DetectionEnginePageComponent', () => { it('renders the chart panels', async () => { const { getByTestId } = render( - + @@ -278,7 +259,7 @@ describe('DetectionEnginePageComponent', () => { MockedFilterGroup.mockImplementationOnce(getMockedFilterGroupWithCustomFilters()); await waitFor(() => { render( - + @@ -316,7 +297,7 @@ describe('DetectionEnginePageComponent', () => { await waitFor(() => { render( - + @@ -362,7 +343,7 @@ describe('DetectionEnginePageComponent', () => { ); await waitFor(() => { render( - + @@ -405,7 +386,7 @@ describe('DetectionEnginePageComponent', () => { ); await waitFor(() => { render( - + @@ -436,7 +417,7 @@ describe('DetectionEnginePageComponent', () => { ); await waitFor(() => { render( - + diff --git a/x-pack/plugins/security_solution/public/explore/components/stat_items/stat_items.test.tsx b/x-pack/plugins/security_solution/public/explore/components/stat_items/stat_items.test.tsx index 206984859c575..dbbdab338b623 100644 --- a/x-pack/plugins/security_solution/public/explore/components/stat_items/stat_items.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/components/stat_items/stat_items.test.tsx @@ -16,14 +16,7 @@ import { BarChart } from '../../../common/components/charts/barchart'; import { AreaChart } from '../../../common/components/charts/areachart'; import { EuiHorizontalRule } from '@elastic/eui'; import { mockUpdateDateRange } from '../../network/components/kpi_network/mock'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; +import { createMockStore } from '../../../common/mock'; import { Provider as ReduxStoreProvider } from 'react-redux'; import { getMockTheme } from '../../../common/lib/kibana/kibana_react.mock'; import * as module from '../../../common/containers/query_toggle'; @@ -57,9 +50,7 @@ jest const mockSetQuerySkip = jest.fn(); describe('Stat Items Component', () => { const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } }); - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(); const testProps = { description: 'HOSTS', fields: [{ key: 'hosts', value: null, color: '#6092C0', icon: 'cross' }], diff --git a/x-pack/plugins/security_solution/public/explore/hosts/components/hosts_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/hosts/components/hosts_table/index.test.tsx index 498efb3fdd62b..866dbc95fb054 100644 --- a/x-pack/plugins/security_solution/public/explore/hosts/components/hosts_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/hosts/components/hosts_table/index.test.tsx @@ -9,16 +9,8 @@ import { shallow } from 'enzyme'; import React from 'react'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { TestProviders, createMockStore } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { hostsModel } from '../../store'; import { HostsTableType } from '../../store/model'; import { HostsTable } from '.'; @@ -57,16 +49,9 @@ jest.mock('../../../../helper_hooks', () => ({ describe('Hosts Table', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(); const mount = useMountAppended(); - beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - describe('rendering', () => { test('it renders the default Hosts table', () => { const wrapper = shallow( diff --git a/x-pack/plugins/security_solution/public/explore/hosts/pages/details/details_tabs.test.tsx b/x-pack/plugins/security_solution/public/explore/hosts/pages/details/details_tabs.test.tsx index df38f06888539..2140b6cd66375 100644 --- a/x-pack/plugins/security_solution/public/explore/hosts/pages/details/details_tabs.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/hosts/pages/details/details_tabs.test.tsx @@ -11,11 +11,9 @@ import useResizeObserver from 'use-resize-observer/polyfilled'; import '../../../../common/mock/match_media'; import { - createSecuritySolutionStorageMock, - kibanaObservable, + createMockStore, mockGlobalState, mockIndexPattern, - SUB_PLUGINS_REDUCER, TestProviders, } from '../../../../common/mock'; import { HostDetailsTabs } from './details_tabs'; @@ -24,8 +22,6 @@ import { useMountAppended } from '../../../../common/utils/use_mount_appended'; import { getHostDetailsPageFilters } from './helpers'; import { HostsType, HostsTableType } from '../../store/model'; import { mockCasesContract } from '@kbn/cases-plugin/public/mocks'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { TableId } from '@kbn/securitysolution-data-table'; jest.mock('../../../../common/lib/kibana', () => { @@ -73,21 +69,14 @@ mockUseResizeObserver.mockImplementation(() => ({})); jest.mock('../../../../common/components/visualization_actions/actions'); jest.mock('../../../../common/components/visualization_actions/lens_embeddable'); -const myState: State = mockGlobalState; -const { storage } = createSecuritySolutionStorageMock(); -const myStore = createStore( - { - ...myState, - dataTable: { - tableById: { - [TableId.hostsPageEvents]: myState.dataTable.tableById['table-test'], - }, +const myStore = createMockStore({ + ...mockGlobalState, + dataTable: { + tableById: { + [TableId.hostsPageEvents]: mockGlobalState.dataTable.tableById['table-test'], }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage -); +}); describe('body', () => { const scenariosMap = { diff --git a/x-pack/plugins/security_solution/public/explore/hosts/pages/hosts.test.tsx b/x-pack/plugins/security_solution/public/explore/hosts/pages/hosts.test.tsx index c4e542f2ea465..94ee4d6e1e28f 100644 --- a/x-pack/plugins/security_solution/public/explore/hosts/pages/hosts.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/hosts/pages/hosts.test.tsx @@ -11,17 +11,9 @@ import { Router } from '@kbn/shared-ux-router'; import type { Filter } from '@kbn/es-query'; import '../../../common/mock/match_media'; -import { - TestProviders, - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../common/mock'; +import { TestProviders, createMockStore } from '../../../common/mock'; import { TabNavigation } from '../../../common/components/navigation/tab_navigation'; import { inputsActions } from '../../../common/store/inputs'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; import { Hosts } from './hosts'; import { HostsTabs } from './hosts_tabs'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; @@ -85,9 +77,7 @@ const mockHistory = { listen: jest.fn(), }; const mockUseSourcererDataView = useSourcererDataView as jest.Mock; -const myState: State = mockGlobalState; -const { storage } = createSecuritySolutionStorageMock(); -const myStore = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const myStore = createMockStore(); describe('Hosts - rendering', () => { beforeEach(() => { diff --git a/x-pack/plugins/security_solution/public/explore/network/components/details/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/details/index.test.tsx index c910a75f42cd3..32ee04c25989c 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/details/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/details/index.test.tsx @@ -10,15 +10,7 @@ import React from 'react'; import type { ActionCreator } from 'typescript-fsa'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; +import { TestProviders } from '../../../../common/mock'; import { networkModel } from '../../store'; import { IpOverview } from '.'; @@ -28,15 +20,6 @@ import type { NarrowDateRange } from '../../../../common/components/ml/types'; import { FlowTargetSourceDest } from '../../../../../common/search_strategy'; describe('IP Overview Component', () => { - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - describe('rendering', () => { const mockProps = { anomaliesData: mockAnomalies, @@ -60,7 +43,7 @@ describe('IP Overview Component', () => { test('it renders the default IP Overview', () => { const wrapper = shallow( - + ); @@ -74,7 +57,7 @@ describe('IP Overview Component', () => { isInDetailsSidePanel: true, }; const wrapper = shallow( - + ); diff --git a/x-pack/plugins/security_solution/public/explore/network/components/kpi_network/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/kpi_network/index.test.tsx index e213f2f166977..b204b6102a036 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/kpi_network/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/kpi_network/index.test.tsx @@ -9,19 +9,11 @@ import { shallow } from 'enzyme'; import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; -import { - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { createMockStore } from '../../../../common/mock'; import '../../../../common/mock/match_media'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { NetworkKpiComponent } from '.'; describe('NetworkKpiComponent', () => { - const state: State = mockGlobalState; const props = { filterQuery: '', from: '2019-06-15T06:00:00.000Z', @@ -32,17 +24,10 @@ describe('NetworkKpiComponent', () => { to: '2019-06-18T06:00:00.000Z', }; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - describe('rendering', () => { test('it renders the default widget', () => { const wrapper = shallow( - + ); diff --git a/x-pack/plugins/security_solution/public/explore/network/components/network_dns_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/network_dns_table/index.test.tsx index 29fef52c3fd06..b8ac590a28132 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/network_dns_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/network_dns_table/index.test.tsx @@ -11,15 +11,7 @@ import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; +import { TestProviders, createMockStore } from '../../../../common/mock'; import { networkModel } from '../../store'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; @@ -30,9 +22,7 @@ jest.mock('../../../../common/lib/kibana'); describe('NetworkTopNFlow Table Component', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); const mount = useMountAppended(); const defaultProps = { @@ -49,7 +39,7 @@ describe('NetworkTopNFlow Table Component', () => { }; beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); }); describe('rendering', () => { diff --git a/x-pack/plugins/security_solution/public/explore/network/components/network_http_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/network_http_table/index.test.tsx index a65c1bf3b472f..7a45999f5d05b 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/network_http_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/network_http_table/index.test.tsx @@ -11,16 +11,8 @@ import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { TestProviders, createMockStore } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { networkModel } from '../../store'; import { NetworkHttpTable } from '.'; @@ -31,7 +23,6 @@ jest.mock('../../../../common/components/link_to'); describe('NetworkHttp Table Component', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; const defaultProps = { data: mockData.edges, fakeTotalCount: getOr(50, 'fakeTotalCount', mockData.pageInfo), @@ -45,12 +36,11 @@ describe('NetworkHttp Table Component', () => { type: networkModel.NetworkType.page, }; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); const mount = useMountAppended(); beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); }); describe('rendering', () => { diff --git a/x-pack/plugins/security_solution/public/explore/network/components/network_top_countries_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/network_top_countries_table/index.test.tsx index c169bda5696d5..d3daacedcde18 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/network_top_countries_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/network_top_countries_table/index.test.tsx @@ -12,17 +12,8 @@ import { Provider as ReduxStoreProvider } from 'react-redux'; import '../../../../common/mock/match_media'; import { FlowTargetSourceDest } from '../../../../../common/search_strategy/security_solution/network'; -import { - mockGlobalState, - mockIndexPattern, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { mockIndexPattern, TestProviders, createMockStore } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { networkModel } from '../../store'; import { NetworkTopCountriesTable } from '.'; @@ -32,7 +23,6 @@ jest.mock('../../../../common/lib/kibana'); describe('NetworkTopCountries Table Component', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; const mount = useMountAppended(); const defaultProps = { data: mockData.NetworkTopCountries.edges, @@ -53,11 +43,10 @@ describe('NetworkTopCountries Table Component', () => { type: networkModel.NetworkType.page, }; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); }); describe('rendering', () => { diff --git a/x-pack/plugins/security_solution/public/explore/network/components/network_top_n_flow_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/network_top_n_flow_table/index.test.tsx index b1f4c11ad54dc..069e03411308a 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/network_top_n_flow_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/network_top_n_flow_table/index.test.tsx @@ -11,16 +11,8 @@ import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { TestProviders, createMockStore } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { networkModel } from '../../store'; import { NetworkTopNFlowTable } from '.'; import { mockData } from './mock'; @@ -31,10 +23,7 @@ jest.mock('../../../../common/components/link_to'); describe('NetworkTopNFlow Table Component', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); const mount = useMountAppended(); const defaultProps = { data: mockData.edges, @@ -51,7 +40,7 @@ describe('NetworkTopNFlow Table Component', () => { }; beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); }); describe('rendering', () => { diff --git a/x-pack/plugins/security_solution/public/explore/network/components/tls_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/tls_table/index.test.tsx index 44112c86b23f2..0d0e77c5d4867 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/tls_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/tls_table/index.test.tsx @@ -11,16 +11,8 @@ import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { TestProviders, createMockStore } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { networkModel } from '../../store'; import { TlsTable } from '.'; import { mockTlsData } from './mock'; @@ -29,7 +21,6 @@ jest.mock('../../../../common/lib/kibana'); describe('Tls Table Component', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; const defaultProps = { data: mockTlsData.edges, fakeTotalCount: getOr(50, 'fakeTotalCount', mockTlsData.pageInfo), @@ -42,12 +33,11 @@ describe('Tls Table Component', () => { totalCount: 1, type: networkModel.NetworkType.details, }; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); const mount = useMountAppended(); beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); }); describe('Rendering', () => { diff --git a/x-pack/plugins/security_solution/public/explore/network/components/users_table/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/components/users_table/index.test.tsx index 42d1b3eaf351b..3880846a9d9ab 100644 --- a/x-pack/plugins/security_solution/public/explore/network/components/users_table/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/components/users_table/index.test.tsx @@ -11,16 +11,8 @@ import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; import '../../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { TestProviders, createMockStore } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { networkModel } from '../../store'; import { UsersTable } from '.'; @@ -31,14 +23,12 @@ jest.mock('../../../../common/lib/kibana'); describe('Users Table Component', () => { const loadPage = jest.fn(); - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(); const mount = useMountAppended(); beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(); }); const defaultProps = { diff --git a/x-pack/plugins/security_solution/public/explore/network/pages/details/index.test.tsx b/x-pack/plugins/security_solution/public/explore/network/pages/details/index.test.tsx index 5ab0674807efc..0a26a241fdb02 100644 --- a/x-pack/plugins/security_solution/public/explore/network/pages/details/index.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/pages/details/index.test.tsx @@ -11,16 +11,8 @@ import { Router, useParams } from 'react-router-dom'; import '../../../../common/mock/match_media'; import { useSourcererDataView } from '../../../../common/containers/sourcerer'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../../common/mock'; +import { TestProviders } from '../../../../common/mock'; import { useMountAppended } from '../../../../common/utils/use_mount_appended'; -import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import { NetworkDetails } from '.'; import { FlowTargetSourceDest } from '../../../../../common/search_strategy'; @@ -151,14 +143,6 @@ describe('Network Details', () => { jest.clearAllMocks(); }); - const state: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - test('it renders', () => { const ip = '123.456.78.90'; (useSourcererDataView as jest.Mock).mockReturnValue({ @@ -170,7 +154,7 @@ describe('Network Details', () => { flowTarget: FlowTargetSourceDest.source, }); const wrapper = mount( - + @@ -190,7 +174,7 @@ describe('Network Details', () => { flowTarget: FlowTargetSourceDest.source, }); const wrapper = mount( - + @@ -214,7 +198,7 @@ describe('Network Details', () => { flowTarget: FlowTargetSourceDest.source, }); const wrapper = mount( - + diff --git a/x-pack/plugins/security_solution/public/explore/network/pages/network.test.tsx b/x-pack/plugins/security_solution/public/explore/network/pages/network.test.tsx index 191377a9abb2e..ebb8f759934bb 100644 --- a/x-pack/plugins/security_solution/public/explore/network/pages/network.test.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/pages/network.test.tsx @@ -12,15 +12,7 @@ import { waitFor } from '@testing-library/react'; import '../../../common/mock/match_media'; import type { Filter } from '@kbn/es-query'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; -import { - TestProviders, - mockGlobalState, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../common/mock'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; +import { TestProviders, createMockStore } from '../../../common/mock'; import { inputsActions } from '../../../common/store/inputs'; import { Network } from './network'; @@ -228,9 +220,7 @@ describe('Network page - rendering', () => { indicesExist: true, indexPattern: { fields: [], title: 'title' }, }); - const myState: State = mockGlobalState; - const { storage } = createSecuritySolutionStorageMock(); - const myStore = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const myStore = createMockStore(); const wrapper = mount( diff --git a/x-pack/plugins/security_solution/public/explore/users/store/middleware_storage.test.ts b/x-pack/plugins/security_solution/public/explore/users/store/middleware_storage.test.ts index a38c6b7e0ea1c..8524427410f5f 100644 --- a/x-pack/plugins/security_solution/public/explore/users/store/middleware_storage.test.ts +++ b/x-pack/plugins/security_solution/public/explore/users/store/middleware_storage.test.ts @@ -5,28 +5,16 @@ * 2.0. */ -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { createStore } from '../../../common/store'; +import { createMockStore, createSecuritySolutionStorageMock } from '../../../common/mock'; import { addUserAssetTableField, removeUserAssetTableField } from './actions'; import { UserAssetTableType } from './model'; import { getUserAssetTableFromStorage } from './storage'; -import type { Store } from 'redux'; -let store: Store; const storage = createSecuritySolutionStorageMock().storage; describe('UsersAssetTable localStorage middleware', () => { - beforeEach(() => { - storage.clear(); - store = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - it('persist asset table when adding and removing fields', async () => { + const store = createMockStore(undefined, undefined, undefined, storage); const fieldName = 'test-field'; // Add field to the table diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/hooks/use_observed_host_fields.test.ts b/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/hooks/use_observed_host_fields.test.ts index ea37bf40bfeef..503e226c94d14 100644 --- a/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/hooks/use_observed_host_fields.test.ts +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/hooks/use_observed_host_fields.test.ts @@ -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', () => { diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/hooks/use_observed_user_items.test.ts b/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/hooks/use_observed_user_items.test.ts index 1c7b5557dd90a..abd771d240cae 100644 --- a/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/hooks/use_observed_user_items.test.ts +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/user_right/hooks/use_observed_user_items.test.ts @@ -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', () => { diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_disabled_module.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_disabled_module.test.tsx index a9d61960c9289..284ab6b91828b 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_disabled_module.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_disabled_module.test.tsx @@ -6,49 +6,16 @@ */ import React from 'react'; -import { Provider } from 'react-redux'; -import { cloneDeep } from 'lodash/fp'; import { render, screen } from '@testing-library/react'; -import { I18nProvider } from '@kbn/i18n-react'; import { CtiDisabledModule } from './cti_disabled_module'; -import { ThemeProvider } from 'styled-components'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { mockTheme } from './mock'; -import { createKibanaContextProviderMock } from '../../../common/lib/kibana/kibana_react.mock'; - -const MockKibanaContextProvider = createKibanaContextProviderMock(); - -jest.mock('../../../common/lib/kibana'); +import { TestProviders } from '../../../common/mock'; describe('CtiDisabledModule', () => { - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - const myState = cloneDeep(state); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - it('renders splitPanel with "danger" variant', () => { render( - - - - - - - - - + + + ); expect(screen.getByTestId('cti-dashboard-links')).toBeInTheDocument(); diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_enabled_module.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_enabled_module.test.tsx index b31d21b070130..d497043bf20a6 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_enabled_module.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/cti_enabled_module.test.tsx @@ -6,28 +6,12 @@ */ import React from 'react'; -import { Provider } from 'react-redux'; -import { cloneDeep } from 'lodash/fp'; import { render, screen } from '@testing-library/react'; -import { I18nProvider } from '@kbn/i18n-react'; import { CtiEnabledModule } from './cti_enabled_module'; -import { ThemeProvider } from 'styled-components'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { mockTheme, mockProps, mockTiDataSources, mockCtiLinksResponse } from './mock'; +import { TestProviders } from '../../../common/mock'; +import { mockProps, mockTiDataSources, mockCtiLinksResponse } from './mock'; import { useCtiDashboardLinks } from '../../containers/overview_cti_links'; import { useTiDataSources } from '../../containers/overview_cti_links/use_ti_data_sources'; -import { createKibanaContextProviderMock } from '../../../common/lib/kibana/kibana_react.mock'; - -const MockKibanaContextProvider = createKibanaContextProviderMock(); - -jest.mock('../../../common/lib/kibana'); jest.mock('../../containers/overview_cti_links/use_ti_data_sources'); const useTiDataSourcesMock = useTiDataSources as jest.Mock; @@ -38,27 +22,11 @@ const useCtiDashboardLinksMock = useCtiDashboardLinks as jest.Mock; useCtiDashboardLinksMock.mockReturnValue(mockCtiLinksResponse); describe('CtiEnabledModule', () => { - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - const myState = cloneDeep(state); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - it('renders CtiWithEvents when there are events', () => { render( - - - - - - - - - + + + ); expect(screen.getByText('Showing: 5 indicators')).toBeInTheDocument(); diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/index.test.tsx index bab60632ab8f9..5af7dea180904 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_cti_links/index.test.tsx @@ -6,28 +6,13 @@ */ import React from 'react'; -import { Provider } from 'react-redux'; -import { cloneDeep } from 'lodash/fp'; import { mount } from 'enzyme'; -import { I18nProvider } from '@kbn/i18n-react'; import { ThreatIntelLinkPanel } from '.'; -import { ThemeProvider } from 'styled-components'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; -import { mockTheme, mockProps, mockTiDataSources, mockCtiLinksResponse } from './mock'; + +import { TestProviders } from '../../../common/mock'; +import { mockProps, mockTiDataSources, mockCtiLinksResponse } from './mock'; import { useTiDataSources } from '../../containers/overview_cti_links/use_ti_data_sources'; import { useCtiDashboardLinks } from '../../containers/overview_cti_links'; -import { createKibanaContextProviderMock } from '../../../common/lib/kibana/kibana_react.mock'; - -const MockKibanaContextProvider = createKibanaContextProviderMock(); - -jest.mock('../../../common/lib/kibana'); jest.mock('../../containers/overview_cti_links/use_ti_data_sources'); const useTiDataSourcesMock = useTiDataSources as jest.Mock; @@ -38,27 +23,11 @@ const useCtiDashboardLinksMock = useCtiDashboardLinks as jest.Mock; useCtiDashboardLinksMock.mockReturnValue(mockCtiLinksResponse); describe('ThreatIntelLinkPanel', () => { - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - - beforeEach(() => { - const myState = cloneDeep(state); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - }); - it('renders CtiEnabledModule when Threat Intel module is enabled', () => { const wrapper = mount( - - - - - - - - - + + + ); expect(wrapper.find('[data-test-subj="cti-enabled-module"]').length).toEqual(1); @@ -68,15 +37,9 @@ describe('ThreatIntelLinkPanel', () => { it('renders CtiDisabledModule when Threat Intel module is disabled', () => { const wrapper = mount( - - - - - - - - - + + + ); expect(wrapper.find('[data-test-subj="cti-disabled-module"]').length).toEqual(1); diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx index c62edc45fb425..6ae38f6b561bf 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx @@ -5,27 +5,17 @@ * 2.0. */ -import { cloneDeep } from 'lodash/fp'; import { mount } from 'enzyme'; import React from 'react'; import '../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../common/mock'; +import { TestProviders } from '../../../common/mock'; import { OverviewHost } from '.'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; import { useHostOverview } from '../../containers/overview_host'; import { useQueryToggle } from '../../../common/containers/query_toggle'; import { render } from '@testing-library/react'; -jest.mock('../../../common/lib/kibana'); jest.mock('../../../common/components/link_to'); jest.mock('../../../common/containers/query_toggle'); @@ -64,22 +54,16 @@ const useHostOverviewMock = useHostOverview as jest.Mock; const mockUseQueryToggle = useQueryToggle as jest.Mock; describe('OverviewHost', () => { - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - beforeEach(() => { jest.clearAllMocks(); mockUseQueryToggle.mockReturnValue({ toggleStatus: true, setToggleStatus: jest.fn() }); - const myState = cloneDeep(state); + useHostOverviewMock.mockReturnValue([false, MOCKED_RESPONSE]); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); }); test('it renders the expected widget title', () => { const wrapper = mount( - + ); @@ -92,7 +76,7 @@ describe('OverviewHost', () => { test('it renders an empty subtitle while loading', () => { useHostOverviewMock.mockReturnValueOnce([true, { overviewHost: {} }]); const wrapper = mount( - + ); @@ -102,7 +86,7 @@ describe('OverviewHost', () => { test('it renders the expected event count in the subtitle after loading events', async () => { const wrapper = mount( - + ); diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx index 4d39760a05f20..158063f2207fe 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx @@ -5,21 +5,12 @@ * 2.0. */ -import { cloneDeep } from 'lodash/fp'; import { mount } from 'enzyme'; import React from 'react'; import '../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - createSecuritySolutionStorageMock, - kibanaObservable, -} from '../../../common/mock'; +import { TestProviders } from '../../../common/mock'; import { OverviewNetwork } from '.'; -import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; import { useNetworkOverview } from '../../containers/overview_network'; import { SecurityPageName } from '../../../app/types'; import { useQueryToggle } from '../../../common/containers/query_toggle'; @@ -83,22 +74,15 @@ const useNetworkOverviewMock = useNetworkOverview as jest.Mock; const mockUseQueryToggle = useQueryToggle as jest.Mock; describe('OverviewNetwork', () => { - const state: State = mockGlobalState; - - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); - beforeEach(() => { jest.clearAllMocks(); useNetworkOverviewMock.mockReturnValue([false, MOCKED_RESPONSE]); mockUseQueryToggle.mockReturnValue({ toggleStatus: true, setToggleStatus: jest.fn() }); - const myState = cloneDeep(state); - store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); }); test('it renders the expected widget title', () => { const wrapper = mount( - + ); @@ -111,7 +95,7 @@ describe('OverviewNetwork', () => { test('it renders an empty subtitle while loading', () => { useNetworkOverviewMock.mockReturnValueOnce([true, { overviewNetwork: {} }]); const wrapper = mount( - + ); @@ -121,7 +105,7 @@ describe('OverviewNetwork', () => { test('it renders the expected event count in the subtitle after loading events', async () => { const wrapper = mount( - + ); @@ -133,7 +117,7 @@ describe('OverviewNetwork', () => { it('it renders View Network', () => { const wrapper = mount( - + ); @@ -143,7 +127,7 @@ describe('OverviewNetwork', () => { it('when click on View Network we call navigateToApp to make sure to navigate to right page', () => { const wrapper = mount( - + ); diff --git a/x-pack/plugins/security_solution/public/resolver/test_utilities/simulator/index.tsx b/x-pack/plugins/security_solution/public/resolver/test_utilities/simulator/index.tsx index 8db99830fbfde..f40ea2ad5a6a1 100644 --- a/x-pack/plugins/security_solution/public/resolver/test_utilities/simulator/index.tsx +++ b/x-pack/plugins/security_solution/public/resolver/test_utilities/simulator/index.tsx @@ -12,7 +12,6 @@ import { mount } from 'enzyme'; import type { History as HistoryPackageHistoryInterface } from 'history'; import { createMemoryHistory } from 'history'; import { coreMock } from '@kbn/core/public/mocks'; -import { createStore } from '../../../common/store/store'; import { spyMiddlewareFactory } from '../spy_middleware_factory'; import { resolverMiddlewareFactory } from '../../store/middleware'; import { MockResolver } from './mock_resolver'; @@ -21,12 +20,7 @@ import { sideEffectSimulatorFactory } from '../../view/side_effect_simulator_fac import { uiSetting } from '../../mocks/ui_setting'; import { EMPTY_RESOLVER } from '../../store/helpers'; import type { State } from '../../../common/store/types'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, -} from '../../../common/mock'; +import { createMockStore, mockGlobalState } from '../../../common/mock'; import { createResolver } from '../../store/actions'; /** * Test a Resolver instance using jest, enzyme, and a mock data layer. @@ -112,17 +106,16 @@ export class Simulator { this.spyMiddleware = spyMiddlewareFactory(); // Create a redux store w/ the top level Resolver reducer and the enhancer that includes the Resolver middleware and the `spyMiddleware` - const { storage } = createSecuritySolutionStorageMock(); - this.store = createStore( + this.store = createMockStore( { ...mockGlobalState, analyzer: { [resolverComponentInstanceID]: EMPTY_RESOLVER, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage, + undefined, + undefined, + undefined, [resolverMiddlewareFactory(dataAccessLayer), this.spyMiddleware.middleware] ); diff --git a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx index 22bae6d134494..e381b01c1f0d6 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.test.tsx @@ -14,16 +14,13 @@ import { useTimelineFullScreen, } from '../../../common/containers/use_full_screen'; import { - createSecuritySolutionStorageMock, - kibanaObservable, + createMockStore, mockGlobalState, mockIndexNames, - SUB_PLUGINS_REDUCER, TestProviders, } from '../../../common/mock'; import { TimelineId } from '../../../../common/types/timeline'; import { GraphOverlay } from '.'; -import { createStore } from '../../../common/store'; import { useStateSyncingActions } from '../../../resolver/view/use_state_syncing_actions'; import { SourcererScopeName } from '../../../common/store/sourcerer/model'; import { TableId } from '@kbn/securitysolution-data-table'; @@ -73,7 +70,6 @@ jest.mock('react-redux', () => { }); describe('GraphOverlay', () => { - const { storage } = createSecuritySolutionStorageMock(); beforeEach(() => { jest.clearAllMocks(); (useGlobalFullScreen as jest.Mock).mockReturnValue({ @@ -121,23 +117,18 @@ describe('GraphOverlay', () => { test('it gets index pattern from default data view', () => { render( } Navigation={
} scopeId={TableId.test} /> @@ -190,37 +181,32 @@ describe('GraphOverlay', () => { const mockedDefaultDataViewPattern = 'default-dataview-pattern'; render( } Navigation={
} scopeId={timelineId} /> @@ -244,27 +230,22 @@ describe('GraphOverlay', () => { const wrapper = render( } @@ -289,23 +270,18 @@ describe('GraphOverlay', () => { const wrapper = render( } Navigation={
} scopeId={timelineId} /> diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/side_panel/index.test.tsx index 5e62b7e03bac3..a79e5283968a3 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/index.test.tsx @@ -9,15 +9,8 @@ import { mount } from 'enzyme'; import React from 'react'; import '../../../common/mock/match_media'; -import { - mockGlobalState, - TestProviders, - SUB_PLUGINS_REDUCER, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../../common/mock'; +import { mockGlobalState, TestProviders, createMockStore } from '../../../common/mock'; import type { State } from '../../../common/store'; -import { createStore } from '../../../common/store'; import { DetailsPanel } from '.'; import { TimelineId, TimelineTabs } from '../../../../common/types/timeline'; import { FlowTargetSourceDest } from '../../../../common/search_strategy/security_solution/network'; @@ -63,8 +56,7 @@ describe('Details Panel Component', () => { }, }; - const { storage } = createSecuritySolutionStorageMock(); - let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + let store = createMockStore(state); const dataLessExpandedDetail = { [TimelineTabs.query]: { @@ -131,7 +123,7 @@ describe('Details Panel Component', () => { hasAssistantPrivilege: false, isAssistantEnabled: true, }); - store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(state); }); test('it should not render the DetailsPanel if no expanded detail has been set in the reducer', () => { @@ -180,7 +172,7 @@ describe('Details Panel Component', () => { }; mockState.timeline.timelineById[TimelineId.active].expandedDetail = eventExpandedDetail; mockState.timeline.timelineById[TimelineId.test].expandedDetail = eventExpandedDetail; - store = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(mockState); mockUseSearchStrategy.mockReturnValue({ loading: true, @@ -244,7 +236,7 @@ describe('Details Panel Component', () => { }; newState.timeline.timelineById[TimelineId.active].activeTab = TimelineTabs.query; newState.timeline.timelineById[TimelineId.active].expandedDetail = eventExpandedDetail; - store = createStore(newState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(newState); const wrapper = mount( @@ -270,7 +262,7 @@ describe('Details Panel Component', () => { mockState.timeline.timelineById[TimelineId.active].expandedDetail = eventPinnedExpandedDetail; mockState.timeline.timelineById[TimelineId.test].expandedDetail = eventPinnedExpandedDetail; mockState.timeline.timelineById[TimelineId.test].activeTab = TimelineTabs.pinned; - store = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(mockState); }); test('it should have the attributes isDraggable to be false when timelineId !== "active" and activeTab === "pinned"', () => { @@ -324,7 +316,7 @@ describe('Details Panel Component', () => { }; mockState.timeline.timelineById[TimelineId.test].expandedDetail = hostExpandedDetail; mockState.timeline.timelineById[TimelineId.active].expandedDetail = hostExpandedDetail; - store = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(mockState); }); afterEach(() => { @@ -365,7 +357,7 @@ describe('Details Panel Component', () => { }; mockState.timeline.timelineById[TimelineId.test].expandedDetail = networkExpandedDetail; mockState.timeline.timelineById[TimelineId.active].expandedDetail = networkExpandedDetail; - store = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + store = createMockStore(mockState); }); afterEach(() => { diff --git a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user_items.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user_items.test.tsx index b44ad190a81f3..be40b936c03ce 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user_items.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/side_panel/new_user_detail/hooks/use_managed_user_items.test.tsx @@ -6,18 +6,11 @@ */ import { renderHook } from '@testing-library/react-hooks'; -import { - createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, -} from '../../../../../common/mock'; +import { mockGlobalState, TestProviders, createMockStore } from '../../../../../common/mock'; import { useManagedUserItems } from './use_managed_user_items'; import { mockEntraUserFields, mockOktaUserFields } from '../__mocks__'; import { UserAssetTableType } from '../../../../../explore/users/store/model'; import React from 'react'; -import { createStore } from '../../../../../common/store'; const mockState = { ...mockGlobalState, @@ -37,8 +30,7 @@ const mockState = { }, }; -const { storage } = createSecuritySolutionStorageMock(); -const mockStore = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); +const mockStore = createMockStore(mockState); const TestWrapper = ({ children }: { children: React.ReactNode }) => ( {children} diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/index.test.tsx index 2cd9587a63de5..6c4f280c6fd46 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/index.test.tsx @@ -6,7 +6,6 @@ */ import React from 'react'; -import type { Store } from 'redux'; import { mount } from 'enzyme'; import { waitFor } from '@testing-library/react'; @@ -16,14 +15,12 @@ import '../../../../common/mock/match_media'; import { mockBrowserFields } from '../../../../common/containers/source/mock'; import { Direction } from '../../../../../common/search_strategy'; import { - createSecuritySolutionStorageMock, defaultHeaders, - kibanaObservable, mockGlobalState, mockTimelineData, - SUB_PLUGINS_REDUCER, + createMockStore, + TestProviders, } from '../../../../common/mock'; -import { TestProviders } from '../../../../common/mock/test_providers'; import { useAppToasts } from '../../../../common/hooks/use_app_toasts'; import { useAppToastsMock } from '../../../../common/hooks/use_app_toasts.mock'; @@ -35,7 +32,6 @@ import { timelineActions } from '../../../store'; import { TimelineId, TimelineTabs } from '../../../../../common/types/timeline'; import { defaultRowRenderers } from './renderers'; import type { State } from '../../../../common/store'; -import { createStore } from '../../../../common/store'; import type { UseFieldBrowserOptionsProps } from '../../fields_browser'; import type { DraggableProvided, @@ -214,7 +210,10 @@ jest.mock('@hello-pangea/dnd', () => ({ })); describe('Body', () => { - const getWrapper = async (childrenComponent: JSX.Element, store?: { store: Store }) => { + const getWrapper = async ( + childrenComponent: JSX.Element, + store?: { store: ReturnType } + ) => { const wrapper = mount(childrenComponent, { wrappingComponent: TestProviders, wrappingComponentProps: store ?? {}, @@ -301,7 +300,6 @@ describe('Body', () => { expect(wrapper.find('[data-test-subj="events"]').first().exists()).toEqual(true); }); test('it renders a tooltip for timestamp', async () => { - const { storage } = createSecuritySolutionStorageMock(); const headersJustTimestamp = defaultHeaders.filter((h) => h.id === '@timestamp'); const state: State = { ...mockGlobalState, @@ -318,7 +316,7 @@ describe('Body', () => { }, }; - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); const wrapper = await getWrapper(, { store }); headersJustTimestamp.forEach(() => { @@ -378,7 +376,6 @@ describe('Body', () => { }); test('Add two notes to an event', async () => { - const { storage } = createSecuritySolutionStorageMock(); const state: State = { ...mockGlobalState, timeline: { @@ -394,7 +391,7 @@ describe('Body', () => { }, }; - const store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); + const store = createMockStore(state); const Proxy = (proxyProps: Props) => ; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/reason_column_renderer.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/reason_column_renderer.test.tsx index d9c30f312a859..6828fa020fff6 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/reason_column_renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/reason_column_renderer.test.tsx @@ -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'; @@ -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'); diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/index.test.tsx index 7928a93dc4885..cfe749a69a4b3 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/index.test.tsx @@ -14,12 +14,10 @@ import '../../../common/mock/match_media'; import { mockBrowserFields } from '../../../common/containers/source/mock'; import { TimelineId } from '../../../../common/types/timeline'; import { - createSecuritySolutionStorageMock, - kibanaObservable, + createMockStore, mockGlobalState, mockIndexNames, mockIndexPattern, - SUB_PLUGINS_REDUCER, TestProviders, } from '../../../common/mock'; @@ -30,7 +28,6 @@ import { DefaultCellRenderer } from './cell_rendering/default_cell_renderer'; import { SELECTOR_TIMELINE_GLOBAL_CONTAINER } from './styles'; import { defaultRowRenderers } from './body/renderers'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; -import { createStore } from '../../../common/store'; import { SourcererScopeName } from '../../../common/store/sourcerer/model'; jest.mock('../../containers', () => ({ @@ -99,7 +96,6 @@ describe('StatefulTimeline', () => { rowRenderers: defaultRowRenderers, timelineId: TimelineId.test, }; - const { storage } = createSecuritySolutionStorageMock(); beforeEach(() => { jest.clearAllMocks(); @@ -155,26 +151,21 @@ describe('StatefulTimeline', () => { test('sourcerer data view updates and timeline already matches the data view, no updates', () => { mount( @@ -185,33 +176,28 @@ describe('StatefulTimeline', () => { test('sourcerer data view updates, update timeline data view', () => { mount( diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/tour/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/tour/index.test.tsx index 8f902d47d6ed1..c5ae53a66032b 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/tour/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/tour/index.test.tsx @@ -12,15 +12,12 @@ import { TIMELINE_TOUR_CONFIG_ANCHORS } from './step_config'; import { useIsElementMounted } from '../../../../detection_engine/rule_management_ui/components/rules_table/rules_table/guided_onboarding/use_is_element_mounted'; import { render, screen, waitFor, fireEvent } from '@testing-library/react'; import { + createMockStore, createSecuritySolutionStorageMock, - kibanaObservable, - mockGlobalState, - SUB_PLUGINS_REDUCER, TestProviders, } from '../../../../common/mock'; import { TimelineTabs } from '../../../../../common/types'; import { TimelineType } from '../../../../../common/api/timeline'; -import { createStore } from '../../../../common/store'; import { useKibana as mockUseKibana } from '../../../../common/lib/kibana/__mocks__'; import { useKibana } from '../../../../common/lib/kibana'; @@ -33,7 +30,7 @@ const mockedUseKibana = mockUseKibana(); const switchTabMock = jest.fn(); const { storage: storageMock } = createSecuritySolutionStorageMock(); -const mockStore = createStore(mockGlobalState, SUB_PLUGINS_REDUCER, kibanaObservable, storageMock); +const mockStore = createMockStore(undefined, undefined, undefined, storageMock); const TestComponent = (props: Partial = {}) => { return ( diff --git a/x-pack/plugins/security_solution/public/timelines/containers/use_timeline_data_filters.test.tsx b/x-pack/plugins/security_solution/public/timelines/containers/use_timeline_data_filters.test.tsx index 7a0dad41789f5..4926f69875be2 100644 --- a/x-pack/plugins/security_solution/public/timelines/containers/use_timeline_data_filters.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/containers/use_timeline_data_filters.test.tsx @@ -6,15 +6,8 @@ */ import { renderHook } from '@testing-library/react-hooks'; -import { - mockGlobalState, - SUB_PLUGINS_REDUCER, - TestProviders, - kibanaObservable, - createSecuritySolutionStorageMock, -} from '../../common/mock'; +import { mockGlobalState, TestProviders, createMockStore } from '../../common/mock'; import { useTimelineDataFilters } from './use_timeline_data_filters'; -import { createStore } from '../../common/store'; import React from 'react'; import { SourcererScopeName } from '../../common/store/sourcerer/model'; @@ -27,29 +20,23 @@ const defaultDataViewPattern = 'test-dataview-patterns'; const timelinePattern = 'test-timeline-patterns'; const alertsPagePatterns = '.siem-signals-spacename'; const pathname = '/alerts'; -const { storage } = createSecuritySolutionStorageMock(); -const store = createStore( - { - ...mockGlobalState, - sourcerer: { - ...mockGlobalState.sourcerer, - defaultDataView: { - ...mockGlobalState.sourcerer.defaultDataView, - patternList: [defaultDataViewPattern], - }, - sourcererScopes: { - ...mockGlobalState.sourcerer.sourcererScopes, - [SourcererScopeName.timeline]: { - ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], - selectedPatterns: [timelinePattern], - }, +const store = createMockStore({ + ...mockGlobalState, + sourcerer: { + ...mockGlobalState.sourcerer, + defaultDataView: { + ...mockGlobalState.sourcerer.defaultDataView, + patternList: [defaultDataViewPattern], + }, + sourcererScopes: { + ...mockGlobalState.sourcerer.sourcererScopes, + [SourcererScopeName.timeline]: { + ...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline], + selectedPatterns: [timelinePattern], }, }, }, - SUB_PLUGINS_REDUCER, - kibanaObservable, - storage -); +}); const wrapper = ({ children }: { children: React.ReactNode }) => ( {children} diff --git a/x-pack/plugins/security_solution/public/types.ts b/x-pack/plugins/security_solution/public/types.ts index bcfeba0b6d985..38fe7593ccaca 100644 --- a/x-pack/plugins/security_solution/public/types.ts +++ b/x-pack/plugins/security_solution/public/types.ts @@ -193,10 +193,6 @@ export interface PluginStart { setOnboardingPageSettings: OnboardingPageService; } -export interface AppObservableLibs { - kibana: CoreStart; -} - export type InspectResponse = Inspect & { response: string[] }; export const CASES_SUB_PLUGIN_KEY = 'cases'; diff --git a/x-pack/plugins/timelines/public/mock/kibana_react.mock.ts b/x-pack/plugins/timelines/public/mock/kibana_react.mock.ts index 7bd449a622b68..1315713dab80a 100644 --- a/x-pack/plugins/timelines/public/mock/kibana_react.mock.ts +++ b/x-pack/plugins/timelines/public/mock/kibana_react.mock.ts @@ -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, @@ -37,15 +35,6 @@ 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(); @@ -53,6 +42,3 @@ export const createKibanaContextProviderMock = () => { return ({ children }: { children: React.ReactNode }) => React.createElement(KibanaContextProvider, { services }, children); }; - -export const getMockTheme = (partialTheme: RecursivePartial): EuiTheme => - partialTheme as EuiTheme; diff --git a/x-pack/plugins/timelines/public/mock/test_providers.tsx b/x-pack/plugins/timelines/public/mock/test_providers.tsx index 08085a7fbf333..0a6bf3711f6b2 100644 --- a/x-pack/plugins/timelines/public/mock/test_providers.tsx +++ b/x-pack/plugins/timelines/public/mock/test_providers.tsx @@ -11,11 +11,10 @@ import { I18nProvider } from '@kbn/i18n-react'; import React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; import { Store } from 'redux'; -import { BehaviorSubject } from 'rxjs'; 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 { @@ -23,8 +22,6 @@ interface Props { store?: Store; } -export const kibanaObservable = new BehaviorSubject(createStartServicesMock()); - interface State { timelineById: Record; }