Skip to content

Commit

Permalink
[7.9] [x-pack/test] convert PO to typescript, improve find/testSubjec…
Browse files Browse the repository at this point in the history
…t usage (elastic#77389) (elastic#77491)

* [x-pack/test] convert PO to typescript, improve find/testSubject usage (elastic#77382)

* fix lint error

* rremove file

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
dmlemeshko and elasticmachine authored Sep 16, 2020
1 parent 94985ed commit 083900b
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 128 deletions.
5 changes: 2 additions & 3 deletions test/functional/page_objects/vega_chart_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

import { Key } from 'selenium-webdriver';
import { FtrProviderContext } from '../ftr_provider_context';

export function VegaChartPageProvider({
Expand Down Expand Up @@ -48,10 +47,10 @@ export function VegaChartPageProvider({
await textarea.click();
let repeats = 20;
while (--repeats > 0) {
await browser.pressKeys(Key.ARROW_UP);
await browser.pressKeys(browser.keys.ARROW_UP);
await common.sleep(50);
}
await browser.pressKeys(Key.ARROW_RIGHT);
await browser.pressKeys(browser.keys.ARROW_RIGHT);
await browser.pressKeys(text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

//import { map as mapAsync } from 'bluebird';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function AccountSettingProvider({ getService }) {
export function AccountSettingProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const userMenu = getService('userMenu');

class AccountSettingsPage {
async verifyAccountSettings(expectedEmail, expectedUserName) {
async verifyAccountSettings(expectedEmail: string, expectedUserName: string) {
await userMenu.clickProvileLink();

const usernameField = await testSubjects.find('username');
Expand All @@ -25,7 +25,7 @@ export function AccountSettingProvider({ getService }) {
await userMenu.closeMenu();
}

async changePassword(currentPassword, newPassword) {
async changePassword(currentPassword: string, newPassword: string) {
await testSubjects.setValue('currentPassword', currentPassword);
await testSubjects.setValue('newPassword', newPassword);
await testSubjects.setValue('confirmNewPassword', newPassword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import _ from 'lodash';
import { APP_ID } from '../../../plugins/maps/common/constants';
import { FtrProviderContext } from '../ftr_provider_context';

export function GisPageProvider({ getService, getPageObjects }) {
export function GisPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'header', 'timePicker']);

const log = getService('log');
Expand All @@ -19,25 +20,27 @@ export function GisPageProvider({ getService, getPageObjects }) {
const comboBox = getService('comboBox');
const renderable = getService('renderable');

function escapeLayerName(layerName) {
function escapeLayerName(layerName: string) {
return layerName.split(' ').join('_');
}

class GisPage {
basePath: string;

constructor() {
this.basePath = '';
}

setBasePath(basePath) {
setBasePath(basePath: string) {
this.basePath = basePath;
}

async setAbsoluteRange(start, end) {
async setAbsoluteRange(start: string, end: string) {
await PageObjects.timePicker.setAbsoluteRange(start, end);
await this.waitForLayersToLoad();
}

async setAndSubmitQuery(query) {
async setAndSubmitQuery(query: string) {
await queryBar.setQuery(query);
await queryBar.submitQuery();
await this.waitForLayersToLoad();
Expand Down Expand Up @@ -70,7 +73,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
// this method waits until the map view has stabilized, signaling that the panning/zooming is complete.
// Pass origView parameter when the new map view determinition is async
// so method knows when panning/zooming has started.
async waitForMapPanAndZoom(origView) {
async waitForMapPanAndZoom(origView?: { lon: number; lat: number; zoom: number }) {
await retry.try(async () => {
log.debug('Waiting for map pan and zoom to complete');
const prevView = await this.getView();
Expand All @@ -94,7 +97,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
});
}

async waitForLayerDeleted(layerName) {
async waitForLayerDeleted(layerName: string) {
log.debug('Wait for layer deleted');
await retry.waitFor('Layer to be deleted', async () => {
const doesLayerExist = await this.doesLayerExist(layerName);
Expand All @@ -104,7 +107,7 @@ export function GisPageProvider({ getService, getPageObjects }) {

// use the search filter box to narrow the results down to a single
// entry, or at least to a single page of results
async loadSavedMap(name) {
async loadSavedMap(name: string) {
log.debug(`Load Saved Map ${name}`);

await retry.try(async () => {
Expand All @@ -121,7 +124,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await this.waitForLayersToLoad();
}

async deleteSavedMaps(search) {
async deleteSavedMaps(search: string) {
await this.searchForMapWithName(search);
await testSubjects.click('checkboxSelectAll');
await testSubjects.click('deleteSelectedItems');
Expand All @@ -139,7 +142,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await renderable.waitForRender();
}

async saveMap(name) {
async saveMap(name: string) {
await testSubjects.click('mapSaveButton');
await testSubjects.setValue('savedObjectTitle', name);
await testSubjects.clickWhenNotDisabled('confirmSaveSavedObjectButton');
Expand Down Expand Up @@ -167,7 +170,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
return exists;
}

async searchForMapWithName(name) {
async searchForMapWithName(name: string) {
log.debug(`searchForMapWithName: ${name}`);

await this.gotoMapListingPage();
Expand All @@ -183,7 +186,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await PageObjects.header.waitUntilLoadingHasFinished();
}

async selectMap(name) {
async selectMap(name: string) {
await testSubjects.click(`mapListingTitleLink-${name.split(' ').join('-')}`);
}

Expand All @@ -208,7 +211,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
}
}

async getMapCountWithName(name) {
async getMapCountWithName(name: string) {
await this.gotoMapListingPage();

log.debug(`getMapCountWithName: ${name}`);
Expand Down Expand Up @@ -247,7 +250,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
}
}

async setView(lat, lon, zoom) {
async setView(lat: number, lon: number, zoom: number) {
log.debug(
`Set view lat: ${lat.toString()}, lon: ${lon.toString()}, zoom: ${zoom.toString()}`
);
Expand All @@ -273,7 +276,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
};
}

async toggleLayerVisibility(layerName) {
async toggleLayerVisibility(layerName: string) {
log.debug(`Toggle layer visibility, layer: ${layerName}`);
await this.openLayerTocActionsPanel(layerName);
await testSubjects.click('layerVisibilityToggleButton');
Expand All @@ -287,23 +290,23 @@ export function GisPageProvider({ getService, getPageObjects }) {
}
}

async clickFitToBounds(layerName) {
async clickFitToBounds(layerName: string) {
log.debug(`Fit to bounds, layer: ${layerName}`);
const origView = await this.getView();
await this.openLayerTocActionsPanel(layerName);
await testSubjects.click('fitToBoundsButton');
await this.waitForMapPanAndZoom(origView);
}

async openLayerTocActionsPanel(layerName) {
async openLayerTocActionsPanel(layerName: string) {
const escapedDisplayName = escapeLayerName(layerName);
const isOpen = await testSubjects.exists(`layerTocActionsPanel${escapedDisplayName}`);
if (!isOpen) {
await testSubjects.click(`layerTocActionsPanelToggleButton${escapedDisplayName}`);
}
}

async openLayerPanel(layerName) {
async openLayerPanel(layerName: string) {
log.debug(`Open layer panel, layer: ${layerName}`);
await this.openLayerTocActionsPanel(layerName);
await testSubjects.click('editLayerButton');
Expand All @@ -314,7 +317,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await this.waitForLayersToLoad();
}

async getLayerTOCDetails(layerName) {
async getLayerTOCDetails(layerName: string) {
return await testSubjects.getVisibleText(`mapLayerTOCDetails${escapeLayerName(layerName)}`);
}

Expand All @@ -339,13 +342,13 @@ export function GisPageProvider({ getService, getPageObjects }) {
}
}

async doesLayerExist(layerName) {
async doesLayerExist(layerName: string) {
return await testSubjects.exists(
`layerTocActionsPanelToggleButton${escapeLayerName(layerName)}`
);
}

async hasFilePickerLoadedFile(fileName) {
async hasFilePickerLoadedFile(fileName: string) {
log.debug(`Has file picker loaded file ${fileName}`);
const filePickerText = await find.byCssSelector('.euiFilePicker__promptText');
const filePickerTextContent = await filePickerText.getVisibleText();
Expand Down Expand Up @@ -380,7 +383,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
});
}

async cancelLayerAdd(layerName) {
async cancelLayerAdd(layerName: string) {
log.debug(`Cancel layer add`);
const cancelExists = await testSubjects.exists('layerAddCancelButton');
if (cancelExists) {
Expand All @@ -392,7 +395,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
}
}

async closeOrCancelLayer(layerName) {
async closeOrCancelLayer(layerName: string) {
log.debug(`Close or cancel layer add`);
const cancelExists = await testSubjects.exists('layerAddCancelButton');
const closeExists = await testSubjects.exists('layerPanelCancelButton');
Expand Down Expand Up @@ -436,24 +439,24 @@ export function GisPageProvider({ getService, getPageObjects }) {
await testSubjects.click('importFileButton');
}

async setIndexName(indexName) {
async setIndexName(indexName: string) {
log.debug(`Set index name to: ${indexName}`);
await testSubjects.setValue('fileUploadIndexNameInput', indexName);
}

async setIndexType(indexType) {
async setIndexType(indexType: string) {
log.debug(`Set index type to: ${indexType}`);
await testSubjects.selectValue('fileImportIndexSelect', indexType);
}

async indexTypeOptionExists(indexType) {
async indexTypeOptionExists(indexType: string) {
log.debug(`Check index type "${indexType}" available`);
return await find.existsByCssSelector(
`select[data-test-subj="fileImportIndexSelect"] > option[value="${indexType}"]`
);
}

async getCodeBlockParsedJson(dataTestSubjName) {
async getCodeBlockParsedJson(dataTestSubjName: string) {
log.debug(`Get parsed code block for ${dataTestSubjName}`);
const indexRespCodeBlock = await testSubjects.find(`${dataTestSubjName}`);
const indexRespJson = await indexRespCodeBlock.getAttribute('innerText');
Expand All @@ -470,7 +473,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
return await this.getCodeBlockParsedJson('indexPatternRespCodeBlock');
}

async setLayerQuery(layerName, query) {
async setLayerQuery(layerName: string, query: string) {
await this.openLayerPanel(layerName);
await testSubjects.click('mapLayerPanelOpenFilterEditorButton');
const filterEditorContainer = await testSubjects.find('mapFilterEditor');
Expand All @@ -492,7 +495,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await this.waitForLayersToLoad();
}

async setJoinWhereQuery(layerName, query) {
async setJoinWhereQuery(layerName: string, query: string) {
await this.openLayerPanel(layerName);
await testSubjects.click('mapJoinWhereExpressionButton');
const filterEditorContainer = await testSubjects.find('mapJoinWhereFilterEditor');
Expand All @@ -518,7 +521,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await testSubjects.click('uploadGeoJson');
}

async uploadJsonFileForIndexing(path) {
async uploadJsonFileForIndexing(path: string) {
await PageObjects.common.setFileInputPath(path);
log.debug(`File selected`);

Expand All @@ -527,7 +530,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
}

// Returns first layer by default
async selectVectorLayer(vectorLayerName) {
async selectVectorLayer(vectorLayerName: string) {
log.debug(`Select EMS vector layer ${vectorLayerName}`);
if (!vectorLayerName) {
throw new Error(`You did not provide the EMS layer to select`);
Expand All @@ -536,14 +539,14 @@ export function GisPageProvider({ getService, getPageObjects }) {
await this.waitForLayersToLoad();
}

async removeLayer(layerName) {
async removeLayer(layerName: string) {
log.debug(`Remove layer ${layerName}`);
await this.openLayerPanel(layerName);
await testSubjects.click(`mapRemoveLayerButton`);
await this.waitForLayerDeleted(layerName);
}

async getLayerErrorText(layerName) {
async getLayerErrorText(layerName: string) {
log.debug(`Remove layer ${layerName}`);
await this.openLayerPanel(layerName);
return await testSubjects.getVisibleText(`layerErrorMessage`);
Expand Down Expand Up @@ -576,7 +579,7 @@ export function GisPageProvider({ getService, getPageObjects }) {

// Method should only be used when multiple requests are expected
// RequestSelector will only display inspectorRequestChooser when there is more than one request
async openInspectorRequest(requestName) {
async openInspectorRequest(requestName: string) {
await inspector.open();
await inspector.openInspectorRequestsView();
log.debug(`Open Inspector request ${requestName}`);
Expand Down Expand Up @@ -607,12 +610,12 @@ export function GisPageProvider({ getService, getPageObjects }) {
return mapboxStyle;
}

getInspectorStatRowHit(stats, rowName) {
getInspectorStatRowHit(stats: string[][], rowName: string) {
const STATS_ROW_NAME_INDEX = 0;
const STATS_ROW_VALUE_INDEX = 1;

const statsRow = stats.find((statsRow) => {
return statsRow[STATS_ROW_NAME_INDEX] === rowName;
const statsRow = stats.find((row) => {
return row[STATS_ROW_NAME_INDEX] === rowName;
});
if (!statsRow) {
throw new Error(`Unable to find value for row ${rowName} in ${stats}`);
Expand All @@ -621,7 +624,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
return statsRow[STATS_ROW_VALUE_INDEX];
}

async triggerSingleRefresh(refreshInterval) {
async triggerSingleRefresh(refreshInterval: number) {
log.debug(`triggerSingleRefresh, refreshInterval: ${refreshInterval}`);
await PageObjects.timePicker.resumeAutoRefresh();
log.debug('waiting to give time for refresh timer to fire');
Expand All @@ -630,7 +633,7 @@ export function GisPageProvider({ getService, getPageObjects }) {
await this.waitForLayersToLoad();
}

async lockTooltipAtPosition(xOffset, yOffset) {
async lockTooltipAtPosition(xOffset: number, yOffset: number) {
await retry.try(async () => {
const mapContainerElement = await testSubjects.find('mapContainer');
await mapContainerElement.moveMouseTo({ xOffset, yOffset });
Expand All @@ -643,12 +646,12 @@ export function GisPageProvider({ getService, getPageObjects }) {
});
}

async setStyleByValue(styleName, fieldName) {
async setStyleByValue(styleName: string, fieldName: string) {
await testSubjects.selectValue(`staticDynamicSelect_${styleName}`, 'DYNAMIC');
await comboBox.set(`styleFieldSelect_${styleName}`, fieldName);
}

async selectCustomColorRamp(styleName) {
async selectCustomColorRamp(styleName: string) {
// open super select menu
await testSubjects.click(`colorMapSelect_${styleName}`);
// Click option
Expand Down
Loading

0 comments on commit 083900b

Please sign in to comment.