Skip to content

Commit

Permalink
[7.x] [SR] Fix bug when editing retention of slm policy (#67137) (#67436
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alisonelizabeth authored May 27, 2020
1 parent c08403d commit c5fabff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const REPOSITORY_EDIT = getRepository({ name: REPOSITORY_NAME });

export const POLICY_NAME = 'my-test-policy';

export const POLICY_EDIT = getPolicy({ name: POLICY_NAME });
export const POLICY_EDIT = getPolicy({ name: POLICY_NAME, retention: { minCount: 1 } });
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { PolicyForm } from '../../public/application/components/policy_form';
import { PolicyFormTestBed } from './helpers/policy_form.helpers';
import { POLICY_EDIT } from './helpers/constant';
import { TIME_UNITS } from '../../common/constants';

const { setup } = pageHelpers.policyEdit;
const { setup: setupPolicyAdd } = pageHelpers.policyAdd;

const EXPIRE_AFTER_VALUE = '5';
const EXPIRE_AFTER_UNIT = 'm';
const EXPIRE_AFTER_UNIT = TIME_UNITS.MINUTE;

jest.mock('ui/i18n', () => {
const I18nContext = ({ children }: any) => children;
Expand Down Expand Up @@ -83,28 +84,23 @@ describe('<PolicyEdit />', () => {
});

describe('form payload', () => {
beforeEach(async () => {
it('should send the correct payload with changed values', async () => {
const { form, actions } = testBed;

const { snapshotName } = POLICY_EDIT;

// Complete step 1
// Complete step 1, change snapshot name
form.setInputValue('snapshotNameInput', `${snapshotName}-edited`);
actions.clickNextButton();

// Complete step 2
// console.log(testBed.component.debug());
// Complete step 2, enable ignore unavailable indices switch
form.toggleEuiSwitch('ignoreUnavailableIndicesToggle');
actions.clickNextButton();

// Complete step 3
// Complete step 3, modify retention
form.setInputValue('expireAfterValueInput', EXPIRE_AFTER_VALUE);
form.setInputValue('expireAfterUnitSelect', EXPIRE_AFTER_UNIT);
actions.clickNextButton();
});

it('should send the correct payload with changed values', async () => {
const { actions } = testBed;

await act(async () => {
actions.clickSubmitButton();
Expand All @@ -120,6 +116,7 @@ describe('<PolicyEdit />', () => {
ignoreUnavailable: true,
},
retention: {
...POLICY_EDIT.retention,
expireAfterValue: Number(EXPIRE_AFTER_VALUE),
expireAfterUnit: EXPIRE_AFTER_UNIT,
},
Expand All @@ -128,6 +125,37 @@ describe('<PolicyEdit />', () => {
};
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
});

it('should provide a default time unit value for retention', async () => {
const { form, actions } = testBed;

// Bypass step 1
actions.clickNextButton();

// Bypass step 2
actions.clickNextButton();

// Step 3: Add expire after value, but do not change unit
form.setInputValue('expireAfterValueInput', EXPIRE_AFTER_VALUE);
actions.clickNextButton();

await act(async () => {
actions.clickSubmitButton();
await nextTick();
});

const latestRequest = server.requests[server.requests.length - 1];

const expected = {
...POLICY_EDIT,
retention: {
...POLICY_EDIT.retention,
expireAfterValue: Number(EXPIRE_AFTER_VALUE),
expireAfterUnit: TIME_UNITS.DAY, // default value
},
};
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ export const PolicyForm: React.FunctionComponent<Props> = ({
...(originalPolicy.config || {}),
},
retention: {
...(originalPolicy.retention || {
expireAfterUnit: TIME_UNITS.DAY,
}),
...originalPolicy.retention,
expireAfterUnit: originalPolicy.retention?.expireAfterUnit ?? TIME_UNITS.DAY,
},
});

Expand Down

0 comments on commit c5fabff

Please sign in to comment.