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] Fix functional tests for index based Data Visualizer #86071

Merged
merged 12 commits into from
Dec 17, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,17 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays elements in the search panel correctly`
);
await ml.dataVisualizerIndexBased.assertSearchPanelExist();
await ml.dataVisualizerIndexBased.assertSampleSizeInputExists();
await ml.dataVisualizerIndexBased.assertFieldTypeInputExists();
await ml.dataVisualizerIndexBased.assertFieldNameInputExists();
await ml.dataVisualizerTable.assertSearchPanelExist();
await ml.dataVisualizerTable.assertSampleSizeInputExists();
await ml.dataVisualizerTable.assertFieldTypeInputExists();
await ml.dataVisualizerTable.assertFieldNameInputExists();

await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays elements in the field count panel correctly`
);
await ml.dataVisualizerIndexBased.assertFieldCountPanelExist();
await ml.dataVisualizerIndexBased.assertMetricFieldsSummaryExist();
await ml.dataVisualizerIndexBased.assertFieldsSummaryExist();
await ml.dataVisualizerIndexBased.assertShowEmptyFieldsSwitchExists();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to move this to the displays the data visualizer table test block and also checking for the search box and the filter buttons there. But this can be done in a future PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rearranged these under the data visualizer table block here 5581931 (#86071)

await ml.dataVisualizerIndexBased.assertVisibleMetricFieldsCount(
testData.expected.visibleMetricFieldsCount
);
Expand All @@ -364,15 +363,15 @@ export default function ({ getService }: FtrProviderContext) {
for (const fieldRow of testData.expected.metricFields as Array<
Required<MetricFieldVisConfig>
>) {
await ml.dataVisualizerIndexBased.assertNumberFieldContents(
await ml.dataVisualizerTable.assertNumberFieldContents(
fieldRow.fieldName,
fieldRow.docCountFormatted,
fieldRow.topValuesCount
);
}

for (const fieldRow of testData.expected.nonMetricFields!) {
await ml.dataVisualizerIndexBased.assertNonMetricFieldContents(
await ml.dataVisualizerTable.assertNonMetricFieldContents(
fieldRow.type,
fieldRow.fieldName!,
fieldRow.docCountFormatted,
Expand All @@ -383,34 +382,34 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep(
`${testData.suiteTitle} sample size control changes non-metric fields`
);
await ml.dataVisualizerIndexBased.setSampleSizeInputValue(1000, 'airline', '1000 (100%)');
await ml.dataVisualizerIndexBased.setSampleSizeInputValue(5000, '@timestamp', '5000 (100%)');
await ml.dataVisualizerTable.setSampleSizeInputValue(1000, 'airline', '1000 (100%)');
await ml.dataVisualizerTable.setSampleSizeInputValue(5000, '@timestamp', '5000 (100%)');

await ml.testExecution.logTestStep('sets and resets field type filter correctly');
await ml.dataVisualizerIndexBased.setFieldTypeFilter(
await ml.dataVisualizerTable.setFieldTypeFilter(
testData.fieldTypeFilters,
testData.expected.fieldTypeFiltersResultCount
);
await ml.dataVisualizerIndexBased.removeFieldTypeFilter(
await ml.dataVisualizerTable.removeFieldTypeFilter(
testData.fieldTypeFilters,
testData.expected.populatedFieldsCount
);

await ml.testExecution.logTestStep('sets and resets field name filter correctly');
await ml.dataVisualizerIndexBased.setFieldNameFilter(
await ml.dataVisualizerTable.setFieldNameFilter(
testData.fieldNameFilters,
testData.expected.fieldNameFiltersResultCount
);
await ml.dataVisualizerIndexBased.removeFieldNameFilter(
await ml.dataVisualizerTable.removeFieldNameFilter(
testData.fieldNameFilters,
testData.expected.populatedFieldsCount
);

await ml.testExecution.logTestStep('displays unpopulated fields correctly');
await ml.dataVisualizerIndexBased.setShowEmptyFieldsSwitchState(true);
for (const field of testData.expected.emptyFields) {
await ml.dataVisualizerTable.assertRowExists(field);
}
await ml.dataVisualizerTable.setShowEmptyFieldsSwitchState(
true,
testData.expected.emptyFields
);
});
}

Expand Down
224 changes: 3 additions & 221 deletions x-pack/test/functional/services/ml/data_visualizer_index_based.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';

import { FtrProviderContext } from '../../ftr_provider_context';
import type { MlDataVisualizerTable } from './data_visualizer_table';
import { asyncForEach } from '../../apps/ml/settings/common';
import { ML_JOB_FIELD_TYPES } from '../../../../plugins/ml/common/constants/field_types';

export function MachineLearningDataVisualizerIndexBasedProvider(
{ getService }: FtrProviderContext,
mlDataVisualizerTable: MlDataVisualizerTable
) {
export function MachineLearningDataVisualizerIndexBasedProvider({
getService,
}: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const browser = getService('browser');

return {
async assertTimeRangeSelectorSectionExists() {
Expand Down Expand Up @@ -46,14 +40,6 @@ export function MachineLearningDataVisualizerIndexBasedProvider(
await testSubjects.existOrFail(`mlFieldDataDocumentCountChart`);
},

async assertSearchPanelExist() {
await testSubjects.existOrFail(`mlDataVisualizerSearchPanel`);
},

async assertSearchQueryInputExist() {
await testSubjects.existOrFail(`mlDataVisualizerQueryInput`);
},

async assertFieldCountPanelExist() {
await testSubjects.existOrFail(`mlDataVisualizerFieldCountPanel`);
},
Expand Down Expand Up @@ -122,105 +108,6 @@ export function MachineLearningDataVisualizerIndexBasedProvider(
await testSubjects.existOrFail(`mlDataVisualizerTable`);
},

async assertShowEmptyFieldsSwitchExists() {
await testSubjects.existOrFail('mlDataVisualizerShowEmptyFieldsSwitch');
},

async assertShowEmptyFieldsCheckState(expectedCheckState: boolean) {
const actualCheckState =
(await testSubjects.getAttribute(
'mlDataVisualizerShowEmptyFieldsSwitch',
'aria-checked'
)) === 'true';
expect(actualCheckState).to.eql(
expectedCheckState,
`Show empty fields check state should be '${expectedCheckState}' (got '${actualCheckState}')`
);
return actualCheckState === expectedCheckState;
},

async setShowEmptyFieldsSwitchState(checkState: boolean) {
if (await this.assertShowEmptyFieldsCheckState(!checkState)) {
await testSubjects.click('mlDataVisualizerShowEmptyFieldsSwitch');
}
await this.assertShowEmptyFieldsCheckState(checkState);
},

async assertFieldNameInputExists() {
await testSubjects.existOrFail('mlDataVisualizerFieldNameSelect');
},

async assertFieldTypeInputExists() {
await testSubjects.existOrFail('mlDataVisualizerFieldTypeSelect');
},

async assertSampleSizeInputExists() {
await testSubjects.existOrFail('mlDataVisualizerShardSizeSelect');
},

async setSampleSizeInputValue(
sampleSize: number,
fieldName: string,
docCountFormatted: string
) {
await this.assertSampleSizeInputExists();
await testSubjects.clickWhenNotDisabled('mlDataVisualizerShardSizeSelect');
await testSubjects.existOrFail(`mlDataVisualizerShardSizeOption ${sampleSize}`);
await testSubjects.click(`mlDataVisualizerShardSizeOption ${sampleSize}`);

await retry.tryForTime(5000, async () => {
await mlDataVisualizerTable.assertFieldDocCount(fieldName, docCountFormatted);
});
},

async setFieldTypeFilter(fieldTypes: string[], expectedRowCount = 1) {
await this.assertFieldNameInputExists();
await testSubjects.clickWhenNotDisabled('mlDataVisualizerFieldTypeSelect-button');
await testSubjects.existOrFail('mlDataVisualizerFieldTypeSelect-popover');
await testSubjects.existOrFail('mlDataVisualizerFieldTypeSelect-searchInput');
const searchBarInput = await testSubjects.find(`mlDataVisualizerFieldTypeSelect-searchInput`);

await asyncForEach(fieldTypes, async (fieldType) => {
await retry.tryForTime(5000, async () => {
await searchBarInput.clearValueWithKeyboard();
await searchBarInput.type(fieldType);
await testSubjects.existOrFail(`mlDataVisualizerFieldTypeSelect-option-${fieldType}`);
await testSubjects.click(`mlDataVisualizerFieldTypeSelect-option-${fieldType}`);
});
});

// escape popover
await browser.pressKeys(browser.keys.ESCAPE);
await mlDataVisualizerTable.assertTableRowCount(expectedRowCount);
},

async removeFieldTypeFilter(fieldTypes: string[], expectedRowCount = 1) {
await this.setFieldTypeFilter(fieldTypes, expectedRowCount);
},

async setFieldNameFilter(fieldNames: string[], expectedRowCount = 1) {
await this.assertFieldNameInputExists();
await testSubjects.clickWhenNotDisabled('mlDataVisualizerFieldNameSelect-button');
await testSubjects.existOrFail('mlDataVisualizerFieldNameSelect-popover');
await testSubjects.existOrFail('mlDataVisualizerFieldNameSelect-searchInput');
const searchBarInput = await testSubjects.find(`mlDataVisualizerFieldNameSelect-searchInput`);

await asyncForEach(fieldNames, async (filterString) => {
await retry.tryForTime(5000, async () => {
await searchBarInput.clearValueWithKeyboard();
await searchBarInput.type(filterString);
await testSubjects.existOrFail(`mlDataVisualizerFieldNameSelect-option-${filterString}`);
await testSubjects.click(`mlDataVisualizerFieldNameSelect-option-${filterString}`);
});
});
await browser.pressKeys(browser.keys.ESCAPE);
await mlDataVisualizerTable.assertTableRowCount(expectedRowCount);
},

async removeFieldNameFilter(fieldNames: string[], expectedRowCount: number) {
await this.setFieldNameFilter(fieldNames, expectedRowCount);
},

async assertActionsPanelExists() {
await testSubjects.existOrFail('mlDataVisualizerActionsPanel');
},
Expand Down Expand Up @@ -248,110 +135,5 @@ export function MachineLearningDataVisualizerIndexBasedProvider(
async clickCreateAdvancedJobButton() {
await testSubjects.clickWhenNotDisabled('mlDataVisualizerCreateAdvancedJobCard');
},

async assertTopValuesContents(fieldName: string, expectedTopValuesCount: number) {
const selector = mlDataVisualizerTable.detailsSelector(fieldName, 'mlFieldDataTopValues');
const topValuesElement = await testSubjects.find(selector);
const topValuesBars = await topValuesElement.findAllByTestSubject('mlFieldDataTopValueBar');
expect(topValuesBars).to.have.length(
expectedTopValuesCount,
`Expected top values count for field '${fieldName}' to be '${expectedTopValuesCount}' (got '${topValuesBars.length}')`
);
},

async assertDistributionPreviewExist(fieldName: string) {
await testSubjects.existOrFail(
mlDataVisualizerTable.rowSelector(fieldName, `mlDataGridChart-${fieldName}`)
);
await testSubjects.existOrFail(
mlDataVisualizerTable.rowSelector(fieldName, `mlDataGridChart-${fieldName}-histogram`)
);
},

async assertNumberFieldContents(
fieldName: string,
docCountFormatted: string,
topValuesCount: number
) {
await mlDataVisualizerTable.assertRowExists(fieldName);
await mlDataVisualizerTable.assertFieldDocCount(fieldName, docCountFormatted);
await mlDataVisualizerTable.ensureDetailsOpen(fieldName);

await testSubjects.existOrFail(
mlDataVisualizerTable.detailsSelector(fieldName, 'mlNumberSummaryTable')
);

await testSubjects.existOrFail(
mlDataVisualizerTable.detailsSelector(fieldName, 'mlTopValues')
);
await this.assertTopValuesContents(fieldName, topValuesCount);

await this.assertDistributionPreviewExist(fieldName);

await mlDataVisualizerTable.ensureDetailsClosed(fieldName);
},

async assertDateFieldContents(fieldName: string, docCountFormatted: string) {
await mlDataVisualizerTable.assertRowExists(fieldName);
await mlDataVisualizerTable.assertFieldDocCount(fieldName, docCountFormatted);
await mlDataVisualizerTable.ensureDetailsOpen(fieldName);

await testSubjects.existOrFail(
mlDataVisualizerTable.detailsSelector(fieldName, 'mlDateSummaryTable')
);
await mlDataVisualizerTable.ensureDetailsClosed(fieldName);
},

async assertKeywordFieldContents(
fieldName: string,
docCountFormatted: string,
topValuesCount: number
) {
await mlDataVisualizerTable.assertRowExists(fieldName);
await mlDataVisualizerTable.assertFieldDocCount(fieldName, docCountFormatted);
await mlDataVisualizerTable.ensureDetailsOpen(fieldName);

await testSubjects.existOrFail(
mlDataVisualizerTable.detailsSelector(fieldName, 'mlFieldDataTopValues')
);
await this.assertTopValuesContents(fieldName, topValuesCount);
await mlDataVisualizerTable.ensureDetailsClosed(fieldName);
},

async assertTextFieldContents(
fieldName: string,
docCountFormatted: string,
expectedExamplesCount: number
) {
await mlDataVisualizerTable.assertRowExists(fieldName);
await mlDataVisualizerTable.assertFieldDocCount(fieldName, docCountFormatted);
await mlDataVisualizerTable.ensureDetailsOpen(fieldName);

const examplesList = await testSubjects.find(
mlDataVisualizerTable.detailsSelector(fieldName, 'mlFieldDataExamplesList')
);
const examplesListItems = await examplesList.findAllByTagName('li');
expect(examplesListItems).to.have.length(
expectedExamplesCount,
`Expected example list item count for field '${fieldName}' to be '${expectedExamplesCount}' (got '${examplesListItems.length}')`
);
await mlDataVisualizerTable.ensureDetailsClosed(fieldName);
},

async assertNonMetricFieldContents(
fieldType: string,
fieldName: string,
docCountFormatted: string,
exampleCount: number
) {
// Currently the data used in the data visualizer tests only contains these field types.
if (fieldType === ML_JOB_FIELD_TYPES.DATE) {
await this.assertDateFieldContents(fieldName, docCountFormatted);
} else if (fieldType === ML_JOB_FIELD_TYPES.KEYWORD) {
await this.assertKeywordFieldContents(fieldName, docCountFormatted, exampleCount);
} else if (fieldType === ML_JOB_FIELD_TYPES.TEXT) {
await this.assertTextFieldContents(fieldName, docCountFormatted, exampleCount);
}
},
};
}
Loading