Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Add functional tests for Field stats flyout in Transforms & DFA creation wizard #150927

Merged
merged 9 commits into from
Feb 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const FieldStatsContent: FC<{
toDate={timeRange.to}
dataViewOrDataViewId={currentDataView}
field={fieldForStats}
data-test-subj={`jobCreatorFieldStatsPopover ${fieldForStats.name}`}
data-test-subj={`mlFieldStatsFlyoutContent ${fieldForStats.name}`}
color={DEFAULT_COLOR}
/>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export const FieldStatsFlyout: FC<{

if (isFlyoutVisible) {
return (
<EuiFlyout type="push" size="xs" onClose={closeFlyout} aria-labelledby={pushedFlyoutTitleId}>
<EuiFlyout
type="push"
size="xs"
onClose={closeFlyout}
aria-labelledby={pushedFlyoutTitleId}
data-test-subj="mlFieldStatsFlyout"
>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="m">
<h3 id={pushedFlyoutTitleId}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const FieldStatsInfoButton = ({
)}
>
<EuiButtonIcon
data-test-subj={`mlInspectFieldStatsButton-${field.id}`}
disabled={field.id === EVENT_RATE_FIELD_ID}
size="xs"
iconType="inspect"
Expand All @@ -56,7 +57,6 @@ export const FieldStatsInfoButton = ({
defaultMessage: 'Inspect field statistics',
}
)}
data-test-subj={'mlAggSelectFieldStatsPopoverButton'}
/>
</EuiToolTip>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

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

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand All @@ -16,7 +17,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('classification creation', function () {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/bm_classification');
await ml.testResources.createIndexPatternIfNeeded('ft_bank_marketing', '@timestamp');
await ml.testResources.createIndexPatternIfNeeded('ft_bank_marketing');
await ml.testResources.setKibanaTimeZoneToUTC();

await ml.securityUI.loginAsMlPowerUser();
Expand Down Expand Up @@ -49,6 +50,18 @@ export default function ({ getService }: FtrProviderContext) {
trainingPercent: 20,
modelMemory: '60mb',
createIndexPattern: true,
fieldStatsEntries: [
{
fieldName: 'age',
type: 'number' as FieldStatsType,
isDependentVariableInput: true,
},
{
fieldName: 'balance.keyword',
type: 'keyword' as FieldStatsType,
isDependentVariableInput: true,
},
],
expected: {
rocCurveColorState: [
// tick/grid/axis
Expand Down Expand Up @@ -138,8 +151,18 @@ export default function ({ getService }: FtrProviderContext) {
testData.expected.runtimeFieldsEditorContent
);

await ml.testExecution.logTestStep('inputs the dependent variable');
await ml.testExecution.logTestStep('opens field stats flyout');
await ml.dataFrameAnalyticsCreation.assertDependentVariableInputExists();
for (const { fieldName, type: fieldType } of testData.fieldStatsEntries.filter(
(e) => e.isDependentVariableInput
)) {
await ml.dataFrameAnalyticsCreation.clickDependentVariableInputFieldStatTrigger(
fieldName,
fieldType
);
}

await ml.testExecution.logTestStep('inputs the dependent variable');
await ml.dataFrameAnalyticsCreation.selectDependentVariable(testData.dependentVariable);

await ml.testExecution.logTestStep('inputs the training percent');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

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

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -38,6 +39,20 @@ export default function ({ getService }: FtrProviderContext) {
});

const dateNow = Date.now();
const fieldStatsEntries = [
{
fieldName: 'airline',
type: 'keyword' as FieldStatsType,
isDependentVariableInput: true,
isIncludeFieldInput: true,
},
{
fieldName: '@version',
type: 'keyword' as FieldStatsType,
isIncludeFieldInput: true,
},
];

const testDataList = [
{
suiteTitle: 'with lucene query',
Expand All @@ -48,6 +63,7 @@ export default function ({ getService }: FtrProviderContext) {
get destinationIndex(): string {
return `user-${this.jobId}`;
},
fieldStatsEntries,
runtimeFields: {
uppercase_airline: {
type: 'keyword',
Expand All @@ -59,6 +75,10 @@ export default function ({ getService }: FtrProviderContext) {
modelMemory: '20mb',
createIndexPattern: true,
expected: {
fieldStatsValues: { airline: ['AAL', 'AWE', 'ASA', 'ACA', 'AMX'] } as Record<
string,
string[]
>,
source: 'ft_farequote_small',
rocCurveColorState: [
// tick/grid/axis
Expand Down Expand Up @@ -99,6 +119,7 @@ export default function ({ getService }: FtrProviderContext) {
get destinationIndex(): string {
return `user-${this.jobId}`;
},
fieldStatsEntries,
runtimeFields: {
uppercase_airline: {
type: 'keyword',
Expand All @@ -110,6 +131,10 @@ export default function ({ getService }: FtrProviderContext) {
modelMemory: '20mb',
createIndexPattern: true,
expected: {
fieldStatsValues: { airline: ['AAL', 'AWE', 'ASA', 'ACA', 'AMX'] } as Record<
string,
string[]
>,
source: 'ft_farequote_small',
rocCurveColorState: [
// tick/grid/axis
Expand Down Expand Up @@ -150,6 +175,7 @@ export default function ({ getService }: FtrProviderContext) {
get destinationIndex(): string {
return `user-${this.jobId}`;
},
fieldStatsEntries,
runtimeFields: {
uppercase_airline: {
type: 'keyword',
Expand All @@ -161,6 +187,9 @@ export default function ({ getService }: FtrProviderContext) {
modelMemory: '20mb',
createIndexPattern: true,
expected: {
fieldStatsValues: {
airline: ['AAL', 'ASA'],
} as Record<string, string[]>,
source: 'ft_farequote_small',
rocCurveColorState: [
// tick/grid/axis
Expand Down Expand Up @@ -213,6 +242,7 @@ export default function ({ getService }: FtrProviderContext) {
modelMemory: '20mb',
createIndexPattern: true,
expected: {
fieldStatsValues: { airline: ['ASA', 'FFT'] } as Record<string, string[]>,
source: 'ft_farequote_small',
rocCurveColorState: [
// tick/grid/axis
Expand Down Expand Up @@ -293,9 +323,30 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataFrameAnalyticsCreation.assertRuntimeMappingsEditorContent(
testData.expected.runtimeFieldsEditorContent
);
await ml.testExecution.logTestStep(
'opens field stats flyout from dependent variable input'
);
await ml.dataFrameAnalyticsCreation.assertDependentVariableInputExists();
for (const { fieldName, type: fieldType } of fieldStatsEntries.filter(
(e) => e.isDependentVariableInput
)) {
await ml.dataFrameAnalyticsCreation.clickDependentVariableInputFieldStatTrigger(
fieldName,
fieldType
);
if (
testData.expected.fieldStatsValues &&
fieldName in testData.expected.fieldStatsValues
) {
await ml.dataFrameAnalyticsCreation.assertFieldStatTopValuesContent(
fieldName,
fieldType,
testData.expected.fieldStatsValues[fieldName] as string[]
);
}
}

await ml.testExecution.logTestStep('inputs the dependent variable');
await ml.dataFrameAnalyticsCreation.assertDependentVariableInputExists();
await ml.dataFrameAnalyticsCreation.selectDependentVariable(testData.dependentVariable);

await ml.testExecution.logTestStep('inputs the training percent');
Expand All @@ -307,6 +358,24 @@ export default function ({ getService }: FtrProviderContext) {

await ml.testExecution.logTestStep('displays the include fields selection');
await ml.dataFrameAnalyticsCreation.assertIncludeFieldsSelectionExists();
for (const { fieldName, type: fieldType } of fieldStatsEntries.filter(
(e) => e.isIncludeFieldInput
)) {
await ml.dataFrameAnalyticsCreation.clickDependentVariableInputFieldStatTrigger(
pheyos marked this conversation as resolved.
Show resolved Hide resolved
fieldName,
fieldType
);
if (
testData.expected.fieldStatsValues &&
fieldName in testData.expected.fieldStatsValues
) {
await ml.dataFrameAnalyticsCreation.assertFieldStatTopValuesContent(
fieldName,
fieldType,
testData.expected.fieldStatsValues[fieldName] as string[]
);
}
}

await ml.testExecution.logTestStep('continues to the additional options step');
await ml.dataFrameAnalyticsCreation.continueToAdditionalOptionsStep();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

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

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand All @@ -16,7 +17,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('outlier detection creation', function () {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/ihp_outlier');
await ml.testResources.createIndexPatternIfNeeded('ft_ihp_outlier', '@timestamp');
await ml.testResources.createIndexPatternIfNeeded('ft_ihp_outlier');
await ml.testResources.setKibanaTimeZoneToUTC();

await ml.securityUI.loginAsMlPowerUser();
Expand All @@ -29,6 +30,14 @@ export default function ({ getService }: FtrProviderContext) {

const jobId = `ihp_1_${Date.now()}`;

const fieldStatsEntries = [
{
fieldName: '1stFlrSF',
type: 'keyword' as FieldStatsType,
isIncludeFieldInput: true,
},
];

const testDataList = [
{
suiteTitle: 'iowa house prices',
Expand Down Expand Up @@ -171,6 +180,16 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep('displays the include fields selection');
await ml.dataFrameAnalyticsCreation.assertIncludeFieldsSelectionExists();

await ml.testExecution.logTestStep('opens field stats flyout from include fields input');
for (const { fieldName, type: fieldType } of fieldStatsEntries.filter(
(e) => e.isIncludeFieldInput
)) {
await ml.dataFrameAnalyticsCreation.clickIncludeFieldsInputFieldStatTrigger(
fieldName,
fieldType
);
}

await ml.testExecution.logTestStep(
'sets the sample size to 10000 for the scatterplot matrix'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,33 @@
* 2.0.
*/

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

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const ml = getService('ml');
const editedDescription = 'Edited description';

const fieldStatsEntries = [
{
fieldName: 'g1',
type: 'number' as FieldStatsType,
isDependentVariableInput: true,
isIncludeFieldInput: true,
},
{
fieldName: 'p3',
type: 'number' as FieldStatsType,
isIncludeFieldInput: true,
},
];

describe('regression creation', function () {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/egs_regression');
await ml.testResources.createIndexPatternIfNeeded('ft_egs_regression', '@timestamp');
await ml.testResources.createIndexPatternIfNeeded('ft_egs_regression');
await ml.testResources.setKibanaTimeZoneToUTC();

await ml.securityUI.loginAsMlPowerUser();
Expand All @@ -38,6 +53,7 @@ export default function ({ getService }: FtrProviderContext) {
get destinationIndex(): string {
return `user-${jobId}`;
},
fieldStatsEntries,
runtimeFields: {
uppercase_stab: {
type: 'keyword',
Expand Down Expand Up @@ -132,8 +148,20 @@ export default function ({ getService }: FtrProviderContext) {
testData.expected.runtimeFieldsEditorContent
);

await ml.testExecution.logTestStep('inputs the dependent variable');
await ml.testExecution.logTestStep(
'opens field stats flyout from dependent variable input'
);
await ml.dataFrameAnalyticsCreation.assertDependentVariableInputExists();
for (const { fieldName, type: fieldType } of fieldStatsEntries.filter(
(e) => e.isDependentVariableInput
)) {
await ml.dataFrameAnalyticsCreation.clickDependentVariableInputFieldStatTrigger(
fieldName,
fieldType
);
}

await ml.testExecution.logTestStep('inputs the dependent variable');
await ml.dataFrameAnalyticsCreation.selectDependentVariable(testData.dependentVariable);

await ml.testExecution.logTestStep('inputs the training percent');
Expand All @@ -146,6 +174,16 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep('displays the include fields selection');
await ml.dataFrameAnalyticsCreation.assertIncludeFieldsSelectionExists();

await ml.testExecution.logTestStep('opens field stats flyout from include fields input');
for (const { fieldName, type: fieldType } of fieldStatsEntries.filter(
(e) => e.isIncludeFieldInput
)) {
await ml.dataFrameAnalyticsCreation.clickDependentVariableInputFieldStatTrigger(
pheyos marked this conversation as resolved.
Show resolved Hide resolved
fieldName,
fieldType
);
}

await ml.testExecution.logTestStep(
'sets the sample size to 10000 for the scatterplot matrix'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export type FieldStatsType = 'number' | 'keyword' | 'date';
Loading