Skip to content

Commit

Permalink
[ML] refactor functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Oct 30, 2020
1 parent 56ce1ad commit ca7c2fc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
this.props.isModelPlotEnabled ? (
<FormattedMessage
id="xpack.ml.timeSeriesExplorer.nonAnomalousResultsWithModelPlotInfo"
defaultMessage="The list contains values for the model plot results."
defaultMessage="The list contains values from the model plot results."
/>
) : (
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export default function ({ getService }: FtrProviderContext) {
'desc'
);

await ml.testExecution.logTestStep('modify the entity config');
await ml.singleMetricViewer.setEntityConfig('geoip.city_name', false, 'name', 'asc');

// make sure anomalous only control has been synced
Expand Down
18 changes: 18 additions & 0 deletions x-pack/test/functional/services/ml/common_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { ProvidedType } from '@kbn/test/types/ftr';

import { FtrProviderContext } from '../../ftr_provider_context';
Expand Down Expand Up @@ -98,5 +99,22 @@ export function MachineLearningCommonUIProvider({ getService }: FtrProviderConte
async assertKibanaHomeFileDataVisLinkNotExists() {
await testSubjects.missingOrFail('homeSynopsisLinkml_file_data_visualizer');
},

async assertRadioGroupValue(testSubject: string, expectedValue: string) {
const assertRadioGroupValue = await testSubjects.find(testSubject);
const input = await assertRadioGroupValue.findByCssSelector(':checked');
const selectedOptionId = await input.getAttribute('id');
expect(selectedOptionId).to.eql(
expectedValue,
`Expected the radio group value to equal "${expectedValue}" (got "${selectedOptionId}")`
);
},

async selectRadioGroupValue(testSubject: string, value: string) {
const radioGroup = await testSubjects.find(testSubject);
const label = await radioGroup.findByCssSelector(`label[for="${value}"]`);
await label.click();
await this.assertRadioGroupValue(testSubject, value);
},
};
}
2 changes: 1 addition & 1 deletion x-pack/test/functional/services/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function MachineLearningProvider(context: FtrProviderContext) {
const settings = MachineLearningSettingsProvider(context);
const settingsCalendar = MachineLearningSettingsCalendarProvider(context, commonUI);
const settingsFilterList = MachineLearningSettingsFilterListProvider(context, commonUI);
const singleMetricViewer = MachineLearningSingleMetricViewerProvider(context);
const singleMetricViewer = MachineLearningSingleMetricViewerProvider(context, commonUI);
const testExecution = MachineLearningTestExecutionProvider(context);
const testResources = MachineLearningTestResourcesProvider(context);

Expand Down
32 changes: 9 additions & 23 deletions x-pack/test/functional/services/ml/single_metric_viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import expect from '@kbn/expect';

import { FtrProviderContext } from '../../ftr_provider_context';
import { MlCommonUI } from './common_ui';

export function MachineLearningSingleMetricViewerProvider({ getService }: FtrProviderContext) {
export function MachineLearningSingleMetricViewerProvider(
{ getService }: FtrProviderContext,
mlCommonUI: MlCommonUI
) {
const comboBox = getService('comboBox');
const testSubjects = getService('testSubjects');

Expand Down Expand Up @@ -135,24 +139,6 @@ export function MachineLearningSingleMetricViewerProvider({ getService }: FtrPro
);
},

// TODO move to some common service for EUI components
async assertRadioGroupValue(testSubject: string, expectedValue: string) {
const sortByRadioGroup = await testSubjects.find(testSubject);
const input = await sortByRadioGroup.findByCssSelector(':checked');
const selectedSortBy = await input.getAttribute('id');
expect(selectedSortBy).to.eql(
expectedValue,
`Expected the radio group value to equal "${expectedValue}"`
);
},

// TODO move to some common service for EUI components
async selectRadioGroupValue(testSubject: string, value: string) {
const sortByRadioGroup = await testSubjects.find(testSubject);
const label = await sortByRadioGroup.findByCssSelector(`label[for="${value}"]`);
await label.click();
},

async assertEntityConfig(
entityFieldName: string,
anomalousOnly: boolean,
Expand All @@ -170,11 +156,11 @@ export function MachineLearningSingleMetricViewerProvider({ getService }: FtrPro
anomalousOnly ? 'enabled' : 'disabled'
}`
);
await this.assertRadioGroupValue(
await mlCommonUI.assertRadioGroupValue(
`mlSingleMetricViewerEntitySelectionConfigSortBy_${entityFieldName}`,
sortBy
);
await this.assertRadioGroupValue(
await mlCommonUI.assertRadioGroupValue(
`mlSingleMetricViewerEntitySelectionConfigOrder_${entityFieldName}`,
order
);
Expand All @@ -191,11 +177,11 @@ export function MachineLearningSingleMetricViewerProvider({ getService }: FtrPro
`mlSingleMetricViewerEntitySelectionConfigAnomalousOnly_${entityFieldName}`,
anomalousOnly ? 'check' : 'uncheck'
);
await this.selectRadioGroupValue(
await mlCommonUI.selectRadioGroupValue(
`mlSingleMetricViewerEntitySelectionConfigSortBy_${entityFieldName}`,
sortBy
);
await this.selectRadioGroupValue(
await mlCommonUI.selectRadioGroupValue(
`mlSingleMetricViewerEntitySelectionConfigOrder_${entityFieldName}`,
order
);
Expand Down

0 comments on commit ca7c2fc

Please sign in to comment.