Skip to content

Commit

Permalink
Improve filters code
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jun 4, 2020
1 parent bca2233 commit 197251b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
34 changes: 17 additions & 17 deletions test/functional/apps/context/_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import expect from '@kbn/expect';

const TEST_INDEX_PATTERN = 'logstash-*';
const TEST_ANCHOR_ID = 'AU_x3_BrGFA8no6QjjaI';
const TEST_ANCHOR_FILTER_FIELD = 'geo.src';
Expand All @@ -40,20 +38,19 @@ export default function ({ getService, getPageObjects }) {
});

it('inclusive filter should be addable via expanded doc table rows', async function () {
await docTable.toggleRowExpanded({ isAnchorRow: true });

await retry.try(async () => {
await retry.waitFor(`filter ${TEST_ANCHOR_FILTER_FIELD} in filterbar`, async () => {
await docTable.toggleRowExpanded({ isAnchorRow: true });
const anchorDetailsRow = await docTable.getAnchorDetailsRow();
await docTable.addInclusiveFilter(anchorDetailsRow, TEST_ANCHOR_FILTER_FIELD);
await PageObjects.context.waitUntilContextLoadingHasFinished();
expect(
await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, TEST_ANCHOR_FILTER_VALUE, true)
).to.be(true);

return await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, TEST_ANCHOR_FILTER_VALUE, true);
});
await retry.waitFor(`filter matching docs in docTable`, async () => {
const fields = await docTable.getFields();
const hasOnlyFilteredRows = fields
return fields
.map((row) => row[2])
.every((fieldContent) => fieldContent === TEST_ANCHOR_FILTER_VALUE);
expect(hasOnlyFilteredRows).to.be(true);
});
});

Expand All @@ -64,26 +61,29 @@ export default function ({ getService, getPageObjects }) {
await filterBar.toggleFilterEnabled(TEST_ANCHOR_FILTER_FIELD);
await PageObjects.context.waitUntilContextLoadingHasFinished();

await retry.try(async () => {
expect(
await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, TEST_ANCHOR_FILTER_VALUE, false)
).to.be(true);
await retry.waitFor(`a disabled filter in filterbar`, async () => {
return await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, TEST_ANCHOR_FILTER_VALUE, false);
});

await retry.waitFor('filters are disabled', async () => {
const fields = await docTable.getFields();
const hasOnlyFilteredRows = fields
.map((row) => row[2])
.every((fieldContent) => fieldContent === TEST_ANCHOR_FILTER_VALUE);
expect(hasOnlyFilteredRows).to.be(false);
return hasOnlyFilteredRows === false;
});

retry.try(async () => {});
});

it('filter for presence should be addable via expanded doc table rows', async function () {
await docTable.toggleRowExpanded({ isAnchorRow: true });

await retry.try(async () => {
await retry.waitFor('an exists filter in the filterbar', 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);
return await filterBar.hasFilter(TEST_ANCHOR_FILTER_FIELD, 'exists', true);
});
});
});
Expand Down
28 changes: 15 additions & 13 deletions test/functional/apps/context/_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ export default function ({ getService, getPageObjects }) {
const retry = getService('retry');
const docTable = getService('docTable');
const PageObjects = getPageObjects(['context']);
let rowLength = 2 * TEST_DEFAULT_CONTEXT_SIZE + 1;
let expectedRowLength = 2 * TEST_DEFAULT_CONTEXT_SIZE + 1;

// eslint-disable-next-line mocha/no-exclusive-tests
describe.only('context size', function contextSize() {
describe('context size', function contextSize() {
before(async function () {
await kibanaServer.uiSettings.update({
'context:defaultSize': `${TEST_DEFAULT_CONTEXT_SIZE}`,
Expand All @@ -39,10 +38,13 @@ export default function ({ getService, getPageObjects }) {
});

it('should default to the `context:defaultSize` setting', async function () {
await retry.waitFor(`number of rows displayed initially is ${rowLength}`, async function () {
const rows = await docTable.getRowsText();
return rows.length === rowLength;
});
await retry.waitFor(
`number of rows displayed initially is ${expectedRowLength}`,
async function () {
const rows = await docTable.getRowsText();
return rows.length === expectedRowLength;
}
);
await retry.waitFor(
`predecessor count picker is set to ${TEST_DEFAULT_CONTEXT_SIZE}`,
async function () {
Expand All @@ -55,26 +57,26 @@ export default function ({ getService, getPageObjects }) {

it('should increase according to the `context:step` setting when clicking the `load newer` button', async function () {
await PageObjects.context.clickPredecessorLoadMoreButton();
rowLength += TEST_STEP_SIZE;
expectedRowLength += TEST_STEP_SIZE;

await retry.waitFor(
`number of rows displayed after clicking load more predecessors is ${rowLength}`,
`number of rows displayed after clicking load more predecessors is ${expectedRowLength}`,
async function () {
const rows = await docTable.getRowsText();
return rows.length === rowLength;
return rows.length === expectedRowLength;
}
);
});

it('should increase according to the `context:step` setting when clicking the `load older` button', async function () {
await PageObjects.context.clickSuccessorLoadMoreButton();
rowLength += TEST_STEP_SIZE;
expectedRowLength += TEST_STEP_SIZE;

await retry.waitFor(
`number of rows displayed after clicking load more successors is ${rowLength}`,
`number of rows displayed after clicking load more successors is ${expectedRowLength}`,
async function () {
const rows = await docTable.getRowsText();
return rows.length === rowLength;
return rows.length === expectedRowLength;
}
);
});
Expand Down

0 comments on commit 197251b

Please sign in to comment.