From f2ebcadc7f526c75e87c32dce365acc6539745ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yulia=20=C4=8Cech?= <6585477+yuliacech@users.noreply.github.com> Date: Thu, 24 Jun 2021 17:51:05 +0200 Subject: [PATCH] Refactored helpers file into separate domain files (#102383) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../edit_policy/edit_policy.helpers.tsx | 96 ------------------- .../edit_policy/features/cold_phase.test.ts | 42 -------- .../features/delete_phase.helpers.ts | 36 +++++++ .../edit_policy/features/delete_phase.test.ts | 59 +++++------- .../edit_policy/features/frozen_phase.test.ts | 18 +--- .../general_behavior.helpers.ts | 8 +- .../features/request_flyout.test.ts | 7 +- .../edit_policy/features/rollover.helpers.ts | 51 ++++++++++ .../edit_policy/features/rollover.test.ts | 17 ++-- .../features/searchable_snapshots.helpers.ts | 59 ++++++++++++ .../features/searchable_snapshots.test.ts | 25 +++-- .../edit_policy/features/timeline.helpers.ts | 29 ++++++ .../edit_policy/features/timeline.test.ts | 6 +- .../edit_policy/features/timing.helpers.ts | 36 +++++++ .../edit_policy/features/timing.test.ts | 41 ++++++++ .../edit_policy/features/warm_phase.test.ts | 42 -------- .../cold_phase_validation.test.ts | 6 +- .../form_validation/error_indicators.test.ts | 6 +- .../hot_phase_validation.test.ts | 10 +- .../policy_name_validation.test.ts | 10 +- .../form_validation/timing.test.ts | 8 +- .../form_validation/validation.helpers.ts | 47 +++++++++ .../warm_phase_validation.test.ts | 8 +- .../policy_serialization.helpers.ts | 45 +++++++++ .../policy_serialization.test.ts | 25 +++-- .../helpers/actions/errors_actions.ts | 10 +- .../helpers/actions/forcemerge_actions.ts | 2 +- ...ts => form_toggle_and_set_value_action.ts} | 15 +-- .../helpers/actions/index.ts | 12 ++- .../helpers/actions/index_priority_actions.ts | 8 +- .../helpers/actions/phases.ts | 76 +++++++++++++++ .../helpers/actions/replicas_action.ts | 20 ++++ .../helpers/actions/rollover_actions.ts | 16 ++-- .../actions/set_wait_for_snapshot_action.ts | 19 ---- .../helpers/actions/shrink_actions.ts | 10 +- .../actions/snapshot_policy_actions.ts | 27 ++++++ 36 files changed, 611 insertions(+), 341 deletions(-) delete mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx delete mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/cold_phase.test.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.helpers.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.helpers.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.helpers.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.helpers.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.helpers.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts delete mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/warm_phase.test.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/validation.helpers.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.helpers.ts rename x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/{set_replicas_action.ts => form_toggle_and_set_value_action.ts} (57%) create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/phases.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/replicas_action.ts delete mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_wait_for_snapshot_action.ts create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx deleted file mode 100644 index 6f1c58b2e9b18..0000000000000 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { TestBedConfig } from '@kbn/test/jest'; -import { AppServicesContext } from '../../../public/types'; - -import { Phase } from '../../../common/types'; - -import { - createNodeAllocationActions, - createFormToggleAction, - createFormSetValueAction, - setReplicas, - createSearchableSnapshotActions, - createTogglePhaseAction, - createSavePolicyAction, - createErrorsActions, - createRolloverActions, - createSetWaitForSnapshotAction, - createMinAgeActions, - createShrinkActions, - createFreezeActions, - createForceMergeActions, - createReadonlyActions, - createIndexPriorityActions, -} from '../helpers'; -import { initTestBed } from './init_test_bed'; - -type SetupReturn = ReturnType; -export type EditPolicyTestBed = SetupReturn extends Promise ? U : SetupReturn; - -export const setup = async (arg?: { - appServicesContext?: Partial; - testBedConfig?: Partial; -}) => { - const testBed = await initTestBed(arg); - - const { exists } = testBed; - - return { - ...testBed, - actions: { - togglePhase: createTogglePhaseAction(testBed), - savePolicy: createSavePolicyAction(testBed), - toggleSaveAsNewPolicy: createFormToggleAction(testBed, 'saveAsNewSwitch'), - setPolicyName: createFormSetValueAction(testBed, 'policyNameField'), - errors: { - ...createErrorsActions(testBed), - }, - timeline: { - hasPhase: (phase: Phase) => exists(`ilmTimelinePhase-${phase}`), - }, - rollover: { - ...createRolloverActions(testBed), - }, - hot: { - ...createForceMergeActions(testBed, 'hot'), - ...createIndexPriorityActions(testBed, 'hot'), - ...createShrinkActions(testBed, 'hot'), - ...createReadonlyActions(testBed, 'hot'), - ...createSearchableSnapshotActions(testBed, 'hot'), - }, - warm: { - ...createMinAgeActions(testBed, 'warm'), - setReplicas: (value: string) => setReplicas(testBed, 'warm', value), - ...createShrinkActions(testBed, 'warm'), - ...createForceMergeActions(testBed, 'warm'), - ...createReadonlyActions(testBed, 'warm'), - ...createIndexPriorityActions(testBed, 'warm'), - ...createNodeAllocationActions(testBed, 'warm'), - }, - cold: { - ...createMinAgeActions(testBed, 'cold'), - setReplicas: (value: string) => setReplicas(testBed, 'cold', value), - ...createFreezeActions(testBed, 'cold'), - ...createReadonlyActions(testBed, 'cold'), - ...createIndexPriorityActions(testBed, 'cold'), - ...createSearchableSnapshotActions(testBed, 'cold'), - ...createNodeAllocationActions(testBed, 'cold'), - }, - frozen: { - ...createMinAgeActions(testBed, 'frozen'), - ...createSearchableSnapshotActions(testBed, 'frozen'), - }, - delete: { - isShown: () => exists('delete-phase'), - ...createMinAgeActions(testBed, 'delete'), - setWaitForSnapshotPolicy: createSetWaitForSnapshotAction(testBed), - }, - }, - }; -}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/cold_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/cold_phase.test.ts deleted file mode 100644 index e5e4267b6270c..0000000000000 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/cold_phase.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { act } from 'react-dom/test-utils'; -import { setupEnvironment } from '../../helpers/setup_environment'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; - -describe(' cold phase', () => { - let testBed: EditPolicyTestBed; - const { server, httpRequestsMockHelpers } = setupEnvironment(); - - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - server.restore(); - }); - - beforeEach(async () => { - httpRequestsMockHelpers.setDefaultResponses(); - - await act(async () => { - testBed = await setup(); - }); - - const { component } = testBed; - component.update(); - }); - - test('shows timing only when enabled', async () => { - const { actions } = testBed; - expect(actions.cold.hasMinAgeInput()).toBeFalsy(); - await actions.togglePhase('cold'); - expect(actions.cold.hasMinAgeInput()).toBeTruthy(); - }); -}); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.helpers.ts new file mode 100644 index 0000000000000..1914a056528e1 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.helpers.ts @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + createMinAgeActions, + createSavePolicyAction, + createSnapshotPolicyActions, + createTogglePhaseAction, +} from '../../helpers'; +import { initTestBed } from '../init_test_bed'; + +type SetupReturn = ReturnType; + +export type DeleteTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupDeleteTestBed = async () => { + const testBed = await initTestBed(); + const { exists } = testBed; + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + savePolicy: createSavePolicyAction(testBed), + delete: { + isShown: () => exists('delete-phase'), + ...createMinAgeActions(testBed, 'delete'), + ...createSnapshotPolicyActions(testBed), + }, + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts index 0c24101461f24..6ba41860eb855 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts @@ -8,16 +8,16 @@ import { act } from 'react-dom/test-utils'; import { API_BASE_PATH } from '../../../../common/constants'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; import { DELETE_PHASE_POLICY, getDefaultHotPhasePolicy, NEW_SNAPSHOT_POLICY_NAME, SNAPSHOT_POLICY_NAME, } from '../constants'; +import { DeleteTestBed, setupDeleteTestBed } from './delete_phase.helpers'; describe(' delete phase', () => { - let testBed: EditPolicyTestBed; + let testBed: DeleteTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); afterAll(() => { @@ -32,7 +32,7 @@ describe(' delete phase', () => { ]); await act(async () => { - testBed = await setup(); + testBed = await setupDeleteTestBed(); }); const { component } = testBed; @@ -43,7 +43,7 @@ describe(' delete phase', () => { httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); await act(async () => { - testBed = await setup(); + testBed = await setupDeleteTestBed(); }); const { component, actions } = testBed; @@ -56,21 +56,6 @@ describe(' delete phase', () => { expect(actions.delete.isShown()).toBeFalsy(); }); - test('shows timing after it was enabled', async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - - await act(async () => { - testBed = await setup(); - }); - - const { component, actions } = testBed; - component.update(); - - expect(actions.delete.hasMinAgeInput()).toBeFalsy(); - await actions.togglePhase('delete'); - expect(actions.delete.hasMinAgeInput()).toBeTruthy(); - }); - describe('wait for snapshot', () => { test('shows snapshot policy name', () => { expect(testBed.find('snapshotPolicyCombobox').prop('data-currentvalue')).toEqual([ @@ -83,7 +68,7 @@ describe(' delete phase', () => { test('updates snapshot policy name', async () => { const { actions } = testBed; - await actions.delete.setWaitForSnapshotPolicy(NEW_SNAPSHOT_POLICY_NAME); + await actions.delete.setSnapshotPolicy(NEW_SNAPSHOT_POLICY_NAME); await actions.savePolicy(); const expected = { @@ -111,16 +96,16 @@ describe(' delete phase', () => { test('shows a callout when the input is not an existing policy', async () => { const { actions } = testBed; - await actions.delete.setWaitForSnapshotPolicy('my_custom_policy'); - expect(testBed.find('noPoliciesCallout').exists()).toBeFalsy(); - expect(testBed.find('policiesErrorCallout').exists()).toBeFalsy(); - expect(testBed.find('customPolicyCallout').exists()).toBeTruthy(); + await actions.delete.setSnapshotPolicy('my_custom_policy'); + expect(actions.delete.hasNoPoliciesCallout()).toBeFalsy(); + expect(actions.delete.hasPolicyErrorCallout()).toBeFalsy(); + expect(actions.delete.hasCustomPolicyCallout()).toBeTruthy(); }); test('removes the action if field is empty', async () => { const { actions } = testBed; - await actions.delete.setWaitForSnapshotPolicy(''); + await actions.delete.setSnapshotPolicy(''); await actions.savePolicy(); const expected = { @@ -146,26 +131,30 @@ describe(' delete phase', () => { // need to call setup on testBed again for it to use a newly defined snapshot policies response httpRequestsMockHelpers.setLoadSnapshotPolicies([]); await act(async () => { - testBed = await setup(); + testBed = await setupDeleteTestBed(); }); - testBed.component.update(); - expect(testBed.find('customPolicyCallout').exists()).toBeFalsy(); - expect(testBed.find('policiesErrorCallout').exists()).toBeFalsy(); - expect(testBed.find('noPoliciesCallout').exists()).toBeTruthy(); + const { component, actions } = testBed; + component.update(); + + expect(actions.delete.hasCustomPolicyCallout()).toBeFalsy(); + expect(actions.delete.hasPolicyErrorCallout()).toBeFalsy(); + expect(actions.delete.hasNoPoliciesCallout()).toBeTruthy(); }); test('shows a callout when there is an error loading snapshot policies', async () => { // need to call setup on testBed again for it to use a newly defined snapshot policies response httpRequestsMockHelpers.setLoadSnapshotPolicies([], { status: 500, body: 'error' }); await act(async () => { - testBed = await setup(); + testBed = await setupDeleteTestBed(); }); - testBed.component.update(); - expect(testBed.find('customPolicyCallout').exists()).toBeFalsy(); - expect(testBed.find('noPoliciesCallout').exists()).toBeFalsy(); - expect(testBed.find('policiesErrorCallout').exists()).toBeTruthy(); + const { component, actions } = testBed; + component.update(); + + expect(actions.delete.hasCustomPolicyCallout()).toBeFalsy(); + expect(actions.delete.hasNoPoliciesCallout()).toBeFalsy(); + expect(actions.delete.hasPolicyErrorCallout()).toBeTruthy(); }); }); }); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts index 982377e2a0365..aaa2b3dafddde 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; +import { TestBed } from '@kbn/test/jest'; import { licensingMock } from '../../../../../licensing/public/mocks'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { initTestBed } from '../init_test_bed'; describe(' frozen phase', () => { - let testBed: EditPolicyTestBed; + let testBed: TestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -28,28 +29,19 @@ describe(' frozen phase', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await initTestBed(); }); const { component } = testBed; component.update(); }); - test('shows timing only when enabled', async () => { - const { actions, exists } = testBed; - - expect(exists('frozen-phase')).toBe(true); - expect(actions.frozen.hasMinAgeInput()).toBeFalsy(); - await actions.togglePhase('frozen'); - expect(actions.frozen.hasMinAgeInput()).toBeTruthy(); - }); - describe('on non-enterprise license', () => { beforeEach(async () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup({ + testBed = await initTestBed({ appServicesContext: { license: licensingMock.createLicense({ license: { type: 'basic' } }), }, diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.helpers.ts index 6b6db2da5946d..384478bcf4c66 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.helpers.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.helpers.ts @@ -5,7 +5,11 @@ * 2.0. */ -import { createNodeAllocationActions, createSavePolicyAction, setReplicas } from '../../../helpers'; +import { + createNodeAllocationActions, + createReplicasAction, + createSavePolicyAction, +} from '../../../helpers'; import { initTestBed } from '../../init_test_bed'; type SetupReturn = ReturnType; @@ -20,7 +24,7 @@ export const setupGeneralNodeAllocation = async () => { actions: { ...createNodeAllocationActions(testBed, 'warm'), savePolicy: createSavePolicyAction(testBed), - setReplicas: (value: string) => setReplicas(testBed, 'warm', value), + ...createReplicasAction(testBed, 'warm'), }, }; }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts index 1cb895e9ac86a..02a700519cb05 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts @@ -6,11 +6,12 @@ */ import { act } from 'react-dom/test-utils'; +import { TestBed } from '@kbn/test/jest'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { initTestBed } from '../init_test_bed'; describe(' request flyout', () => { - let testBed: EditPolicyTestBed; + let testBed: TestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -26,7 +27,7 @@ describe(' request flyout', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await initTestBed(); }); const { component } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.helpers.ts new file mode 100644 index 0000000000000..b15e956c84b4c --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.helpers.ts @@ -0,0 +1,51 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + createForceMergeActions, + createMinAgeActions, + createReadonlyActions, + createRolloverActions, + createSearchableSnapshotActions, + createShrinkActions, + createTogglePhaseAction, +} from '../../helpers'; +import { initTestBed } from '../init_test_bed'; + +type SetupReturn = ReturnType; + +export type RolloverTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupRolloverTestBed = async () => { + const testBed = await initTestBed(); + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + ...createRolloverActions(testBed), + hot: { + ...createForceMergeActions(testBed, 'hot'), + ...createShrinkActions(testBed, 'hot'), + ...createReadonlyActions(testBed, 'hot'), + ...createSearchableSnapshotActions(testBed, 'hot'), + }, + warm: { + ...createMinAgeActions(testBed, 'warm'), + }, + cold: { + ...createMinAgeActions(testBed, 'cold'), + }, + frozen: { + ...createMinAgeActions(testBed, 'frozen'), + }, + delete: { + ...createMinAgeActions(testBed, 'delete'), + }, + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts index 8e9586e52577b..432b07efca038 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts @@ -6,12 +6,11 @@ */ import { act } from 'react-dom/test-utils'; -import { licensingMock } from '../../../../../licensing/public/mocks'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { RolloverTestBed, setupRolloverTestBed } from './rollover.helpers'; describe(' rollover', () => { - let testBed: EditPolicyTestBed; + let testBed: RolloverTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); afterAll(() => { @@ -22,11 +21,7 @@ describe(' rollover', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup({ - appServicesContext: { - license: licensingMock.createLicense({ license: { type: 'enterprise' } }), - }, - }); + testBed = await setupRolloverTestBed(); }); const { component } = testBed; @@ -35,14 +30,14 @@ describe(' rollover', () => { test('shows forcemerge when rollover enabled', async () => { const { actions } = testBed; - expect(actions.hot.forceMergeFieldExists()).toBeTruthy(); + expect(actions.hot.forceMergeExists()).toBeTruthy(); }); test('hides forcemerge when rollover is disabled', async () => { const { actions } = testBed; await actions.rollover.toggleDefault(); await actions.rollover.toggle(); - expect(actions.hot.forceMergeFieldExists()).toBeFalsy(); + expect(actions.hot.forceMergeExists()).toBeFalsy(); }); test('shows shrink input when rollover enabled', async () => { @@ -71,6 +66,8 @@ describe(' rollover', () => { test('hides and disables searchable snapshot field', async () => { const { actions } = testBed; + + expect(actions.hot.searchableSnapshotsExists()).toBeTruthy(); await actions.rollover.toggleDefault(); await actions.rollover.toggle(); await actions.togglePhase('cold'); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.helpers.ts new file mode 100644 index 0000000000000..cdb5dc16d1964 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.helpers.ts @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + createForceMergeActions, + createFreezeActions, + createMinAgeActions, + createReadonlyActions, + createRolloverActions, + createSavePolicyAction, + createSearchableSnapshotActions, + createShrinkActions, + createTogglePhaseAction, +} from '../../helpers'; +import { initTestBed } from '../init_test_bed'; +import { AppServicesContext } from '../../../../public/types'; + +type SetupReturn = ReturnType; + +export type SearchableSnapshotsTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupSearchableSnapshotsTestBed = async (args?: { + appServicesContext?: Partial; +}) => { + const testBed = await initTestBed(args); + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + savePolicy: createSavePolicyAction(testBed), + ...createRolloverActions(testBed), + hot: { + ...createSearchableSnapshotActions(testBed, 'hot'), + ...createForceMergeActions(testBed, 'hot'), + ...createShrinkActions(testBed, 'hot'), + }, + warm: { + ...createForceMergeActions(testBed, 'warm'), + ...createShrinkActions(testBed, 'warm'), + ...createReadonlyActions(testBed, 'warm'), + }, + cold: { + ...createMinAgeActions(testBed, 'cold'), + ...createSearchableSnapshotActions(testBed, 'cold'), + ...createFreezeActions(testBed, 'cold'), + ...createReadonlyActions(testBed, 'cold'), + }, + frozen: { + ...createMinAgeActions(testBed, 'frozen'), + ...createSearchableSnapshotActions(testBed, 'frozen'), + }, + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts index d400966cdae38..66f42d5482fdb 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts @@ -9,10 +9,13 @@ import { act } from 'react-dom/test-utils'; import { licensingMock } from '../../../../../licensing/public/mocks'; import { setupEnvironment } from '../../helpers'; import { getDefaultHotPhasePolicy } from '../constants'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { + SearchableSnapshotsTestBed, + setupSearchableSnapshotsTestBed, +} from './searchable_snapshots.helpers'; describe(' searchable snapshots', () => { - let testBed: EditPolicyTestBed; + let testBed: SearchableSnapshotsTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); afterAll(() => { @@ -23,7 +26,7 @@ describe(' searchable snapshots', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await setupSearchableSnapshotsTestBed(); }); const { component } = testBed; @@ -36,7 +39,7 @@ describe(' searchable snapshots', () => { await actions.togglePhase('warm'); await actions.togglePhase('cold'); - expect(actions.warm.forceMergeFieldExists()).toBeTruthy(); + expect(actions.warm.forceMergeExists()).toBeTruthy(); expect(actions.warm.shrinkExists()).toBeTruthy(); expect(actions.warm.readonlyExists()).toBeTruthy(); expect(actions.cold.searchableSnapshotsExists()).toBeTruthy(); @@ -45,7 +48,7 @@ describe(' searchable snapshots', () => { await actions.hot.setSearchableSnapshot('my-repo'); - expect(actions.warm.forceMergeFieldExists()).toBeFalsy(); + expect(actions.warm.forceMergeExists()).toBeFalsy(); expect(actions.warm.shrinkExists()).toBeFalsy(); expect(actions.warm.readonlyExists()).toBeFalsy(); // searchable snapshot in cold is still visible @@ -60,7 +63,7 @@ describe(' searchable snapshots', () => { await actions.rollover.toggle(); await actions.rollover.toggleDefault(); - expect(actions.hot.forceMergeFieldExists()).toBeTruthy(); + expect(actions.hot.forceMergeExists()).toBeTruthy(); expect(actions.hot.shrinkExists()).toBeTruthy(); expect(actions.hot.searchableSnapshotsExists()).toBeTruthy(); }); @@ -122,7 +125,9 @@ describe(' searchable snapshots', () => { httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] }); await act(async () => { - testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } }); + testBed = await setupSearchableSnapshotsTestBed({ + appServicesContext: { cloud: { isCloudEnabled: true } }, + }); }); const { component } = testBed; @@ -149,7 +154,9 @@ describe(' searchable snapshots', () => { httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['found-snapshots'] }); await act(async () => { - testBed = await setup({ appServicesContext: { cloud: { isCloudEnabled: true } } }); + testBed = await setupSearchableSnapshotsTestBed({ + appServicesContext: { cloud: { isCloudEnabled: true } }, + }); }); const { component } = testBed; @@ -184,7 +191,7 @@ describe(' searchable snapshots', () => { httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['my-repo'] }); await act(async () => { - testBed = await setup({ + testBed = await setupSearchableSnapshotsTestBed({ appServicesContext: { license: licensingMock.createLicense({ license: { type: 'basic' } }), }, diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.helpers.ts new file mode 100644 index 0000000000000..8303fdbac4837 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.helpers.ts @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { createTogglePhaseAction } from '../../helpers'; +import { initTestBed } from '../init_test_bed'; +import { Phase } from '../../../../common/types'; + +type SetupReturn = ReturnType; + +export type TimelineTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupTimelineTestBed = async () => { + const testBed = await initTestBed(); + const { exists } = testBed; + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + timeline: { + hasPhase: (phase: Phase) => exists(`ilmTimelinePhase-${phase}`), + }, + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts index a4f2a24bcee8b..33aeb80b38cae 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts @@ -7,10 +7,10 @@ import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { setupTimelineTestBed, TimelineTestBed } from './timeline.helpers'; describe(' timeline', () => { - let testBed: EditPolicyTestBed; + let testBed: TimelineTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); afterAll(() => { @@ -21,7 +21,7 @@ describe(' timeline', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await setupTimelineTestBed(); }); const { component } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.helpers.ts new file mode 100644 index 0000000000000..57d6f53a21c78 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.helpers.ts @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { createMinAgeActions, createTogglePhaseAction } from '../../helpers'; +import { initTestBed } from '../init_test_bed'; + +type SetupReturn = ReturnType; + +export type TimingTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupTimingTestBed = async () => { + const testBed = await initTestBed(); + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + warm: { + ...createMinAgeActions(testBed, 'warm'), + }, + cold: { + ...createMinAgeActions(testBed, 'cold'), + }, + frozen: { + ...createMinAgeActions(testBed, 'frozen'), + }, + delete: { + ...createMinAgeActions(testBed, 'delete'), + }, + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts new file mode 100644 index 0000000000000..985ee807ed827 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.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 + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { act } from 'react-dom/test-utils'; +import { setupEnvironment } from '../../helpers'; +import { setupTimingTestBed, TimingTestBed } from './timing.helpers'; +import { PhaseWithTiming } from '../../../../common/types'; + +describe(' timing', () => { + let testBed: TimingTestBed; + const { server, httpRequestsMockHelpers } = setupEnvironment(); + + afterAll(() => { + server.restore(); + }); + + beforeEach(async () => { + httpRequestsMockHelpers.setDefaultResponses(); + + await act(async () => { + testBed = await setupTimingTestBed(); + }); + + const { component } = testBed; + component.update(); + }); + + ['warm', 'cold', 'frozen', 'delete'].forEach((phase: string) => { + test(`timing is only shown when ${phase} phase is enabled`, async () => { + const { actions } = testBed; + const phaseWithTiming = phase as PhaseWithTiming; + expect(actions[phaseWithTiming].hasMinAgeInput()).toBeFalsy(); + await actions.togglePhase(phaseWithTiming); + expect(actions[phaseWithTiming].hasMinAgeInput()).toBeTruthy(); + }); + }); +}); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/warm_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/warm_phase.test.ts deleted file mode 100644 index ae9f306483820..0000000000000 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/warm_phase.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { act } from 'react-dom/test-utils'; -import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; - -describe(' warm phase', () => { - let testBed: EditPolicyTestBed; - const { server, httpRequestsMockHelpers } = setupEnvironment(); - - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - server.restore(); - }); - - beforeEach(async () => { - httpRequestsMockHelpers.setDefaultResponses(); - - await act(async () => { - testBed = await setup(); - }); - - const { component } = testBed; - component.update(); - }); - - test('shows timing only when enabled', async () => { - const { actions } = testBed; - expect(actions.warm.hasMinAgeInput()).toBeFalsy(); - await actions.togglePhase('warm'); - expect(actions.warm.hasMinAgeInput()).toBeTruthy(); - }); -}); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts index 9a14571c6ec3b..4725631e6f894 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts @@ -8,10 +8,10 @@ import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; describe(' cold phase validation', () => { - let testBed: EditPolicyTestBed; + let testBed: ValidationTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -35,7 +35,7 @@ describe(' cold phase validation', () => { ]); await act(async () => { - testBed = await setup(); + testBed = await setupValidationTestBed(); }); const { component, actions } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts index 0a047714bd345..1464f683ef766 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts @@ -7,10 +7,10 @@ import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; describe(' error indicators', () => { - let testBed: EditPolicyTestBed; + let testBed: ValidationTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -26,7 +26,7 @@ describe(' error indicators', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await setupValidationTestBed(); }); const { component } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts index 296b128eb8f52..6cbc28ec161f2 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts @@ -8,11 +8,11 @@ import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; describe(' hot phase validation', () => { - let testBed: EditPolicyTestBed; - let actions: EditPolicyTestBed['actions']; + let testBed: ValidationTestBed; + let actions: ValidationTestBed['actions']; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -27,7 +27,7 @@ describe(' hot phase validation', () => { beforeEach(async () => { httpRequestsMockHelpers.setLoadPolicies([]); await act(async () => { - testBed = await setup(); + testBed = await setupValidationTestBed(); }); const { component } = testBed; @@ -159,13 +159,11 @@ describe(' hot phase validation', () => { describe('shrink', () => { test(`doesn't allow 0 for shrink`, async () => { - await actions.hot.toggleShrink(); await actions.hot.setShrink('0'); actions.errors.waitForValidation(); actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for shrink`, async () => { - await actions.hot.toggleShrink(); await actions.hot.setShrink('-1'); actions.errors.waitForValidation(); actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts index 08b794466da49..799fbf89d47df 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts @@ -8,12 +8,12 @@ import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; import { getGeneratedPolicies } from '../constants'; +import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; describe(' policy name validation', () => { - let testBed: EditPolicyTestBed; - let actions: EditPolicyTestBed['actions']; + let testBed: ValidationTestBed; + let actions: ValidationTestBed['actions']; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -29,7 +29,7 @@ describe(' policy name validation', () => { httpRequestsMockHelpers.setLoadPolicies(getGeneratedPolicies()); await act(async () => { - testBed = await setup(); + testBed = await setupValidationTestBed(); }); const { component } = testBed; @@ -56,7 +56,7 @@ describe(' policy name validation', () => { test(`doesn't allow to save as new policy but using the same name`, async () => { await act(async () => { - testBed = await setup({ + testBed = await setupValidationTestBed({ testBedConfig: { memoryRouter: { initialEntries: [`/policies/edit/testy0`], diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts index ac11e8a162e02..be4f99103b319 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts @@ -10,11 +10,11 @@ import { i18nTexts } from '../../../../public/application/sections/edit_policy/i import { PhaseWithTiming } from '../../../../common/types'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; describe(' timing validation', () => { - let testBed: EditPolicyTestBed; - let actions: EditPolicyTestBed['actions']; + let testBed: ValidationTestBed; + let actions: ValidationTestBed['actions']; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -31,7 +31,7 @@ describe(' timing validation', () => { httpRequestsMockHelpers.setLoadPolicies([]); await act(async () => { - testBed = await setup(); + testBed = await setupValidationTestBed(); }); const { component } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/validation.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/validation.helpers.ts new file mode 100644 index 0000000000000..84ee96cd46987 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/validation.helpers.ts @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { TestBedConfig } from '@kbn/test/jest'; +import { + createColdPhaseActions, + createDeletePhaseActions, + createErrorsActions, + createFormSetValueAction, + createFormToggleAction, + createFrozenPhaseActions, + createHotPhaseActions, + createRolloverActions, + createSavePolicyAction, + createTogglePhaseAction, + createWarmPhaseActions, +} from '../../helpers'; +import { initTestBed } from '../init_test_bed'; + +type SetupReturn = ReturnType; + +export type ValidationTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupValidationTestBed = async (arg?: { testBedConfig?: Partial }) => { + const testBed = await initTestBed(arg); + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + setPolicyName: createFormSetValueAction(testBed, 'policyNameField'), + savePolicy: createSavePolicyAction(testBed), + toggleSaveAsNewPolicy: createFormToggleAction(testBed, 'saveAsNewSwitch'), + ...createRolloverActions(testBed), + ...createErrorsActions(testBed), + ...createHotPhaseActions(testBed), + ...createWarmPhaseActions(testBed), + ...createColdPhaseActions(testBed), + ...createFrozenPhaseActions(testBed), + ...createDeletePhaseActions(testBed), + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts index bef99ea8cb891..0b8bfceebfaf4 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts @@ -8,10 +8,10 @@ import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; describe(' warm phase validation', () => { - let testBed: EditPolicyTestBed; + let testBed: ValidationTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -28,7 +28,7 @@ describe(' warm phase validation', () => { httpRequestsMockHelpers.setLoadPolicies([]); await act(async () => { - testBed = await setup(); + testBed = await setupValidationTestBed(); }); const { component, actions } = testBed; @@ -60,7 +60,6 @@ describe(' warm phase validation', () => { describe('shrink', () => { test(`doesn't allow 0 for shrink`, async () => { const { actions } = testBed; - await actions.warm.toggleShrink(); await actions.warm.setShrink('0'); actions.errors.waitForValidation(); @@ -69,7 +68,6 @@ describe(' warm phase validation', () => { }); test(`doesn't allow -1 for shrink`, async () => { const { actions } = testBed; - await actions.warm.toggleShrink(); await actions.warm.setShrink('-1'); actions.errors.waitForValidation(); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.helpers.ts new file mode 100644 index 0000000000000..52d4debca9315 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.helpers.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { AppServicesContext } from '../../../../public/types'; +import { + createColdPhaseActions, + createDeletePhaseActions, + createFormSetValueAction, + createFrozenPhaseActions, + createHotPhaseActions, + createRolloverActions, + createSavePolicyAction, + createTogglePhaseAction, + createWarmPhaseActions, +} from '../../helpers'; +import { initTestBed } from '../init_test_bed'; + +type SetupReturn = ReturnType; + +export type SerializationTestBed = SetupReturn extends Promise ? U : SetupReturn; + +export const setupSerializationTestBed = async (arg?: { + appServicesContext?: Partial; +}) => { + const testBed = await initTestBed(arg); + + return { + ...testBed, + actions: { + togglePhase: createTogglePhaseAction(testBed), + savePolicy: createSavePolicyAction(testBed), + setPolicyName: createFormSetValueAction(testBed, 'policyNameField'), + ...createRolloverActions(testBed), + ...createHotPhaseActions(testBed), + ...createWarmPhaseActions(testBed), + ...createColdPhaseActions(testBed), + ...createFrozenPhaseActions(testBed), + ...createDeletePhaseActions(testBed), + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts index 8c345cf784f9f..6e164cc06681c 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts @@ -13,10 +13,10 @@ import { POLICY_WITH_INCLUDE_EXCLUDE, POLICY_WITH_KNOWN_AND_UNKNOWN_FIELDS, } from '../constants'; -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; +import { SerializationTestBed, setupSerializationTestBed } from './policy_serialization.helpers'; describe(' serialization', () => { - let testBed: EditPolicyTestBed; + let testBed: SerializationTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); afterAll(() => { @@ -27,7 +27,7 @@ describe(' serialization', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component } = testBed; @@ -44,7 +44,7 @@ describe(' serialization', () => { it('preserves policy settings it did not configure', async () => { httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_KNOWN_AND_UNKNOWN_FIELDS]); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component, actions } = testBed; @@ -91,7 +91,7 @@ describe(' serialization', () => { httpRequestsMockHelpers.setLoadPolicies([]); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component, actions } = testBed; @@ -125,7 +125,7 @@ describe(' serialization', () => { httpRequestsMockHelpers.setLoadPolicies([]); await act(async () => { - testBed = await setup({ + testBed = await setupSerializationTestBed({ appServicesContext: { license: licensingMock.createLicense({ license: { type: 'basic' } }), }, @@ -171,10 +171,8 @@ describe(' serialization', () => { await actions.hot.toggleForceMerge(); await actions.hot.setForcemergeSegmentsCount('123'); await actions.hot.setBestCompression(true); - await actions.hot.toggleShrink(); await actions.hot.setShrink('2'); await actions.hot.toggleReadonly(); - await actions.hot.toggleIndexPriority(); await actions.hot.setIndexPriority('123'); await actions.savePolicy(); @@ -243,7 +241,7 @@ describe(' serialization', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component } = testBed; @@ -276,7 +274,6 @@ describe(' serialization', () => { await actions.warm.setDataAllocation('node_attrs'); await actions.warm.setSelectedNodeAttribute('test:123'); await actions.warm.setReplicas('123'); - await actions.warm.toggleShrink(); await actions.warm.setShrink('123'); await actions.warm.toggleForceMerge(); await actions.warm.setForcemergeSegmentsCount('123'); @@ -338,7 +335,7 @@ describe(' serialization', () => { httpRequestsMockHelpers.setLoadSnapshotPolicies([]); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component } = testBed; @@ -375,7 +372,7 @@ describe(' serialization', () => { httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component } = testBed; @@ -504,7 +501,7 @@ describe(' serialization', () => { }); await act(async () => { - testBed = await setup(); + testBed = await setupSerializationTestBed(); }); const { component } = testBed; @@ -534,7 +531,7 @@ describe(' serialization', () => { test('default value', async () => { const { actions } = testBed; await actions.togglePhase('delete'); - await actions.delete.setWaitForSnapshotPolicy('test'); + await actions.delete.setSnapshotPolicy('test'); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; const entirePolicy = JSON.parse(JSON.parse(latestRequest.requestBody).body); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts index a92747a95a2ca..7acc6a3e2f26b 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts @@ -32,9 +32,11 @@ const createExpectMessagesAction = (testBed: TestBed) => ( export const createErrorsActions = (testBed: TestBed) => { const { exists } = testBed; return { - waitForValidation: createWaitForValidationAction(testBed), - haveGlobalCallout: () => exists('policyFormErrorsCallout'), - havePhaseCallout: (phase: Phase) => exists(`phaseErrorIndicator-${phase}`), - expectMessages: createExpectMessagesAction(testBed), + errors: { + waitForValidation: createWaitForValidationAction(testBed), + haveGlobalCallout: () => exists('policyFormErrorsCallout'), + havePhaseCallout: (phase: Phase) => exists(`phaseErrorIndicator-${phase}`), + expectMessages: createExpectMessagesAction(testBed), + }, }; }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts index a7e4983165bac..400f3d2070e6a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts @@ -25,7 +25,7 @@ export const createForceMergeActions = (testBed: TestBed, phase: Phase) => { const { exists } = testBed; const toggleSelector = `${phase}-forceMergeSwitch`; return { - forceMergeFieldExists: () => exists(toggleSelector), + forceMergeExists: () => exists(toggleSelector), toggleForceMerge: createFormToggleAction(testBed, toggleSelector), setForcemergeSegmentsCount: createFormSetValueAction( testBed, diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_replicas_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_and_set_value_action.ts similarity index 57% rename from x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_replicas_action.ts rename to x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_and_set_value_action.ts index b07d7783379fb..643e0f23a9dea 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_replicas_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_and_set_value_action.ts @@ -6,16 +6,17 @@ */ import { TestBed } from '@kbn/test/jest'; - -import { Phase } from '../../../../common/types'; import { createFormToggleAction } from './form_toggle_action'; import { createFormSetValueAction } from './form_set_value_action'; -export const setReplicas = async (testBed: TestBed, phase: Phase, value: string) => { +export const createFormToggleAndSetValueAction = ( + testBed: TestBed, + toggleSelector: string, + inputSelector: string +) => async (value: string) => { const { exists } = testBed; - - if (!exists(`${phase}-selectedReplicaCount`)) { - await createFormToggleAction(testBed, `${phase}-setReplicasSwitch`)(); + if (!exists(inputSelector)) { + await createFormToggleAction(testBed, toggleSelector)(); } - await createFormSetValueAction(testBed, `${phase}-selectedReplicaCount`)(value); + await createFormSetValueAction(testBed, inputSelector)(value); }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index.ts index 7366bf2f35c70..acfaee3c236e9 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index.ts @@ -7,17 +7,25 @@ export { createNodeAllocationActions } from './node_allocation_actions'; export { createTogglePhaseAction } from './toggle_phase_action'; -export { setReplicas } from './set_replicas_action'; +export { createReplicasAction } from './replicas_action'; export { createSavePolicyAction } from './save_policy_action'; export { createFormToggleAction } from './form_toggle_action'; export { createFormSetValueAction } from './form_set_value_action'; +export { createFormToggleAndSetValueAction } from './form_toggle_and_set_value_action'; export { createSearchableSnapshotActions } from './searchable_snapshot_actions'; export { createErrorsActions } from './errors_actions'; export { createRolloverActions } from './rollover_actions'; -export { createSetWaitForSnapshotAction } from './set_wait_for_snapshot_action'; +export { createSnapshotPolicyActions } from './snapshot_policy_actions'; export { createMinAgeActions } from './min_age_actions'; export { createForceMergeActions } from './forcemerge_actions'; export { createReadonlyActions } from './readonly_actions'; export { createIndexPriorityActions } from './index_priority_actions'; export { createShrinkActions } from './shrink_actions'; export { createFreezeActions } from './freeze_actions'; +export { + createHotPhaseActions, + createWarmPhaseActions, + createColdPhaseActions, + createFrozenPhaseActions, + createDeletePhaseActions, +} from './phases'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index_priority_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index_priority_actions.ts index 3b48da2a0c69f..eeab42c408244 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index_priority_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index_priority_actions.ts @@ -8,7 +8,7 @@ import { TestBed } from '@kbn/test/jest'; import { Phase } from '../../../../common/types'; import { createFormToggleAction } from './form_toggle_action'; -import { createFormSetValueAction } from './form_set_value_action'; +import { createFormToggleAndSetValueAction } from './form_toggle_and_set_value_action'; export const createIndexPriorityActions = (testBed: TestBed, phase: Phase) => { const { exists } = testBed; @@ -16,6 +16,10 @@ export const createIndexPriorityActions = (testBed: TestBed, phase: Phase) => { return { indexPriorityExists: () => exists(toggleSelector), toggleIndexPriority: createFormToggleAction(testBed, toggleSelector), - setIndexPriority: createFormSetValueAction(testBed, `${phase}-indexPriority`), + setIndexPriority: createFormToggleAndSetValueAction( + testBed, + toggleSelector, + `${phase}-indexPriority` + ), }; }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/phases.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/phases.ts new file mode 100644 index 0000000000000..18cc0f01ca06c --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/phases.ts @@ -0,0 +1,76 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { TestBed } from '@kbn/test/jest'; +import { + createForceMergeActions, + createShrinkActions, + createReadonlyActions, + createIndexPriorityActions, + createSearchableSnapshotActions, + createMinAgeActions, + createNodeAllocationActions, + createReplicasAction, + createFreezeActions, + createSnapshotPolicyActions, +} from './'; + +export const createHotPhaseActions = (testBed: TestBed) => { + return { + hot: { + ...createForceMergeActions(testBed, 'hot'), + ...createShrinkActions(testBed, 'hot'), + ...createReadonlyActions(testBed, 'hot'), + ...createIndexPriorityActions(testBed, 'hot'), + ...createSearchableSnapshotActions(testBed, 'hot'), + }, + }; +}; +export const createWarmPhaseActions = (testBed: TestBed) => { + return { + warm: { + ...createMinAgeActions(testBed, 'warm'), + ...createForceMergeActions(testBed, 'warm'), + ...createShrinkActions(testBed, 'warm'), + ...createReadonlyActions(testBed, 'warm'), + ...createIndexPriorityActions(testBed, 'warm'), + ...createNodeAllocationActions(testBed, 'warm'), + ...createReplicasAction(testBed, 'warm'), + }, + }; +}; +export const createColdPhaseActions = (testBed: TestBed) => { + return { + cold: { + ...createMinAgeActions(testBed, 'cold'), + ...createReplicasAction(testBed, 'cold'), + ...createReadonlyActions(testBed, 'cold'), + ...createFreezeActions(testBed, 'cold'), + ...createIndexPriorityActions(testBed, 'cold'), + ...createNodeAllocationActions(testBed, 'cold'), + ...createSearchableSnapshotActions(testBed, 'cold'), + }, + }; +}; + +export const createFrozenPhaseActions = (testBed: TestBed) => { + return { + frozen: { + ...createMinAgeActions(testBed, 'frozen'), + ...createSearchableSnapshotActions(testBed, 'frozen'), + }, + }; +}; + +export const createDeletePhaseActions = (testBed: TestBed) => { + return { + delete: { + ...createMinAgeActions(testBed, 'delete'), + ...createSnapshotPolicyActions(testBed), + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/replicas_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/replicas_action.ts new file mode 100644 index 0000000000000..f987ce6d0ca2f --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/replicas_action.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { TestBed } from '@kbn/test/jest'; +import { Phase } from '../../../../common/types'; +import { createFormToggleAndSetValueAction } from './form_toggle_and_set_value_action'; + +export const createReplicasAction = (testBed: TestBed, phase: Phase) => { + return { + setReplicas: createFormToggleAndSetValueAction( + testBed, + `${phase}-setReplicasSwitch`, + `${phase}-selectedReplicaCount` + ), + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts index daf4db7fab278..6d05f3d63f577 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts @@ -53,12 +53,14 @@ const createSetMaxSizeAction = (testBed: TestBed) => async (value: string, units export const createRolloverActions = (testBed: TestBed) => { const { exists } = testBed; return { - toggle: createFormToggleAction(testBed, 'rolloverSwitch'), - toggleDefault: createFormToggleAction(testBed, 'useDefaultRolloverSwitch'), - setMaxPrimaryShardSize: createSetPrimaryShardSizeAction(testBed), - setMaxDocs: createFormSetValueAction(testBed, 'hot-selectedMaxDocuments'), - setMaxAge: createSetMaxAgeAction(testBed), - setMaxSize: createSetMaxSizeAction(testBed), - hasSettingRequiredCallout: (): boolean => exists('rolloverSettingsRequired'), + rollover: { + toggle: createFormToggleAction(testBed, 'rolloverSwitch'), + toggleDefault: createFormToggleAction(testBed, 'useDefaultRolloverSwitch'), + setMaxPrimaryShardSize: createSetPrimaryShardSizeAction(testBed), + setMaxDocs: createFormSetValueAction(testBed, 'hot-selectedMaxDocuments'), + setMaxAge: createSetMaxAgeAction(testBed), + setMaxSize: createSetMaxSizeAction(testBed), + hasSettingRequiredCallout: (): boolean => exists('rolloverSettingsRequired'), + }, }; }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_wait_for_snapshot_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_wait_for_snapshot_action.ts deleted file mode 100644 index a0bc9da8d3063..0000000000000 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_wait_for_snapshot_action.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { act } from 'react-dom/test-utils'; -import { TestBed } from '@kbn/test/jest'; - -export const createSetWaitForSnapshotAction = (testBed: TestBed) => async ( - snapshotPolicyName: string -) => { - const { find, component } = testBed; - act(() => { - find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]); - }); - component.update(); -}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts index 0531850384124..29c3e4a04a9a1 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts @@ -7,15 +7,17 @@ import { TestBed } from '@kbn/test/jest'; import { Phase } from '../../../../common/types'; -import { createFormToggleAction } from './form_toggle_action'; -import { createFormSetValueAction } from './form_set_value_action'; +import { createFormToggleAndSetValueAction } from './form_toggle_and_set_value_action'; export const createShrinkActions = (testBed: TestBed, phase: Phase) => { const { exists } = testBed; const toggleSelector = `${phase}-shrinkSwitch`; return { shrinkExists: () => exists(toggleSelector), - toggleShrink: createFormToggleAction(testBed, toggleSelector), - setShrink: createFormSetValueAction(testBed, `${phase}-primaryShardCount`), + setShrink: createFormToggleAndSetValueAction( + testBed, + toggleSelector, + `${phase}-primaryShardCount` + ), }; }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts new file mode 100644 index 0000000000000..0a49c3cf295bd --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { TestBed } from '@kbn/test/target/types/jest'; +import { act } from 'react-dom/test-utils'; + +const createSetWaitForSnapshotAction = (testBed: TestBed) => async (snapshotPolicyName: string) => { + const { find, component } = testBed; + act(() => { + find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]); + }); + component.update(); +}; + +export const createSnapshotPolicyActions = (testBed: TestBed) => { + const { exists } = testBed; + return { + setSnapshotPolicy: createSetWaitForSnapshotAction(testBed), + hasCustomPolicyCallout: () => exists('customPolicyCallout'), + hasPolicyErrorCallout: () => exists('policiesErrorCallout'), + hasNoPoliciesCallout: () => exists('noPoliciesCallout'), + }; +};