Skip to content

Commit

Permalink
[ML] Add functional tests for Field stats flyout in Anomaly detection…
Browse files Browse the repository at this point in the history
… job creation wizards (#151336)
  • Loading branch information
qn895 committed Feb 16, 2023
1 parent 31797f5 commit bd89b11
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '@kbn/ml-plugin/common/constants/categorization_job';
import { FtrProviderContext } from '../../../ftr_provider_context';
import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -74,6 +75,13 @@ export default function ({ getService }: FtrProviderContext) {

const calendarId = `wizard-test-calendar_${Date.now()}`;

const fieldStatsEntries = [
{
fieldName: 'field1',
type: 'keyword' as FieldStatsType,
},
];

describe('categorization', function () {
this.tags(['ml']);
before(async () => {
Expand Down Expand Up @@ -129,8 +137,18 @@ export default function ({ getService }: FtrProviderContext) {
await ml.jobWizardCategorization.assertCategorizationDetectorTypeSelectionExists();
await ml.jobWizardCategorization.selectCategorizationDetectorType(detectorTypeIdentifier);

await ml.testExecution.logTestStep(`job creation selects the categorization field`);
await ml.testExecution.logTestStep(
'job creation opens field stats flyout from categorization field input'
);
await ml.jobWizardCategorization.assertCategorizationFieldInputExists();
for (const { fieldName, type: fieldType } of fieldStatsEntries) {
await ml.jobWizardCategorization.assertFieldStatFlyoutContentFromCategorizationFieldInputTrigger(
fieldName,
fieldType
);
}

await ml.testExecution.logTestStep(`job creation selects the categorization field`);
await ml.jobWizardCategorization.selectCategorizationField(categorizationFieldIdentifier);
await ml.jobWizardCategorization.assertCategorizationExamplesCallout(
CATEGORY_EXAMPLES_VALIDATION_STATUS.VALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';
import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -71,6 +72,14 @@ export default function ({ getService }: FtrProviderContext) {

const calendarId = `wizard-test-calendar_${Date.now()}`;

const fieldStatsEntries = [
{
fieldName: '@version.keyword',
type: 'keyword' as FieldStatsType,
expectedValues: ['1'],
},
];

describe('multi metric', function () {
this.tags(['ml']);
before(async () => {
Expand Down Expand Up @@ -129,9 +138,20 @@ export default function ({ getService }: FtrProviderContext) {
}

await ml.testExecution.logTestStep(
'job creation inputs the split field and displays split cards'
'job creation opens field stats flyout from split field input'
);
await ml.jobWizardMultiMetric.assertSplitFieldInputExists();
for (const { fieldName, type: fieldType, expectedValues } of fieldStatsEntries) {
await ml.jobWizardMultiMetric.assertFieldStatFlyoutContentFromSplitFieldInputTrigger(
fieldName,
fieldType,
expectedValues
);
}

await ml.testExecution.logTestStep(
'job creation inputs the split field and displays split cards'
);
await ml.jobWizardMultiMetric.selectSplitField(splitField);

await ml.jobWizardMultiMetric.assertDetectorSplitExists(splitField);
Expand All @@ -140,8 +160,19 @@ export default function ({ getService }: FtrProviderContext) {

await ml.jobWizardCommon.assertInfluencerSelection([splitField]);

await ml.testExecution.logTestStep('job creation displays the influencer field');
await ml.testExecution.logTestStep(
'job creation opens field stats flyout from influencer field input'
);
await ml.jobWizardCommon.assertInfluencerInputExists();
for (const { fieldName, type: fieldType, expectedValues } of fieldStatsEntries) {
await ml.jobWizardCommon.assertFieldStatFlyoutContentFromInfluencerInputTrigger(
fieldName,
fieldType,
expectedValues
);
}

await ml.testExecution.logTestStep('job creation displays the influencer field');
await ml.jobWizardCommon.assertInfluencerSelection([splitField]);

await ml.testExecution.logTestStep('job creation inputs the bucket span');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';
import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -33,6 +34,14 @@ export default function ({ getService }: FtrProviderContext) {
numberOfBackCards: 5,
},
];
const fieldStatsEntries = [
{
fieldName: 'currency',
type: 'keyword' as FieldStatsType,
expectedValues: ['EUR'],
},
];

const bucketSpan = '2h';
const memoryLimit = '8mb';

Expand Down Expand Up @@ -133,8 +142,19 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep('job creation displays the pick fields step');
await ml.jobWizardCommon.advanceToPickFieldsSection();

await ml.testExecution.logTestStep('job creation selects the population field');
await ml.testExecution.logTestStep(
'job creation opens field stats flyout from population field input'
);
await ml.jobWizardPopulation.assertPopulationFieldInputExists();
for (const { fieldName, type: fieldType, expectedValues } of fieldStatsEntries) {
await ml.jobWizardPopulation.assertFieldStatFlyoutContentFromPopulationFieldInputTrigger(
fieldName,
fieldType,
expectedValues
);
}

await ml.testExecution.logTestStep('job creation selects the population field');
await ml.jobWizardPopulation.selectPopulationField(populationField);

await ml.testExecution.logTestStep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';
import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const config = getService('config');
Expand Down Expand Up @@ -79,6 +80,14 @@ export default function ({ getService }: FtrProviderContext) {
? remoteName + indexPatternName
: indexPatternName;

const fieldStatsEntries = [
{
fieldName: '@version.keyword',
type: 'keyword' as FieldStatsType,
expectedValues: ['1'],
},
];

describe('single metric', function () {
this.tags(['ml']);
before(async () => {
Expand Down Expand Up @@ -127,8 +136,17 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep('job creation displays the pick fields step');
await ml.jobWizardCommon.advanceToPickFieldsSection();

await ml.testExecution.logTestStep('job creation selects field and aggregation');
await ml.testExecution.logTestStep('job creation opens field stats flyout from agg input');
await ml.jobWizardCommon.assertAggAndFieldInputExists();
for (const { fieldName, type: fieldType, expectedValues } of fieldStatsEntries) {
await ml.jobWizardCommon.assertFieldStatFlyoutContentFromAggSelectionInputTrigger(
fieldName,
fieldType,
expectedValues
);
}

await ml.testExecution.logTestStep('job creation selects field and aggregation');
await ml.jobWizardCommon.selectAggAndField(aggAndFieldIdentifier, true);
await ml.jobWizardCommon.assertAnomalyChartExists('LINE');

Expand Down Expand Up @@ -255,7 +273,6 @@ export default function ({ getService }: FtrProviderContext) {
await ml.jobWizardCommon.advanceToPickFieldsSection();

await ml.testExecution.logTestStep('job cloning pre-fills field and aggregation');
await ml.jobWizardCommon.assertAggAndFieldInputExists();
await ml.jobWizardCommon.assertAggAndFieldSelection([aggAndFieldIdentifier]);
await ml.jobWizardCommon.assertAnomalyChartExists('LINE');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { AnalyticsTableRowDetails } from '../../../services/ml/data_frame_analytics_table';
import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { FieldStatsType } from './types';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { AnalyticsTableRowDetails } from '../../../services/ml/data_frame_analytics_table';
import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { FieldStatsType } from './types';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { AnalyticsTableRowDetails } from '../../../services/ml/data_frame_analytics_table';
import type { FieldStatsType } from './types';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { FtrProviderContext } from '../../../ftr_provider_context';
import type { AnalyticsTableRowDetails } from '../../../services/ml/data_frame_analytics_table';
import type { FieldStatsType } from './types';
import type { FieldStatsType } from '../common/types';

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { FtrProviderContext } from '../../ftr_provider_context';
import type { CanvasElementColorStats } from '../canvas_element';
import type { MlCommonUI } from './common_ui';
import type { MlApi } from './api';
import type { MlFieldStatsFlyout } from './field_stats_flyout';
import type { MlCommonFieldStatsFlyout } from './field_stats_flyout';

export function MachineLearningDataFrameAnalyticsCreationProvider(
{ getPageObject, getService }: FtrProviderContext,
mlCommonUI: MlCommonUI,
mlApi: MlApi,
mlFieldStatsFlyout: MlFieldStatsFlyout
mlCommonFieldStatsFlyout: MlCommonFieldStatsFlyout
) {
const headerPage = getPageObject('header');
const commonPage = getPageObject('common');
Expand Down Expand Up @@ -209,7 +209,7 @@ export function MachineLearningDataFrameAnalyticsCreationProvider(
fieldType: 'keyword' | 'date' | 'number',
expectedContent?: string[]
) {
await mlFieldStatsFlyout.assertFieldStatFlyoutContentFromTrigger(
await mlCommonFieldStatsFlyout.assertFieldStatFlyoutContentFromTrigger(
'mlAnalyticsCreateJobWizardIncludesSelect',
fieldName,
fieldType,
Expand Down Expand Up @@ -275,7 +275,7 @@ export function MachineLearningDataFrameAnalyticsCreationProvider(
fieldType: 'keyword' | 'date' | 'number',
expectedContent?: string[]
) {
await mlFieldStatsFlyout.assertFieldStatFlyoutContentFromComboBoxTrigger(
await mlCommonFieldStatsFlyout.assertFieldStatFlyoutContentFromComboBoxTrigger(
'mlAnalyticsCreateJobWizardDependentVariableSelect loaded',
fieldName,
fieldType,
Expand All @@ -288,7 +288,7 @@ export function MachineLearningDataFrameAnalyticsCreationProvider(
fieldType: 'keyword' | 'date' | 'number',
expectedContent: string[]
) {
await mlFieldStatsFlyout.assertTopValuesContent(fieldName, fieldType, expectedContent);
await mlCommonFieldStatsFlyout.assertTopValuesContent(fieldName, fieldType, expectedContent);
},

async assertDependentVariableInputMissing() {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/services/ml/field_stats_flyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ProvidedType } from '@kbn/test';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export type MlFieldStatsFlyout = ProvidedType<typeof MachineLearningFieldStatsFlyoutProvider>;
export type MlCommonFieldStatsFlyout = ProvidedType<typeof MachineLearningFieldStatsFlyoutProvider>;

export function MachineLearningFieldStatsFlyoutProvider({ getService }: FtrProviderContext) {
const browser = getService('browser');
Expand Down
25 changes: 20 additions & 5 deletions x-pack/test/functional/services/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,26 @@ export function MachineLearningProvider(context: FtrProviderContext) {
const jobTable = MachineLearningJobTableProvider(context, commonUI, customUrls);
const jobTypeSelection = MachineLearningJobTypeSelectionProvider(context);
const jobWizardAdvanced = MachineLearningJobWizardAdvancedProvider(context, commonUI);
const jobWizardCategorization = MachineLearningJobWizardCategorizationProvider(context);
const jobWizardCommon = MachineLearningJobWizardCommonProvider(context, commonUI, customUrls);
const jobWizardMultiMetric = MachineLearningJobWizardMultiMetricProvider(context);
const jobWizardPopulation = MachineLearningJobWizardPopulationProvider(context);
const jobWizardCategorization = MachineLearningJobWizardCategorizationProvider(
context,
commonFieldStatsFlyout
);
const jobWizardCommon = MachineLearningJobWizardCommonProvider(
context,
commonUI,
customUrls,
commonFieldStatsFlyout
);
const jobWizardGeo = MachineLearningJobWizardGeoProvider(context);
const jobWizardMultiMetric = MachineLearningJobWizardMultiMetricProvider(
context,
commonFieldStatsFlyout
);
const jobWizardPopulation = MachineLearningJobWizardPopulationProvider(
context,
commonFieldStatsFlyout
);

const lensVisualizations = MachineLearningLensVisualizationsProvider(context, commonUI);
const navigation = MachineLearningNavigationProvider(context);
const overviewPage = MachineLearningOverviewPageProvider(context);
Expand Down Expand Up @@ -178,9 +193,9 @@ export function MachineLearningProvider(context: FtrProviderContext) {
jobWizardAdvanced,
jobWizardCategorization,
jobWizardCommon,
jobWizardGeo,
jobWizardMultiMetric,
jobWizardPopulation,
jobWizardGeo,
lensVisualizations,
mlNodesPanel,
navigation,
Expand Down
21 changes: 19 additions & 2 deletions x-pack/test/functional/services/ml/job_wizard_categorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import expect from '@kbn/expect';

import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '@kbn/ml-plugin/common/constants/categorization_job';
import { FtrProviderContext } from '../../ftr_provider_context';
import type { FtrProviderContext } from '../../ftr_provider_context';
import type { MlCommonFieldStatsFlyout } from './field_stats_flyout';

export function MachineLearningJobWizardCategorizationProvider({ getService }: FtrProviderContext) {
export function MachineLearningJobWizardCategorizationProvider(
{ getService }: FtrProviderContext,
mlCommonFieldStatsFlyout: MlCommonFieldStatsFlyout
) {
const comboBox = getService('comboBox');
const testSubjects = getService('testSubjects');

Expand All @@ -31,6 +35,19 @@ export function MachineLearningJobWizardCategorizationProvider({ getService }: F
await testSubjects.existOrFail('mlCategorizationFieldNameSelect > comboBoxInput');
},

async assertFieldStatFlyoutContentFromCategorizationFieldInputTrigger(
fieldName: string,
fieldType: 'keyword' | 'date' | 'number',
expectedTopValues?: string[]
) {
await mlCommonFieldStatsFlyout.assertFieldStatFlyoutContentFromComboBoxTrigger(
'mlCategorizationFieldNameSelect',
fieldName,
fieldType,
expectedTopValues
);
},

async selectCategorizationField(identifier: string) {
await comboBox.set('mlCategorizationFieldNameSelect > comboBoxInput', identifier);

Expand Down
Loading

0 comments on commit bd89b11

Please sign in to comment.