2021-02-10 19:48:32 +01:00
|
|
|
/*
|
|
|
|
* 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 and the Server Side Public License, v 1; you may not use this file except
|
|
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
|
|
* Side Public License, v 1.
|
|
|
|
*/
|
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
import { FtrService } from '../ftr_provider_context';
|
2021-02-10 19:48:32 +01:00
|
|
|
|
|
|
|
interface SaveModalArgs {
|
|
|
|
addToDashboard?: 'new' | 'existing' | null;
|
2021-03-18 18:40:02 +01:00
|
|
|
saveToLibrary?: boolean;
|
2021-02-10 19:48:32 +01:00
|
|
|
dashboardId?: string;
|
|
|
|
saveAsNew?: boolean;
|
|
|
|
redirectToOrigin?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
type DashboardPickerOption =
|
|
|
|
| 'add-to-library-option'
|
|
|
|
| 'existing-dashboard-option'
|
|
|
|
| 'new-dashboard-option';
|
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
export class TimeToVisualizePageObject extends FtrService {
|
|
|
|
private readonly testSubjects = this.ctx.getService('testSubjects');
|
|
|
|
private readonly log = this.ctx.getService('log');
|
|
|
|
private readonly find = this.ctx.getService('find');
|
|
|
|
private readonly common = this.ctx.getPageObject('common');
|
|
|
|
private readonly dashboard = this.ctx.getPageObject('dashboard');
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
public async ensureSaveModalIsOpen() {
|
|
|
|
await this.testSubjects.exists('savedObjectSaveModal', { timeout: 5000 });
|
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
public async ensureDashboardOptionsAreDisabled() {
|
|
|
|
const dashboardSelector = await this.testSubjects.find('add-to-dashboard-options');
|
|
|
|
await dashboardSelector.findByCssSelector(`input[id="new-dashboard-option"]:disabled`);
|
|
|
|
await dashboardSelector.findByCssSelector(`input[id="existing-dashboard-option"]:disabled`);
|
2021-03-18 18:40:02 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
const librarySelector = await this.testSubjects.find('add-to-library-checkbox');
|
|
|
|
await librarySelector.findByCssSelector(`input[id="add-to-library-checkbox"]:disabled`);
|
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
public async resetNewDashboard() {
|
|
|
|
await this.common.navigateToApp('dashboard');
|
|
|
|
await this.dashboard.gotoDashboardLandingPage(true);
|
|
|
|
await this.dashboard.clickNewDashboard(false);
|
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
public async setSaveModalValues(
|
|
|
|
vizName: string,
|
|
|
|
{ saveAsNew, redirectToOrigin, addToDashboard, dashboardId, saveToLibrary }: SaveModalArgs = {}
|
|
|
|
) {
|
2021-06-22 09:59:36 +02:00
|
|
|
await this.testSubjects.setValue('savedObjectTitle', vizName, {
|
|
|
|
typeCharByChar: true,
|
|
|
|
clearWithKeyboard: true,
|
|
|
|
});
|
2021-06-04 19:17:00 +02:00
|
|
|
|
|
|
|
const hasSaveAsNew = await this.testSubjects.exists('saveAsNewCheckbox');
|
|
|
|
if (hasSaveAsNew && saveAsNew !== undefined) {
|
|
|
|
const state = saveAsNew ? 'check' : 'uncheck';
|
|
|
|
this.log.debug('save as new checkbox exists. Setting its state to', state);
|
|
|
|
await this.testSubjects.setEuiSwitch('saveAsNewCheckbox', state);
|
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
const hasDashboardSelector = await this.testSubjects.exists('add-to-dashboard-options');
|
|
|
|
if (hasDashboardSelector && addToDashboard !== undefined) {
|
|
|
|
let option: DashboardPickerOption = 'add-to-library-option';
|
|
|
|
if (addToDashboard) {
|
|
|
|
option = dashboardId ? 'existing-dashboard-option' : 'new-dashboard-option';
|
2021-02-10 19:48:32 +01:00
|
|
|
}
|
2021-06-04 19:17:00 +02:00
|
|
|
this.log.debug('save modal dashboard selector, choosing option:', option);
|
|
|
|
const dashboardSelector = await this.testSubjects.find('add-to-dashboard-options');
|
|
|
|
const label = await dashboardSelector.findByCssSelector(`label[for="${option}"]`);
|
|
|
|
await label.click();
|
|
|
|
|
|
|
|
if (dashboardId) {
|
|
|
|
await this.testSubjects.setValue('dashboardPickerInput', dashboardId);
|
|
|
|
await this.find.clickByButtonText(dashboardId);
|
2021-03-18 18:40:02 +01:00
|
|
|
}
|
2021-06-04 19:17:00 +02:00
|
|
|
}
|
2021-03-18 18:40:02 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
const hasSaveToLibrary = await this.testSubjects.exists('add-to-library-checkbox');
|
|
|
|
if (hasSaveToLibrary && saveToLibrary !== undefined) {
|
|
|
|
const libraryCheckbox = await this.find.byCssSelector('#add-to-library-checkbox');
|
|
|
|
const isChecked = await libraryCheckbox.isSelected();
|
|
|
|
const needsClick = isChecked !== saveToLibrary;
|
|
|
|
const state = saveToLibrary ? 'check' : 'uncheck';
|
|
|
|
|
|
|
|
this.log.debug('save to library checkbox exists. Setting its state to', state);
|
|
|
|
if (needsClick) {
|
|
|
|
const selector = await this.testSubjects.find('add-to-library-checkbox');
|
|
|
|
const label = await selector.findByCssSelector(`label[for="add-to-library-checkbox"]`);
|
|
|
|
await label.click();
|
2021-03-18 18:40:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
const hasRedirectToOrigin = await this.testSubjects.exists('returnToOriginModeSwitch');
|
|
|
|
if (hasRedirectToOrigin && redirectToOrigin !== undefined) {
|
|
|
|
const state = redirectToOrigin ? 'check' : 'uncheck';
|
|
|
|
this.log.debug('redirect to origin checkbox exists. Setting its state to', state);
|
|
|
|
await this.testSubjects.setEuiSwitch('returnToOriginModeSwitch', state);
|
2021-02-10 19:48:32 +01:00
|
|
|
}
|
2021-06-04 19:17:00 +02:00
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
public async libraryNotificationExists(panelTitle: string) {
|
|
|
|
this.log.debug('searching for library modal on panel:', panelTitle);
|
|
|
|
const panel = await this.testSubjects.find(
|
|
|
|
`embeddablePanelHeading-${panelTitle.replace(/ /g, '')}`
|
|
|
|
);
|
|
|
|
const libraryActionExists = await this.testSubjects.descendantExists(
|
|
|
|
'embeddablePanelNotification-ACTION_LIBRARY_NOTIFICATION',
|
|
|
|
panel
|
|
|
|
);
|
|
|
|
return libraryActionExists;
|
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
public async saveFromModal(
|
|
|
|
vizName: string,
|
|
|
|
saveModalArgs: SaveModalArgs = { addToDashboard: null }
|
|
|
|
) {
|
|
|
|
await this.ensureSaveModalIsOpen();
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
await this.setSaveModalValues(vizName, saveModalArgs);
|
|
|
|
this.log.debug('Click Save Visualization button');
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
await this.testSubjects.click('confirmSaveSavedObjectButton');
|
2021-02-10 19:48:32 +01:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
await this.common.waitForSaveModalToClose();
|
|
|
|
}
|
2021-02-10 19:48:32 +01:00
|
|
|
}
|