Skip to content

Commit

Permalink
Added Component Integration Test For Force Merging an Index (#122176)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts

Co-authored-by: Ignacio Rivas <[email protected]>

Co-authored-by: Ignacio Rivas <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
3 people authored Jan 1, 2022
1 parent bfea0b0 commit 87f753d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type TestSubjects =
| 'deleteTemplatesConfirmation'
| 'documentationLink'
| 'emptyPrompt'
| 'forcemergeIndexMenuButton'
| 'filterList.filterItem'
| 'ilmPolicyLink'
| 'includeStatsSwitch'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IndicesTestBed extends TestBed<TestSubjects> {
clickDataStreamAt: (index: number) => void;
clickManageContextMenuButton: () => void;
clickContextMenuOption: (optionDataTestSubject: string) => void;
clickModalConfirm: () => void;
};
findDataStreamDetailPanel: () => ReactWrapper;
findDataStreamDetailPanelTitle: () => string;
Expand Down Expand Up @@ -97,6 +98,15 @@ export const setup = async (overridingDependencies: any = {}): Promise<IndicesTe
component.update();
};

const clickModalConfirm = async () => {
const { find, component } = testBed;

await act(async () => {
find('confirmModalConfirmButton').simulate('click');
});
component.update();
};

const findDataStreamDetailPanel = () => {
const { find } = testBed;
return find('dataStreamDetailPanel');
Expand All @@ -116,6 +126,7 @@ export const setup = async (overridingDependencies: any = {}): Promise<IndicesTe
clickDataStreamAt,
clickManageContextMenuButton,
clickContextMenuOption,
clickModalConfirm,
},
findDataStreamDetailPanel,
findDataStreamDetailPanelTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('<IndexManagementHome />', () => {

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');
Expand Down Expand Up @@ -291,6 +291,26 @@ describe('<IndexManagementHome />', () => {
// 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', () => {
Expand Down

0 comments on commit 87f753d

Please sign in to comment.