diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/constants.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/constants.ts new file mode 100644 index 0000000000000..db29ed844b606 --- /dev/null +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/constants.ts @@ -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', + }, + }, +}; diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/home.helpers.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/home.helpers.ts index d2857d5f5f54b..eed13fb298465 100644 --- a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/home.helpers.ts +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/home.helpers.ts @@ -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, @@ -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, @@ -28,13 +30,15 @@ const testBedConfig: TestBedConfig = { const initTestBed = registerTestBed(IndexManagementHome, testBedConfig); export interface IdxMgmtHomeTestBed extends TestBed { + 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; }; } @@ -42,16 +46,21 @@ export const setup = async (): Promise => { 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') => { @@ -68,23 +77,32 @@ export const setup = async (): Promise => { 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 "-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) @@ -104,13 +122,15 @@ export const setup = async (): Promise => { return { ...testBed, + findAction, actions: { selectHomeTab, selectDetailsTab, clickReloadButton, - clickTemplateActionAt, + clickTemplateAction, clickTemplateAt, clickCloseDetailsButton, + clickActionMenu, }, }; }; @@ -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' @@ -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'; diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts index 90320740d09ae..906b384dddc70 100644 --- a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/http_requests.ts @@ -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, }; }; diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/index.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/index.ts index ec4af7c0df417..6dce4453a67f9 100644 --- a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/index.ts +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/index.ts @@ -5,6 +5,9 @@ */ 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'; @@ -12,4 +15,7 @@ export { setupEnvironment } from './setup_environment'; export const pageHelpers = { home: { setup: homeSetup }, + templateCreate: { setup: templateCreateSetup }, + templateClone: { setup: templateCloneSetup }, + templateEdit: { setup: templateEditSetup }, }; diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_clone.helpers.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_clone.helpers.ts new file mode 100644 index 0000000000000..1401ea7c04906 --- /dev/null +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_clone.helpers.ts @@ -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); diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_create.helpers.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_create.helpers.ts new file mode 100644 index 0000000000000..67c429185ac9b --- /dev/null +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_create.helpers.ts @@ -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); diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_edit.helpers.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_edit.helpers.ts new file mode 100644 index 0000000000000..9976b395376b4 --- /dev/null +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_edit.helpers.ts @@ -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); diff --git a/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_form.helpers.ts b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_form.helpers.ts new file mode 100644 index 0000000000000..84b1f4a77e226 --- /dev/null +++ b/x-pack/legacy/plugins/index_management/__jest__/client_integration/helpers/template_form.helpers.ts @@ -0,0 +1,156 @@ +/* + * 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 { TestBed } from '../../../../../../test_utils'; +import { Template } from '../../../common/types'; + +export interface TemplateFormTestBed extends TestBed { + actions: { + clickNextButton: () => void; + clickBackButton: () => void; + clickSubmitButton: () => void; + completeStepOne: ({ name, indexPatterns, order, version }: Partial