diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts b/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts index 58edb1aae80e2..b9f1191da8af7 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts @@ -28,6 +28,14 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => { ]); }; + const setReloadIndicesResponse = (response: HttpResponse = []) => { + server.respondWith('POST', `${API_BASE_PATH}/indices/reload`, [ + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify(response), + ]); + }; + const setLoadDataStreamsResponse = (response: HttpResponse = []) => { server.respondWith('GET', `${API_BASE_PATH}/data_streams`, [ 200, @@ -118,6 +126,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => { return { setLoadTemplatesResponse, setLoadIndicesResponse, + setReloadIndicesResponse, setLoadDataStreamsResponse, setLoadDataStreamResponse, setDeleteDataStreamResponse, diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts index 900f7ddbf084b..2576b5f92b7b2 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts @@ -47,9 +47,12 @@ export const setup = async (overridingDependencies: any = {}): Promise { - const { find } = testBed; - const contextMenu = find('indexContextMenu'); - contextMenu.find(`button[data-test-subj="${optionDataTestSubject}"]`).simulate('click'); + const { find, component } = testBed; + + await act(async () => { + find(`indexContextMenu.${optionDataTestSubject}`).simulate('click'); + }); + component.update(); }; const clickIncludeHiddenIndicesToggle = () => { @@ -57,9 +60,13 @@ export const setup = async (overridingDependencies: any = {}): Promise { - const { find } = testBed; - find('indexActionsContextMenuButton').simulate('click'); + const clickManageContextMenuButton = async () => { + const { find, component } = testBed; + + await act(async () => { + find('indexActionsContextMenuButton').simulate('click'); + }); + component.update(); }; const getIncludeHiddenIndicesToggleStatus = () => { diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts index e23c1a59eb135..f95ea373d58b4 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts @@ -10,7 +10,7 @@ import { act } from 'react-dom/test-utils'; import { API_BASE_PATH } from '../../../common/constants'; import { setupEnvironment, nextTick } from '../helpers'; import { IndicesTestBed, setup } from './indices_tab.helpers'; -import { createDataStreamPayload } from './data_streams_tab.helpers'; +import { createDataStreamPayload, createNonDataStreamIndex } from './data_streams_tab.helpers'; /** * The below import is required to avoid a console error warn from the "brace" package @@ -23,9 +23,14 @@ import { createMemoryHistory } from 'history'; stubWebWorker(); // unhandled promise rejection https://github.com/elastic/kibana/issues/112699 -describe.skip('', () => { - const { server, httpRequestsMockHelpers } = setupEnvironment(); +describe('', () => { let testBed: IndicesTestBed; + let server: ReturnType['server']; + let httpRequestsMockHelpers: ReturnType['httpRequestsMockHelpers']; + + beforeEach(() => { + ({ server, httpRequestsMockHelpers } = setupEnvironment()); + }); afterAll(() => { server.restore(); @@ -108,19 +113,9 @@ describe.skip('', () => { describe('index detail panel with % character in index name', () => { const indexName = 'test%'; + beforeEach(async () => { - const index = { - health: 'green', - status: 'open', - primary: 1, - replica: 1, - documents: 10000, - documents_deleted: 100, - size: '156kb', - primary_size: '156kb', - name: indexName, - }; - httpRequestsMockHelpers.setLoadIndicesResponse([index]); + httpRequestsMockHelpers.setLoadIndicesResponse([createNonDataStreamIndex(indexName)]); testBed = await setup(); const { component, find } = testBed; @@ -165,20 +160,11 @@ describe.skip('', () => { describe('index actions', () => { const indexName = 'testIndex'; + beforeEach(async () => { - const index = { - health: 'green', - status: 'open', - primary: 1, - replica: 1, - documents: 10000, - documents_deleted: 100, - size: '156kb', - primary_size: '156kb', - name: indexName, - }; - - httpRequestsMockHelpers.setLoadIndicesResponse([index]); + httpRequestsMockHelpers.setLoadIndicesResponse([createNonDataStreamIndex(indexName)]); + httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexName] }); + testBed = await setup(); const { find, component } = testBed; component.update(); @@ -188,11 +174,15 @@ describe.skip('', () => { test('should be able to flush index', async () => { const { actions } = testBed; + await actions.clickManageContextMenuButton(); await actions.clickContextMenuOption('flushIndexMenuButton'); - const latestRequest = server.requests[server.requests.length - 1]; - expect(latestRequest.url).toBe(`${API_BASE_PATH}/indices/flush`); + const requestsCount = server.requests.length; + expect(server.requests[requestsCount - 2].url).toBe(`${API_BASE_PATH}/indices/flush`); + // After the indices are flushed, we imediately reload them. So we need to expect to see + // a reload server call also. + expect(server.requests[requestsCount - 1].url).toBe(`${API_BASE_PATH}/indices/reload`); }); }); });