Skip to content

Commit

Permalink
[ML] Move setMultiSelectFilter, removeMultiSelectFilter to mlCommonUi…
Browse files Browse the repository at this point in the history
…, remove Filtered, rearrange assertion block
  • Loading branch information
qn895 committed Dec 17, 2020
1 parent a64d33a commit 5581931
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,15 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataVisualizerIndexBased.assertTotalDocCountChartExist();

await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays elements in the search panel correctly`
`${testData.suiteTitle} displays elements in the data visualizer table correctly`
);
await ml.dataVisualizerIndexBased.assertDataVisualizerTableExist();

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();
Expand All @@ -352,11 +351,6 @@ export default function ({ getService }: FtrProviderContext) {
);
await ml.dataVisualizerIndexBased.assertTotalFieldsCount(testData.expected.totalFieldsCount);

await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays the data visualizer table`
);
await ml.dataVisualizerIndexBased.assertDataVisualizerTableExist();

await ml.testExecution.logTestStep(
'displays details for metric fields and non-metric fields correctly'
);
Expand Down
45 changes: 45 additions & 0 deletions x-pack/test/functional/services/ml/common_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function MachineLearningCommonUIProvider({ getService }: FtrProviderConte
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const find = getService('find');
const browser = getService('browser');

return {
async setValueWithChecks(
Expand Down Expand Up @@ -116,5 +117,49 @@ export function MachineLearningCommonUIProvider({ getService }: FtrProviderConte
await label.click();
await this.assertRadioGroupValue(testSubject, value);
},

async setMultiSelectFilter(testDataSubj: string, fieldTypes: string[]) {
await testSubjects.clickWhenNotDisabled(`${testDataSubj}-button`);
await testSubjects.existOrFail(`${testDataSubj}-popover`);
await testSubjects.existOrFail(`${testDataSubj}-searchInput`);
const searchBarInput = await testSubjects.find(`${testDataSubj}-searchInput`);

for (const fieldType of fieldTypes) {
await retry.tryForTime(5000, async () => {
await searchBarInput.clearValueWithKeyboard();
await searchBarInput.type(fieldType);
if (!(await testSubjects.exists(`${testDataSubj}-option-${fieldType}-checked`))) {
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}`);
await testSubjects.click(`${testDataSubj}-option-${fieldType}`);
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}-checked`);
}
});
}

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

async removeMultiSelectFilter(testDataSubj: string, fieldTypes: string[]) {
await testSubjects.clickWhenNotDisabled(`${testDataSubj}-button`);
await testSubjects.existOrFail(`${testDataSubj}-popover`);
await testSubjects.existOrFail(`${testDataSubj}-searchInput`);
const searchBarInput = await testSubjects.find(`${testDataSubj}-searchInput`);

for (const fieldType of fieldTypes) {
await retry.tryForTime(5000, async () => {
await searchBarInput.clearValueWithKeyboard();
await searchBarInput.type(fieldType);
if (!(await testSubjects.exists(`${testDataSubj}-option-${fieldType}`))) {
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}-checked`);
await testSubjects.click(`${testDataSubj}-option-${fieldType}-checked`);
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}`);
}
});
}

// escape popover
await browser.pressKeys(browser.keys.ESCAPE);
},
};
}
91 changes: 14 additions & 77 deletions x-pack/test/functional/services/ml/data_visualizer_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import expect from '@kbn/expect';
import { ProvidedType } from '@kbn/test/types/ftr';
import { FtrProviderContext } from '../../ftr_provider_context';
import { ML_JOB_FIELD_TYPES } from '../../../../plugins/ml/common/constants/field_types';
import { MlCommonUI } from './common_ui';
export type MlDataVisualizerTable = ProvidedType<typeof MachineLearningDataVisualizerTableProvider>;

