diff --git a/packages/kbn-test/src/jest/utils/testbed/types.ts b/packages/kbn-test/src/jest/utils/testbed/types.ts index 520a78d03d701..fdc000215c4f1 100644 --- a/packages/kbn-test/src/jest/utils/testbed/types.ts +++ b/packages/kbn-test/src/jest/utils/testbed/types.ts @@ -121,7 +121,7 @@ export interface TestBed { * * @param switchTestSubject The test subject of the EuiSwitch (can be a nested path. e.g. "myForm.mySwitch"). */ - toggleEuiSwitch: (switchTestSubject: T, isChecked?: boolean) => void; + toggleEuiSwitch: (switchTestSubject: T) => void; /** * The EUI ComboBox is a special input as it needs the ENTER key to be pressed * in order to register the value set. This helpers automatically does that. 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 index 67a978bb08471..58da73942000d 100644 --- 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 @@ -5,20 +5,29 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; import { TestBedConfig } from '@kbn/test/jest'; - import { AppServicesContext } from '../../../public/types'; import { Phase, - createEnablePhaseAction, createNodeAllocationActions, createFormToggleAction, createFormSetValueAction, setReplicas, - savePolicy, + createSearchableSnapshotActions, + createTogglePhaseAction, + createSavePolicyAction, + createErrorsActions, + createRolloverActions, + createSetWaitForSnapshotAction, + createMinAgeActions, + createShrinkActions, + createFreezeActions, + createForceMergeActions, + createReadonlyActions, + createIndexPriorityActions, } from '../helpers'; + import { initTestBed } from './init_test_bed'; type SetupReturn = ReturnType; @@ -30,242 +39,57 @@ export const setup = async (arg?: { }) => { const testBed = await initTestBed(arg); - const { find, component, form, exists } = testBed; - - const createFormCheckboxAction = (dataTestSubject: string) => async (checked: boolean) => { - await act(async () => { - form.selectCheckBox(dataTestSubject, checked); - }); - component.update(); - }; - - const setWaitForSnapshotPolicy = async (snapshotPolicyName: string) => { - act(() => { - find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]); - }); - component.update(); - }; - - const toggleDefaultRollover = createFormToggleAction(testBed, 'useDefaultRolloverSwitch'); - - const toggleRollover = createFormToggleAction(testBed, 'rolloverSwitch'); - - const setMaxPrimaryShardSize = async (value: string, units?: string) => { - await act(async () => { - find('hot-selectedMaxPrimaryShardSize').simulate('change', { target: { value } }); - if (units) { - find('hot-selectedMaxPrimaryShardSize.select').simulate('change', { - target: { value: units }, - }); - } - }); - component.update(); - }; - - const setMaxSize = async (value: string, units?: string) => { - await act(async () => { - find('hot-selectedMaxSizeStored').simulate('change', { target: { value } }); - if (units) { - find('hot-selectedMaxSizeStoredUnits.select').simulate('change', { - target: { value: units }, - }); - } - }); - component.update(); - }; - - const setMaxDocs = createFormSetValueAction(testBed, 'hot-selectedMaxDocuments'); - - const setMaxAge = async (value: string, units?: string) => { - await act(async () => { - find('hot-selectedMaxAge').simulate('change', { target: { value } }); - if (units) { - find('hot-selectedMaxAgeUnits.select').simulate('change', { target: { value: units } }); - } - }); - component.update(); - }; - - const createForceMergeActions = (phase: Phase) => { - const toggleSelector = `${phase}-forceMergeSwitch`; - return { - forceMergeFieldExists: () => exists(toggleSelector), - toggleForceMerge: createFormToggleAction(testBed, toggleSelector), - setForcemergeSegmentsCount: createFormSetValueAction( - testBed, - `${phase}-selectedForceMergeSegments` - ), - setBestCompression: createFormCheckboxAction(`${phase}-bestCompression`), - }; - }; - - const createIndexPriorityActions = (phase: Phase) => { - const toggleSelector = `${phase}-indexPrioritySwitch`; - return { - indexPriorityExists: () => exists(toggleSelector), - toggleIndexPriority: createFormToggleAction(testBed, toggleSelector), - setIndexPriority: createFormSetValueAction(testBed, `${phase}-indexPriority`), - }; - }; - - const createMinAgeActions = (phase: Phase) => { - return { - hasMinAgeInput: () => exists(`${phase}-selectedMinimumAge`), - setMinAgeValue: createFormSetValueAction(testBed, `${phase}-selectedMinimumAge`), - setMinAgeUnits: createFormSetValueAction(testBed, `${phase}-selectedMinimumAgeUnits`), - hasRolloverTipOnMinAge: () => exists(`${phase}-rolloverMinAgeInputIconTip`), - }; - }; - - const createShrinkActions = (phase: Phase) => { - const toggleSelector = `${phase}-shrinkSwitch`; - return { - shrinkExists: () => exists(toggleSelector), - toggleShrink: createFormToggleAction(testBed, toggleSelector), - setShrink: createFormSetValueAction(testBed, `${phase}-primaryShardCount`), - }; - }; - - const createSetFreeze = (phase: Phase) => - createFormToggleAction(testBed, `${phase}-freezeSwitch`); - const createFreezeExists = (phase: Phase) => () => exists(`${phase}-freezeSwitch`); - - const createReadonlyActions = (phase: Phase) => { - const toggleSelector = `${phase}-readonlySwitch`; - return { - readonlyExists: () => exists(toggleSelector), - toggleReadonly: createFormToggleAction(testBed, toggleSelector), - }; - }; - - const createSearchableSnapshotActions = (phase: Phase) => { - const fieldSelector = `searchableSnapshotField-${phase}`; - const licenseCalloutSelector = `${fieldSelector}.searchableSnapshotDisabledDueToLicense`; - const toggleSelector = `${fieldSelector}.searchableSnapshotToggle`; - - const toggleSearchableSnapshot = createFormToggleAction(testBed, toggleSelector); - return { - searchableSnapshotDisabled: () => - exists(licenseCalloutSelector) && find(licenseCalloutSelector).props().disabled === true, - searchableSnapshotsExists: () => exists(fieldSelector), - findSearchableSnapshotToggle: () => find(toggleSelector), - searchableSnapshotDisabledDueToLicense: () => - exists(`${fieldSelector}.searchableSnapshotDisabledDueToLicense`), - toggleSearchableSnapshot, - setSearchableSnapshot: async (value: string) => { - if (!exists(`searchableSnapshotField-${phase}.searchableSnapshotCombobox`)) { - await toggleSearchableSnapshot(true); - } - act(() => { - find(`searchableSnapshotField-${phase}.searchableSnapshotCombobox`).simulate('change', [ - { label: value }, - ]); - }); - component.update(); - }, - }; - }; - - const enableDeletePhase = async (isEnabled: boolean) => { - const buttonSelector = isEnabled ? 'enableDeletePhaseButton' : 'disableDeletePhaseButton'; - await act(async () => { - find(buttonSelector).simulate('click'); - }); - component.update(); - }; - - const hasRolloverSettingRequiredCallout = (): boolean => exists('rolloverSettingsRequired'); - - const expectErrorMessages = (expectedMessages: string[]) => { - const errorMessages = component.find('.euiFormErrorText'); - expect(errorMessages.length).toBe(expectedMessages.length); - expectedMessages.forEach((expectedErrorMessage) => { - let foundErrorMessage; - for (let i = 0; i < errorMessages.length; i++) { - if (errorMessages.at(i).text() === expectedErrorMessage) { - foundErrorMessage = true; - } - } - expect(foundErrorMessage).toBe(true); - }); - }; - - /* - * We rely on a setTimeout (dedounce) to display error messages under the form fields. - * This handler runs all the timers so we can assert for errors in our tests. - */ - const runTimers = () => { - act(() => { - jest.runAllTimers(); - }); - component.update(); - }; + const { exists } = testBed; return { ...testBed, - runTimers, actions: { - saveAsNewPolicy: createFormToggleAction(testBed, 'saveAsNewSwitch'), + togglePhase: createTogglePhaseAction(testBed), + savePolicy: createSavePolicyAction(testBed), + toggleSaveAsNewPolicy: createFormToggleAction(testBed, 'saveAsNewSwitch'), setPolicyName: createFormSetValueAction(testBed, 'policyNameField'), - setWaitForSnapshotPolicy, - savePolicy: () => savePolicy(testBed), - hasGlobalErrorCallout: () => exists('policyFormErrorsCallout'), - expectErrorMessages, + errors: { + ...createErrorsActions(testBed), + }, timeline: { - hasHotPhase: () => exists('ilmTimelineHotPhase'), - hasWarmPhase: () => exists('ilmTimelineWarmPhase'), - hasColdPhase: () => exists('ilmTimelineColdPhase'), - hasFrozenPhase: () => exists('ilmTimelineFrozenPhase'), - hasDeletePhase: () => exists('ilmTimelineDeletePhase'), + hasPhase: (phase: Phase) => exists(`ilmTimelinePhase-${phase}`), + }, + rollover: { + ...createRolloverActions(testBed), }, hot: { - setMaxSize, - setMaxDocs, - setMaxAge, - setMaxPrimaryShardSize, - toggleRollover, - toggleDefaultRollover, - hasRolloverSettingRequiredCallout, - hasErrorIndicator: () => exists('phaseErrorIndicator-hot'), - ...createForceMergeActions('hot'), - ...createIndexPriorityActions('hot'), - ...createShrinkActions('hot'), - ...createReadonlyActions('hot'), - ...createSearchableSnapshotActions('hot'), + ...createForceMergeActions(testBed, 'hot'), + ...createIndexPriorityActions(testBed, 'hot'), + ...createShrinkActions(testBed, 'hot'), + ...createReadonlyActions(testBed, 'hot'), + ...createSearchableSnapshotActions(testBed, 'hot'), }, warm: { - enable: createEnablePhaseAction(testBed, 'warm'), - ...createMinAgeActions('warm'), + ...createMinAgeActions(testBed, 'warm'), setReplicas: (value: string) => setReplicas(testBed, 'warm', value), - hasErrorIndicator: () => exists('phaseErrorIndicator-warm'), - ...createShrinkActions('warm'), - ...createForceMergeActions('warm'), - ...createReadonlyActions('warm'), - ...createIndexPriorityActions('warm'), + ...createShrinkActions(testBed, 'warm'), + ...createForceMergeActions(testBed, 'warm'), + ...createReadonlyActions(testBed, 'warm'), + ...createIndexPriorityActions(testBed, 'warm'), ...createNodeAllocationActions(testBed, 'warm'), }, cold: { - enable: createEnablePhaseAction(testBed, 'cold'), - ...createMinAgeActions('cold'), + ...createMinAgeActions(testBed, 'cold'), setReplicas: (value: string) => setReplicas(testBed, 'cold', value), - setFreeze: createSetFreeze('cold'), - freezeExists: createFreezeExists('cold'), - ...createReadonlyActions('cold'), - hasErrorIndicator: () => exists('phaseErrorIndicator-cold'), - ...createIndexPriorityActions('cold'), - ...createSearchableSnapshotActions('cold'), + ...createFreezeActions(testBed, 'cold'), + ...createReadonlyActions(testBed, 'cold'), + ...createIndexPriorityActions(testBed, 'cold'), + ...createSearchableSnapshotActions(testBed, 'cold'), ...createNodeAllocationActions(testBed, 'cold'), }, frozen: { - enable: createEnablePhaseAction(testBed, 'frozen'), - ...createMinAgeActions('frozen'), - hasErrorIndicator: () => exists('phaseErrorIndicator-frozen'), - ...createSearchableSnapshotActions('frozen'), + ...createMinAgeActions(testBed, 'frozen'), + ...createSearchableSnapshotActions(testBed, 'frozen'), }, delete: { - isShown: () => exists('delete-phaseContent'), - enable: enableDeletePhase, - ...createMinAgeActions('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 index dfb7411eb941f..e5e4267b6270c 100644 --- 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 @@ -8,7 +8,6 @@ import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers/setup_environment'; import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; -import { getDefaultHotPhasePolicy } from '../constants'; describe(' cold phase', () => { let testBed: EditPolicyTestBed; @@ -24,16 +23,7 @@ describe(' cold phase', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: { data: ['node1'] }, - nodesByAttributes: { 'attribute:true': ['node1'] }, - isUsingDeprecatedDataRoleConfig: true, - }); - httpRequestsMockHelpers.setNodesDetails('attribute:true', [ - { nodeId: 'testNodeId', stats: { name: 'testNodeName', host: 'testHost' } }, - ]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -46,7 +36,7 @@ describe(' cold phase', () => { test('shows timing only when enabled', async () => { const { actions } = testBed; expect(actions.cold.hasMinAgeInput()).toBeFalsy(); - await actions.cold.enable(true); + 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.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts index 0d49024ac6d67..6403cfead8bd0 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 @@ -50,8 +50,10 @@ describe(' delete phase', () => { component.update(); expect(actions.delete.isShown()).toBeFalsy(); - await actions.delete.enable(true); + await actions.togglePhase('delete'); expect(actions.delete.isShown()).toBeTruthy(); + await actions.togglePhase('delete'); + expect(actions.delete.isShown()).toBeFalsy(); }); test('shows timing after it was enabled', async () => { @@ -65,7 +67,7 @@ describe(' delete phase', () => { component.update(); expect(actions.delete.hasMinAgeInput()).toBeFalsy(); - await actions.delete.enable(true); + await actions.togglePhase('delete'); expect(actions.delete.hasMinAgeInput()).toBeTruthy(); }); @@ -81,7 +83,7 @@ describe(' delete phase', () => { test('updates snapshot policy name', async () => { const { actions } = testBed; - await actions.setWaitForSnapshotPolicy(NEW_SNAPSHOT_POLICY_NAME); + await actions.delete.setWaitForSnapshotPolicy(NEW_SNAPSHOT_POLICY_NAME); await actions.savePolicy(); const expected = { @@ -109,7 +111,7 @@ describe(' delete phase', () => { test('shows a callout when the input is not an existing policy', async () => { const { actions } = testBed; - await actions.setWaitForSnapshotPolicy('my_custom_policy'); + 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(); @@ -118,7 +120,7 @@ describe(' delete phase', () => { test('removes the action if field is empty', async () => { const { actions } = testBed; - await actions.setWaitForSnapshotPolicy(''); + await actions.delete.setWaitForSnapshotPolicy(''); await actions.savePolicy(); const expected = { 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 3103a4198fc3b..3736e9c43e269 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 @@ -10,7 +10,6 @@ import { act } from 'react-dom/test-utils'; import { licensingMock } from '../../../../../licensing/public/mocks'; import { setupEnvironment } from '../../helpers/setup_environment'; import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; -import { getDefaultHotPhasePolicy } from '../constants'; describe(' frozen phase', () => { let testBed: EditPolicyTestBed; @@ -26,16 +25,7 @@ describe(' frozen phase', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: { data: ['node1'] }, - nodesByAttributes: { 'attribute:true': ['node1'] }, - isUsingDeprecatedDataRoleConfig: true, - }); - httpRequestsMockHelpers.setNodesDetails('attribute:true', [ - { nodeId: 'testNodeId', stats: { name: 'testNodeName', host: 'testHost' } }, - ]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -50,19 +40,13 @@ describe(' frozen phase', () => { expect(exists('frozen-phase')).toBe(true); expect(actions.frozen.hasMinAgeInput()).toBeFalsy(); - await actions.frozen.enable(true); + await actions.togglePhase('frozen'); expect(actions.frozen.hasMinAgeInput()).toBeTruthy(); }); describe('on non-enterprise license', () => { beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - isUsingDeprecatedDataRoleConfig: false, - nodesByAttributes: { test: ['123'] }, - nodesByRoles: { data: ['123'] }, - }); - httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['my-repo'] }); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup({ diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.helpers.ts index ba376f9cddd93..9741ee87bda10 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.helpers.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.helpers.ts @@ -8,7 +8,7 @@ import { TestBedConfig } from '@kbn/test/jest'; import { AppServicesContext } from '../../../../../public/types'; -import { createEnablePhaseAction, createNodeAllocationActions } from '../../../helpers'; +import { createTogglePhaseAction, createNodeAllocationActions } from '../../../helpers'; import { initTestBed } from '../../init_test_bed'; type SetupReturn = ReturnType; @@ -24,12 +24,11 @@ export const setupCloudNodeAllocation = async (arg?: { return { ...testBed, actions: { + togglePhase: createTogglePhaseAction(testBed), warm: { - enable: createEnablePhaseAction(testBed, 'warm'), ...createNodeAllocationActions(testBed, 'warm'), }, cold: { - enable: createEnablePhaseAction(testBed, 'cold'), ...createNodeAllocationActions(testBed, 'cold'), }, }, diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts index 06b667f666808..7ca68bd76759e 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts @@ -67,7 +67,7 @@ describe(' node allocation cloud-aware behavior', () => { const { actions, component, exists } = testBed; component.update(); - await actions.warm.enable(true); + await actions.togglePhase('warm'); expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy(); // Assert that default, custom and 'none' options exist @@ -91,7 +91,7 @@ describe(' node allocation cloud-aware behavior', () => { const { actions, component, exists, find } = testBed; component.update(); - await actions.warm.enable(true); + await actions.togglePhase('warm'); expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy(); // Assert that custom and 'none' options exist @@ -115,7 +115,7 @@ describe(' node allocation cloud-aware behavior', () => { testBed.component.update(); const { actions, component, exists, find } = testBed; - await actions.warm.enable(true); + await actions.togglePhase('warm'); expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy(); await actions.warm.openNodeAttributesSection(); @@ -137,8 +137,8 @@ describe(' node allocation cloud-aware behavior', () => { testBed.component.update(); const { actions, component, exists } = testBed; - await actions.warm.enable(true); - await actions.cold.enable(true); + await actions.togglePhase('warm'); + await actions.togglePhase('cold'); expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy(); expect(exists('cloudDataTierCallout')).toBeFalsy(); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.helpers.ts index 52593e67df768..9848915f8feb9 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.helpers.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { createEnablePhaseAction, createNodeAllocationActions } from '../../../helpers'; +import { createNodeAllocationActions, createTogglePhaseAction } from '../../../helpers'; import { initTestBed } from '../../init_test_bed'; type SetupReturn = ReturnType; @@ -18,7 +18,7 @@ export const setupColdPhaseNodeAllocation = async () => { return { ...testBed, actions: { - enable: createEnablePhaseAction(testBed, 'cold'), + toggleColdPhase: () => createTogglePhaseAction(testBed)('cold'), ...createNodeAllocationActions(testBed, 'cold'), }, }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts index f833c8e316117..3b968c1dca4ab 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts @@ -56,7 +56,7 @@ describe(' node allocation in the cold phase', () => { const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeFalsy(); expect(actions.hasWillUseFallbackTierNotice()).toBeFalsy(); @@ -67,7 +67,7 @@ describe(' node allocation in the cold phase', () => { server.respondImmediately = false; const { actions } = testBed; - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeTruthy(); expect(actions.hasDataTierAllocationControls()).toBeTruthy(); @@ -83,7 +83,7 @@ describe(' node allocation in the cold phase', () => { describe('and some are defined', () => { test('shows the node attributes input', async () => { const { actions } = testBed; - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeFalsy(); await actions.setDataAllocation('node_attrs'); @@ -95,7 +95,7 @@ describe(' node allocation in the cold phase', () => { test('shows view node attributes link when an attribute is selected and shows flyout when clicked', async () => { const { actions } = testBed; - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeFalsy(); await actions.setDataAllocation('node_attrs'); @@ -116,7 +116,7 @@ describe(' node allocation in the cold phase', () => { await setup(); const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeFalsy(); await actions.setDataAllocation('node_attrs'); @@ -186,7 +186,7 @@ describe(' node allocation in the cold phase', () => { const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeFalsy(); expect(actions.hasNoTiersAvailableNotice()).toBeTruthy(); @@ -213,7 +213,7 @@ describe(' node allocation in the cold phase', () => { const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.toggleColdPhase(); expect(actions.isAllocationLoading()).toBeFalsy(); expect(actions.hasWillUseFallbackTierNotice()).toBeTruthy(); 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 8dd5a75ac0d22..6b6db2da5946d 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,7 @@ * 2.0. */ -import { createNodeAllocationActions, savePolicy, setReplicas } from '../../../helpers'; +import { createNodeAllocationActions, createSavePolicyAction, setReplicas } from '../../../helpers'; import { initTestBed } from '../../init_test_bed'; type SetupReturn = ReturnType; @@ -19,7 +19,7 @@ export const setupGeneralNodeAllocation = async () => { ...testBed, actions: { ...createNodeAllocationActions(testBed, 'warm'), - savePolicy: () => savePolicy(testBed), + savePolicy: createSavePolicyAction(testBed), setReplicas: (value: string) => setReplicas(testBed, 'warm', value), }, }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.helpers.ts index e39629da79cd8..5c576ebf74ccb 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.helpers.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { createNodeAllocationActions, createEnablePhaseAction } from '../../../helpers'; +import { createNodeAllocationActions, createTogglePhaseAction } from '../../../helpers'; import { initTestBed } from '../../init_test_bed'; type SetupReturn = ReturnType; @@ -18,7 +18,7 @@ export const setupWarmPhaseNodeAllocation = async () => { return { ...testBed, actions: { - enable: createEnablePhaseAction(testBed, 'warm'), + togglePhase: () => createTogglePhaseAction(testBed)('warm'), ...createNodeAllocationActions(testBed, 'warm'), }, }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts index 0ab18c6e05736..1a1ed988d266e 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts @@ -56,7 +56,7 @@ describe(' node allocation in the warm phase', () => { const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeFalsy(); expect(actions.hasDefaultAllocationBehaviorNotice()).toBeFalsy(); @@ -67,7 +67,7 @@ describe(' node allocation in the warm phase', () => { server.respondImmediately = false; const { actions } = testBed; - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeTruthy(); expect(actions.hasDataTierAllocationControls()).toBeTruthy(); @@ -83,7 +83,7 @@ describe(' node allocation in the warm phase', () => { describe('and some are defined', () => { test('shows the node attributes input', async () => { const { actions } = testBed; - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeFalsy(); await actions.setDataAllocation('node_attrs'); @@ -94,7 +94,7 @@ describe(' node allocation in the warm phase', () => { test('shows view node attributes link when an attribute is selected and shows flyout when clicked', async () => { const { actions } = testBed; - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeFalsy(); await actions.setDataAllocation('node_attrs'); @@ -115,7 +115,7 @@ describe(' node allocation in the warm phase', () => { await setup(); const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeFalsy(); await actions.setDataAllocation('node_attrs'); @@ -185,7 +185,7 @@ describe(' node allocation in the warm phase', () => { const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeFalsy(); expect(actions.hasNoTiersAvailableNotice()).toBeTruthy(); @@ -202,7 +202,7 @@ describe(' node allocation in the warm phase', () => { const { actions, component } = testBed; component.update(); - await actions.enable(true); + await actions.togglePhase(); expect(actions.isAllocationLoading()).toBeFalsy(); expect(actions.hasWillUseFallbackTierNotice()).toBeTruthy(); 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 fbd0152e19cc4..de9a1b403ad33 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 @@ -8,7 +8,6 @@ import { act } from 'react-dom/test-utils'; import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; import { setupEnvironment } from '../../helpers/setup_environment'; -import { getDefaultHotPhasePolicy } from '../constants'; describe(' request flyout', () => { let testBed: EditPolicyTestBed; @@ -24,7 +23,7 @@ describe(' request flyout', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); 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 ad4d67826b1ed..b58fe4086c7f0 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 @@ -5,11 +5,10 @@ * 2.0. */ -import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; -import { setupEnvironment } from '../../helpers/setup_environment'; -import { getDefaultHotPhasePolicy } from '../constants'; import { act } from 'react-dom/test-utils'; import { licensingMock } from '../../../../../licensing/public/mocks'; +import { setupEnvironment } from '../../helpers/setup_environment'; +import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; describe(' rollover', () => { let testBed: EditPolicyTestBed; @@ -20,14 +19,7 @@ describe(' rollover', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); - httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['abc'] }); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup({ @@ -48,8 +40,8 @@ describe(' rollover', () => { test('hides forcemerge when rollover is disabled', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); expect(actions.hot.forceMergeFieldExists()).toBeFalsy(); }); @@ -60,8 +52,8 @@ describe(' rollover', () => { test('hides shrink input when rollover is disabled', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); expect(actions.hot.shrinkExists()).toBeFalsy(); }); @@ -72,16 +64,16 @@ describe(' rollover', () => { test('hides readonly input when rollover is disabled', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); expect(actions.hot.readonlyExists()).toBeFalsy(); }); test('hides and disables searchable snapshot field', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); - await actions.cold.enable(true); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); + await actions.togglePhase('cold'); expect(actions.hot.searchableSnapshotsExists()).toBeFalsy(); }); @@ -89,10 +81,10 @@ describe(' rollover', () => { test('shows rollover tip on minimum age', async () => { const { actions } = testBed; - await actions.warm.enable(true); - await actions.cold.enable(true); - await actions.frozen.enable(true); - await actions.delete.enable(true); + await actions.togglePhase('warm'); + await actions.togglePhase('cold'); + await actions.togglePhase('frozen'); + await actions.togglePhase('delete'); expect(actions.warm.hasRolloverTipOnMinAge()).toBeTruthy(); expect(actions.cold.hasRolloverTipOnMinAge()).toBeTruthy(); @@ -102,13 +94,13 @@ describe(' rollover', () => { test('hiding rollover tip on minimum age', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); - await actions.warm.enable(true); - await actions.cold.enable(true); - await actions.frozen.enable(true); - await actions.delete.enable(true); + await actions.togglePhase('warm'); + await actions.togglePhase('cold'); + await actions.togglePhase('frozen'); + await actions.togglePhase('delete'); expect(actions.warm.hasRolloverTipOnMinAge()).toBeFalsy(); expect(actions.cold.hasRolloverTipOnMinAge()).toBeFalsy(); 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 ede40521deb97..21a76b16c17ef 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 @@ -20,13 +20,7 @@ describe(' searchable snapshots', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -39,8 +33,8 @@ describe(' searchable snapshots', () => { test('enabling searchable snapshot should hide force merge, freeze, readonly and shrink in subsequent phases', async () => { const { actions } = testBed; - await actions.warm.enable(true); - await actions.cold.enable(true); + await actions.togglePhase('warm'); + await actions.togglePhase('cold'); expect(actions.warm.forceMergeFieldExists()).toBeTruthy(); expect(actions.warm.shrinkExists()).toBeTruthy(); @@ -62,9 +56,9 @@ describe(' searchable snapshots', () => { test('disabling rollover toggle, but enabling default rollover', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); - await actions.hot.toggleDefaultRollover(true); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); + await actions.rollover.toggleDefault(); expect(actions.hot.forceMergeFieldExists()).toBeTruthy(); expect(actions.hot.shrinkExists()).toBeTruthy(); @@ -76,10 +70,10 @@ describe(' searchable snapshots', () => { const repository = 'myRepo'; await actions.hot.setSearchableSnapshot(repository); - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('10'); - await actions.cold.toggleSearchableSnapshot(true); - await actions.frozen.enable(true); + await actions.cold.toggleSearchableSnapshot(); + await actions.togglePhase('frozen'); await actions.frozen.setMinAgeValue('15'); await actions.savePolicy(); @@ -97,10 +91,10 @@ describe(' searchable snapshots', () => { const { actions } = testBed; await actions.hot.setSearchableSnapshot('myRepo'); - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('10'); - await actions.cold.toggleSearchableSnapshot(true); - await actions.frozen.enable(true); + await actions.cold.toggleSearchableSnapshot(); + await actions.togglePhase('frozen'); await actions.frozen.setMinAgeValue('15'); // We update the repository in one phase @@ -137,7 +131,7 @@ describe(' searchable snapshots', () => { test('defaults searchable snapshot to true on cloud', async () => { const { find, actions } = testBed; - await actions.cold.enable(true); + await actions.togglePhase('cold'); expect( find('searchableSnapshotField-cold.searchableSnapshotToggle').props()['aria-checked'] ).toBe(true); @@ -164,9 +158,9 @@ describe(' searchable snapshots', () => { test('correctly sets snapshot repository default to "found-snapshots"', async () => { const { actions } = testBed; - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('10'); - await actions.cold.toggleSearchableSnapshot(true); + await actions.cold.toggleSearchableSnapshot(); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; expect(latestRequest.method).toBe('POST'); @@ -208,7 +202,7 @@ describe(' searchable snapshots', () => { expect(actions.cold.searchableSnapshotsExists()).toBeFalsy(); expect(actions.frozen.searchableSnapshotsExists()).toBeFalsy(); - await actions.cold.enable(true); + await actions.togglePhase('cold'); // Still hidden in hot expect(actions.hot.searchableSnapshotsExists()).toBeFalsy(); 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 a6cce7fdfaca0..5a117caa99378 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,7 +7,6 @@ import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers/setup_environment'; -import { getDefaultHotPhasePolicy } from '../constants'; import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; describe(' timeline', () => { @@ -19,13 +18,7 @@ describe(' timeline', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -38,27 +31,27 @@ describe(' timeline', () => { test('showing all phases on the timeline', async () => { const { actions } = testBed; // This is how the default policy should look - expect(actions.timeline.hasHotPhase()).toBe(true); - expect(actions.timeline.hasWarmPhase()).toBe(false); - expect(actions.timeline.hasColdPhase()).toBe(false); - expect(actions.timeline.hasDeletePhase()).toBe(false); - - await actions.warm.enable(true); - expect(actions.timeline.hasHotPhase()).toBe(true); - expect(actions.timeline.hasWarmPhase()).toBe(true); - expect(actions.timeline.hasColdPhase()).toBe(false); - expect(actions.timeline.hasDeletePhase()).toBe(false); - - await actions.cold.enable(true); - expect(actions.timeline.hasHotPhase()).toBe(true); - expect(actions.timeline.hasWarmPhase()).toBe(true); - expect(actions.timeline.hasColdPhase()).toBe(true); - expect(actions.timeline.hasDeletePhase()).toBe(false); - - await actions.delete.enable(true); - expect(actions.timeline.hasHotPhase()).toBe(true); - expect(actions.timeline.hasWarmPhase()).toBe(true); - expect(actions.timeline.hasColdPhase()).toBe(true); - expect(actions.timeline.hasDeletePhase()).toBe(true); + expect(actions.timeline.hasPhase('hot')).toBe(true); + expect(actions.timeline.hasPhase('warm')).toBe(false); + expect(actions.timeline.hasPhase('cold')).toBe(false); + expect(actions.timeline.hasPhase('delete')).toBe(false); + + await actions.togglePhase('warm'); + expect(actions.timeline.hasPhase('hot')).toBe(true); + expect(actions.timeline.hasPhase('warm')).toBe(true); + expect(actions.timeline.hasPhase('cold')).toBe(false); + expect(actions.timeline.hasPhase('delete')).toBe(false); + + await actions.togglePhase('cold'); + expect(actions.timeline.hasPhase('hot')).toBe(true); + expect(actions.timeline.hasPhase('warm')).toBe(true); + expect(actions.timeline.hasPhase('cold')).toBe(true); + expect(actions.timeline.hasPhase('delete')).toBe(false); + + await actions.togglePhase('delete'); + expect(actions.timeline.hasPhase('hot')).toBe(true); + expect(actions.timeline.hasPhase('warm')).toBe(true); + expect(actions.timeline.hasPhase('cold')).toBe(true); + expect(actions.timeline.hasPhase('delete')).toBe(true); }); }); 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 index 2252f8d1f5fa8..8ec2f2e1b4598 100644 --- 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 @@ -8,7 +8,6 @@ import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers/setup_environment'; import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; -import { getDefaultHotPhasePolicy } from '../constants'; describe(' warm phase', () => { let testBed: EditPolicyTestBed; @@ -24,16 +23,7 @@ describe(' warm phase', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: { data: ['node1'] }, - nodesByAttributes: { 'attribute:true': ['node1'] }, - isUsingDeprecatedDataRoleConfig: true, - }); - httpRequestsMockHelpers.setNodesDetails('attribute:true', [ - { nodeId: 'testNodeId', stats: { name: 'testNodeName', host: 'testHost' } }, - ]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -46,7 +36,7 @@ describe(' warm phase', () => { test('shows timing only when enabled', async () => { const { actions } = testBed; expect(actions.warm.hasMinAgeInput()).toBeFalsy(); - await actions.warm.enable(true); + 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 455a7bd442167..669bcfdd34f63 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 @@ -12,7 +12,6 @@ import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; describe(' cold phase validation', () => { let testBed: EditPolicyTestBed; - let runTimers: () => void; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -42,9 +41,7 @@ describe(' cold phase validation', () => { const { component, actions } = testBed; component.update(); await actions.setPolicyName('mypolicy'); - await actions.cold.enable(true); - - ({ runTimers } = testBed); + await actions.togglePhase('cold'); }); describe('replicas', () => { @@ -53,9 +50,9 @@ describe(' cold phase validation', () => { await actions.cold.setReplicas('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); }); test(`allows 0 for replicas`, async () => { @@ -63,9 +60,9 @@ describe(' cold phase validation', () => { await actions.cold.setReplicas('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([]); + actions.errors.expectMessages([]); }); }); @@ -75,9 +72,9 @@ describe(' cold phase validation', () => { await actions.cold.setIndexPriority('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); }); test(`allows 0 for index priority`, async () => { @@ -85,9 +82,9 @@ describe(' cold phase validation', () => { await actions.cold.setIndexPriority('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([]); + actions.errors.expectMessages([]); }); }); }); 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 86cf4ab5a4858..5c70a9025df67 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,12 +7,10 @@ import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers/setup_environment'; -import { getDefaultHotPhasePolicy } from '../constants'; import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; describe(' error indicators', () => { let testBed: EditPolicyTestBed; - let runTimers: () => void; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -25,13 +23,7 @@ describe(' error indicators', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -39,8 +31,6 @@ describe(' error indicators', () => { const { component } = testBed; component.update(); - - ({ runTimers } = testBed); }); test('shows phase error indicators correctly', async () => { // This test simulates a user configuring a policy phase by phase. The flow is the following: @@ -56,99 +46,98 @@ describe(' error indicators', () => { const { actions } = testBed; // 0. No validation issues - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(false); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); // 1. Hot phase validation issue - await actions.hot.toggleForceMerge(true); + await actions.hot.toggleForceMerge(); await actions.hot.setForcemergeSegmentsCount('-22'); - runTimers(); - expect(actions.hot.hasErrorIndicator()).toBe(true); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(false); + actions.errors.waitForValidation(); + expect(actions.errors.havePhaseCallout('hot')).toBe(true); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); // 2. Warm phase validation issue - await actions.warm.enable(true); - await actions.warm.toggleForceMerge(true); + await actions.togglePhase('warm'); + await actions.warm.toggleForceMerge(); await actions.warm.setForcemergeSegmentsCount('-22'); - runTimers(); - expect(actions.hot.hasErrorIndicator()).toBe(true); - expect(actions.warm.hasErrorIndicator()).toBe(true); - expect(actions.cold.hasErrorIndicator()).toBe(false); + actions.errors.waitForValidation(); + expect(actions.errors.havePhaseCallout('hot')).toBe(true); + expect(actions.errors.havePhaseCallout('warm')).toBe(true); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); // 3. Cold phase validation issue - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setReplicas('-33'); - runTimers(); - expect(actions.hot.hasErrorIndicator()).toBe(true); - expect(actions.warm.hasErrorIndicator()).toBe(true); - expect(actions.cold.hasErrorIndicator()).toBe(true); + actions.errors.waitForValidation(); + expect(actions.errors.havePhaseCallout('hot')).toBe(true); + expect(actions.errors.havePhaseCallout('warm')).toBe(true); + expect(actions.errors.havePhaseCallout('cold')).toBe(true); // 4. Fix validation issue in hot await actions.hot.setForcemergeSegmentsCount('1'); - runTimers(); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(true); - expect(actions.cold.hasErrorIndicator()).toBe(true); + actions.errors.waitForValidation(); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(true); + expect(actions.errors.havePhaseCallout('cold')).toBe(true); // 5. Fix validation issue in warm await actions.warm.setForcemergeSegmentsCount('1'); - runTimers(); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(true); + actions.errors.waitForValidation(); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(true); // 6. Fix validation issue in cold await actions.cold.setReplicas('1'); - runTimers(); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(false); + actions.errors.waitForValidation(); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); }); test('global error callout should show, after clicking the "Save" button, if there are any form errors', async () => { const { actions } = testBed; - expect(actions.hasGlobalErrorCallout()).toBe(false); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(false); + expect(actions.errors.haveGlobalCallout()).toBe(false); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); - await actions.saveAsNewPolicy(true); + await actions.toggleSaveAsNewPolicy(); await actions.setPolicyName(''); - runTimers(); + actions.errors.waitForValidation(); await actions.savePolicy(); - expect(actions.hasGlobalErrorCallout()).toBe(true); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(false); + expect(actions.errors.haveGlobalCallout()).toBe(true); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); }); - test('clears all error indicators if last erroring field is unmounted', async () => { + test('clears all error indicators if last erring field is unmounted', async () => { const { actions } = testBed; - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('7'); // introduce validation error await actions.cold.setSearchableSnapshot(''); - runTimers(); await actions.savePolicy(); - runTimers(); + actions.errors.waitForValidation(); - expect(actions.hasGlobalErrorCallout()).toBe(true); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(true); + expect(actions.errors.haveGlobalCallout()).toBe(true); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(true); // unmount the field - await actions.cold.toggleSearchableSnapshot(false); + await actions.cold.toggleSearchableSnapshot(); - expect(actions.hasGlobalErrorCallout()).toBe(false); - expect(actions.hot.hasErrorIndicator()).toBe(false); - expect(actions.warm.hasErrorIndicator()).toBe(false); - expect(actions.cold.hasErrorIndicator()).toBe(false); + expect(actions.errors.haveGlobalCallout()).toBe(false); + expect(actions.errors.havePhaseCallout('hot')).toBe(false); + expect(actions.errors.havePhaseCallout('warm')).toBe(false); + expect(actions.errors.havePhaseCallout('cold')).toBe(false); }); }); 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 46fbf69fbcad5..879aab872b19b 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 @@ -12,7 +12,7 @@ import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; describe(' hot phase validation', () => { let testBed: EditPolicyTestBed; - let runTimers: () => void; + let actions: EditPolicyTestBed['actions']; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -30,190 +30,159 @@ describe(' hot phase validation', () => { testBed = await setup(); }); - const { component, actions } = testBed; + const { component } = testBed; component.update(); + ({ actions } = testBed); await actions.setPolicyName('mypolicy'); - - ({ runTimers } = testBed); }); describe('rollover', () => { test(`doesn't allow no max primary shard size, no max index size, no max age, no max docs`, async () => { - const { actions } = testBed; - - await actions.hot.toggleDefaultRollover(false); - expect(actions.hot.hasRolloverSettingRequiredCallout()).toBeFalsy(); + await actions.rollover.toggleDefault(); + expect(actions.rollover.hasSettingRequiredCallout()).toBeFalsy(); - await actions.hot.setMaxPrimaryShardSize(''); - await actions.hot.setMaxAge(''); - await actions.hot.setMaxDocs(''); - await actions.hot.setMaxSize(''); + await actions.rollover.setMaxPrimaryShardSize(''); + await actions.rollover.setMaxAge(''); + await actions.rollover.setMaxDocs(''); + await actions.rollover.setMaxSize(''); - runTimers(); + actions.errors.waitForValidation(); - expect(actions.hot.hasRolloverSettingRequiredCallout()).toBeTruthy(); + expect(actions.rollover.hasSettingRequiredCallout()).toBeTruthy(); }); test(`doesn't allow -1 for max primary shard size`, async () => { - const { actions } = testBed; + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxPrimaryShardSize('-1'); - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxPrimaryShardSize('-1'); + actions.errors.waitForValidation(); - runTimers(); - - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow 0 for max primary shard size`, async () => { - const { actions } = testBed; - - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxPrimaryShardSize('0'); + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxPrimaryShardSize('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for max size`, async () => { - const { actions } = testBed; + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxSize('-1'); - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxSize('-1'); + actions.errors.waitForValidation(); - runTimers(); - - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow 0 for max size`, async () => { - const { actions } = testBed; - - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxSize('0'); + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxSize('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for max age`, async () => { - const { actions } = testBed; - - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxAge('-1'); + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxAge('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow 0 for max age`, async () => { - const { actions } = testBed; + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxAge('0'); - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxAge('0'); + actions.errors.waitForValidation(); - runTimers(); - - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow decimals for max age`, async () => { - const { actions } = testBed; - - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxAge('5.5'); + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxAge('5.5'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.integerRequired]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.integerRequired]); }); test(`doesn't allow -1 for max docs`, async () => { - const { actions } = testBed; + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxDocs('-1'); - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxDocs('-1'); + actions.errors.waitForValidation(); - runTimers(); - - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow 0 for max docs`, async () => { - const { actions } = testBed; - - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxDocs('0'); + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxDocs('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow decimals for max docs`, async () => { - const { actions } = testBed; + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxDocs('5.5'); - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxDocs('5.5'); + actions.errors.waitForValidation(); - runTimers(); - - actions.expectErrorMessages([i18nTexts.editPolicy.errors.integerRequired]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.integerRequired]); }); }); describe('forcemerge', () => { test(`doesn't allow 0 for forcemerge`, async () => { - const { actions } = testBed; - await actions.hot.toggleForceMerge(true); + await actions.hot.toggleForceMerge(); await actions.hot.setForcemergeSegmentsCount('0'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for forcemerge`, async () => { - const { actions } = testBed; - await actions.hot.toggleForceMerge(true); + await actions.hot.toggleForceMerge(); await actions.hot.setForcemergeSegmentsCount('-1'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); }); describe('shrink', () => { test(`doesn't allow 0 for shrink`, async () => { - const { actions } = testBed; - await actions.hot.toggleShrink(true); + await actions.hot.toggleShrink(); await actions.hot.setShrink('0'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for shrink`, async () => { - const { actions } = testBed; - await actions.hot.toggleShrink(true); + await actions.hot.toggleShrink(); await actions.hot.setShrink('-1'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); }); describe('index priority', () => { test(`doesn't allow -1 for index priority`, async () => { - const { actions } = testBed; - await actions.hot.setIndexPriority('-1'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); }); test(`allows 0 for index priority`, async () => { - const { actions } = testBed; - await actions.hot.setIndexPriority('0'); - runTimers(); - actions.expectErrorMessages([]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([]); }); }); }); 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 0acb425b1d975..41d2b6d166dce 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 @@ -13,7 +13,7 @@ import { getGeneratedPolicies } from '../constants'; describe(' policy name validation', () => { let testBed: EditPolicyTestBed; - let runTimers: () => void; + let actions: EditPolicyTestBed['actions']; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -34,28 +34,24 @@ describe(' policy name validation', () => { const { component } = testBed; component.update(); - - ({ runTimers } = testBed); + ({ actions } = testBed); }); test(`doesn't allow empty policy name`, async () => { - const { actions } = testBed; await actions.savePolicy(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.policyNameRequiredMessage]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.policyNameRequiredMessage]); }); test(`doesn't allow policy name with space`, async () => { - const { actions } = testBed; await actions.setPolicyName('my policy'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.policyNameContainsInvalidChars]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.policyNameContainsInvalidChars]); }); test(`doesn't allow policy name that is already used`, async () => { - const { actions } = testBed; await actions.setPolicyName('testy0'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.policyNameAlreadyUsedErrorMessage]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.policyNameAlreadyUsedErrorMessage]); }); test(`doesn't allow to save as new policy but using the same name`, async () => { @@ -69,31 +65,28 @@ describe(' policy name validation', () => { }, }); }); - const { component, actions } = testBed; + const { component } = testBed; component.update(); + ({ actions } = testBed); - ({ runTimers } = testBed); - - await actions.saveAsNewPolicy(true); - runTimers(); + await actions.toggleSaveAsNewPolicy(); + actions.errors.waitForValidation(); await actions.savePolicy(); - actions.expectErrorMessages([ + actions.errors.expectMessages([ i18nTexts.editPolicy.errors.policyNameMustBeDifferentErrorMessage, ]); }); test(`doesn't allow policy name with comma`, async () => { - const { actions } = testBed; await actions.setPolicyName('my,policy'); - runTimers(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.policyNameContainsInvalidChars]); + actions.errors.waitForValidation(); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.policyNameContainsInvalidChars]); }); test(`doesn't allow policy name starting with underscore`, async () => { - const { actions } = testBed; await actions.setPolicyName('_mypolicy'); - runTimers(); - actions.expectErrorMessages([ + actions.errors.waitForValidation(); + actions.errors.expectMessages([ i18nTexts.editPolicy.errors.policyNameStartsWithUnderscoreErrorMessage, ]); }); 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 c0b30efe150c4..c164605e5cd4b 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 @@ -13,7 +13,7 @@ import { setupEnvironment } from '../../helpers/setup_environment'; describe(' timing validation', () => { let testBed: EditPolicyTestBed; - let runTimers: () => void; + let actions: EditPolicyTestBed['actions']; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -26,27 +26,17 @@ describe(' timing validation', () => { }); beforeEach(async () => { + httpRequestsMockHelpers.setDefaultResponses(); httpRequestsMockHelpers.setLoadPolicies([]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: { data: ['node1'] }, - nodesByAttributes: { 'attribute:true': ['node1'] }, - isUsingDeprecatedDataRoleConfig: false, - }); - - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); - - httpRequestsMockHelpers.setListSnapshotRepos({ repositories: ['my-repo'] }); - await act(async () => { testBed = await setup(); }); - const { component, actions } = testBed; + const { component } = testBed; component.update(); + ({ actions } = testBed); await actions.setPolicyName('mypolicy'); - - ({ runTimers } = testBed); }); [ @@ -79,66 +69,68 @@ describe(' timing validation', () => { ['warm', 'cold', 'delete', 'frozen'].forEach((phase: string) => { const { name, value, error } = testConfig; test(`${phase}: ${name}`, async () => { - const { actions } = testBed; - await actions[phase as 'warm' | 'cold' | 'delete' | 'frozen'].enable(true); + await actions.togglePhase(phase as 'warm' | 'cold' | 'delete' | 'frozen'); // 1. We first set as dummy value to have a starting min_age value await actions[phase as 'warm' | 'cold' | 'delete' | 'frozen'].setMinAgeValue('111'); // 2. At this point we are sure there will be a change of value and that any validation // will be displayed under the field. await actions[phase as 'warm' | 'cold' | 'delete' | 'frozen'].setMinAgeValue(value); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages(error); + actions.errors.expectMessages(error); }); }); }); test('should validate that min_age is equal or greater than previous phase min_age', async () => { - const { actions, form } = testBed; - await actions.warm.enable(true); - await actions.cold.enable(true); - await actions.frozen.enable(true); - await actions.delete.enable(true); + await actions.togglePhase('warm'); + await actions.togglePhase('cold'); + await actions.togglePhase('frozen'); + await actions.togglePhase('delete'); await actions.warm.setMinAgeValue('10'); await actions.cold.setMinAgeValue('9'); - runTimers(); - expect(form.getErrorsMessages('cold-phase')).toEqual([ - 'Must be greater or equal than the warm phase value (10d)', - ]); + actions.errors.waitForValidation(); + actions.errors.expectMessages( + ['Must be greater or equal than the warm phase value (10d)'], + 'cold' + ); await actions.frozen.setMinAgeValue('8'); - runTimers(); - expect(form.getErrorsMessages('frozen-phase')).toEqual([ - 'Must be greater or equal than the cold phase value (9d)', - ]); + actions.errors.waitForValidation(); + actions.errors.expectMessages( + ['Must be greater or equal than the cold phase value (9d)'], + 'frozen' + ); await actions.delete.setMinAgeValue('7'); - runTimers(); - expect(form.getErrorsMessages('delete-phaseContent')).toEqual([ - 'Must be greater or equal than the frozen phase value (8d)', - ]); + actions.errors.waitForValidation(); + actions.errors.expectMessages( + ['Must be greater or equal than the frozen phase value (8d)'], + 'delete' + ); // Disable the warm phase - await actions.warm.enable(false); + await actions.togglePhase('warm'); // No more error for the cold phase - expect(form.getErrorsMessages('cold-phase')).toEqual([]); + actions.errors.expectMessages([], 'cold'); // Change to smaller unit for cold phase await actions.cold.setMinAgeUnits('h'); // No more error for the frozen phase... - expect(form.getErrorsMessages('frozen-phase')).toEqual([]); + actions.errors.expectMessages([], 'frozen'); // ...but the delete phase has still the error - expect(form.getErrorsMessages('delete-phaseContent')).toEqual([ - 'Must be greater or equal than the frozen phase value (8d)', - ]); + actions.errors.expectMessages( + ['Must be greater or equal than the frozen phase value (8d)'], + 'delete' + ); await actions.delete.setMinAgeValue('9'); // No more error for the delete phase - expect(form.getErrorsMessages('delete-phaseContent')).toEqual([]); + actions.errors.expectMessages([], 'delete'); }); }); 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 bfb263e204de9..70794491d4edd 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 @@ -12,7 +12,6 @@ import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; describe(' warm phase validation', () => { let testBed: EditPolicyTestBed; - let runTimers: () => void; const { server, httpRequestsMockHelpers } = setupEnvironment(); beforeAll(() => { @@ -25,15 +24,8 @@ describe(' warm phase validation', () => { }); beforeEach(async () => { + httpRequestsMockHelpers.setDefaultResponses(); httpRequestsMockHelpers.setLoadPolicies([]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: { data: ['node1'] }, - nodesByAttributes: { 'attribute:true': ['node1'] }, - isUsingDeprecatedDataRoleConfig: true, - }); - httpRequestsMockHelpers.setNodesDetails('attribute:true', [ - { nodeId: 'testNodeId', stats: { name: 'testNodeName', host: 'testHost' } }, - ]); await act(async () => { testBed = await setup(); @@ -42,98 +34,88 @@ describe(' warm phase validation', () => { const { component, actions } = testBed; component.update(); await actions.setPolicyName('mypolicy'); - await actions.warm.enable(true); - - ({ runTimers } = testBed); + await actions.togglePhase('warm'); }); describe('replicas', () => { test(`doesn't allow -1 for replicas`, async () => { const { actions } = testBed; - await actions.warm.setReplicas('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); }); test(`allows 0 for replicas`, async () => { const { actions } = testBed; - await actions.warm.setReplicas('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([]); + actions.errors.expectMessages([]); }); }); describe('shrink', () => { test(`doesn't allow 0 for shrink`, async () => { const { actions } = testBed; - - await actions.warm.toggleShrink(true); + await actions.warm.toggleShrink(); await actions.warm.setShrink('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for shrink`, async () => { const { actions } = testBed; - - await actions.warm.toggleShrink(true); + await actions.warm.toggleShrink(); await actions.warm.setShrink('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); }); describe('forcemerge', () => { test(`doesn't allow 0 for forcemerge`, async () => { const { actions } = testBed; - - await actions.warm.toggleForceMerge(true); + await actions.warm.toggleForceMerge(); await actions.warm.setForcemergeSegmentsCount('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); test(`doesn't allow -1 for forcemerge`, async () => { const { actions } = testBed; - - await actions.warm.toggleForceMerge(true); + await actions.warm.toggleForceMerge(); await actions.warm.setForcemergeSegmentsCount('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.numberGreatThan0Required]); }); }); describe('index priority', () => { test(`doesn't allow -1 for index priority`, async () => { const { actions } = testBed; - await actions.warm.setIndexPriority('-1'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); + actions.errors.expectMessages([i18nTexts.editPolicy.errors.nonNegativeNumberRequired]); }); test(`allows 0 for index priority`, async () => { const { actions } = testBed; - await actions.warm.setIndexPriority('0'); - runTimers(); + actions.errors.waitForValidation(); - actions.expectErrorMessages([]); + actions.errors.expectMessages([]); }); }); }); 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 15d89c988f729..dfc81e9e0d9d7 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 @@ -24,13 +24,7 @@ describe(' serialization', () => { }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -57,9 +51,9 @@ describe(' serialization', () => { component.update(); // Set max docs to test whether we keep the unknown fields in that object after serializing - await actions.hot.setMaxDocs('1000'); + await actions.rollover.setMaxDocs('1000'); // Remove the delete phase to ensure that we also correctly remove data - await actions.delete.enable(false); + await actions.togglePhase('delete'); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; @@ -170,17 +164,17 @@ describe(' serialization', () => { test('setting all values', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.setMaxSize('123', 'mb'); - await actions.hot.setMaxDocs('123'); - await actions.hot.setMaxAge('123', 'h'); - await actions.hot.toggleForceMerge(true); + await actions.rollover.toggleDefault(); + await actions.rollover.setMaxSize('123', 'mb'); + await actions.rollover.setMaxDocs('123'); + await actions.rollover.setMaxAge('123', 'h'); + await actions.hot.toggleForceMerge(); await actions.hot.setForcemergeSegmentsCount('123'); await actions.hot.setBestCompression(true); - await actions.hot.toggleShrink(true); + await actions.hot.toggleShrink(); await actions.hot.setShrink('2'); - await actions.hot.toggleReadonly(true); - await actions.hot.toggleIndexPriority(true); + await actions.hot.toggleReadonly(); + await actions.hot.toggleIndexPriority(); await actions.hot.setIndexPriority('123'); await actions.savePolicy(); @@ -232,8 +226,8 @@ describe(' serialization', () => { test('disabling rollover', async () => { const { actions } = testBed; - await actions.hot.toggleDefaultRollover(false); - await actions.hot.toggleRollover(false); + await actions.rollover.toggleDefault(); + await actions.rollover.toggle(); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; const policy = JSON.parse(JSON.parse(latestRequest.requestBody).body); @@ -246,13 +240,7 @@ describe(' serialization', () => { describe('warm phase', () => { beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -264,7 +252,7 @@ describe(' serialization', () => { test('default values', async () => { const { actions } = testBed; - await actions.warm.enable(true); + await actions.togglePhase('warm'); await actions.warm.setMinAgeValue('11'); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; @@ -283,17 +271,17 @@ describe(' serialization', () => { test('setting all values', async () => { const { actions } = testBed; - await actions.warm.enable(true); + await actions.togglePhase('warm'); await actions.warm.setMinAgeValue('11'); await actions.warm.setDataAllocation('node_attrs'); await actions.warm.setSelectedNodeAttribute('test:123'); await actions.warm.setReplicas('123'); - await actions.warm.toggleShrink(true); + await actions.warm.toggleShrink(); await actions.warm.setShrink('123'); - await actions.warm.toggleForceMerge(true); + await actions.warm.toggleForceMerge(); await actions.warm.setForcemergeSegmentsCount('123'); await actions.warm.setBestCompression(true); - await actions.warm.toggleReadonly(true); + await actions.warm.toggleReadonly(); await actions.warm.setIndexPriority('123'); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; @@ -384,13 +372,7 @@ describe(' serialization', () => { describe('cold phase', () => { beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); - httpRequestsMockHelpers.setListNodes({ - nodesByRoles: {}, - nodesByAttributes: { test: ['123'] }, - isUsingDeprecatedDataRoleConfig: false, - }); - httpRequestsMockHelpers.setLoadSnapshotPolicies([]); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { testBed = await setup(); @@ -403,7 +385,7 @@ describe(' serialization', () => { test('default values', async () => { const { actions } = testBed; - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('11'); await actions.savePolicy(); const latestRequest = server.requests[server.requests.length - 1]; @@ -423,14 +405,14 @@ describe(' serialization', () => { test('setting all values, excluding searchable snapshot', async () => { const { actions } = testBed; - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('123'); await actions.cold.setMinAgeUnits('s'); await actions.cold.setDataAllocation('node_attrs'); await actions.cold.setSelectedNodeAttribute('test:123'); await actions.cold.setReplicas('123'); - await actions.cold.setFreeze(true); - await actions.cold.toggleReadonly(true); + await actions.cold.setFreeze(); + await actions.cold.toggleReadonly(); await actions.cold.setIndexPriority('123'); await actions.savePolicy(); @@ -474,7 +456,7 @@ describe(' serialization', () => { // Setting searchable snapshot field disables setting replicas so we test this separately test('setting searchable snapshot', async () => { const { actions } = testBed; - await actions.cold.enable(true); + await actions.togglePhase('cold'); await actions.cold.setMinAgeValue('10'); await actions.cold.setSearchableSnapshot('my-repo'); await actions.savePolicy(); @@ -489,7 +471,7 @@ describe(' serialization', () => { describe('frozen phase', () => { test('default value', async () => { const { actions } = testBed; - await actions.frozen.enable(true); + await actions.togglePhase('frozen'); await actions.frozen.setMinAgeValue('13'); await actions.frozen.setSearchableSnapshot('myRepo'); @@ -551,8 +533,8 @@ describe(' serialization', () => { describe('delete phase', () => { test('default value', async () => { const { actions } = testBed; - await actions.delete.enable(true); - await actions.setWaitForSnapshotPolicy('test'); + await actions.togglePhase('delete'); + await actions.delete.setWaitForSnapshotPolicy('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 new file mode 100644 index 0000000000000..8d5708950a75f --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts @@ -0,0 +1,40 @@ +/* + * 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'; +import { Phase } from '../types'; + +const createWaitForValidationAction = (testBed: TestBed) => () => { + const { component } = testBed; + act(() => { + jest.runAllTimers(); + }); + component.update(); +}; + +const createExpectMessagesAction = (testBed: TestBed) => ( + expectedMessages: string[], + phase?: Phase +) => { + const { form } = testBed; + if (phase) { + expect(form.getErrorsMessages(`${phase}-phase`)).toEqual(expectedMessages); + } else { + expect(form.getErrorsMessages()).toEqual(expectedMessages); + } +}; + +export const createErrorsActions = (testBed: TestBed) => { + const { exists } = testBed; + return { + 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 new file mode 100644 index 0000000000000..61b16d18648f5 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.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 { act } from 'react-dom/test-utils'; +import { TestBed } from '@kbn/test/jest'; +import { createFormToggleAction } from './form_toggle_action'; +import { createFormSetValueAction } from './form_set_value_action'; +import { Phase } from '../types'; + +const createFormCheckboxAction = (testBed: TestBed, dataTestSubject: string) => async ( + checked: boolean +) => { + const { form, component } = testBed; + await act(async () => { + form.selectCheckBox(dataTestSubject, checked); + }); + component.update(); +}; + +export const createForceMergeActions = (testBed: TestBed, phase: Phase) => { + const { exists } = testBed; + const toggleSelector = `${phase}-forceMergeSwitch`; + return { + forceMergeFieldExists: () => exists(toggleSelector), + toggleForceMerge: createFormToggleAction(testBed, toggleSelector), + setForcemergeSegmentsCount: createFormSetValueAction( + testBed, + `${phase}-selectedForceMergeSegments` + ), + setBestCompression: createFormCheckboxAction(testBed, `${phase}-bestCompression`), + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_form_set_value_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts similarity index 100% rename from x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_form_set_value_action.ts rename to x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_form_toggle_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts similarity index 82% rename from x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_form_toggle_action.ts rename to x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts index 579bb661871da..6bf47f5d513f6 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_form_toggle_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts @@ -8,13 +8,11 @@ import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test/jest'; -export const createFormToggleAction = (testBed: TestBed, dataTestSubject: string) => async ( - checked: boolean -) => { +export const createFormToggleAction = (testBed: TestBed, dataTestSubject: string) => async () => { const { form, component } = testBed; await act(async () => { - form.toggleEuiSwitch(dataTestSubject, checked); + form.toggleEuiSwitch(dataTestSubject); }); component.update(); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/freeze_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/freeze_actions.ts new file mode 100644 index 0000000000000..87b03ff4e1deb --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/freeze_actions.ts @@ -0,0 +1,18 @@ +/* + * 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 { createFormToggleAction } from './form_toggle_action'; +import { Phase } from '../types'; + +export const createFreezeActions = (testBed: TestBed, phase: Phase) => { + const { exists } = testBed; + return { + setFreeze: createFormToggleAction(testBed, `${phase}-freezeSwitch`), + freezeExists: (): boolean => exists(`${phase}-freezeSwitch`), + }; +}; 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 new file mode 100644 index 0000000000000..7366bf2f35c70 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index.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 + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { createNodeAllocationActions } from './node_allocation_actions'; +export { createTogglePhaseAction } from './toggle_phase_action'; +export { setReplicas } from './set_replicas_action'; +export { createSavePolicyAction } from './save_policy_action'; +export { createFormToggleAction } from './form_toggle_action'; +export { createFormSetValueAction } from './form_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 { 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'; 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 new file mode 100644 index 0000000000000..a0423c12be5c3 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/index_priority_actions.ts @@ -0,0 +1,21 @@ +/* + * 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 { createFormToggleAction } from './form_toggle_action'; +import { createFormSetValueAction } from './form_set_value_action'; +import { Phase } from '../types'; + +export const createIndexPriorityActions = (testBed: TestBed, phase: Phase) => { + const { exists } = testBed; + const toggleSelector = `${phase}-indexPrioritySwitch`; + return { + indexPriorityExists: () => exists(toggleSelector), + toggleIndexPriority: createFormToggleAction(testBed, toggleSelector), + setIndexPriority: createFormSetValueAction(testBed, `${phase}-indexPriority`), + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/min_age_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/min_age_actions.ts new file mode 100644 index 0000000000000..4a2491f3561ee --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/min_age_actions.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 { createFormSetValueAction } from './form_set_value_action'; +import { Phase } from '../types'; + +export const createMinAgeActions = (testBed: TestBed, phase: Phase) => { + const { exists } = testBed; + return { + hasMinAgeInput: () => exists(`${phase}-selectedMinimumAge`), + setMinAgeValue: createFormSetValueAction(testBed, `${phase}-selectedMinimumAge`), + setMinAgeUnits: createFormSetValueAction(testBed, `${phase}-selectedMinimumAgeUnits`), + hasRolloverTipOnMinAge: () => exists(`${phase}-rolloverMinAgeInputIconTip`), + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_node_allocation_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts similarity index 94% rename from x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_node_allocation_actions.ts rename to x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts index 416a2afa54d54..b4b97b7c88a5e 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_node_allocation_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts @@ -8,9 +8,9 @@ import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test/jest'; -import { Phase } from './types'; -import { DataTierAllocationType } from '../../../public/application/sections/edit_policy/types'; -import { createFormSetValueAction } from './create_form_set_value_action'; +import { DataTierAllocationType } from '../../../../public/application/sections/edit_policy/types'; +import { Phase } from '../types'; +import { createFormSetValueAction } from './form_set_value_action'; export const createNodeAllocationActions = (testBed: TestBed, phase: Phase) => { const { component, find, exists } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/readonly_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/readonly_actions.ts new file mode 100644 index 0000000000000..ee9161c91209e --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/readonly_actions.ts @@ -0,0 +1,19 @@ +/* + * 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 { createFormToggleAction } from './form_toggle_action'; +import { Phase } from '../types'; + +export const createReadonlyActions = (testBed: TestBed, phase: Phase) => { + const { exists } = testBed; + const toggleSelector = `${phase}-readonlySwitch`; + return { + readonlyExists: () => exists(toggleSelector), + toggleReadonly: createFormToggleAction(testBed, toggleSelector), + }; +}; 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 new file mode 100644 index 0000000000000..daf4db7fab278 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts @@ -0,0 +1,64 @@ +/* + * 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'; +import { createFormToggleAction } from './form_toggle_action'; +import { createFormSetValueAction } from './form_set_value_action'; + +const createSetPrimaryShardSizeAction = (testBed: TestBed) => async ( + value: string, + units?: string +) => { + const { find, component } = testBed; + await act(async () => { + find('hot-selectedMaxPrimaryShardSize').simulate('change', { target: { value } }); + if (units) { + find('hot-selectedMaxPrimaryShardSize.select').simulate('change', { + target: { value: units }, + }); + } + }); + component.update(); +}; + +const createSetMaxAgeAction = (testBed: TestBed) => async (value: string, units?: string) => { + const { find, component } = testBed; + await act(async () => { + find('hot-selectedMaxAge').simulate('change', { target: { value } }); + if (units) { + find('hot-selectedMaxAgeUnits.select').simulate('change', { target: { value: units } }); + } + }); + component.update(); +}; + +const createSetMaxSizeAction = (testBed: TestBed) => async (value: string, units?: string) => { + const { find, component } = testBed; + await act(async () => { + find('hot-selectedMaxSizeStored').simulate('change', { target: { value } }); + if (units) { + find('hot-selectedMaxSizeStoredUnits.select').simulate('change', { + target: { value: units }, + }); + } + }); + component.update(); +}; + +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'), + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/save_policy_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts similarity index 86% rename from x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/save_policy_action.ts rename to x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts index 37ce4f84f03ba..3fcd1205b6e1a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/save_policy_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts @@ -8,7 +8,7 @@ import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test/jest'; -export const savePolicy = async (testBed: TestBed) => { +export const createSavePolicyAction = (testBed: TestBed) => async () => { const { find, component } = testBed; await act(async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts new file mode 100644 index 0000000000000..d7ccd32694759 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts @@ -0,0 +1,37 @@ +/* + * 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'; +import { Phase } from '../types'; +import { createFormToggleAction } from './form_toggle_action'; + +export const createSearchableSnapshotActions = (testBed: TestBed, phase: Phase) => { + const { exists, find, component } = testBed; + const fieldSelector = `searchableSnapshotField-${phase}`; + const licenseCalloutSelector = `${fieldSelector}.searchableSnapshotDisabledDueToLicense`; + const toggleSelector = `${fieldSelector}.searchableSnapshotToggle`; + + const toggleSearchableSnapshot = createFormToggleAction(testBed, toggleSelector); + return { + searchableSnapshotDisabledDueToLicense: () => + exists(licenseCalloutSelector) && find(toggleSelector).props().disabled === true, + searchableSnapshotsExists: () => exists(fieldSelector), + toggleSearchableSnapshot, + setSearchableSnapshot: async (value: string) => { + if (!exists(`searchableSnapshotField-${phase}.searchableSnapshotCombobox`)) { + await toggleSearchableSnapshot(); + } + act(() => { + find(`searchableSnapshotField-${phase}.searchableSnapshotCombobox`).simulate('change', [ + { label: value }, + ]); + }); + component.update(); + }, + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/set_replicas_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_replicas_action.ts similarity index 76% rename from x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/set_replicas_action.ts rename to x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_replicas_action.ts index 049c1a205cbd4..cabd3012001b7 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/set_replicas_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_replicas_action.ts @@ -7,15 +7,15 @@ import { TestBed } from '@kbn/test/jest'; -import { Phase } from './types'; -import { createFormToggleAction } from './create_form_toggle_action'; -import { createFormSetValueAction } from './create_form_set_value_action'; +import { Phase } from '../types'; +import { createFormToggleAction } from './form_toggle_action'; +import { createFormSetValueAction } from './form_set_value_action'; export const setReplicas = async (testBed: TestBed, phase: Phase, value: string) => { const { exists } = testBed; if (!exists(`${phase}-selectedReplicaCount`)) { - await createFormToggleAction(testBed, `${phase}-setReplicasSwitch`)(true); + await createFormToggleAction(testBed, `${phase}-setReplicasSwitch`)(); } await createFormSetValueAction(testBed, `${phase}-selectedReplicaCount`)(value); }; 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 new file mode 100644 index 0000000000000..a0bc9da8d3063 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/set_wait_for_snapshot_action.ts @@ -0,0 +1,19 @@ +/* + * 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 new file mode 100644 index 0000000000000..9d227ef2624a4 --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts @@ -0,0 +1,21 @@ +/* + * 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 { createFormToggleAction } from './form_toggle_action'; +import { createFormSetValueAction } from './form_set_value_action'; +import { Phase } from '../types'; + +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`), + }; +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts new file mode 100644 index 0000000000000..fb1575d05bdef --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.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 { TestBed } from '@kbn/test/jest'; + +import { act } from 'react-dom/test-utils'; +import { Phase } from '../types'; + +const toggleDeletePhase = async (testBed: TestBed) => { + const { find, component } = testBed; + + let button = find('disableDeletePhaseButton'); + if (!button.length) { + button = find('enableDeletePhaseButton'); + } + if (!button.length) { + throw new Error(`Button to enable/disable delete phase was not found.`); + } + + await act(async () => { + button.simulate('click'); + }); + component.update(); +}; + +const togglePhase = async (testBed: TestBed, phase: Phase) => { + const { form, component } = testBed; + await act(async () => { + form.toggleEuiSwitch(`enablePhaseSwitch-${phase}`); + }); + + component.update(); +}; + +export const createTogglePhaseAction = (testBed: TestBed) => async (phase: Phase) => { + if (phase === 'delete') { + await toggleDeletePhase(testBed); + } else { + await togglePhase(testBed, phase); + } +}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_enable_phase_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_enable_phase_action.ts deleted file mode 100644 index e0988daf52192..0000000000000 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/create_enable_phase_action.ts +++ /dev/null @@ -1,15 +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 { TestBed } from '@kbn/test/jest'; - -import { Phase } from './types'; -import { createFormToggleAction } from './create_form_toggle_action'; - -export const createEnablePhaseAction = (testBed: TestBed, phase: Phase) => { - return createFormToggleAction(testBed, `enablePhaseSwitch-${phase}`); -}; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/http_requests.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/http_requests.ts index 6ef2b4c231ce1..ccb57cb1067e2 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/http_requests.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/http_requests.ts @@ -12,6 +12,7 @@ import { ListSnapshotReposResponse, NodesDetailsResponse, } from '../../../common/types'; +import { getDefaultHotPhasePolicy } from '../edit_policy/constants'; export const init = () => { const server = fakeServer.create(); @@ -68,11 +69,23 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => { ]); }; + const setDefaultResponses = () => { + setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); + setLoadSnapshotPolicies([]); + setListSnapshotRepos({ repositories: ['abc'] }); + setListNodes({ + nodesByRoles: {}, + nodesByAttributes: { test: ['123'] }, + isUsingDeprecatedDataRoleConfig: false, + }); + }; + return { setLoadPolicies, setLoadSnapshotPolicies, setListNodes, setNodesDetails, setListSnapshotRepos, + setDefaultResponses, }; }; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts index 1388cf97d4e22..5b2e1827cd6e8 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts @@ -7,9 +7,4 @@ export { Phase } from './types'; -export { createNodeAllocationActions } from './create_node_allocation_actions'; -export { createEnablePhaseAction } from './create_enable_phase_action'; -export { setReplicas } from './set_replicas_action'; -export { savePolicy } from './save_policy_action'; -export { createFormToggleAction } from './create_form_toggle_action'; -export { createFormSetValueAction } from './create_form_set_value_action'; +export * from './actions'; diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/delete_phase/delete_phase.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/delete_phase/delete_phase.tsx index 7b613757fa474..4b4962cc7c3a4 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/delete_phase/delete_phase.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/delete_phase/delete_phase.tsx @@ -73,7 +73,7 @@ export const DeletePhase: FunctionComponent = () => { <> } className="ilmDeletePhase ilmPhase" diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx index 8a0028dcb8b19..6edc6568ef766 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx @@ -178,7 +178,7 @@ export const Timeline: FunctionComponent = memo(
{/* These are the actual color bars for the timeline */}
@@ -189,7 +189,7 @@ export const Timeline: FunctionComponent = memo(
{exists(phaseAgeInMilliseconds.phases.warm) && (
@@ -201,7 +201,7 @@ export const Timeline: FunctionComponent = memo( )} {exists(phaseAgeInMilliseconds.phases.cold) && (
@@ -213,7 +213,7 @@ export const Timeline: FunctionComponent = memo( )} {exists(phaseAgeInMilliseconds.phases.frozen) && (
@@ -228,7 +228,7 @@ export const Timeline: FunctionComponent = memo( {hasDeletePhase && (
diff --git a/x-pack/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts b/x-pack/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts index 6e884069f1373..1e8546bef50e5 100644 --- a/x-pack/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts +++ b/x-pack/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts @@ -140,7 +140,7 @@ describe('', () => { await act(async () => { // Toggle "All indices" switch - form.toggleEuiSwitch('allIndicesToggle', false); + form.toggleEuiSwitch('allIndicesToggle'); await nextTick(); component.update(); }); @@ -158,7 +158,7 @@ describe('', () => { await act(async () => { // Toggle "All indices" switch - form.toggleEuiSwitch('allIndicesToggle', false); + form.toggleEuiSwitch('allIndicesToggle'); await nextTick(); }); component.update();