From 939c952ae6465c72eaa5f7a50e1174e557059d16 Mon Sep 17 00:00:00 2001 From: John Dorlus Date: Mon, 20 Dec 2021 16:12:39 -0500 Subject: [PATCH] Add Component Integration Test for Opening a Closed Index (#114404) * Added Component Integration Test for Opening A closed Index. * Fixed open index test and changed the structure of the tests to consolidate boilerplate. * Fixed PR based on feedback. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts --- .../home/indices_tab.test.ts | 60 +++++++++++++++++-- .../index_actions_context_menu.js | 2 +- 2 files changed, 56 insertions(+), 6 deletions(-) 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 b9d0c9ca8f2d6..d38546497730d 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 @@ -158,17 +158,23 @@ describe('', () => { }); describe('index actions', () => { - const indexName = 'testIndex'; - const indexMock = createNonDataStreamIndex(indexName); + const indexNameA = 'testIndexA'; + const indexNameB = 'testIndexB'; + const indexMockA = createNonDataStreamIndex(indexNameA); + const indexMockB = createNonDataStreamIndex(indexNameB); beforeEach(async () => { httpRequestsMockHelpers.setLoadIndicesResponse([ { - ...indexMock, + ...indexMockA, isFrozen: true, }, + { + ...indexMockB, + status: 'closed', + }, ]); - httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexName] }); + httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexNameA, indexNameB] }); testBed = await setup(); const { component, find } = testBed; @@ -177,6 +183,7 @@ describe('', () => { find('indexTableIndexNameLink').at(0).simulate('click'); }); + test('should be able to close an open index', async () => { const { actions } = testBed; @@ -188,6 +195,22 @@ describe('', () => { expect(latestRequest.url).toBe(`${API_BASE_PATH}/indices/close`); }); + test('should be able to open a closed index', async () => { + testBed = await setup(); + const { component, find, actions } = testBed; + + component.update(); + + find('indexTableIndexNameLink').at(1).simulate('click'); + + await actions.clickManageContextMenuButton(); + await actions.clickContextMenuOption('openIndexMenuButton'); + + // A refresh call was added after closing an index so we need to check the second to last request. + const latestRequest = server.requests[server.requests.length - 2]; + expect(latestRequest.url).toBe(`${API_BASE_PATH}/indices/open`); + }); + test('should be able to flush index', async () => { const { actions } = testBed; @@ -215,7 +238,7 @@ describe('', () => { test('should be able to unfreeze a frozen index', async () => { const { actions, exists } = testBed; - httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMock, isFrozen: false }]); + httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMockA, isFrozen: false }]); // Open context menu await actions.clickManageContextMenuButton(); @@ -234,4 +257,31 @@ describe('', () => { expect(exists('unfreezeIndexMenuButton')).toBe(false); }); }); + + describe('Edit index settings', () => { + test('shows error callout when request fails', async () => { + const { actions, find, component, exists } = testBed; + + mockGetAceEditorValue.mockReturnValue(`{ + "index.routing.allocation.include._tier_preference": "non_existent_tier" + }`); + + const error = { + statusCode: 400, + error: 'Bad Request', + message: 'invalid tier names found in ...', + }; + httpRequestsMockHelpers.setUpdateIndexSettingsResponse(undefined, error); + + await actions.selectIndexDetailsTab('edit_settings'); + + await act(async () => { + find('updateEditIndexSettingsButton').simulate('click'); + }); + + component.update(); + + expect(exists('updateIndexSettingsErrorCallout')).toBe(true); + }); + }); }); diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_actions_context_menu/index_actions_context_menu.js b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_actions_context_menu/index_actions_context_menu.js index 80f830bdc7b99..c3af6c6599bf7 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_actions_context_menu/index_actions_context_menu.js +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_actions_context_menu/index_actions_context_menu.js @@ -659,9 +659,9 @@ export class IndexActionsContextMenu extends Component { repositionOnScroll >