diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/test_subjects.ts b/x-pack/plugins/index_management/__jest__/client_integration/helpers/test_subjects.ts index 5da1fc61742e6..f7066fbeda95e 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/test_subjects.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/helpers/test_subjects.ts @@ -21,6 +21,7 @@ export type TestSubjects = | 'deleteTemplatesConfirmation' | 'documentationLink' | 'emptyPrompt' + | 'forcemergeIndexMenuButton' | 'filterList.filterItem' | 'ilmPolicyLink' | 'includeStatsSwitch' 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 c1b8dfcc0034f..018025b25246b 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 @@ -30,6 +30,7 @@ export interface IndicesTestBed extends TestBed { clickDataStreamAt: (index: number) => void; clickManageContextMenuButton: () => void; clickContextMenuOption: (optionDataTestSubject: string) => void; + clickModalConfirm: () => void; }; findDataStreamDetailPanel: () => ReactWrapper; findDataStreamDetailPanelTitle: () => string; @@ -97,6 +98,15 @@ export const setup = async (overridingDependencies: any = {}): Promise { + const { find, component } = testBed; + + await act(async () => { + find('confirmModalConfirmButton').simulate('click'); + }); + component.update(); + }; + const findDataStreamDetailPanel = () => { const { find } = testBed; return find('dataStreamDetailPanel'); @@ -116,6 +126,7 @@ export const setup = async (overridingDependencies: any = {}): Promise', () => { test("should be able to clear an index's cache", async () => { const { actions } = testBed; - actions.clickManageContextMenuButton(); + await actions.clickManageContextMenuButton(); await actions.clickManageContextMenuButton(); await actions.clickContextMenuOption('clearCacheIndexMenuButton'); @@ -291,6 +291,26 @@ describe('', () => { // The unfreeze action should not be present anymore expect(exists('unfreezeIndexMenuButton')).toBe(false); }); + + test('should be able to force merge an index', async () => { + const { actions, exists } = testBed; + + httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMockA, isFrozen: false }]); + + // Open context menu + await actions.clickManageContextMenuButton(); + // Check that the force merge action exists for the current index and merge it + expect(exists('forcemergeIndexMenuButton')).toBe(true); + await actions.clickContextMenuOption('forcemergeIndexMenuButton'); + + await actions.clickModalConfirm(); + + const requestsCount = server.requests.length; + expect(server.requests[requestsCount - 2].url).toBe(`${API_BASE_PATH}/indices/forcemerge`); + // After the index is force merged, we immediately do a reload. So we need to expect to see + // a reload server call also. + expect(server.requests[requestsCount - 1].url).toBe(`${API_BASE_PATH}/indices/reload`); + }); }); describe('Edit index settings', () => {