Skip to content

Commit

Permalink
Merge branch 'master' into graph_saved_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 20, 2020
2 parents f4c91bb + 87e07ef commit 8b9e938
Show file tree
Hide file tree
Showing 159 changed files with 2,823 additions and 630 deletions.
1 change: 1 addition & 0 deletions .sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ files:
- 'x-pack/legacy/plugins/rollup/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/security/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/canvas/**/*.s+(a|c)ss'
- 'x-pack/plugins/triggers_actions_ui/**/*.s+(a|c)ss'
ignore:
- 'x-pack/legacy/plugins/canvas/shareable_runtime/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/lens/**/*.s+(a|c)ss'
Expand Down
3 changes: 1 addition & 2 deletions test/functional/apps/visualize/_tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function({ getService, getPageObjects }) {
const log = getService('log');
const retry = getService('retry');
const inspector = getService('inspector');
const find = getService('find');
const filterBar = getService('filterBar');
const testSubjects = getService('testSubjects');
const browser = getService('browser');
Expand Down Expand Up @@ -279,7 +278,7 @@ export default function({ getService, getPageObjects }) {
it('should suppress zoom warning if suppress warnings button clicked', async () => {
last = true;
await PageObjects.visChart.waitForVisualization();
await find.clickByCssSelector('[data-test-subj="suppressZoomWarnings"]');
await testSubjects.click('suppressZoomWarnings');
await PageObjects.tileMap.clickMapZoomOut(waitForLoading);
await testSubjects.waitForDeleted('suppressZoomWarnings');
await PageObjects.tileMap.clickMapZoomIn(waitForLoading);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
private async loginIfPrompted(appUrl: string) {
let currentUrl = await browser.getCurrentUrl();
log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`);
await find.byCssSelector('[data-test-subj="kibanaChrome"]', 6 * defaultFindTimeout); // 60 sec waiting
await testSubjects.find('kibanaChrome', 6 * defaultFindTimeout); // 60 sec waiting
const loginPage = currentUrl.includes('/login');
const wantedLoginPage = appUrl.includes('/login') || appUrl.includes('/logout');

Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
public async clickFieldListPlusFilter(field: string, value: string) {
// this method requires the field details to be open from clickFieldListItem()
// testSubjects.find doesn't handle spaces in the data-test-subj value
await find.clickByCssSelector(`[data-test-subj="plus-${field}-${value}"]`);
await testSubjects.click(`plus-${field}-${value}`);
await header.waitUntilLoadingHasFinished();
}

public async clickFieldListMinusFilter(field: string, value: string) {
// this method requires the field details to be open from clickFieldListItem()
// testSubjects.find doesn't handle spaces in the data-test-subj value
await find.clickByCssSelector('[data-test-subj="minus-' + field + '-' + value + '"]');
await testSubjects.click(`minus-${field}-${value}`);
await header.waitUntilLoadingHasFinished();
}

Expand Down
2 changes: 1 addition & 1 deletion test/functional/page_objects/newsfeed_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function NewsfeedPageProvider({ getService, getPageObjects }: FtrProvider

async getNewsfeedList() {
const list = await testSubjects.find('NewsfeedFlyout');
const cells = await list.findAllByCssSelector('[data-test-subj="newsHeadAlert"]');
const cells = await list.findAllByTestSubject('newsHeadAlert');

const objects = [];
for (const cell of cells) {
Expand Down
3 changes: 1 addition & 2 deletions test/functional/page_objects/settings_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,8 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider
}

async getScriptedFieldsTabCount() {
const selector = '[data-test-subj="tab-count-scriptedFields"]';
return await retry.try(async () => {
const theText = await (await find.byCssSelector(selector)).getVisibleText();
const theText = await testSubjects.getVisibleText('tab-count-scriptedFields');
return theText.replace(/\((.*)\)/, '$1');
});
}
Expand Down
5 changes: 2 additions & 3 deletions test/functional/page_objects/timelion_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

export function TimelionPageProvider({ getService, getPageObjects }) {
const testSubjects = getService('testSubjects');
const find = getService('find');
const log = getService('log');
const PageObjects = getPageObjects(['common', 'header']);
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -55,12 +54,12 @@ export function TimelionPageProvider({ getService, getPageObjects }) {
}

async getSuggestionItemsText() {
const elements = await find.allByCssSelector('[data-test-subj="timelionSuggestionListItem"]');
const elements = await testSubjects.findAll('timelionSuggestionListItem');
return await Promise.all(elements.map(async element => await element.getVisibleText()));
}

async clickSuggestion(suggestionIndex = 0, waitTime = 500) {
const elements = await find.allByCssSelector('[data-test-subj="timelionSuggestionListItem"]');
const elements = await testSubjects.findAll('timelionSuggestionListItem');
if (suggestionIndex > elements.length) {
throw new Error(
`Unable to select suggestion ${suggestionIndex}, only ${elements.length} suggestions available.`
Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/visual_builder_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
const labels = await testSubjects.findAll('aggRow');
const label = labels[aggNth];

return (await label.findAllByCssSelector('[data-test-subj = "comboBoxInput"]'))[1];
return (await label.findAllByTestSubject('comboBoxInput'))[1];
}

public async clickColorPicker(): Promise<void> {
Expand Down Expand Up @@ -533,7 +533,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
*/
public async getAggregationCount(nth: number = 0): Promise<number> {
const series = await this.getSeries();
const aggregation = await series[nth].findAllByCssSelector('[data-test-subj="draggable"]');
const aggregation = await series[nth].findAllByTestSubject('draggable');
return aggregation.length;
}

Expand Down
2 changes: 1 addition & 1 deletion test/functional/page_objects/visualize_editor_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function VisualizeEditorPageProvider({ getService, getPageObjects }: FtrP
*/
public async clickBucket(bucketName: string, type = 'buckets') {
await testSubjects.click(`visEditorAdd_${type}`);
await find.clickByCssSelector(`[data-test-subj="visEditorAdd_${type}_${bucketName}"`);
await testSubjects.click(`visEditorAdd_${type}_${bucketName}`);
}

public async clickEnableCustomRanges() {
Expand Down
10 changes: 4 additions & 6 deletions test/functional/services/combo_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
return;
}

const clearBtn = await comboBox.findByCssSelector('[data-test-subj="comboBoxClearButton"]');
const clearBtn = await comboBox.findByTestSubject('comboBoxClearButton');
await clearBtn.click();

const clearButtonStillExists = await this.doesClearButtonExist(comboBox);
Expand All @@ -230,8 +230,8 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

public async doesClearButtonExist(comboBoxElement: WebElementWrapper): Promise<boolean> {
const found = await comboBoxElement.findAllByCssSelector(
'[data-test-subj="comboBoxClearButton"]',
const found = await comboBoxElement.findAllByTestSubject(
'comboBoxClearButton',
WAIT_FOR_EXISTS_TIME
);
return found.length > 0;
Expand Down Expand Up @@ -264,9 +264,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
public async openOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
const isOptionsListOpen = await testSubjects.exists('~comboBoxOptionsList');
if (!isOptionsListOpen) {
const toggleBtn = await comboBoxElement.findByCssSelector(
'[data-test-subj="comboBoxToggleListButton"]'
);
const toggleBtn = await comboBoxElement.findByTestSubject('comboBoxToggleListButton');
await toggleBtn.click();
}
}
Expand Down
18 changes: 8 additions & 10 deletions test/functional/services/doc_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont

public async getBodyRows(): Promise<WebElementWrapper[]> {
const table = await this.getTable();
return await table.findAllByCssSelector('[data-test-subj~="docTableRow"]');
return await table.findAllByTestSubject('~docTableRow');
}

public async getAnchorRow(): Promise<WebElementWrapper> {
const table = await this.getTable();
return await table.findByCssSelector('[data-test-subj~="docTableAnchorRow"]');
return await table.findByTestSubject('~docTableAnchorRow');
}

public async getRow(options: SelectOptions): Promise<WebElementWrapper> {
Expand All @@ -73,7 +73,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
options: SelectOptions = { isAnchorRow: false, rowIndex: 0 }
): Promise<void> {
const row = await this.getRow(options);
const toggle = await row.findByCssSelector('[data-test-subj~="docTableExpandToggleColumn"]');
const toggle = await row.findByTestSubject('~docTableExpandToggleColumn');
await toggle.click();
}

Expand All @@ -90,7 +90,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
const detailsRow = options.isAnchorRow
? await this.getAnchorDetailsRow()
: (await this.getDetailsRows())[options.rowIndex];
return await detailsRow.findAllByCssSelector('[data-test-subj~="docTableRowAction"]');
return await detailsRow.findAllByTestSubject('~docTableRowAction');
}

public async getFields(options: { isAnchorRow: boolean } = { isAnchorRow: false }) {
Expand Down Expand Up @@ -122,15 +122,13 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
detailsRow: WebElementWrapper,
fieldName: WebElementWrapper
): Promise<WebElementWrapper> {
return await detailsRow.findByCssSelector(`[data-test-subj~="tableDocViewRow-${fieldName}"]`);
return await detailsRow.findByTestSubject(`~tableDocViewRow-${fieldName}`);
}

public async getAddInclusiveFilterButton(
tableDocViewRow: WebElementWrapper
): Promise<WebElementWrapper> {
return await tableDocViewRow.findByCssSelector(
`[data-test-subj~="addInclusiveFilterButton"]`
);
return await tableDocViewRow.findByTestSubject(`~addInclusiveFilterButton`);
}

public async addInclusiveFilter(
Expand All @@ -146,7 +144,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
public async getAddExistsFilterButton(
tableDocViewRow: WebElementWrapper
): Promise<WebElementWrapper> {
return await tableDocViewRow.findByCssSelector(`[data-test-subj~="addExistsFilterButton"]`);
return await tableDocViewRow.findByTestSubject(`~addExistsFilterButton`);
}

public async addExistsFilter(
Expand All @@ -171,7 +169,7 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
const detailsRow = await row.findByXpath(
'./following-sibling::*[@data-test-subj="docTableDetailsRow"]'
);
return detailsRow.findByCssSelector('[data-test-subj~="docViewer"]');
return detailsRow.findByTestSubject('~docViewer');
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,40 @@ export class WebElementWrapper {
});
}

/**
* Gets the first element inside this element matching the given data-test-subj selector.
*
* @param {string} selector
* @return {Promise<WebElementWrapper>}
*/
public async findByTestSubject(selector: string) {
return await this.retryCall(async function find(wrapper) {
return wrapper._wrap(
await wrapper._webElement.findElement(wrapper.By.css(testSubjSelector(selector))),
wrapper.By.css(selector)
);
});
}

/**
* Gets all elements inside this element matching the given data-test-subj selector.
*
* @param {string} selector
* @param {number} timeout
* @return {Promise<WebElementWrapper[]>}
*/
public async findAllByTestSubject(selector: string, timeout?: number) {
return await this.retryCall(async function findAll(wrapper) {
return wrapper._wrapAll(
await wrapper._findWithCustomTimeout(
async () =>
await wrapper._webElement.findElements(wrapper.By.css(testSubjSelector(selector))),
timeout
)
);
});
}

/**
* Gets the first element inside this element matching the given CSS class name.
* https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_WebElement.html#findElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import _ from 'lodash';
import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source';
import { EMSTMSSource } from '../layers/sources/ems_tms_source';
import chrome from 'ui/chrome';
import { getInjectedVarFunc } from '../kibana_services';
import { getKibanaTileMap } from '../meta';

export function getInitialLayers(layerListJSON, initialLayers = []) {
Expand All @@ -22,7 +22,7 @@ export function getInitialLayers(layerListJSON, initialLayers = []) {
return [layer.toLayerDescriptor(), ...initialLayers];
}

const isEmsEnabled = chrome.getInjected('isEmsEnabled', true);
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
if (isEmsEnabled) {
const descriptor = EMSTMSSource.createDescriptor({ isAutoSelect: true });
const source = new EMSTMSSource(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
jest.mock('../meta', () => {
return {};
});

jest.mock('ui/chrome', () => {
return {};
});
jest.mock('../kibana_services');

import { getInitialLayers } from './get_initial_layers';

const layerListNotProvided = undefined;

describe('Saved object has layer list', () => {
beforeEach(() => {
require('../kibana_services').getInjectedVarFunc = () => jest.fn();
});

it('Should get initial layers from saved object', () => {
const layerListFromSavedObject = [
{
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('EMS is enabled', () => {
require('../meta').getKibanaTileMap = () => {
return null;
};
require('ui/chrome').getInjected = key => {
require('../kibana_services').getInjectedVarFunc = () => key => {
switch (key) {
case 'emsTileLayerId':
return {
Expand All @@ -75,7 +76,7 @@ describe('EMS is enabled', () => {
case 'isEmsEnabled':
return true;
default:
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
}
};
});
Expand Down Expand Up @@ -109,12 +110,12 @@ describe('EMS is not enabled', () => {
return null;
};

require('ui/chrome').getInjected = key => {
require('../kibana_services').getInjectedVarFunc = () => key => {
switch (key) {
case 'isEmsEnabled':
return false;
default:
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
}
};
});
Expand Down
10 changes: 5 additions & 5 deletions x-pack/legacy/plugins/maps/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n';
import { capabilities } from 'ui/capabilities';
import { render, unmountComponentAtNode } from 'react-dom';
import { uiModules } from 'ui/modules';
import { timefilter } from 'ui/timefilter';
import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services';
import { Provider } from 'react-redux';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createMapStore } from '../../../../../plugins/maps/public/reducers/store';
Expand Down Expand Up @@ -52,7 +52,7 @@ import {
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import { docTitle } from 'ui/doc_title';
import { indexPatternService, getInspector } from '../kibana_services';

import { toastNotifications } from 'ui/notify';
import { getInitialLayers } from './get_initial_layers';
import { getInitialQuery } from './get_initial_query';
Expand Down Expand Up @@ -396,7 +396,7 @@ app.controller(
const indexPatterns = [];
const getIndexPatternPromises = nextIndexPatternIds.map(async indexPatternId => {
try {
const indexPattern = await indexPatternService.get(indexPatternId);
const indexPattern = await getIndexPatternService().get(indexPatternId);
indexPatterns.push(indexPattern);
} catch (err) {
// unable to fetch index pattern
Expand Down Expand Up @@ -519,8 +519,8 @@ app.controller(
}

// Hide angular timepicer/refresh UI from top nav
timefilter.disableTimeRangeSelector();
timefilter.disableAutoRefreshSelector();
getTimeFilter().disableTimeRangeSelector();
getTimeFilter().disableAutoRefreshSelector();
$scope.showDatePicker = true; // used by query-bar directive to enable timepikcer in query bar
$scope.topNavMenu = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Maps can contain geo fields from multiple index patterns. GeoFieldWithIndex is used to:
// 1) Combine the geo field along with associated index pattern state.
// 2) Package asynchronously looked up state via indexPatternService to avoid
// 2) Package asynchronously looked up state via getIndexPatternService() to avoid
// PITA of looking up async state in downstream react consumers.
export type GeoFieldWithIndex = {
geoFieldName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { indexPatternService } from '../../../kibana_services';
import { getIndexPatternService } from '../../../kibana_services';
import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox';

import { npStart } from 'ui/new_platform';
Expand All @@ -47,7 +47,7 @@ export class FilterEditor extends Component {
const indexPatterns = [];
const getIndexPatternPromises = indexPatternIds.map(async indexPatternId => {
try {
const indexPattern = await indexPatternService.get(indexPatternId);
const indexPattern = await getIndexPatternService().get(indexPatternId);
indexPatterns.push(indexPattern);
} catch (err) {
// unable to fetch index pattern
Expand Down
Loading

0 comments on commit 8b9e938

Please sign in to comment.