Skip to content

Commit

Permalink
Add delete data stream action and detail panel (#68919)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
cjcenizal and elasticmachine authored Jun 25, 2020
1 parent bcc6209 commit b48c8bf
Show file tree
Hide file tree
Showing 24 changed files with 860 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setLoadDataStreamResponse = (response: HttpResponse = []) => {
server.respondWith('GET', `${API_BASE_PATH}/data_streams/:id`, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(response),
]);
};

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

const setDeleteTemplateResponse = (response: HttpResponse = []) => {
server.respondWith('POST', `${API_BASE_PATH}/delete_index_templates`, [
200,
Expand Down Expand Up @@ -80,6 +96,8 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
setLoadTemplatesResponse,
setLoadIndicesResponse,
setLoadDataStreamsResponse,
setLoadDataStreamResponse,
setDeleteDataStreamResponse,
setDeleteTemplateResponse,
setLoadTemplateResponse,
setCreateTemplateResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from 'react';
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import { merge } from 'lodash';

import {
notificationServiceMock,
Expand All @@ -33,7 +34,7 @@ export const services = {
services.uiMetricService.setup({ reportUiStats() {} } as any);
setExtensionsService(services.extensionsService);
setUiMetricService(services.uiMetricService);
const appDependencies = { services, core: {}, plugins: {} } as any;
const appDependencies = { services, core: { getUrlForApp: () => {} }, plugins: {} } as any;

export const setupEnvironment = () => {
// Mock initialization of services
Expand All @@ -51,8 +52,13 @@ export const setupEnvironment = () => {
};
};

export const WithAppDependencies = (Comp: any) => (props: any) => (
<AppContextProvider value={appDependencies}>
<Comp {...props} />
</AppContextProvider>
);
export const WithAppDependencies = (Comp: any, overridingDependencies: any = {}) => (
props: any
) => {
const mergedDependencies = merge({}, appDependencies, overridingDependencies);
return (
<AppContextProvider value={mergedDependencies}>
<Comp {...props} />
</AppContextProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { act } from 'react-dom/test-utils';
import { ReactWrapper } from 'enzyme';

import {
registerTestBed,
Expand All @@ -17,27 +18,38 @@ import { IndexManagementHome } from '../../../public/application/sections/home';
import { indexManagementStore } from '../../../public/application/store'; // eslint-disable-line @kbn/eslint/no-restricted-paths
import { WithAppDependencies, services, TestSubjects } from '../helpers';

const testBedConfig: TestBedConfig = {
store: () => indexManagementStore(services as any),
memoryRouter: {
initialEntries: [`/indices`],
componentRoutePath: `/:section(indices|data_streams|templates)`,
},
doMountAsync: true,
};

const initTestBed = registerTestBed(WithAppDependencies(IndexManagementHome), testBedConfig);

export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
actions: {
goToDataStreamsList: () => void;
clickEmptyPromptIndexTemplateLink: () => void;
clickReloadButton: () => void;
clickNameAt: (index: number) => void;
clickIndicesAt: (index: number) => void;
clickDeletActionAt: (index: number) => void;
clickConfirmDelete: () => void;
clickDeletDataStreamButton: () => void;
};
findDeleteActionAt: (index: number) => ReactWrapper;
findDeleteConfirmationModal: () => ReactWrapper;
findDetailPanel: () => ReactWrapper;
findDetailPanelTitle: () => string;
findEmptyPromptIndexTemplateLink: () => ReactWrapper;
}

export const setup = async (): Promise<DataStreamsTabTestBed> => {
export const setup = async (overridingDependencies: any = {}): Promise<DataStreamsTabTestBed> => {
const testBedConfig: TestBedConfig = {
store: () => indexManagementStore(services as any),
memoryRouter: {
initialEntries: [`/indices`],
componentRoutePath: `/:section(indices|data_streams|templates)`,
},
doMountAsync: true,
};

const initTestBed = registerTestBed(
WithAppDependencies(IndexManagementHome, overridingDependencies),
testBedConfig
);
const testBed = await initTestBed();

/**
Expand All @@ -48,15 +60,17 @@ export const setup = async (): Promise<DataStreamsTabTestBed> => {
testBed.find('data_streamsTab').simulate('click');
};

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

const findEmptyPromptIndexTemplateLink = () => {
const { find } = testBed;
const templateLink = find('dataStreamsEmptyPromptTemplateLink');
return templateLink;
};

const clickEmptyPromptIndexTemplateLink = async () => {
const { component, router } = testBed;
await act(async () => {
router.navigateTo(templateLink.props().href!);
router.navigateTo(findEmptyPromptIndexTemplateLink().props().href!);
});

component.update();
};

Expand All @@ -65,10 +79,15 @@ export const setup = async (): Promise<DataStreamsTabTestBed> => {
find('reloadButton').simulate('click');
};

const clickIndicesAt = async (index: number) => {
const { component, table, router } = testBed;
const findTestSubjectAt = (testSubject: string, index: number) => {
const { table } = testBed;
const { rows } = table.getMetaData('dataStreamTable');
const indicesLink = findTestSubject(rows[index].reactWrapper, 'indicesLink');
return findTestSubject(rows[index].reactWrapper, testSubject);
};

const clickIndicesAt = async (index: number) => {
const { component, router } = testBed;
const indicesLink = findTestSubjectAt('indicesLink', index);

await act(async () => {
router.navigateTo(indicesLink.props().href!);
Expand All @@ -77,14 +96,71 @@ export const setup = async (): Promise<DataStreamsTabTestBed> => {
component.update();
};

const clickNameAt = async (index: number) => {
const { component, router } = testBed;
const nameLink = findTestSubjectAt('nameLink', index);

await act(async () => {
router.navigateTo(nameLink.props().href!);
});

component.update();
};

const findDeleteActionAt = findTestSubjectAt.bind(null, 'deleteDataStream');

const clickDeletActionAt = (index: number) => {
findDeleteActionAt(index).simulate('click');
};

const findDeleteConfirmationModal = () => {
const { find } = testBed;
return find('deleteDataStreamsConfirmation');
};

const clickConfirmDelete = async () => {
const modal = document.body.querySelector('[data-test-subj="deleteDataStreamsConfirmation"]');
const confirmButton: HTMLButtonElement | null = modal!.querySelector(
'[data-test-subj="confirmModalConfirmButton"]'
);

await act(async () => {
confirmButton!.click();
});
};

const clickDeletDataStreamButton = () => {
const { find } = testBed;
find('deleteDataStreamButton').simulate('click');
};

const findDetailPanel = () => {
const { find } = testBed;
return find('dataStreamDetailPanel');
};

const findDetailPanelTitle = () => {
const { find } = testBed;
return find('dataStreamDetailPanelTitle').text();
};

return {
...testBed,
actions: {
goToDataStreamsList,
clickEmptyPromptIndexTemplateLink,
clickReloadButton,
clickNameAt,
clickIndicesAt,
clickDeletActionAt,
clickConfirmDelete,
clickDeletDataStreamButton,
},
findDeleteActionAt,
findDeleteConfirmationModal,
findDetailPanel,
findDetailPanelTitle,
findEmptyPromptIndexTemplateLink,
};
};

Expand Down
Loading

0 comments on commit b48c8bf

Please sign in to comment.