Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[7.x] [ILM] Migrate Hot phase to Form Lib (#80012) #81013

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const CheckBoxField = ({ field, euiFieldProps = {}, ...rest }: Props) =>
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiCheckbox
label={field.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const ComboBoxField = ({ field, euiFieldProps = {}, ...rest }: Props) =>
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiComboBox
noSuggestions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const MultiSelectField = ({ field, euiFieldProps = {}, ...rest }: Props)
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSelectable
allowExclusions={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const NumericField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiFieldNumber
isInvalid={isInvalid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const RadioGroupField = ({ field, euiFieldProps = {}, ...rest }: Props) =
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiRadioGroup
idSelected={field.value as string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const RangeField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiRange
value={field.value as number}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const SelectField = ({ field, euiFieldProps, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSelect
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const SuperSelectField = ({ field, euiFieldProps = { options: [] }, ...re
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSuperSelect
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const TextAreaField = ({ field, euiFieldProps = {}, ...rest }: Props) =>
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiTextArea
isInvalid={isInvalid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const TextField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiFieldText
isInvalid={isInvalid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const ToggleField = ({ field, euiFieldProps = {}, ...rest }: Props) => {
error={errorMessage}
isInvalid={isInvalid}
fullWidth
data-test-subj={rest['data-test-subj']}
describedByIds={rest.idAria ? [rest.idAria] : undefined}
{...rest}
>
<EuiSwitch
label={field.label}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ export const POLICY_NAME = 'my_policy';
export const SNAPSHOT_POLICY_NAME = 'my_snapshot_policy';
export const NEW_SNAPSHOT_POLICY_NAME = 'my_new_snapshot_policy';

export const DEFAULT_POLICY: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
policy: {
name: '',
phases: {
hot: {
min_age: '123ms',
actions: {
rollover: {},
},
},
},
},
name: '',
};

export const DELETE_PHASE_POLICY: PolicyFromES = {
version: 1,
modified_date: Date.now().toString(),
Expand All @@ -19,8 +36,12 @@ export const DELETE_PHASE_POLICY: PolicyFromES = {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_size: '50gb',
},
set_priority: {
priority: 100,
},
},
},
delete: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { act } from 'react-dom/test-utils';

import { registerTestBed, TestBed, TestBedConfig } from '../../../../../test_utils';
import { registerTestBed, TestBedConfig } from '../../../../../test_utils';

import { POLICY_NAME } from './constants';
import { TestSubjects } from '../helpers';
Expand Down Expand Up @@ -43,39 +43,110 @@ const testBedConfig: TestBedConfig = {
},
};

const initTestBed = registerTestBed(EditPolicy, testBedConfig);
const initTestBed = registerTestBed<TestSubjects>(EditPolicy, testBedConfig);

export interface EditPolicyTestBed extends TestBed<TestSubjects> {
actions: {
setWaitForSnapshotPolicy: (snapshotPolicyName: string) => void;
savePolicy: () => void;
};
}
type SetupReturn = ReturnType<typeof setup>;

export type EditPolicyTestBed = SetupReturn extends Promise<infer U> ? U : SetupReturn;

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

const { find, component } = testBed;

const setWaitForSnapshotPolicy = async (snapshotPolicyName: string) => {
const { component } = testBed;
act(() => {
testBed.find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]);
find('snapshotPolicyCombobox').simulate('change', [{ label: snapshotPolicyName }]);
});
component.update();
};

const savePolicy = async () => {
const { component, find } = testBed;
await act(async () => {
find('savePolicyButton').simulate('click');
});
component.update();
};

const toggleRollover = async (checked: boolean) => {
await act(async () => {
find('rolloverSwitch').simulate('click', { target: { checked } });
});
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 = async (value: string) => {
await act(async () => {
find('hot-selectedMaxDocuments').simulate('change', { target: { value } });
});
component.update();
};

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 toggleForceMerge = (phase: string) => async (checked: boolean) => {
await act(async () => {
find(`${phase}-forceMergeSwitch`).simulate('click', { target: { checked } });
});
component.update();
};

const setForcemergeSegmentsCount = (phase: string) => async (value: string) => {
await act(async () => {
find(`${phase}-selectedForceMergeSegments`).simulate('change', { target: { value } });
});
component.update();
};

const setBestCompression = (phase: string) => async (checked: boolean) => {
await act(async () => {
find(`${phase}-bestCompression`).simulate('click', { target: { checked } });
});
component.update();
};

const setIndexPriority = (phase: string) => async (value: string) => {
await act(async () => {
find(`${phase}-phaseIndexPriority`).simulate('change', { target: { value } });
});
component.update();
};

return {
...testBed,
actions: {
setWaitForSnapshotPolicy,
savePolicy,
hot: {
setMaxSize,
setMaxDocs,
setMaxAge,
toggleRollover,
toggleForceMerge: toggleForceMerge('hot'),
setForcemergeSegments: setForcemergeSegmentsCount('hot'),
setBestCompression: setBestCompression('hot'),
setIndexPriority: setIndexPriority('hot'),
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { setupEnvironment } from '../helpers/setup_environment';
import { EditPolicyTestBed, setup } from './edit_policy.helpers';

import { API_BASE_PATH } from '../../../common/constants';
import { DELETE_PHASE_POLICY, NEW_SNAPSHOT_POLICY_NAME, SNAPSHOT_POLICY_NAME } from './constants';
import {
DELETE_PHASE_POLICY,
NEW_SNAPSHOT_POLICY_NAME,
SNAPSHOT_POLICY_NAME,
DEFAULT_POLICY,
} from './constants';

window.scrollTo = jest.fn();

Expand All @@ -21,6 +26,83 @@ describe('<EditPolicy />', () => {
server.restore();
});

describe('hot phase', () => {
describe('serialization', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([DEFAULT_POLICY]);
httpRequestsMockHelpers.setLoadSnapshotPolicies([]);

await act(async () => {
testBed = await setup();
});

const { component } = testBed;
component.update();
});

test('setting all values', async () => {
const { actions } = testBed;

await actions.hot.setMaxSize('123', 'mb');
await actions.hot.setMaxDocs('123');
await actions.hot.setMaxAge('123', 'h');
await actions.hot.toggleForceMerge(true);
await actions.hot.setForcemergeSegments('123');
await actions.hot.setBestCompression(true);
await actions.hot.setIndexPriority('123');

await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toMatchInlineSnapshot(`
Object {
"name": "my_policy",
"phases": Object {
"hot": Object {
"actions": Object {
"forcemerge": Object {
"index_codec": "best_compression",
"max_num_segments": 123,
},
"rollover": Object {
"max_age": "123h",
"max_docs": 123,
"max_size": "123mb",
},
"set_priority": Object {
"priority": 123,
},
},
"min_age": "0ms",
},
},
}
`);
});

test('disabling rollover', async () => {
const { actions } = testBed;
await actions.hot.toggleRollover(false);
await actions.savePolicy();
const latestRequest = server.requests[server.requests.length - 1];
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toMatchInlineSnapshot(`
Object {
"name": "my_policy",
"phases": Object {
"hot": Object {
"actions": Object {
"set_priority": Object {
"priority": 100,
},
},
"min_age": "0ms",
},
},
}
`);
});
});
});

describe('delete phase', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadPolicies([DELETE_PHASE_POLICY]);
Expand Down
Loading