[Discover] Fix incorrect filter generated by "Filter for field present" (#58586) (#60224)

* Fix _exists_ filter handling

* Add functional test
This commit is contained in:
Matthias Wilhelm 2020-03-16 11:58:22 +01:00 committed by GitHub
parent 6a12882e4a
commit 0f97a58d74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View file

@ -97,9 +97,11 @@ export function generateFilters(
const filterType =
fieldName === '_exists_' ? esFilters.FILTERS.EXISTS : esFilters.FILTERS.PHRASE;
const actualFieldObj = fieldName === '_exists_' ? ({ name: value } as IFieldType) : fieldObj;
filter = esFilters.buildFilter(
tmpIndexPattern,
fieldObj,
actualFieldObj,
filterType,
negate,
false,

View file

@ -39,14 +39,13 @@ export default function({ getService, getPageObjects }) {
});
});
it('should be addable via expanded doc table rows', async function() {
it('inclusive filter should be addable via expanded doc table rows', async function() {
await docTable.toggleRowExpanded({ isAnchorRow: true });
await retry.try(async () => {
const anchorDetailsRow = await docTable.getAnchorDetailsRow();
await docTable.addInclusiveFilter(anchorDetailsRow, TEST_ANCHOR_FILTER_FIELD);
await PageObjects.context.waitUntilContextLoadingHasFinished();
// await docTable.toggleRowExpanded({ isAnchorRow: true });
expect(
await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, TEST_ANCHOR_FILTER_VALUE, true)
).to.be(true);
@ -58,7 +57,7 @@ export default function({ getService, getPageObjects }) {
});
});
it('should be toggleable via the filter bar', async function() {
it('inclusive filter should be toggleable via the filter bar', async function() {
await filterBar.addFilter(TEST_ANCHOR_FILTER_FIELD, 'IS', TEST_ANCHOR_FILTER_VALUE);
await PageObjects.context.waitUntilContextLoadingHasFinished();
// disable filter
@ -76,5 +75,16 @@ export default function({ getService, getPageObjects }) {
expect(hasOnlyFilteredRows).to.be(false);
});
});
it('filter for presence should be addable via expanded doc table rows', async function() {
await docTable.toggleRowExpanded({ isAnchorRow: true });
await retry.try(async () => {
const anchorDetailsRow = await docTable.getAnchorDetailsRow();
await docTable.addExistsFilter(anchorDetailsRow, TEST_ANCHOR_FILTER_FIELD);
await PageObjects.context.waitUntilContextLoadingHasFinished();
expect(await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, 'exists', true)).to.be(true);
});
});
});
}

View file

@ -98,13 +98,12 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
const $ = await table.parseDomContent();
const rowLocator = options.isAnchorRow ? '~docTableAnchorRow' : '~docTableRow';
const rows = $.findTestSubjects(rowLocator).toArray();
const fields = rows.map((row: any) =>
return rows.map((row: any) =>
$(row)
.find('[data-test-subj~="docTableField"]')
.toArray()
.map((field: any) => $(field).text())
);
return fields;
}
public async getHeaderFields(selector?: string): Promise<string[]> {
@ -144,6 +143,22 @@ export function DocTableProvider({ getService, getPageObjects }: FtrProviderCont
await PageObjects.header.awaitGlobalLoadingIndicatorHidden();
}
public async getAddExistsFilterButton(
tableDocViewRow: WebElementWrapper
): Promise<WebElementWrapper> {
return await tableDocViewRow.findByCssSelector(`[data-test-subj~="addExistsFilterButton"]`);
}
public async addExistsFilter(
detailsRow: WebElementWrapper,
fieldName: WebElementWrapper
): Promise<void> {
const tableDocViewRow = await this.getTableDocViewRow(detailsRow, fieldName);
const addInclusiveFilterButton = await this.getAddExistsFilterButton(tableDocViewRow);
await addInclusiveFilterButton.click();
await PageObjects.header.awaitGlobalLoadingIndicatorHidden();
}
public async toggleRowExpanded(
options: SelectOptions = { isAnchorRow: false, rowIndex: 0 }
): Promise<WebElementWrapper> {