kibana/test/functional/services/esql.ts
Stratoula Kalafateli 884b94e9e9
[ES|QL] Query history (#178302)
## Summary

Closes https://github.com/elastic/kibana/issues/173217

Implements the query history component in the ESQL editor. The query
history component displays the 20 most recent queries and it doesn't
duplicate. If the user reruns a query it will update an existing one and
not create a new entry.

<img width="1676" alt="image"
src="23c8822d-3520-4952-b6cf-9cf7bb486389">

<img width="1678" alt="image"
src="3fdeccbc-5763-46c6-a940-e2b39dd95179">

### Important notes

Right now, the query history component has been implemented at:

- Unified search ES|QL editor
- Lens inline editing component
- Alerts
- Maps

I have hid it from ML data visualizer because it was very difficult to
implement it there. There is a quite complex logic fetching the fields
statistics so it was a bit complicated to add it there. ML team can
follow up as they know the logic already and would be easier for them to
adjust.

#### Flajy test runner
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5553

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2024-03-28 15:59:47 +01:00

52 lines
2 KiB
TypeScript

/*
* 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 { FtrService } from '../ftr_provider_context';
export class ESQLService extends FtrService {
private readonly retry = this.ctx.getService('retry');
private readonly testSubjects = this.ctx.getService('testSubjects');
public async getHistoryItems(): Promise<string[][]> {
const queryHistory = await this.testSubjects.find('TextBasedLangEditor-queryHistory');
const tableBody = await this.retry.try(async () => queryHistory.findByTagName('tbody'));
const $ = await tableBody.parseDomContent();
return $('tr')
.toArray()
.map((tr) => {
return $(tr)
.find('td')
.toArray()
.map((cell) => {
// if this is an EUI table, filter down to the specific cell content
// otherwise this will include mobile-specific header information
const euiTableCellContent = $(cell).find('.euiTableCellContent');
if (euiTableCellContent.length > 0) {
return $(cell).find('.euiTableCellContent').text().trim();
} else {
return $(cell).text().trim();
}
});
});
}
public async getHistoryItem(rowIndex = 0) {
const queryHistory = await this.testSubjects.find('TextBasedLangEditor-queryHistory');
const tableBody = await this.retry.try(async () => queryHistory.findByTagName('tbody'));
const rows = await this.retry.try(async () => tableBody.findAllByTagName('tr'));
return rows[rowIndex];
}
public async clickHistoryItem(rowIndex = 0) {
const row = await this.getHistoryItem(rowIndex);
const toggle = await row.findByTestSubject('TextBasedLangEditor-queryHistory-runQuery-button');
await toggle.click();
}
}