kibana/x-pack/test/functional/page_objects/grok_debugger_page.ts
Anton Dosov e89313327e
[CodeEditor] Add grok highlighting (#159334)
## Summary

Close https://github.com/elastic/kibana/issues/155506

<img width="971" alt="Screenshot 2023-06-12 at 17 11 18"
src="7522bcba-e3aa-4229-93b2-27d12a335426">


I didn't introduce any custom colors here but just used built-in token
types for highlighting (`string` for red and `variable` for blue)
2023-06-13 12:05:26 +02:00

54 lines
1.8 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrService } from '../ftr_provider_context';
export class GrokDebuggerPageObject extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly monacoEditor = this.ctx.getService('monacoEditor');
private readonly retry = this.ctx.getService('retry');
async simulateButton() {
return await this.testSubjects.find('btnSimulate');
}
async getEventOutput() {
return await this.testSubjects.getVisibleText('eventOutputCodeBlock');
}
async setEventInput(value: string) {
await this.monacoEditor.setCodeEditorValue(value, 0);
}
async setPatternInput(pattern: string) {
await this.monacoEditor.setCodeEditorValue(pattern, 1);
}
async setCustomPatternInput(customPattern: string) {
await this.monacoEditor.setCodeEditorValue(customPattern, 2);
}
async toggleSetCustomPattern() {
await this.testSubjects.click('grokDebuggerContainer > btnToggleCustomPatternsInput');
}
async executeGrokSimulation(input: string, pattern: string, customPattern: string | null) {
let value;
await this.setEventInput(input);
await this.setPatternInput(pattern);
if (customPattern) {
await this.toggleSetCustomPattern();
await this.setCustomPatternInput(customPattern);
}
await (await this.simulateButton()).click();
await this.retry.try(async () => {
value = JSON.parse(await this.getEventOutput());
expect(Object.keys(value).length).to.be.greaterThan(0);
});
return value;
}
}