Skip to content

Commit

Permalink
[ML] Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Jun 22, 2021
1 parent dcd6cfa commit 6c51e92
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ const FieldEditorComponent = ({
Boolean(field?.type) && field?.type !== (updatedType && updatedType[0].value);

return (
<Form form={form} className="indexPatternFieldEditor__form">
<Form
form={form}
className="indexPatternFieldEditor__form"
data-test-subj={'indexPatternFieldEditorForm'}
>
<EuiFlexGroup>
{/* Name */}
<EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function MachineLearningDataVisualizerIndexPatternManagementProvider(
) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const find = getService('find');
const fieldEditor = getService('fieldEditor');
const comboBox = getService('comboBox');

Expand All @@ -27,7 +26,11 @@ export function MachineLearningDataVisualizerIndexPatternManagementProvider(
await testSubjects.existOrFail('dataVisualizerIndexPatternManagementMenu');
},
async assertIndexPatternFieldEditorExists() {
await find.byClassName('indexPatternFieldEditor__form');
await testSubjects.existOrFail('indexPatternFieldEditorForm');
},

async assertIndexPatternFieldEditorNotExist() {
await testSubjects.missingOrFail('indexPatternFieldEditorForm');
},

async clickIndexPatternManagementButton() {
Expand Down Expand Up @@ -71,17 +74,18 @@ export function MachineLearningDataVisualizerIndexPatternManagementProvider(
},

async addRuntimeField(name: string, script: string, fieldType: string) {
await this.clickIndexPatternManagementButton();
await this.clickAddIndexPatternFieldAction();

await retry.tryForTime(5000, async () => {
await this.clickIndexPatternManagementButton();
await this.clickAddIndexPatternFieldAction();

await this.assertIndexPatternFieldEditorExists();
await fieldEditor.setName(name);
await fieldEditor.enableValue();
await fieldEditor.typeScript(script);
await this.setIndexPatternFieldEditorFieldType(fieldType);

await fieldEditor.save();
await this.assertIndexPatternFieldEditorNotExist();
});
},

Expand All @@ -92,6 +96,7 @@ export function MachineLearningDataVisualizerIndexPatternManagementProvider(
await fieldEditor.enableCustomLabel();
await fieldEditor.setCustomLabel(newName);
await fieldEditor.save();
await this.assertIndexPatternFieldEditorNotExist();
});
},

Expand Down
38 changes: 20 additions & 18 deletions x-pack/test/functional/services/ml/data_visualizer_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function MachineLearningDataVisualizerTableProvider(
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const find = getService('find');
const browser = getService('browser');

return new (class DataVisualizerTable {
public async parseDataVisualizerTable() {
Expand Down Expand Up @@ -153,22 +154,25 @@ export function MachineLearningDataVisualizerTableProvider(
);
}

public async ensureAllMenuPopoversClosed() {
await retry.tryForTime(5000, async () => {
await browser.pressKeys(browser.keys.ESCAPE);
const popoverExists = await find.existsByCssSelector('euiContextMenuPanel');
expect(popoverExists).to.eql(false, 'All popovers should be closed');
});
}

public async ensureActionsMenuOpen(fieldName: string) {
await retry.tryForTime(30 * 1000, async () => {
const panel = await find.existsByCssSelector('euiContextMenuPanel');
if (!panel) {
await testSubjects.click(this.rowSelector(fieldName, 'euiCollapsedItemActionsButton'));
await find.existsByCssSelector('euiContextMenuPanel');
}
await this.ensureAllMenuPopoversClosed();
await testSubjects.click(this.rowSelector(fieldName, 'euiCollapsedItemActionsButton'));
await find.existsByCssSelector('euiContextMenuPanel');
});
}

public async ensureActionsMenuClosed(fieldName: string, action: string) {
public async assertActionsMenuClosed(fieldName: string, action: string) {
await retry.tryForTime(30 * 1000, async () => {
if (await testSubjects.exists(action)) {
await testSubjects.click(this.rowSelector(fieldName, 'euiCollapsedItemActionsButton'));
await testSubjects.missingOrFail(action, { timeout: 5000 });
}
await testSubjects.missingOrFail(action, { timeout: 5000 });
});
}

Expand Down Expand Up @@ -204,31 +208,28 @@ export function MachineLearningDataVisualizerTableProvider(
}' (got '${isEnabled ? 'enabled' : 'disabled'}')`
);
}

public async clickActionMenuDeleteIndexPatternFieldButton(fieldName: string) {
const testSubj = 'dataVisualizerActionDeleteIndexPatternFieldButton';
await retry.tryForTime(5000, async () => {
await this.ensureActionsMenuOpen(fieldName);

const button = await find.byCssSelector(
'[data-test-subj="dataVisualizerActionDeleteIndexPatternFieldButton"][class="euiContextMenuItem"]'
`[data-test-subj="${testSubj}"][class="euiContextMenuItem"]`
);
await button.click();
await this.ensureActionsMenuClosed(fieldName, testSubj);
await this.assertActionsMenuClosed(fieldName, testSubj);
await testSubjects.existOrFail('runtimeFieldDeleteConfirmModal');
});
}

public async assertActionMenuExists(fieldName: string) {
const actionButton = this.rowSelector(fieldName, 'euiCollapsedItemActionsButton');
await testSubjects.existOrFail(actionButton);
}

public async assertViewInLensActionEnabled(fieldName: string, expectedValue: boolean) {
const actionButton = this.rowSelector(fieldName, 'dataVisualizerActionViewInLensButton');
await testSubjects.existOrFail(actionButton);
const isEnabled = await testSubjects.isEnabled(actionButton);
expect(isEnabled).to.eql(
expectedValue,
`Expected "Edit index pattern" button for '${fieldName}' to be '${
`Expected "Explore in lens" button for '${fieldName}' to be '${
expectedValue ? 'enabled' : 'disabled'
}' (got '${isEnabled ? 'enabled' : 'disabled'}')`
);
Expand Down Expand Up @@ -263,6 +264,7 @@ export function MachineLearningDataVisualizerTableProvider(
await testSubjects.click(
this.rowSelector(fieldName, 'dataVisualizerActionEditIndexPatternFieldButton')
);
await testSubjects.existOrFail('indexPatternFieldEditorForm');
});
}

Expand Down

0 comments on commit 6c51e92

Please sign in to comment.