Skip to content

Commit

Permalink
[ML] e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jun 17, 2020
1 parent 87faf26 commit 3a387e5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export const AddToDashboardControl: FC<AddToDashboardControlProps> = ({
search={search}
pagination={true}
sorting={true}
data-test-subj="mlDashboardSelection"
/>
</EuiFormRow>
</EuiModalBody>
Expand All @@ -293,6 +294,7 @@ export const AddToDashboardControl: FC<AddToDashboardControlProps> = ({
);
});
}}
data-test-subj="mlAddAndEditDashboardButton"
>
<FormattedMessage
id="xpack.ml.explorer.dashboardsTable.addAndEditDashboardLabel"
Expand All @@ -303,6 +305,7 @@ export const AddToDashboardControl: FC<AddToDashboardControlProps> = ({
fill
onClick={onClose.bind(null, addSwimlaneToDashboardCallback)}
disabled={noSwimlaneSelected || selectedItems.length === 0}
data-test-subj="mlAddToDashboardsButton"
>
<FormattedMessage
id="xpack.ml.explorer.dashboardsTable.addToDashboardLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await esArchiver.loadIfNeeded('ml/farequote');
await ml.testResources.createIndexPatternIfNeeded('ft_farequote', '@timestamp');
await ml.testResources.createMLTestDashboardIfNeeded();
await ml.testResources.setKibanaTimeZoneToUTC();

await ml.securityUI.loginAsMlPowerUser();
Expand Down Expand Up @@ -125,6 +126,12 @@ export default function ({ getService }: FtrProviderContext) {
it('anomalies table is not empty', async () => {
await ml.anomaliesTable.assertTableNotEmpty();
});

it('should allow to attach anomaly swimlane embeddable to the dashboard', async () => {
await ml.anomalyExplorer.openAddToDashboardControl();
const dashboardId = await ml.testResources.getDashboardId('ML Test');
await ml.anomalyExplorer.addAndEditSwimlaneInDashboard(dashboardId!);
});
});
}
});
Expand Down
16 changes: 16 additions & 0 deletions x-pack/test/functional/services/ml/anomaly_explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';

export function MachineLearningAnomalyExplorerProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const find = getService('find');

return {
async assertAnomalyExplorerEmptyListMessageExists() {
Expand Down Expand Up @@ -66,5 +67,20 @@ export function MachineLearningAnomalyExplorerProvider({ getService }: FtrProvid
async assertSwimlaneViewByExists() {
await testSubjects.existOrFail('mlAnomalyExplorerSwimlaneViewBy');
},

async openAddToDashboardControl() {
await testSubjects.click('mlAnomalyTimelinePanelMenu');
await testSubjects.click('mlAnomalyTimelinePanelAddToDashboardButton');
await testSubjects.existOrFail('mlAddToDashboardModal');
},

async addAndEditSwimlaneInDashboard(dashboardId: string) {
await testSubjects.isDisplayed('mlDashboardSelection');
await testSubjects.isDisplayed(`checkboxSelectRow-${dashboardId}`);
await testSubjects.click(`checkboxSelectRow-${dashboardId}`);
await testSubjects.clickWhenNotDisabled('mlAddAndEditDashboardButton');
const swimlane = await find.byClassName('ml-swimlanes');
expect(await swimlane.isDisplayed()).to.be(true);
},
};
}
35 changes: 34 additions & 1 deletion x-pack/test/functional/services/ml/test_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { ProvidedType } from '@kbn/test/types/ftr';
import { savedSearches } from './test_resources_data';
import { savedSearches, dashboards } from './test_resources_data';
import { COMMON_REQUEST_HEADERS } from './common';
import { FtrProviderContext } from '../../ftr_provider_context';

Expand Down Expand Up @@ -70,6 +70,10 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
return this.getSavedObjectIdByTitle(title, SavedObjectType.SEARCH);
},

async getDashboardId(title: string): Promise<string | undefined> {
return this.getSavedObjectIdByTitle(title, SavedObjectType.DASHBOARD);
},

async createIndexPattern(title: string, timeFieldName?: string): Promise<string> {
log.debug(
`Creating index pattern with title '${title}'${
Expand Down Expand Up @@ -127,6 +131,20 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
return createResponse.id;
},

async createDashboard(title: string, body: object): Promise<string> {
log.debug(`Creating dashboard with title '${title}'`);

const createResponse = await supertest
.post(`/api/saved_objects/${SavedObjectType.DASHBOARD}`)
.set(COMMON_REQUEST_HEADERS)
.send(body)
.expect(200)
.then((res: any) => res.body);

log.debug(` > Created with id '${createResponse.id}'`);
return createResponse.id;
},

async createSavedSearchIfNeeded(savedSearch: any): Promise<string> {
const title = savedSearch.requestBody.attributes.title;
const savedSearchId = await this.getSavedSearchId(title);
Expand Down Expand Up @@ -171,6 +189,21 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
await this.createSavedSearchIfNeeded(savedSearches.farequoteFilter);
},

async createMLTestDashboardIfNeeded() {
await this.createDashboardIfNeeded(dashboards.mlTestDashboard);
},

async createDashboardIfNeeded(dashboard: any) {
const title = dashboard.requestBody.attributes.title;
const dashboardId = await this.getDashboardId(title);
if (dashboardId !== undefined) {
log.debug(`Dashboard with title '${title}' already exists. Nothing to create.`);
return dashboardId;
} else {
return await this.createDashboard(title, dashboard.requestBody);
}
},

async createSavedSearchFarequoteLuceneIfNeeded() {
await this.createSavedSearchIfNeeded(savedSearches.farequoteLucene);
},
Expand Down
19 changes: 19 additions & 0 deletions x-pack/test/functional/services/ml/test_resources_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,22 @@ export const savedSearches = {
},
},
};

export const dashboards = {
mlTestDashboard: {
requestBody: {
attributes: {
title: 'ML Test',
hits: 0,
description: '',
panelsJSON: '[]',
optionsJSON: '{"hidePanelTitles":false,"useMargins":true}',
version: 1,
timeRestore: false,
kibanaSavedObjectMeta: {
searchSourceJSON: '{"query":{"language":"kuery","query":""},"filter":[]}',
},
},
},
},
};

0 comments on commit 3a387e5

Please sign in to comment.