Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete data stream action and detail panel #68919

Merged
merged 8 commits into from
Jun 25, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

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 +88,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
setLoadTemplatesResponse,
setLoadIndicesResponse,
setLoadDataStreamsResponse,
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 dependencies = merge(appDependencies, overridingDependencies);
return (
<AppContextProvider value={appDependencies}>
<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,37 @@ 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;
};
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 +59,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 +78,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 +95,65 @@ 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 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,
},
findDeleteActionAt,
findDeleteConfirmationModal,
findDetailPanel,
findDetailPanelTitle,
findEmptyPromptIndexTemplateLink,
};
};

Expand Down
Loading