Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const TEMPLATE_NAME = 'my_template';

export const INDEX_PATTERNS = ['my_index_pattern'];

export const SETTINGS = {
number_of_shards: 1,
index: {
lifecycle: {
name: 'my_policy',
},
},
};

export const ALIASES = {
alias: {
filter: {
term: { user: 'my_user' },
},
},
};

export const MAPPINGS = {
_source: {
enabled: false,
},
properties: {
host_name: {
type: 'keyword',
},
created_at: {
type: 'date',
format: 'EEE MMM dd HH:mm:ss Z yyyy',
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ReactWrapper } from 'enzyme';
import { act } from 'react-dom/test-utils';
import {
registerTestBed,
Expand All @@ -15,6 +16,7 @@ import {
import { IndexManagementHome } from '../../../public/sections/home';
import { BASE_PATH } from '../../../common/constants';
import { indexManagementStore } from '../../../public/store';
import { Template } from '../../../common/types';

const testBedConfig: TestBedConfig = {
store: indexManagementStore,
Expand All @@ -28,30 +30,37 @@ const testBedConfig: TestBedConfig = {
const initTestBed = registerTestBed(IndexManagementHome, testBedConfig);

export interface IdxMgmtHomeTestBed extends TestBed<IdxMgmtTestSubjects> {
findAction: (action: 'edit' | 'clone' | 'delete') => ReactWrapper;
actions: {
selectHomeTab: (tab: 'indices' | 'index templates') => void;
selectHomeTab: (tab: 'indicesTab' | 'templatesTab') => void;
selectDetailsTab: (tab: 'summary' | 'settings' | 'mappings' | 'aliases') => void;
clickReloadButton: () => void;
clickTemplateActionAt: (index: number, action: 'delete') => void;
clickTemplateAction: (name: Template['name'], action: 'edit' | 'clone' | 'delete') => void;
clickTemplateAt: (index: number) => void;
clickCloseDetailsButton: () => void;
clickActionMenu: (name: Template['name']) => void;
};
}

export const setup = async (): Promise<IdxMgmtHomeTestBed> => {
const testBed = await initTestBed();

/**
* User Actions
* Additional helpers
*/
const findAction = (action: 'edit' | 'clone' | 'delete') => {
const actions = ['edit', 'clone', 'delete'];
const { component } = testBed;

const selectHomeTab = (tab: 'indices' | 'index templates') => {
const tabs = ['indices', 'index templates'];
return component.find('.euiContextMenuItem').at(actions.indexOf(action));
};

testBed
.find('tab')
.at(tabs.indexOf(tab))
.simulate('click');
/**
* User Actions
*/

const selectHomeTab = (tab: 'indicesTab' | 'templatesTab') => {
testBed.find(tab).simulate('click');
};

const selectDetailsTab = (tab: 'summary' | 'settings' | 'mappings' | 'aliases') => {
Expand All @@ -68,23 +77,32 @@ export const setup = async (): Promise<IdxMgmtHomeTestBed> => {
find('reloadButton').simulate('click');
};

const clickTemplateActionAt = async (index: number, action: 'delete') => {
const { component, table } = testBed;
const { rows } = table.getMetaData('templatesTable');
const currentRow = rows[index];
const lastColumn = currentRow.columns[currentRow.columns.length - 1].reactWrapper;
const button = findTestSubject(lastColumn, `${action}TemplateButton`);
const clickActionMenu = async (templateName: Template['name']) => {
const { component } = testBed;

// @ts-ignore (remove when react 16.9.0 is released)
await act(async () => {
button.simulate('click');
component.update();
});
// When a table has > 2 actions, EUI displays an overflow menu with an id "<template_name>-actions"
// The template name may contain a period (.) so we use bracket syntax for selector
component.find(`div[id="${templateName}-actions"] button`).simulate('click');
};

const clickTemplateAction = (
templateName: Template['name'],
action: 'edit' | 'clone' | 'delete'
) => {
const actions = ['edit', 'clone', 'delete'];
const { component } = testBed;

clickActionMenu(templateName);

component
.find('.euiContextMenuItem')
.at(actions.indexOf(action))
.simulate('click');
};

const clickTemplateAt = async (index: number) => {
const { component, table, router } = testBed;
const { rows } = table.getMetaData('templatesTable');
const { rows } = table.getMetaData('templateTable');
const templateLink = findTestSubject(rows[index].reactWrapper, 'templateDetailsLink');

// @ts-ignore (remove when react 16.9.0 is released)
Expand All @@ -104,13 +122,15 @@ export const setup = async (): Promise<IdxMgmtHomeTestBed> => {

return {
...testBed,
findAction,
actions: {
selectHomeTab,
selectDetailsTab,
clickReloadButton,
clickTemplateActionAt,
clickTemplateAction,
clickTemplateAt,
clickCloseDetailsButton,
clickActionMenu,
},
};
};
Expand All @@ -122,14 +142,19 @@ export type TestSubjects =
| 'appTitle'
| 'cell'
| 'closeDetailsButton'
| 'createTemplateButton'
| 'deleteSystemTemplateCallOut'
| 'deleteTemplateButton'
| 'deleteTemplatesButton'
| 'deleteTemplatesConfirmation'
| 'documentationLink'
| 'emptyPrompt'
| 'manageTemplateButton'
| 'mappingsTab'
| 'noAliasesCallout'
| 'noMappingsCallout'
| 'noSettingsCallout'
| 'indicesList'
| 'indicesTab'
| 'reloadButton'
| 'row'
| 'sectionError'
Expand All @@ -138,11 +163,11 @@ export type TestSubjects =
| 'summaryTab'
| 'summaryTitle'
| 'systemTemplatesSwitch'
| 'tab'
| 'templateDetails'
| 'templateDetails.deleteTemplateButton'
| 'templateDetails.manageTemplateButton'
| 'templateDetails.sectionLoading'
| 'templateDetails.tab'
| 'templateDetails.title'
| 'templatesList'
| 'templatesTable';
| 'templateList'
| 'templateTable'
| 'templatesTab';
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,35 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setCreateTemplateResponse = (response?: HttpResponse, error?: any) => {
const status = error ? error.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);

server.respondWith('PUT', `${API_PATH}/templates`, [
status,
{ 'Content-Type': 'application/json' },
body,
]);
};

const setUpdateTemplateResponse = (response?: HttpResponse, error?: any) => {
const status = error ? error.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);

server.respondWith('PUT', `${API_PATH}/templates/:name`, [
status,
{ 'Content-Type': 'application/json' },
body,
]);
};

return {
setLoadTemplatesResponse,
setLoadIndicesResponse,
setDeleteTemplateResponse,
setLoadTemplateResponse,
setCreateTemplateResponse,
setUpdateTemplateResponse,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
*/

import { setup as homeSetup } from './home.helpers';
import { setup as templateCreateSetup } from './template_create.helpers';
import { setup as templateCloneSetup } from './template_clone.helpers';
import { setup as templateEditSetup } from './template_edit.helpers';

export { nextTick, getRandomString, findTestSubject, TestBed } from '../../../../../../test_utils';

export { setupEnvironment } from './setup_environment';

export const pageHelpers = {
home: { setup: homeSetup },
templateCreate: { setup: templateCreateSetup },
templateClone: { setup: templateCloneSetup },
templateEdit: { setup: templateEditSetup },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { registerTestBed, TestBedConfig } from '../../../../../../test_utils';
import { BASE_PATH } from '../../../common/constants';
import { TemplateClone } from '../../../public/sections/template_clone';
import { formSetup } from './template_form.helpers';
import { TEMPLATE_NAME } from './constants';

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [`${BASE_PATH}clone_template/${TEMPLATE_NAME}`],
componentRoutePath: `${BASE_PATH}clone_template/:name`,
},
doMountAsync: true,
};

const initTestBed = registerTestBed(TemplateClone, testBedConfig);

export const setup = formSetup.bind(null, initTestBed);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { registerTestBed, TestBedConfig } from '../../../../../../test_utils';
import { BASE_PATH } from '../../../common/constants';
import { TemplateCreate } from '../../../public/sections/template_create';
import { formSetup } from './template_form.helpers';

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [`${BASE_PATH}create_template`],
componentRoutePath: `${BASE_PATH}create_template`,
},
doMountAsync: true,
};

const initTestBed = registerTestBed(TemplateCreate, testBedConfig);

export const setup = formSetup.bind(null, initTestBed);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { registerTestBed, TestBedConfig } from '../../../../../../test_utils';
import { BASE_PATH } from '../../../common/constants';
import { TemplateEdit } from '../../../public/sections/template_edit';
import { formSetup } from './template_form.helpers';
import { TEMPLATE_NAME } from './constants';

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [`${BASE_PATH}edit_template/${TEMPLATE_NAME}`],
componentRoutePath: `${BASE_PATH}edit_template/:name`,
},
doMountAsync: true,
};

const initTestBed = registerTestBed(TemplateEdit, testBedConfig);

export const setup = formSetup.bind(null, initTestBed);
Loading