Skip to content

Commit

Permalink
Merge branch 'master' into integrations/update_links_and_permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 18, 2021
2 parents f56b0e8 + 3f5ad2a commit 02d7b81
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setReloadIndicesResponse = (response: HttpResponse = []) => {
server.respondWith('POST', `${API_BASE_PATH}/indices/reload`, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(response),
]);
};

const setLoadDataStreamsResponse = (response: HttpResponse = []) => {
server.respondWith('GET', `${API_BASE_PATH}/data_streams`, [
200,
Expand Down Expand Up @@ -118,6 +126,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
return {
setLoadTemplatesResponse,
setLoadIndicesResponse,
setReloadIndicesResponse,
setLoadDataStreamsResponse,
setLoadDataStreamResponse,
setDeleteDataStreamResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,26 @@ export const setup = async (overridingDependencies: any = {}): Promise<IndicesTe
*/

const clickContextMenuOption = async (optionDataTestSubject: string) => {
const { find } = testBed;
const contextMenu = find('indexContextMenu');
contextMenu.find(`button[data-test-subj="${optionDataTestSubject}"]`).simulate('click');
const { find, component } = testBed;

await act(async () => {
find(`indexContextMenu.${optionDataTestSubject}`).simulate('click');
});
component.update();
};

const clickIncludeHiddenIndicesToggle = () => {
const { find } = testBed;
find('indexTableIncludeHiddenIndicesToggle').simulate('click');
};

const clickManageContextMenuButton = () => {
const { find } = testBed;
find('indexActionsContextMenuButton').simulate('click');
const clickManageContextMenuButton = async () => {
const { find, component } = testBed;

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

const getIncludeHiddenIndicesToggleStatus = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { act } from 'react-dom/test-utils';
import { API_BASE_PATH } from '../../../common/constants';
import { setupEnvironment, nextTick } from '../helpers';
import { IndicesTestBed, setup } from './indices_tab.helpers';
import { createDataStreamPayload } from './data_streams_tab.helpers';
import { createDataStreamPayload, createNonDataStreamIndex } from './data_streams_tab.helpers';

/**
* The below import is required to avoid a console error warn from the "brace" package
Expand All @@ -23,9 +23,14 @@ import { createMemoryHistory } from 'history';
stubWebWorker();

// unhandled promise rejection https://github.com/elastic/kibana/issues/112699
describe.skip('<IndexManagementHome />', () => {
const { server, httpRequestsMockHelpers } = setupEnvironment();
describe('<IndexManagementHome />', () => {
let testBed: IndicesTestBed;
let server: ReturnType<typeof setupEnvironment>['server'];
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers'];

beforeEach(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
});

afterAll(() => {
server.restore();
Expand Down Expand Up @@ -108,19 +113,9 @@ describe.skip('<IndexManagementHome />', () => {

describe('index detail panel with % character in index name', () => {
const indexName = 'test%';

beforeEach(async () => {
const index = {
health: 'green',
status: 'open',
primary: 1,
replica: 1,
documents: 10000,
documents_deleted: 100,
size: '156kb',
primary_size: '156kb',
name: indexName,
};
httpRequestsMockHelpers.setLoadIndicesResponse([index]);
httpRequestsMockHelpers.setLoadIndicesResponse([createNonDataStreamIndex(indexName)]);

testBed = await setup();
const { component, find } = testBed;
Expand Down Expand Up @@ -165,20 +160,11 @@ describe.skip('<IndexManagementHome />', () => {

describe('index actions', () => {
const indexName = 'testIndex';

beforeEach(async () => {
const index = {
health: 'green',
status: 'open',
primary: 1,
replica: 1,
documents: 10000,
documents_deleted: 100,
size: '156kb',
primary_size: '156kb',
name: indexName,
};

httpRequestsMockHelpers.setLoadIndicesResponse([index]);
httpRequestsMockHelpers.setLoadIndicesResponse([createNonDataStreamIndex(indexName)]);
httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexName] });

testBed = await setup();
const { find, component } = testBed;
component.update();
Expand All @@ -188,11 +174,15 @@ describe.skip('<IndexManagementHome />', () => {

test('should be able to flush index', async () => {
const { actions } = testBed;

await actions.clickManageContextMenuButton();
await actions.clickContextMenuOption('flushIndexMenuButton');

const latestRequest = server.requests[server.requests.length - 1];
expect(latestRequest.url).toBe(`${API_BASE_PATH}/indices/flush`);
const requestsCount = server.requests.length;
expect(server.requests[requestsCount - 2].url).toBe(`${API_BASE_PATH}/indices/flush`);
// After the indices are flushed, we imediately reload them. So we need to expect to see
// a reload server call also.
expect(server.requests[requestsCount - 1].url).toBe(`${API_BASE_PATH}/indices/reload`);
});
});
});

0 comments on commit 02d7b81

Please sign in to comment.