Add Component Integration Test for Opening a Closed Index (#114404) (#121706)

* 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
This commit is contained in:
John Dorlus 2021-12-22 19:58:19 -05:00 committed by GitHub
parent e23739e7d7
commit 7dca9c0eab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View file

@ -183,17 +183,23 @@ describe('<IndexManagementHome />', () => {
});
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;
@ -202,6 +208,7 @@ describe('<IndexManagementHome />', () => {
find('indexTableIndexNameLink').at(0).simulate('click');
});
test('should be able to close an open index', async () => {
const { actions } = testBed;
@ -213,6 +220,22 @@ describe('<IndexManagementHome />', () => {
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;
@ -240,7 +263,7 @@ describe('<IndexManagementHome />', () => {
test('should be able to unfreeze a frozen index', async () => {
const { actions, exists } = testBed;
httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMock, isFrozen: false }]);
httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMockA }]);
// Open context menu
await actions.clickManageContextMenuButton();
@ -253,10 +276,6 @@ describe('<IndexManagementHome />', () => {
// After the index is unfrozen, we imediately 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`);
// Open context menu once again, since clicking an action will close it.
await actions.clickManageContextMenuButton();
// The unfreeze action should not be present anymore
expect(exists('unfreezeIndexMenuButton')).toBe(false);
});
});

View file

@ -659,9 +659,9 @@ export class IndexActionsContextMenu extends Component {
repositionOnScroll
>
<EuiContextMenu
data-test-subj="indexContextMenu"
initialPanelId={0}
panels={panels}
data-test-subj="indexContextMenu"
/>
</EuiPopover>
</div>