Skip to content

Commit

Permalink
Add jest tests for edit policy callout
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed May 18, 2022
1 parent 06c968b commit ac47b02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,29 @@ export const POLICY_WITH_KNOWN_AND_UNKNOWN_FIELDS = {
name: POLICY_NAME,
} as any as PolicyFromES;

export const POLICY_MANAGED_BY_ES: PolicyFromES = {
version: 1,
modifiedDate: Date.now().toString(),
policy: {
name: POLICY_NAME,
phases: {
hot: {
min_age: '0ms',
actions: {
rollover: {
max_age: '30d',
max_primary_shard_size: '50gb',
},
},
},
},
_meta: {
managed: true,
},
},
name: POLICY_NAME,
};

export const getGeneratedPolicies = (): PolicyFromES[] => {
const policy = {
phases: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { act } from 'react-dom/test-utils';
import { TestBed } from '@kbn/test-jest-helpers';
import { setupEnvironment } from '../../helpers';
import { initTestBed } from '../init_test_bed';
import { getDefaultHotPhasePolicy, POLICY_NAME } from '../constants';
import { getDefaultHotPhasePolicy, POLICY_NAME, POLICY_MANAGED_BY_ES } from '../constants';

describe('<EditPolicy /> edit warning', () => {
let testBed: TestBed;
Expand Down Expand Up @@ -54,6 +54,19 @@ describe('<EditPolicy /> edit warning', () => {
expect(exists('editWarning')).toBe(true);
});

test('an edit warning callout is shown for an existing, managed policy', async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_MANAGED_BY_ES]);

await act(async () => {
testBed = await initTestBed(httpSetup);
});
const { exists, component } = testBed;
component.update();

expect(exists('editWarning')).toBe(true);
expect(exists('editManagedPolicyCallOut')).toBe(true);
});

test('no indices link if no indices', async () => {
httpRequestsMockHelpers.setLoadPolicies([
{ ...getDefaultHotPhasePolicy(POLICY_NAME), indices: [] },
Expand Down

0 comments on commit ac47b02

Please sign in to comment.