Skip to content

Commit

Permalink
[ML] Fix applying retention policy settings for cloning.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Jan 24, 2022
1 parent 71b7585 commit f81c9e2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export const StepDetailsForm: FC<StepDetailsFormProps> = React.memo(
defaults.isRetentionPolicyEnabled
);
const [retentionPolicyDateField, setRetentionPolicyDateField] = useState(
isRetentionPolicyAvailable ? dateFieldNames[0] : ''
isRetentionPolicyAvailable ? defaults.retentionPolicyDateField : ''
);
const [retentionPolicyMaxAge, setRetentionPolicyMaxAge] = useState(
defaults.retentionPolicyMaxAge
Expand Down
28 changes: 28 additions & 0 deletions x-pack/test/functional/apps/transform/cloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function getTransformConfig(): TransformPivotConfig {
description:
'ecommerce batch transform with avg(products.base_price) grouped by terms(category)',
frequency: '3s',
retention_policy: { time: { field: 'order_date', max_age: '1d' } },
settings: {
max_page_search_size: 250,
},
Expand Down Expand Up @@ -72,6 +73,7 @@ function getTransformConfigWithRuntimeMappings(): TransformPivotConfig {
},
description: 'ecommerce batch transform grouped by terms(rt_gender_lower)',
frequency: '3s',
retention_policy: { time: { field: 'order_date', max_age: '3d' } },
settings: {
max_page_search_size: 250,
},
Expand Down Expand Up @@ -157,6 +159,9 @@ export default function ({ getService }: FtrProviderContext) {
`Women's Clothing`,
],
},
retentionPolicySwitchEnabled: true,
retentionPolicyField: 'order_date',
retentionPolicyMaxAge: '1d',
},
},
{
Expand Down Expand Up @@ -186,6 +191,9 @@ export default function ({ getService }: FtrProviderContext) {
column: 0,
values: [`female`, `male`],
},
retentionPolicySwitchEnabled: true,
retentionPolicyField: 'order_date',
retentionPolicyMaxAge: '3d',
},
},
{
Expand All @@ -210,6 +218,7 @@ export default function ({ getService }: FtrProviderContext) {
'July 12th 2019, 23:45:36',
],
},
retentionPolicySwitchEnabled: false,
},
},
];
Expand Down Expand Up @@ -303,6 +312,7 @@ export default function ({ getService }: FtrProviderContext) {
testData.expected.transformPreview.values
);

// assert details step form
await transform.testExecution.logTestStep('should load the details step');
await transform.wizard.advanceToDetailsStep();

Expand Down Expand Up @@ -331,6 +341,24 @@ export default function ({ getService }: FtrProviderContext) {
await transform.wizard.assertContinuousModeSwitchExists();
await transform.wizard.assertContinuousModeSwitchCheckState(false);

await transform.testExecution.logTestStep(
'should display the retention policy settings with pre-filled configuration'
);
await transform.wizard.assertRetentionPolicySwitchExists();
await transform.wizard.assertRetentionPolicySwitchCheckState(
testData.expected.retentionPolicySwitchEnabled
);
if (testData.expected.retentionPolicySwitchEnabled) {
await transform.wizard.assertRetentionPolicyFieldSelectExists();
await transform.wizard.assertRetentionPolicyFieldSelectValue(
testData.expected.retentionPolicyField
);
await transform.wizard.assertRetentionPolicyMaxAgeInputExists();
await transform.wizard.assertRetentionsPolicyMaxAgeValue(
testData.expected.retentionPolicyMaxAge
);
}

await transform.testExecution.logTestStep(
'should display the advanced settings and show pre-filled configuration'
);
Expand Down
51 changes: 51 additions & 0 deletions x-pack/test/functional/services/transform/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,57 @@ export function TransformWizardProvider({ getService, getPageObjects }: FtrProvi
);
},

async assertRetentionPolicySwitchExists() {
await testSubjects.existOrFail(`transformRetentionPolicySwitch`, { allowHidden: true });
},

async assertRetentionPolicySwitchCheckState(expectedCheckState: boolean) {
const actualCheckState =
(await testSubjects.getAttribute('transformRetentionPolicySwitch', 'aria-checked')) ===
'true';
expect(actualCheckState).to.eql(
expectedCheckState,
`Retention policy switch check state should be '${expectedCheckState}' (got '${actualCheckState}')`
);
},

async assertRetentionPolicyFieldSelectExists() {
await testSubjects.existOrFail(`transformRetentionPolicyDateFieldSelect`, {
allowHidden: true,
});
},

async assertRetentionPolicyFieldSelectValue(expectedValue: string) {
await testSubjects.existOrFail(`transformRetentionPolicyDateFieldSelect`, {
timeout: 1000,
});
const actualValue = await testSubjects.getAttribute(
'transformRetentionPolicyDateFieldSelect',
'value'
);
expect(actualValue).to.eql(
expectedValue,
`Retention policy field option value should be '${expectedValue}' (got '${actualValue}')`
);
},

async assertRetentionPolicyMaxAgeInputExists() {
await testSubjects.existOrFail(`transformRetentionPolicyMaxAgeInput`, {
allowHidden: true,
});
},

async assertRetentionsPolicyMaxAgeValue(expectedValue: string) {
const actualValue = await testSubjects.getAttribute(
'transformRetentionPolicyMaxAgeInput',
'value'
);
expect(actualValue).to.eql(
expectedValue,
`Transform retention policy max age input text should be '${expectedValue}' (got '${actualValue}')`
);
},

async assertTransformAdvancedSettingsAccordionExists() {
await testSubjects.existOrFail('transformWizardAccordionAdvancedSettings');
},
Expand Down

0 comments on commit f81c9e2

Please sign in to comment.