Skip to content

Commit

Permalink
Attempt to squash flaky FTR tests around Add Filter popover
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Aug 9, 2022
1 parent 426230d commit 9c28689
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const AddFilterPopover = React.memo(function AddFilterPopover({
iconType="plusInCircleFilled"
aria-label={buttonIconLabel}
data-test-subj="addFilter"
onClick={() => setIsAddFilterPopoverOpen(!isAddFilterPopoverOpen)}
onClick={() => setIsAddFilterPopoverOpen((isOpen) => !isOpen)}
size="m"
{...buttonProps}
/>
Expand All @@ -63,6 +63,7 @@ export const AddFilterPopover = React.memo(function AddFilterPopover({
closePopover={() => setIsAddFilterPopoverOpen(false)}
anchorPosition="downLeft"
panelPaddingSize="none"
panelProps={{ 'data-test-subj': 'addFilterPopover' }}
initialFocus=".filterEditor__hiddenItem"
ownFocus
repositionOnScroll
Expand Down
52 changes: 29 additions & 23 deletions test/functional/services/filter_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class FilterBarService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly common = this.ctx.getPageObject('common');
private readonly header = this.ctx.getPageObject('header');
private readonly retry = this.ctx.getService('retry');

/**
* Checks if specified filter exists
Expand Down Expand Up @@ -127,32 +128,37 @@ export class FilterBarService extends FtrService {
* filterBar.addFilter('extension', 'is one of', ['jpg', 'png']);
*/
public async addFilter(field: string, operator: string, ...values: any): Promise<void> {
await this.testSubjects.click('addFilter');
await this.comboBox.set('filterFieldSuggestionList', field);
await this.comboBox.set('filterOperatorList', operator);
const params = await this.testSubjects.find('filterParams');
const paramsComboBoxes = await params.findAllByCssSelector(
'[data-test-subj~="filterParamsComboBox"]',
1000
);
const paramFields = await params.findAllByTagName('input', 1000);
for (let i = 0; i < values.length; i++) {
let fieldValues = values[i];
if (!Array.isArray(fieldValues)) {
fieldValues = [fieldValues];
}

if (paramsComboBoxes && paramsComboBoxes.length > 0) {
for (let j = 0; j < fieldValues.length; j++) {
await this.comboBox.setElement(paramsComboBoxes[i], fieldValues[j]);
await this.retry.try(async () => {
await this.testSubjects.click('addFilter');
await this.testSubjects.existOrFail('addFilterPopover');

await this.comboBox.set('filterFieldSuggestionList', field);
await this.comboBox.set('filterOperatorList', operator);
const params = await this.testSubjects.find('filterParams');
const paramsComboBoxes = await params.findAllByCssSelector(
'[data-test-subj~="filterParamsComboBox"]',
1000
);
const paramFields = await params.findAllByTagName('input', 1000);
for (let i = 0; i < values.length; i++) {
let fieldValues = values[i];
if (!Array.isArray(fieldValues)) {
fieldValues = [fieldValues];
}
} else if (paramFields && paramFields.length > 0) {
for (let j = 0; j < fieldValues.length; j++) {
await paramFields[i].type(fieldValues[j]);

if (paramsComboBoxes && paramsComboBoxes.length > 0) {
for (let j = 0; j < fieldValues.length; j++) {
await this.comboBox.setElement(paramsComboBoxes[i], fieldValues[j]);
}
} else if (paramFields && paramFields.length > 0) {
for (let j = 0; j < fieldValues.length; j++) {
await paramFields[i].type(fieldValues[j]);
}
}
}
}
await this.testSubjects.click('saveFilter');

await this.testSubjects.clickWhenNotDisabled('saveFilter');
});
await this.header.awaitGlobalLoadingIndicatorHidden();
}

Expand Down

0 comments on commit 9c28689

Please sign in to comment.