-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split reactive_form into smaller files
- Loading branch information
Showing
6 changed files
with
339 additions
and
241 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
..._lifecycle_management/__jest__/client_integration/edit_policy/features/cold_phase.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,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
import { setupEnvironment } from '../../helpers/setup_environment'; | ||
import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; | ||
import { getDefaultHotPhasePolicy } from '../constants'; | ||
|
||
describe('<EditPolicy /> cold phase', () => { | ||
let testBed: EditPolicyTestBed; | ||
const { server, httpRequestsMockHelpers } = setupEnvironment(); | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
server.restore(); | ||
}); | ||
|
||
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([]); | ||
|
||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
}); | ||
|
||
test('shows timing only when enabled', async () => { | ||
const { actions } = testBed; | ||
expect(actions.cold.hasMinAgeInput()).toBeFalsy(); | ||
await actions.cold.enable(true); | ||
expect(actions.cold.hasMinAgeInput()).toBeTruthy(); | ||
}); | ||
}); |
169 changes: 169 additions & 0 deletions
169
...ifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.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,169 @@ | ||
/* | ||
* 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 { | ||
DELETE_PHASE_POLICY, | ||
getDefaultHotPhasePolicy, | ||
NEW_SNAPSHOT_POLICY_NAME, | ||
SNAPSHOT_POLICY_NAME, | ||
} from '../constants'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { EditPolicyTestBed, setup } from '../edit_policy.helpers'; | ||
import { API_BASE_PATH } from '../../../../common/constants'; | ||
import { setupEnvironment } from '../../helpers/setup_environment'; | ||
|
||
describe('<EditPolicy /> delete phase', () => { | ||
let testBed: EditPolicyTestBed; | ||
const { server, httpRequestsMockHelpers } = setupEnvironment(); | ||
|
||
afterAll(() => { | ||
server.restore(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([DELETE_PHASE_POLICY]); | ||
httpRequestsMockHelpers.setLoadSnapshotPolicies([ | ||
SNAPSHOT_POLICY_NAME, | ||
NEW_SNAPSHOT_POLICY_NAME, | ||
]); | ||
|
||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
}); | ||
|
||
test('is hidden when disabled', async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); | ||
|
||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
expect(actions.delete.isShown()).toBeFalsy(); | ||
await actions.delete.enablePhase(); | ||
expect(actions.delete.isShown()).toBeTruthy(); | ||
}); | ||
|
||
test('shows timing after it was enabled', async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); | ||
|
||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
expect(actions.delete.hasMinAgeInput()).toBeFalsy(); | ||
await actions.delete.enablePhase(); | ||
expect(actions.delete.hasMinAgeInput()).toBeTruthy(); | ||
}); | ||
|
||
describe('wait for snapshot', () => { | ||
test('shows snapshot policy name', () => { | ||
expect(testBed.find('snapshotPolicyCombobox').prop('data-currentvalue')).toEqual([ | ||
{ | ||
label: DELETE_PHASE_POLICY.policy.phases.delete?.actions.wait_for_snapshot?.policy, | ||
}, | ||
]); | ||
}); | ||
|
||
test('updates snapshot policy name', async () => { | ||
const { actions } = testBed; | ||
|
||
await actions.setWaitForSnapshotPolicy(NEW_SNAPSHOT_POLICY_NAME); | ||
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: NEW_SNAPSHOT_POLICY_NAME, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
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('shows a callout when the input is not an existing policy', async () => { | ||
const { actions } = testBed; | ||
|
||
await actions.setWaitForSnapshotPolicy('my_custom_policy'); | ||
expect(testBed.find('noPoliciesCallout').exists()).toBeFalsy(); | ||
expect(testBed.find('policiesErrorCallout').exists()).toBeFalsy(); | ||
expect(testBed.find('customPolicyCallout').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('removes the action if field is empty', async () => { | ||
const { actions } = testBed; | ||
|
||
await 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); | ||
}); | ||
|
||
test('shows a callout when there are no snapshot policies', async () => { | ||
// need to call setup on testBed again for it to use a newly defined snapshot policies response | ||
httpRequestsMockHelpers.setLoadSnapshotPolicies([]); | ||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
testBed.component.update(); | ||
expect(testBed.find('customPolicyCallout').exists()).toBeFalsy(); | ||
expect(testBed.find('policiesErrorCallout').exists()).toBeFalsy(); | ||
expect(testBed.find('noPoliciesCallout').exists()).toBeTruthy(); | ||
}); | ||
|
||
test('shows a callout when there is an error loading snapshot policies', async () => { | ||
// need to call setup on testBed again for it to use a newly defined snapshot policies response | ||
httpRequestsMockHelpers.setLoadSnapshotPolicies([], { status: 500, body: 'error' }); | ||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
testBed.component.update(); | ||
expect(testBed.find('customPolicyCallout').exists()).toBeFalsy(); | ||
expect(testBed.find('noPoliciesCallout').exists()).toBeFalsy(); | ||
expect(testBed.find('policiesErrorCallout').exists()).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
...lifecycle_management/__jest__/client_integration/edit_policy/features/json_flyout.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,66 @@ | ||
/* | ||
* 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 { EditPolicyTestBed, setup } from '../edit_policy.helpers'; | ||
import { setupEnvironment } from '../../helpers/setup_environment'; | ||
import { getDefaultHotPhasePolicy } from '../constants'; | ||
|
||
describe('<EditPolicy /> request flyout', () => { | ||
let testBed: EditPolicyTestBed; | ||
const { server, httpRequestsMockHelpers } = setupEnvironment(); | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
server.restore(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); | ||
|
||
await act(async () => { | ||
testBed = await setup(); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
}); | ||
|
||
test('renders a json in flyout for a default policy', async () => { | ||
const { find, component } = testBed; | ||
await act(async () => { | ||
find('requestButton').simulate('click'); | ||
}); | ||
component.update(); | ||
|
||
const json = component.find(`code`).text(); | ||
const expected = `PUT _ilm/policy/my_policy\n${JSON.stringify( | ||
{ | ||
policy: { | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: { | ||
rollover: { | ||
max_age: '30d', | ||
max_size: '50gb', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
null, | ||
2 | ||
)}`; | ||
expect(json).toBe(expected); | ||
}); | ||
}); |
109 changes: 0 additions & 109 deletions
109
...fecycle_management/__jest__/client_integration/edit_policy/features/reactive_form.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.