diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index d544d3c800bbe..135b6121d1dd5 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -19,7 +19,7 @@ import { Plugin, IndexPatternsContract } from '.'; import { fieldFormatsServiceMock } from './field_formats/mocks'; -import { searchSetupMock, searchStartMock } from './search/mocks'; +import { searchServiceMock } from './search/mocks'; import { queryServiceMock } from './query/mocks'; import { AutocompleteStart, AutocompleteSetup } from './autocomplete'; @@ -41,7 +41,7 @@ const createSetupContract = (): Setup => { const querySetupMock = queryServiceMock.createSetupContract(); return { autocomplete: automcompleteSetupMock, - search: searchSetupMock, + search: searchServiceMock.createSetupContract(), fieldFormats: fieldFormatsServiceMock.createSetupContract(), query: querySetupMock, }; @@ -55,7 +55,7 @@ const createStartContract = (): Start => { createFiltersFromRangeSelectAction: jest.fn(), }, autocomplete: autocompleteStartMock, - search: searchStartMock, + search: searchServiceMock.createStartContract(), fieldFormats: fieldFormatsServiceMock.createStartContract(), query: queryStartMock, ui: { diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts index 436b522744622..4148055c1eb58 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts +++ b/src/plugins/data/public/search/legacy/default_search_strategy.test.ts @@ -19,7 +19,7 @@ import { IUiSettingsClient } from 'kibana/public'; import { defaultSearchStrategy } from './default_search_strategy'; -import { searchStartMock } from '../mocks'; +import { searchServiceMock } from '../mocks'; import { SearchStrategySearchParams } from './types'; import { UI_SETTINGS } from '../../../common'; @@ -51,7 +51,7 @@ describe('defaultSearchStrategy', function () { searchMockResponse.abort.mockClear(); searchMock.mockClear(); - const searchService = searchStartMock; + const searchService = searchServiceMock.createStartContract(); searchService.aggs.calculateAutoTimeExpression = jest.fn().mockReturnValue('1d'); searchService.__LEGACY.esClient.search = searchMock; searchService.__LEGACY.esClient.msearch = msearchMock; diff --git a/src/plugins/data/public/search/mocks.ts b/src/plugins/data/public/search/mocks.ts index fcdbeb515423d..45f4416859640 100644 --- a/src/plugins/data/public/search/mocks.ts +++ b/src/plugins/data/public/search/mocks.ts @@ -23,23 +23,32 @@ import { searchSourceMock, createSearchSourceMock } from './search_source/mocks' export * from './search_source/mocks'; -const searchSetupMock: jest.Mocked = { - aggs: searchAggsSetupMock(), - registerSearchStrategy: jest.fn(), -}; +function createSetupContract(): jest.Mocked { + return { + aggs: searchAggsSetupMock(), + registerSearchStrategy: jest.fn(), + }; +} -const searchStartMock: jest.Mocked = { - aggs: searchAggsStartMock(), - setInterceptor: jest.fn(), - getSearchStrategy: jest.fn(), - search: jest.fn(), - searchSource: searchSourceMock, - __LEGACY: { - esClient: { - search: jest.fn(), - msearch: jest.fn(), +function createStartContract(): jest.Mocked { + return { + aggs: searchAggsStartMock(), + setInterceptor: jest.fn(), + getSearchStrategy: jest.fn(), + search: jest.fn(), + searchSource: searchSourceMock, + __LEGACY: { + esClient: { + search: jest.fn(), + msearch: jest.fn(), + }, }, - }, + }; +} + +export const searchServiceMock = { + createSetupContract, + createStartContract, }; -export { searchSetupMock, searchStartMock, createSearchSourceMock }; +export { createSearchSourceMock }; diff --git a/src/plugins/vis_type_table/public/table_vis_controller.test.ts b/src/plugins/vis_type_table/public/table_vis_controller.test.ts index 4607324ca150c..e7d7f6726b0cd 100644 --- a/src/plugins/vis_type_table/public/table_vis_controller.test.ts +++ b/src/plugins/vis_type_table/public/table_vis_controller.test.ts @@ -36,9 +36,9 @@ import { coreMock } from '../../../core/public/mocks'; import { IAggConfig, search } from '../../data/public'; // TODO: remove linting disable // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { searchStartMock } from '../../data/public/search/mocks'; +import { searchServiceMock } from '../../data/public/search/mocks'; -const { createAggConfigs } = searchStartMock.aggs; +const { createAggConfigs } = searchServiceMock.createStartContract().aggs; const { tabifyAggResponse } = search; diff --git a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.test.ts b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.test.ts index 3013f9966f068..6b8820b92ba84 100644 --- a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.test.ts +++ b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.test.ts @@ -25,6 +25,7 @@ describe('Async search strategy', () => { mockCoreSetup = coreMock.createSetup(); mockDataStart = dataPluginMock.createStartContract(); (mockDataStart.search.getSearchStrategy as jest.Mock).mockReturnValue({ search: mockSearch }); + mockCoreSetup.getStartServices.mockResolvedValue([ undefined as any, { data: mockDataStart }, @@ -92,6 +93,7 @@ describe('Async search strategy', () => { await asyncSearch.search(mockRequest, mockOptions).toPromise(); + expect(mockDataStart.search.getSearchStrategy).toBeCalledTimes(1); expect(mockSearch).toBeCalledTimes(2); expect(mockSearch.mock.calls[0][0]).toEqual(mockRequest); expect(mockSearch.mock.calls[1][0]).toEqual({ id: 1, serverStrategy: 'foo' }); diff --git a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts index 7de4dd28ad3d7..49b27bba33a60 100644 --- a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts @@ -70,7 +70,7 @@ export function asyncSearchStrategyProvider( return timer(pollInterval).pipe( // Send future requests using just the ID from the response mergeMap(() => { - return search({ id, serverStrategy }, options); + return syncSearch.search({ id, serverStrategy }, options); }) ); }),