Skip to content

Commit d4c28ec

Browse files
authored
Functional tests: convert more test/services to TS (#45176) (#45396)
* 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
1 parent d8e10b6 commit d4c28ec

File tree

13 files changed

+346
-175
lines changed

13 files changed

+346
-175
lines changed

test/functional/apps/visualize/_tag_cloud.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default function ({ getService, getPageObjects }) {
124124
];
125125

126126
await inspector.open();
127-
await await inspector.setTablePageSize('50');
127+
await await inspector.setTablePageSize(50);
128128
await inspector.expectTableData(expectedTableData);
129129
});
130130

test/functional/services/combo_box.ts

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,32 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
3333
// wrapper around EuiComboBox interactions
3434
class ComboBox {
3535
/**
36-
* set value inside combobox
36+
* Finds combobox element and sets specified value
3737
*
38-
* @param comboBoxSelector test subject selector
39-
* @param value
38+
* @param comboBoxSelector data-test-subj selector
39+
* @param value option text
4040
*/
41+
4142
public async set(comboBoxSelector: string, value: string): Promise<void> {
4243
log.debug(`comboBox.set, comboBoxSelector: ${comboBoxSelector}`);
4344
const comboBox = await testSubjects.find(comboBoxSelector);
4445
await this.setElement(comboBox, value);
4546
}
4647

47-
private async clickOption(isMouseClick: boolean, element: WebElementWrapper) {
48+
/**
49+
* Clicks option in combobox dropdown
50+
*
51+
* @param isMouseClick if 'true', click will be done with mouse
52+
* @param element element that wraps up option
53+
*/
54+
private async clickOption(isMouseClick: boolean, element: WebElementWrapper): Promise<void> {
4855
return isMouseClick ? await element.clickMouseButton() : await element.click();
4956
}
5057

5158
/**
52-
* set value inside combobox element
59+
* Sets value for specified combobox element
5360
*
54-
* @param comboBoxElement
61+
* @param comboBoxElement element that wraps up EuiComboBox
5562
* @param value
5663
*/
5764
public async setElement(
@@ -66,7 +73,8 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
6673
return;
6774
}
6875

69-
await this._filterOptionsList(comboBoxElement, value);
76+
comboBoxElement.scrollIntoViewIfNecessary();
77+
await this.setFilterValue(comboBoxElement, value);
7078
await this.openOptionsList(comboBoxElement);
7179

7280
if (value !== undefined) {
@@ -90,30 +98,42 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
9098
}
9199

92100
/**
93-
* This method set custom value to comboBox.
101+
* Finds combobox element and sets custom value
94102
* It applies changes by pressing Enter key. Sometimes it may lead to auto-submitting a form.
95103
*
96-
* @param comboBoxSelector test subject selector
97-
* @param value
104+
* @param comboBoxSelector data-test-subj selector
105+
* @param value option text
98106
*/
99-
async setCustom(comboBoxSelector: string, value: string) {
107+
public async setCustom(comboBoxSelector: string, value: string): Promise<void> {
100108
log.debug(`comboBox.setCustom, comboBoxSelector: ${comboBoxSelector}, value: ${value}`);
101109
const comboBoxElement = await testSubjects.find(comboBoxSelector);
102-
await this._filterOptionsList(comboBoxElement, value);
110+
await this.setFilterValue(comboBoxElement, value);
103111
await PageObjects.common.pressEnterKey();
104112
await this.closeOptionsList(comboBoxElement);
105113
}
106114

107-
async filterOptionsList(comboBoxSelector: string, filterValue: string) {
115+
/**
116+
* Finds combobox element and sets filter value
117+
*
118+
* @param comboBoxSelector data-test-subj selector
119+
* @param filterValue text
120+
*/
121+
public async filterOptionsList(comboBoxSelector: string, filterValue: string): Promise<void> {
108122
log.debug(
109123
`comboBox.filterOptionsList, comboBoxSelector: ${comboBoxSelector}, filter: ${filterValue}`
110124
);
111125
const comboBox = await testSubjects.find(comboBoxSelector);
112-
await this._filterOptionsList(comboBox, filterValue);
126+
await this.setFilterValue(comboBox, filterValue);
113127
await this.closeOptionsList(comboBox);
114128
}
115129

116-
private async _filterOptionsList(
130+
/**
131+
* Sets new filter value in specified combobox element
132+
*
133+
* @param comboBoxElement element that wraps up EuiComboBox
134+
* @param filterValue text
135+
*/
136+
private async setFilterValue(
117137
comboBoxElement: WebElementWrapper,
118138
filterValue: string
119139
): Promise<void> {
@@ -124,10 +144,20 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
124144
await this.waitForOptionsListLoading(comboBoxElement);
125145
}
126146

147+
/**
148+
* Waits options list to be loaded
149+
*
150+
* @param comboBoxElement element that wraps up EuiComboBox
151+
*/
127152
private async waitForOptionsListLoading(comboBoxElement: WebElementWrapper): Promise<void> {
128153
await comboBoxElement.waitForDeletedByCssSelector('.euiLoadingSpinner');
129154
}
130155

156+
/**
157+
* Returns options list as a single string
158+
*
159+
* @param comboBoxSelector data-test-subj selector
160+
*/
131161
public async getOptionsList(comboBoxSelector: string): Promise<string> {
132162
log.debug(`comboBox.getOptionsList, comboBoxSelector: ${comboBoxSelector}`);
133163
const comboBox = await testSubjects.find(comboBoxSelector);
@@ -145,37 +175,33 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
145175
return optionsText;
146176
}
147177

178+
/**
179+
* Finds combobox element and checks if it has selected options
180+
*
181+
* @param comboBoxSelector data-test-subj selector
182+
*/
148183
public async doesComboBoxHaveSelectedOptions(comboBoxSelector: string): Promise<boolean> {
149184
log.debug(`comboBox.doesComboBoxHaveSelectedOptions, comboBoxSelector: ${comboBoxSelector}`);
150185
const comboBox = await testSubjects.find(comboBoxSelector);
151-
const selectedOptions = await comboBox.findAllByClassName(
152-
'euiComboBoxPill',
153-
WAIT_FOR_EXISTS_TIME
154-
);
155-
return selectedOptions.length > 0;
186+
const $ = await comboBox.parseDomContent();
187+
return $('.euiComboBoxPill').toArray().length > 0;
156188
}
157189

190+
/**
191+
* Returns selected options
192+
* @param comboBoxSelector data-test-subj selector
193+
*/
158194
public async getComboBoxSelectedOptions(comboBoxSelector: string): Promise<string[]> {
159195
log.debug(`comboBox.getComboBoxSelectedOptions, comboBoxSelector: ${comboBoxSelector}`);
160-
return await retry.try(async () => {
161-
const comboBox = await testSubjects.find(comboBoxSelector);
162-
const selectedOptions = await comboBox.findAllByClassName(
163-
'euiComboBoxPill',
164-
WAIT_FOR_EXISTS_TIME
165-
);
166-
if (selectedOptions.length === 0) {
167-
return [];
168-
}
169-
return Promise.all(
170-
selectedOptions.map(async optionElement => {
171-
return await optionElement.getVisibleText();
172-
})
173-
);
174-
});
196+
const comboBox = await testSubjects.find(comboBoxSelector);
197+
const $ = await comboBox.parseDomContent();
198+
return $('.euiComboBoxPill')
199+
.toArray()
200+
.map(option => $(option).text());
175201
}
176202

177203
/**
178-
* clearing value from combobox
204+
* Finds combobox element and clears value in the input field by clicking clear button
179205
*
180206
* @param comboBoxSelector data-test-subj selector
181207
*/
@@ -209,9 +235,9 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
209235
}
210236

211237
/**
212-
* closing option list for combobox
238+
* Closes options list
213239
*
214-
* @param comboBoxElement
240+
* @param comboBoxElement element that wraps up EuiComboBox
215241
*/
216242
public async closeOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
217243
const isOptionsListOpen = await testSubjects.exists('comboBoxOptionsList');
@@ -222,9 +248,9 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
222248
}
223249

224250
/**
225-
* opened list of options for combobox
251+
* Opens options list
226252
*
227-
* @param comboBoxElement
253+
* @param comboBoxElement element that wraps up EuiComboBox
228254
*/
229255
public async openOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
230256
const isOptionsListOpen = await testSubjects.exists('comboBoxOptionsList');
@@ -237,10 +263,10 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
237263
}
238264

239265
/**
240-
* check if option is already selected
266+
* Checks if specified option is already selected
241267
*
242-
* @param comboBoxElement
243-
* @param value
268+
* @param comboBoxElement element that wraps up EuiComboBox
269+
* @param value option text
244270
*/
245271
public async isOptionSelected(
246272
comboBoxElement: WebElementWrapper,

test/functional/services/embedding.js renamed to test/functional/services/embedding.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
* under the License.
1818
*/
1919

20-
export function EmbeddingProvider({ getService, getPageObjects }) {
20+
import { FtrProviderContext } from '../ftr_provider_context';
21+
22+
export function EmbeddingProvider({ getService, getPageObjects }: FtrProviderContext) {
2123
const browser = getService('browser');
2224
const log = getService('log');
2325
const PageObjects = getPageObjects(['header']);
2426

2527
class Embedding {
26-
27-
async openInEmbeddedMode() {
28+
/**
29+
* Opens current page in embeded mode
30+
*/
31+
public async openInEmbeddedMode(): Promise<void> {
2832
const currentUrl = await browser.getCurrentUrl();
2933
log.debug(`Opening in embedded mode: ${currentUrl}`);
3034
await browser.get(`${currentUrl}&embed=true`);
3135
await PageObjects.header.waitUntilLoadingHasFinished();
3236
}
33-
3437
}
3538

3639
return new Embedding();

0 commit comments

Comments
 (0)