Skip to content

Commit

Permalink
Functional tests: convert more test/services to TS (#45176) (#45386)
Browse files Browse the repository at this point in the history
* convert more test/services to TS

* Update test/functional/services/combo_box.ts

Co-Authored-By: Tre' <[email protected]>

* Update test/functional/services/combo_box.ts

Co-Authored-By: Tre' <[email protected]>

* Update test/functional/services/combo_box.ts

Co-Authored-By: Tre' <[email protected]>

* fix lint error
  • Loading branch information
dmlemeshko authored Sep 11, 2019
1 parent fd1b0fc commit cb681ed
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 176 deletions.
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_tag_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function ({ getService, getPageObjects }) {
];

await inspector.open();
await await inspector.setTablePageSize('50');
await await inspector.setTablePageSize(50);
await inspector.expectTableData(expectedTableData);
});

Expand Down
111 changes: 68 additions & 43 deletions test/functional/services/combo_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,32 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
// wrapper around EuiComboBox interactions
class ComboBox {
/**
* set value inside combobox
* Finds combobox element and sets specified value
*
* @param comboBoxSelector test subject selector
* @param value
* @param comboBoxSelector data-test-subj selector
* @param value option text
*/

public async set(comboBoxSelector: string, value: string): Promise<void> {
log.debug(`comboBox.set, comboBoxSelector: ${comboBoxSelector}`);
const comboBox = await testSubjects.find(comboBoxSelector);
await this.setElement(comboBox, value);
}

private async clickOption(isMouseClick: boolean, element: WebElementWrapper) {
/**
* Clicks option in combobox dropdown
*
* @param isMouseClick if 'true', click will be done with mouse
* @param element element that wraps up option
*/
private async clickOption(isMouseClick: boolean, element: WebElementWrapper): Promise<void> {
return isMouseClick ? await element.clickMouseButton() : await element.click();
}

/**
* set value inside combobox element
* Sets value for specified combobox element
*
* @param comboBoxElement
* @param comboBoxElement element that wraps up EuiComboBox
* @param value
*/
public async setElement(
Expand All @@ -69,7 +76,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

comboBoxElement.scrollIntoViewIfNecessary();
await this._filterOptionsList(comboBoxElement, value);
await this.setFilterValue(comboBoxElement, value);
await this.openOptionsList(comboBoxElement);

if (value !== undefined) {
Expand All @@ -93,30 +100,42 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* This method set custom value to comboBox.
* Finds combobox element and sets custom value
* It applies changes by pressing Enter key. Sometimes it may lead to auto-submitting a form.
*
* @param comboBoxSelector test subject selector
* @param value
* @param comboBoxSelector data-test-subj selector
* @param value option text
*/
async setCustom(comboBoxSelector: string, value: string) {
public async setCustom(comboBoxSelector: string, value: string): Promise<void> {
log.debug(`comboBox.setCustom, comboBoxSelector: ${comboBoxSelector}, value: ${value}`);
const comboBoxElement = await testSubjects.find(comboBoxSelector);
await this._filterOptionsList(comboBoxElement, value);
await this.setFilterValue(comboBoxElement, value);
await PageObjects.common.pressEnterKey();
await this.closeOptionsList(comboBoxElement);
}

async filterOptionsList(comboBoxSelector: string, filterValue: string) {
/**
* Finds combobox element and sets filter value
*
* @param comboBoxSelector data-test-subj selector
* @param filterValue text
*/
public async filterOptionsList(comboBoxSelector: string, filterValue: string): Promise<void> {
log.debug(
`comboBox.filterOptionsList, comboBoxSelector: ${comboBoxSelector}, filter: ${filterValue}`
);
const comboBox = await testSubjects.find(comboBoxSelector);
await this._filterOptionsList(comboBox, filterValue);
await this.setFilterValue(comboBox, filterValue);
await this.closeOptionsList(comboBox);
}

private async _filterOptionsList(
/**
* Sets new filter value in specified combobox element
*
* @param comboBoxElement element that wraps up EuiComboBox
* @param filterValue text
*/
private async setFilterValue(
comboBoxElement: WebElementWrapper,
filterValue: string
): Promise<void> {
Expand All @@ -127,10 +146,20 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
await this.waitForOptionsListLoading(comboBoxElement);
}

/**
* Waits options list to be loaded
*
* @param comboBoxElement element that wraps up EuiComboBox
*/
private async waitForOptionsListLoading(comboBoxElement: WebElementWrapper): Promise<void> {
await comboBoxElement.waitForDeletedByCssSelector('.euiLoadingSpinner');
}

/**
* Returns options list as a single string
*
* @param comboBoxSelector data-test-subj selector
*/
public async getOptionsList(comboBoxSelector: string): Promise<string> {
log.debug(`comboBox.getOptionsList, comboBoxSelector: ${comboBoxSelector}`);
const comboBox = await testSubjects.find(comboBoxSelector);
Expand All @@ -148,37 +177,33 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
return optionsText;
}

/**
* Finds combobox element and checks if it has selected options
*
* @param comboBoxSelector data-test-subj selector
*/
public async doesComboBoxHaveSelectedOptions(comboBoxSelector: string): Promise<boolean> {
log.debug(`comboBox.doesComboBoxHaveSelectedOptions, comboBoxSelector: ${comboBoxSelector}`);
const comboBox = await testSubjects.find(comboBoxSelector);
const selectedOptions = await comboBox.findAllByClassName(
'euiComboBoxPill',
WAIT_FOR_EXISTS_TIME
);
return selectedOptions.length > 0;
const $ = await comboBox.parseDomContent();
return $('.euiComboBoxPill').toArray().length > 0;
}

/**
* Returns selected options
* @param comboBoxSelector data-test-subj selector
*/
public async getComboBoxSelectedOptions(comboBoxSelector: string): Promise<string[]> {
log.debug(`comboBox.getComboBoxSelectedOptions, comboBoxSelector: ${comboBoxSelector}`);
return await retry.try(async () => {
const comboBox = await testSubjects.find(comboBoxSelector);
const selectedOptions = await comboBox.findAllByClassName(
'euiComboBoxPill',
WAIT_FOR_EXISTS_TIME
);
if (selectedOptions.length === 0) {
return [];
}
return Promise.all(
selectedOptions.map(async optionElement => {
return await optionElement.getVisibleText();
})
);
});
const comboBox = await testSubjects.find(comboBoxSelector);
const $ = await comboBox.parseDomContent();
return $('.euiComboBoxPill')
.toArray()
.map(option => $(option).text());
}

/**
* clearing value from combobox
* Finds combobox element and clears value in the input field by clicking clear button
*
* @param comboBoxSelector data-test-subj selector
*/
Expand Down Expand Up @@ -212,9 +237,9 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* closing option list for combobox
* Closes options list
*
* @param comboBoxElement
* @param comboBoxElement element that wraps up EuiComboBox
*/
public async closeOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
const isOptionsListOpen = await testSubjects.exists('comboBoxOptionsList');
Expand All @@ -225,9 +250,9 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* opened list of options for combobox
* Opens options list
*
* @param comboBoxElement
* @param comboBoxElement element that wraps up EuiComboBox
*/
public async openOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
const isOptionsListOpen = await testSubjects.exists('comboBoxOptionsList');
Expand All @@ -240,10 +265,10 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* check if option is already selected
* Checks if specified option is already selected
*
* @param comboBoxElement
* @param value
* @param comboBoxElement element that wraps up EuiComboBox
* @param value option text
*/
public async isOptionSelected(
comboBoxElement: WebElementWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
* under the License.
*/

export function EmbeddingProvider({ getService, getPageObjects }) {
import { FtrProviderContext } from '../ftr_provider_context';

export function EmbeddingProvider({ getService, getPageObjects }: FtrProviderContext) {
const browser = getService('browser');
const log = getService('log');
const PageObjects = getPageObjects(['header']);

class Embedding {

async openInEmbeddedMode() {
/**
* Opens current page in embeded mode
*/
public async openInEmbeddedMode(): Promise<void> {
const currentUrl = await browser.getCurrentUrl();
log.debug(`Opening in embedded mode: ${currentUrl}`);
await browser.get(`${currentUrl}&embed=true`);
await PageObjects.header.waitUntilLoadingHasFinished();
}

}

return new Embedding();
Expand Down
Loading

0 comments on commit cb681ed

Please sign in to comment.