Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.12] [Search Embeddable] Add highlighting when searching (#93178) #93373

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ export class SearchEmbeddable
if (forceFetch || isFetchRequired) {
this.filtersSearchSource!.setField('filter', this.input.filters);
this.filtersSearchSource!.setField('query', this.input.query);
if (this.input.query?.query || this.input.filters?.length) {
this.filtersSearchSource!.setField('highlightAll', true);
} else {
this.filtersSearchSource!.removeField('highlightAll');
}

this.prevFilters = this.input.filters;
this.prevQuery = this.input.query;
Expand Down
1 change: 1 addition & 0 deletions test/functional/apps/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./dashboard_back_button'));
loadTestFile(require.resolve('./dashboard_error_handling'));
loadTestFile(require.resolve('./legacy_urls'));
loadTestFile(require.resolve('./saved_search_embeddable'));

// Note: This one must be last because it unloads some data for one of its tests!
// No, this isn't ideal, but loading/unloading takes so much time and these are all bunched
Expand Down
63 changes: 63 additions & 0 deletions test/functional/apps/dashboard/saved_search_embeddable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const dashboardAddPanel = getService('dashboardAddPanel');
const filterBar = getService('filterBar');
const find = getService('find');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const PageObjects = getPageObjects(['common', 'dashboard', 'header', 'timePicker', 'discover']);

describe('dashboard saved search embeddable', () => {
before(async () => {
await esArchiver.loadIfNeeded('logstash_functional');
await esArchiver.loadIfNeeded('dashboard/current/data');
await esArchiver.loadIfNeeded('dashboard/current/kibana');
await kibanaServer.uiSettings.replace({
defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c',
});
await PageObjects.common.navigateToApp('dashboard');
await filterBar.ensureFieldEditorModalIsClosed();
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.timePicker.setAbsoluteRange(
'Sep 22, 2015 @ 00:00:00.000',
'Sep 23, 2015 @ 00:00:00.000'
);
});

it('highlighting on filtering works', async function () {
await dashboardAddPanel.addSavedSearch('Rendering-Test:-saved-search');
await filterBar.addFilter('agent', 'is', 'Mozilla');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.waitForRenderComplete();
const dataTable = await find.byCssSelector(`[data-test-subj="embeddedSavedSearchDocTable"]`);
const $ = await dataTable.parseDomContent();
const marks = $('mark')
.toArray()
.map((mark) => $(mark).text());
expect(marks.length).to.be(50);
});

it('removing a filter removes highlights', async function () {
await filterBar.removeAllFilters();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.dashboard.waitForRenderComplete();
const dataTable = await find.byCssSelector(`[data-test-subj="embeddedSavedSearchDocTable"]`);
const $ = await dataTable.parseDomContent();
const marks = $('mark')
.toArray()
.map((mark) => $(mark).text());
expect(marks.length).to.be(0);
});
});
}