-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ILM] Migrate Hot phase to Form Lib #80012
Changes from all commits
0b59256
ea04a60
5f265af
16adb9b
4cd11d6
0eb0610
d9f4c5f
f030d70
deb67bf
d087b44
bed6317
200b6d4
3655f0f
5dc6023
d1fdd66
a33ab32
2cbc917
f78b566
b0a8096
22017f7
eab1538
a8ab7b6
b7a7f37
759a0a0
100ad62
9d869c8
844be4b
7da30bd
7f48a65
e5665d0
55346ba
b560f21
371ff40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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'; | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice trick! I guess we'll never hit the right part of the ternary right? But this is a way to extract |
||
|
||
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 |
---|---|---|
|
@@ -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(); | ||
|
||
|
@@ -21,6 +26,83 @@ describe('<EditPolicy />', () => { | |
server.restore(); | ||
}); | ||
|
||
describe('hot phase', () => { | ||
describe('serialization', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome to have the serialization test here! 👍 |
||
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]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 👍 Can we make this change to all the components?