export function MachineLearningDataVisualizerTableProvider({ getService }: FtrProviderContext) {
export function MachineLearningDataVisualizerTableProvider(
{ getService }: FtrProviderContext,
mlCommonUI: MlCommonUI
) {
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const browser = getService('browser');

return new (class DataVisualizerTable {
public async parseDataVisualizerTable() {
Expand Down Expand Up @@ -60,7 +63,7 @@ export function MachineLearningDataVisualizerTableProvider({ getService }: FtrPr
const tableRows = await this.parseDataVisualizerTable();
expect(tableRows).to.have.length(
expectedRowCount,
`Filtered Data Visualizer table should have ${expectedRowCount} row(s) (got '${tableRows.length}')`
`Data Visualizer table should have ${expectedRowCount} row(s) (got '${tableRows.length}')`
);
});
}
Expand Down Expand Up @@ -169,94 +172,28 @@ export function MachineLearningDataVisualizerTableProvider({ getService }: FtrPr
});
}

public async setMultiSelectFilter(
testDataSubj: string,
fieldTypes: string[],
expectedRowCount = 1
) {
await testSubjects.clickWhenNotDisabled(`${testDataSubj}-button`);
await testSubjects.existOrFail(`${testDataSubj}-popover`);
await testSubjects.existOrFail(`${testDataSubj}-searchInput`);
const searchBarInput = await testSubjects.find(`${testDataSubj}-searchInput`);

for (const fieldType of fieldTypes) {
await retry.tryForTime(5000, async () => {
await searchBarInput.clearValueWithKeyboard();
await searchBarInput.type(fieldType);
if (!(await testSubjects.exists(`${testDataSubj}-option-${fieldType}-checked`))) {
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}`);
await testSubjects.click(`${testDataSubj}-option-${fieldType}`);
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}-checked`);
}
});
}

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

async removeMultiSelectFilter(
testDataSubj: string,
fieldTypes: string[],
expectedRowCount = 1
) {
await testSubjects.clickWhenNotDisabled(`${testDataSubj}-button`);
await testSubjects.existOrFail(`${testDataSubj}-popover`);
await testSubjects.existOrFail(`${testDataSubj}-searchInput`);
const searchBarInput = await testSubjects.find(`${testDataSubj}-searchInput`);

for (const fieldType of fieldTypes) {
await retry.tryForTime(5000, async () => {
await searchBarInput.clearValueWithKeyboard();
await searchBarInput.type(fieldType);
if (!(await testSubjects.exists(`${testDataSubj}-option-${fieldType}`))) {
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}-checked`);
await testSubjects.click(`${testDataSubj}-option-${fieldType}-checked`);
await testSubjects.existOrFail(`${testDataSubj}-option-${fieldType}`);
}
});
}

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

public async setFieldTypeFilter(fieldTypes: string[], expectedRowCount = 1) {
await this.assertFieldTypeInputExists();
await this.setMultiSelectFilter(
'mlDataVisualizerFieldTypeSelect',
fieldTypes,
expectedRowCount
);
await mlCommonUI.setMultiSelectFilter('mlDataVisualizerFieldTypeSelect', fieldTypes);
await this.assertTableRowCount(expectedRowCount);
}

async removeFieldTypeFilter(fieldTypes: string[], expectedRowCount = 1) {
await this.assertFieldTypeInputExists();
await this.removeMultiSelectFilter(
'mlDataVisualizerFieldTypeSelect',
fieldTypes,
expectedRowCount
);
await mlCommonUI.removeMultiSelectFilter('mlDataVisualizerFieldTypeSelect', fieldTypes);
await this.assertTableRowCount(expectedRowCount);
}

public async setFieldNameFilter(fieldNames: string[], expectedRowCount = 1) {
await this.assertFieldNameInputExists();
await this.setMultiSelectFilter(
'mlDataVisualizerFieldNameSelect',
fieldNames,
expectedRowCount
);
await mlCommonUI.setMultiSelectFilter('mlDataVisualizerFieldNameSelect', fieldNames);
await this.assertTableRowCount(expectedRowCount);
}

public async removeFieldNameFilter(fieldNames: string[], expectedRowCount: number) {
await this.assertFieldNameInputExists();
await this.removeMultiSelectFilter(
'mlDataVisualizerFieldNameSelect',
fieldNames,
expectedRowCount
);
await mlCommonUI.removeMultiSelectFilter('mlDataVisualizerFieldNameSelect', fieldNames);
await this.assertTableRowCount(expectedRowCount);
}

public async assertShowEmptyFieldsSwitchExists() {
Expand Down
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 @@ -63,7 +63,7 @@ export function MachineLearningProvider(context: FtrProviderContext) {
const dataFrameAnalyticsTable = MachineLearningDataFrameAnalyticsTableProvider(context);

const dataVisualizer = MachineLearningDataVisualizerProvider(context);
const dataVisualizerTable = MachineLearningDataVisualizerTableProvider(context);
const dataVisualizerTable = MachineLearningDataVisualizerTableProvider(context, commonUI);

const dataVisualizerFileBased = MachineLearningDataVisualizerFileBasedProvider(context, commonUI);
const dataVisualizerIndexBased = MachineLearningDataVisualizerIndexBasedProvider(context);
Expand Down

0 comments on commit 5581931

Please sign in to comment.