From 87f753dba0515c23a1cc4bdf6feac2df2200baea Mon Sep 17 00:00:00 2001 From: John Dorlus Date: Fri, 31 Dec 2021 23:51:03 -0500 Subject: [PATCH] Added Component Integration Test For Force Merging an Index (#122176) * Added new test for force merge action. Also added an await in the clear index cache test because there were overlapping act calls. * Removed calls from previous copied test. * Update x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts Co-authored-by: Ignacio Rivas * Update x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts Co-authored-by: Ignacio Rivas Co-authored-by: Ignacio Rivas Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../helpers/test_subjects.ts | 1 + .../home/indices_tab.helpers.ts | 11 ++++++++++ .../home/indices_tab.test.ts | 22 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) 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', () => {