[TSVB] Add more functional tests for Timeseries Annotations (#123906)

* [TSVB] Add more functional tests for Timeseries Annotations

* Move common code to beforeEach block

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Diana Derevyankina 2022-01-29 00:29:04 +03:00 committed by GitHub
parent 69c5cfec2b
commit 110dc8b7cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 114 additions and 40 deletions

View file

@ -442,42 +442,124 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
describe('Annotations', () => {
it('should display correct annotations amount with tooltip data for the selected annotation', async () => {
beforeEach(async () => {
await visualBuilder.clickAnnotationsTab();
await visualBuilder.clickAnnotationsAddDataSourceButton();
});
it('should display correct annotations data for extension.raw field', async () => {
const expectedAnnotationsData = [
{
dataValue: 1442743200000,
details: 'extension: css',
header: '2015-09-20 10:00',
},
{
dataValue: 1442754000000,
details: 'extension: jpg',
header: '2015-09-20 13:00',
},
{
dataValue: 1442818800000,
details: 'extension: jpg',
header: '2015-09-21 07:00',
},
];
await visualBuilder.setAnnotationFilter('geo.dest : "AW" or geo.src : "AM"');
await visualBuilder.setAnnotationFields('extension.raw');
await visualBuilder.setAnnotationRowTemplate('extension: {{extension.raw}}');
const annotationsData = await visualBuilder.getAnnotationsData();
expect(annotationsData).to.eql(expectedAnnotationsData);
});
it('should display correct annotations data for machine.os.raw and memory fields', async () => {
const expectedAnnotationsData = [
{
dataValue: 1442721600000,
details: 'OS: win 7, memory: 0',
header: '2015-09-20 04:00',
},
{
dataValue: 1442743200000,
details: 'OS: win xp, memory: 0',
header: '2015-09-20 10:00',
},
{
dataValue: 1442772000000,
details: 'OS: ios, memory: 246280',
header: '2015-09-20 18:00',
},
{
dataValue: 1442815200000,
details: 'OS: ios, memory: 0',
header: '2015-09-21 06:00',
},
{
dataValue: 1442826000000,
details: 'OS: win 8, memory: 0',
header: '2015-09-21 09:00',
},
{
dataValue: 1442851200000,
details: 'OS: win 7, memory: 0',
header: '2015-09-21 16:00',
},
];
await visualBuilder.setAnnotationFilter('bytes = 0');
await visualBuilder.setAnnotationFields('machine.os.raw, memory');
await visualBuilder.setAnnotationRowTemplate(
'OS: {{machine.os.raw}}, memory: {{memory}}'
);
const annotationsCount = await visualBuilder.getAnnotationsCount();
await visualBuilder.clickAnnotationIcon(3);
const annotationTooltipHeader = await visualBuilder.getAnnotationTooltipHeader();
const annotationTooltipDetails = await visualBuilder.getAnnotationTooltipDetails();
const annotationsData = await visualBuilder.getAnnotationsData();
expect(annotationsCount).to.be(6);
expect(annotationTooltipHeader).to.be('2015-09-21 06:00');
expect(annotationTooltipDetails).to.be('OS: ios, memory: 0');
expect(annotationsData).to.eql(expectedAnnotationsData);
});
it('should display correct annotations amount with tooltip data for the selected annotation when using runtime field', async () => {
await visualBuilder.clickAnnotationsTab();
await visualBuilder.clickAnnotationsAddDataSourceButton();
await visualBuilder.setAnnotationFilter('memory > 300000');
it('should display correct annotations data when using runtime field', async () => {
const expectedAnnotationsData = [
{
dataValue: 1442736000000,
details: 'hello world from US!',
header: '2015-09-20 08:00',
},
{
dataValue: 1442746800000,
details: 'hello world from CN!',
header: '2015-09-20 11:00',
},
{
dataValue: 1442761200000,
details: 'hello world from MX!',
header: '2015-09-20 15:00',
},
{
dataValue: 1442822400000,
details: 'hello world from IN!',
header: '2015-09-21 08:00',
},
{
dataValue: 1442826000000,
details: 'hello world from TH!',
header: '2015-09-21 09:00',
},
{
dataValue: 1442829600000,
details: 'hello world from SY!',
header: '2015-09-21 10:00',
},
];
await visualBuilder.setAnnotationFilter('memory > 300000 and geo.src: "US"');
await visualBuilder.setAnnotationFields('hello_world_runtime_field, geo.dest');
await visualBuilder.setAnnotationRowTemplate(
'{{hello_world_runtime_field}} from {{geo.dest}}!'
);
const annotationsCount = await visualBuilder.getAnnotationsCount();
await visualBuilder.clickAnnotationIcon(5);
const annotationTooltipHeader = await visualBuilder.getAnnotationTooltipHeader();
const annotationTooltipDetails = await visualBuilder.getAnnotationTooltipDetails();
const annotationsData = await visualBuilder.getAnnotationsData();
expect(annotationsCount).to.be(30);
expect(annotationTooltipHeader).to.be('2015-09-20 11:00');
expect(annotationTooltipDetails).to.be('hello world from GA!');
expect(annotationsData).to.eql(expectedAnnotationsData);
});
});

View file

@ -485,26 +485,6 @@ export class VisualBuilderPageObject extends FtrService {
await annotationRowTemplateInput.type(template);
}
public async getAnnotationsCount() {
const annotationsIcons = (await this.find.allByCssSelector('.echAnnotation')) ?? [];
return annotationsIcons.length;
}
public async clickAnnotationIcon(nth: number = 0) {
const annotationsIcons = (await this.find.allByCssSelector('.echAnnotation')) ?? [];
await annotationsIcons[nth].click();
}
public async getAnnotationTooltipHeader() {
const annotationTooltipHeader = await this.find.byClassName('echAnnotation__header');
return await annotationTooltipHeader.getVisibleText();
}
public async getAnnotationTooltipDetails() {
const annotationTooltipDetails = await this.find.byClassName('echAnnotation__details');
return await annotationTooltipDetails.getVisibleText();
}
public async toggleIndexPatternSelectionModePopover(shouldOpen: boolean) {
await this.retry.try(async () => {
const isPopoverOpened = await this.testSubjects.exists(
@ -900,7 +880,11 @@ export class VisualBuilderPageObject extends FtrService {
return legendItems.map(({ name }) => name);
}
public async getChartItems(chartData?: DebugState, itemType: 'areas' | 'bars' = 'areas') {
public async getChartItems(
chartData?: DebugState,
itemType: 'areas' | 'bars' | 'annotations' = 'areas'
) {
await this.header.waitUntilLoadingHasFinished();
return (await this.getChartDebugState(chartData))?.[itemType];
}
@ -914,6 +898,14 @@ export class VisualBuilderPageObject extends FtrService {
return areas?.[nth]?.lines.y1.points.map(({ x, y }) => [x, y]);
}
public async getAnnotationsData(chartData?: DebugState) {
const annotations = (await this.getChartItems(
chartData,
'annotations'
)) as DebugState['annotations'];
return annotations?.map(({ data }) => data);
}
public async getVisualizeError() {
const visError = await this.testSubjects.find(`visualization-error`);
const errorSpans = await visError.findAllByClassName('euiText--extraSmall');