forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ILM] Add "wait for snapshot" policy field to Delete phase (elastic#6…
…8505) * [ILM] Add "wait for snapshot" text field to edit policy form (Delete phase) * [ILM] Add jest client integration tests for delete phase Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
6c1f977
commit ce12f5c
Showing
11 changed files
with
337 additions
and
3 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ck/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/contants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const POLICY_NAME = 'my_policy'; | ||
|
||
export const DELETE_PHASE_POLICY = { | ||
version: 1, | ||
modified_date: Date.now(), | ||
policy: { | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: { | ||
rollover: { | ||
max_size: '50gb', | ||
}, | ||
}, | ||
}, | ||
delete: { | ||
min_age: '0ms', | ||
actions: { | ||
wait_for_snapshot: { | ||
policy: 'my_snapshot_policy', | ||
}, | ||
delete: { | ||
delete_searchable_snapshot: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
name: POLICY_NAME, | ||
}; |
58 changes: 58 additions & 0 deletions
58
...ndex_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../test_utils'; | ||
|
||
import { POLICY_NAME } from './contants'; | ||
import { TestSubjects } from '../helpers'; | ||
|
||
import { EditPolicy } from '../../../public/application/sections/edit_policy'; | ||
import { indexLifecycleManagementStore } from '../../../public/application/store'; | ||
|
||
const testBedConfig: TestBedConfig = { | ||
store: () => indexLifecycleManagementStore(), | ||
memoryRouter: { | ||
initialEntries: [`/policies/edit/${POLICY_NAME}`], | ||
componentRoutePath: `/policies/edit/:policyName`, | ||
}, | ||
}; | ||
|
||
const initTestBed = registerTestBed(EditPolicy, testBedConfig); | ||
|
||
export interface EditPolicyTestBed extends TestBed<TestSubjects> { | ||
actions: { | ||
setWaitForSnapshotPolicy: (snapshotPolicyName: string) => void; | ||
savePolicy: () => void; | ||
}; | ||
} | ||
|
||
export const setup = async (): Promise<EditPolicyTestBed> => { | ||
const testBed = await initTestBed(); | ||
|
||
const setWaitForSnapshotPolicy = (snapshotPolicyName: string) => { | ||
const { component, form } = testBed; | ||
form.setInputValue('waitForSnapshotField', snapshotPolicyName, true); | ||
component.update(); | ||
}; | ||
|
||
const savePolicy = async () => { | ||
const { component, find } = testBed; | ||
await act(async () => { | ||
find('savePolicyButton').simulate('click'); | ||
}); | ||
component.update(); | ||
}; | ||
|
||
return { | ||
...testBed, | ||
actions: { | ||
setWaitForSnapshotPolicy, | ||
savePolicy, | ||
}, | ||
}; | ||
}; |
96 changes: 96 additions & 0 deletions
96
...ns/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { setupEnvironment } from '../helpers/setup_environment'; | ||
|
||
import { EditPolicyTestBed, setup } from './edit_policy.helpers'; | ||
import { DELETE_PHASE_POLICY } from './contants'; | ||
|
||
import { API_BASE_PATH } from '../../../common/constants'; | ||
|
||
window.scrollTo = jest.fn(); | ||
|
||
describe('<EditPolicy />', () => { | ||
let testBed: EditPolicyTestBed; | ||
const { server, httpRequestsMockHelpers } = setupEnvironment(); | ||
afterAll(() => { | ||
server.restore(); | ||
}); | ||
|
||
describe('delete phase', () => { | ||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([DELETE_PHASE_POLICY]); | ||
|
||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
}); | ||
|
||
test('wait for snapshot policy field should correctly display snapshot policy name', () => { | ||
expect(testBed.find('waitForSnapshotField').props().value).toEqual( | ||
DELETE_PHASE_POLICY.policy.phases.delete.actions.wait_for_snapshot.policy | ||
); | ||
}); | ||
|
||
test('wait for snapshot field should correctly update snapshot policy name', async () => { | ||
const { actions } = testBed; | ||
|
||
const newPolicyName = 'my_new_snapshot_policy'; | ||
actions.setWaitForSnapshotPolicy(newPolicyName); | ||
await actions.savePolicy(); | ||
|
||
const expected = { | ||
name: DELETE_PHASE_POLICY.name, | ||
phases: { | ||
...DELETE_PHASE_POLICY.policy.phases, | ||
delete: { | ||
...DELETE_PHASE_POLICY.policy.phases.delete, | ||
actions: { | ||
...DELETE_PHASE_POLICY.policy.phases.delete.actions, | ||
wait_for_snapshot: { | ||
policy: newPolicyName, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const latestRequest = server.requests[server.requests.length - 1]; | ||
expect(latestRequest.url).toBe(`${API_BASE_PATH}/policies`); | ||
expect(latestRequest.method).toBe('POST'); | ||
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected); | ||
}); | ||
|
||
test('wait for snapshot field should delete action if field is empty', async () => { | ||
const { actions } = testBed; | ||
|
||
actions.setWaitForSnapshotPolicy(''); | ||
await actions.savePolicy(); | ||
|
||
const expected = { | ||
name: DELETE_PHASE_POLICY.name, | ||
phases: { | ||
...DELETE_PHASE_POLICY.policy.phases, | ||
delete: { | ||
...DELETE_PHASE_POLICY.policy.phases.delete, | ||
actions: { | ||
...DELETE_PHASE_POLICY.policy.phases.delete.actions, | ||
}, | ||
}, | ||
}, | ||
}; | ||
delete expected.phases.delete.actions.wait_for_snapshot; | ||
|
||
const latestRequest = server.requests[server.requests.length - 1]; | ||
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
...k/plugins/index_lifecycle_management/__jest__/client_integration/helpers/http_requests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SinonFakeServer, fakeServer } from 'sinon'; | ||
import { API_BASE_PATH } from '../../../common/constants'; | ||
|
||
export const init = () => { | ||
const server = fakeServer.create(); | ||
server.respondImmediately = true; | ||
server.respondWith([200, {}, 'DefaultServerResponse']); | ||
|
||
return { | ||
server, | ||
httpRequestsMockHelpers: registerHttpRequestMockHelpers(server), | ||
}; | ||
}; | ||
|
||
const registerHttpRequestMockHelpers = (server: SinonFakeServer) => { | ||
const setLoadPolicies = (response: any = []) => { | ||
server.respondWith('GET', `${API_BASE_PATH}/policies`, [ | ||
200, | ||
{ 'Content-Type': 'application/json' }, | ||
JSON.stringify(response), | ||
]); | ||
}; | ||
|
||
return { | ||
setLoadPolicies, | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export type TestSubjects = 'waitForSnapshotField' | 'savePolicyButton'; |
39 changes: 39 additions & 0 deletions
39
...ugins/index_lifecycle_management/__jest__/client_integration/helpers/setup_environment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import axios from 'axios'; | ||
import axiosXhrAdapter from 'axios/lib/adapters/xhr'; | ||
|
||
import { init as initHttp } from '../../../public/application/services/http'; | ||
import { init as initHttpRequests } from './http_requests'; | ||
import { init as initUiMetric } from '../../../public/application/services/ui_metric'; | ||
import { init as initNotification } from '../../../public/application/services/notification'; | ||
|
||
import { usageCollectionPluginMock } from '../../../../../../src/plugins/usage_collection/public/mocks'; | ||
|
||
import { | ||
notificationServiceMock, | ||
fatalErrorsServiceMock, | ||
} from '../../../../../../src/core/public/mocks'; | ||
|
||
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter }); | ||
|
||
export const setupEnvironment = () => { | ||
initUiMetric(usageCollectionPluginMock.createSetupContract()); | ||
initNotification( | ||
notificationServiceMock.createSetupContract().toasts, | ||
fatalErrorsServiceMock.createSetupContract() | ||
); | ||
|
||
mockHttpClient.interceptors.response.use(({ data }) => data); | ||
initHttp(mockHttpClient); | ||
const { server, httpRequestsMockHelpers } = initHttpRequests(); | ||
|
||
return { | ||
server, | ||
httpRequestsMockHelpers, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.