Skip to content

Commit

Permalink
Functional tests: convert more test/services to TS (elastic#45176)
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' <wayne.seymour@elastic.co>

* Update test/functional/services/combo_box.ts

Co-Authored-By: Tre' <wayne.seymour@elastic.co>

* Update test/functional/services/combo_box.ts

Co-Authored-By: Tre' <wayne.seymour@elastic.co>

* fix lint error
  • Loading branch information
dmlemeshko committed Sep 11, 2019
1 parent d8e10b6 commit f1b59ae
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 175 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
112 changes: 69 additions & 43 deletions test/functional/services/combo_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,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 @@ -66,7 +73,8 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
return;
}

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

if (value !== undefined) {
Expand All @@ -90,30 +98,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 @@ -124,10 +144,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 @@ -145,37 +175,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 @@ -209,9 +235,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 @@ -222,9 +248,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 @@ -237,10 +263,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 f1b59ae

Please sign in to comment.