grafana/public/app/plugins/datasource/elasticsearch/specs/query_def.test.ts
Ivana Huckova 3fd810417f
Elasticsearch: Create Raw Doc metric to render raw JSON docs in columns in the new table panel (#26233)
* test

* WIP: Create v2 version

* Update tests, remove conosole logs, refactor

* Remove incorrect types

* Update type

* Rename legacy and new metrics

* Update

* Run request when Raw Data tto Raw Document switch

* Fix size updating

* Remove _source field from table results as we are showing each source field as column

* Remove _source just for metrics, not logs

* Revert "Remove _source just for metrics, not logs"

This reverts commit 611b6922f7.

* Revert "Remove _source field from table results as we are showing each source field as column"

This reverts commit 31a9d5f81b.

* Add vis preference for logs

* Update visualisation to logs

* Revert "Revert "Remove _source just for metrics""

This reverts commit a102ab2894.

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
2020-07-15 15:20:39 +02:00

118 lines
3.1 KiB
TypeScript

import * as queryDef from '../query_def';
describe('ElasticQueryDef', () => {
describe('getPipelineAggOptions', () => {
describe('with zero targets', () => {
const response = queryDef.getPipelineAggOptions([]);
test('should return zero', () => {
expect(response.length).toBe(0);
});
});
describe('with count and sum targets', () => {
const targets = {
metrics: [
{ type: 'count', field: '@value' },
{ type: 'sum', field: '@value' },
],
};
const response = queryDef.getPipelineAggOptions(targets);
test('should return zero', () => {
expect(response.length).toBe(2);
});
});
describe('with count and moving average targets', () => {
const targets = {
metrics: [
{ type: 'count', field: '@value' },
{ type: 'moving_avg', field: '@value' },
],
};
const response = queryDef.getPipelineAggOptions(targets);
test('should return one', () => {
expect(response.length).toBe(1);
});
});
describe('with derivatives targets', () => {
const targets = {
metrics: [{ type: 'derivative', field: '@value' }],
};
const response = queryDef.getPipelineAggOptions(targets);
test('should return zero', () => {
expect(response.length).toBe(0);
});
});
});
describe('isPipelineMetric', () => {
describe('moving_avg', () => {
const result = queryDef.isPipelineAgg('moving_avg');
test('is pipe line metric', () => {
expect(result).toBe(true);
});
});
describe('count', () => {
const result = queryDef.isPipelineAgg('count');
test('is not pipe line metric', () => {
expect(result).toBe(false);
});
});
});
describe('isPipelineAggWithMultipleBucketPaths', () => {
describe('bucket_script', () => {
const result = queryDef.isPipelineAggWithMultipleBucketPaths('bucket_script');
test('should have multiple bucket paths support', () => {
expect(result).toBe(true);
});
});
describe('moving_avg', () => {
const result = queryDef.isPipelineAggWithMultipleBucketPaths('moving_avg');
test('should not have multiple bucket paths support', () => {
expect(result).toBe(false);
});
});
});
describe('pipeline aggs depending on esverison', () => {
describe('using esversion undefined', () => {
test('should not get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(undefined).length).toBe(11);
});
});
describe('using esversion 1', () => {
test('should not get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(1).length).toBe(11);
});
});
describe('using esversion 2', () => {
test('should get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(2).length).toBe(15);
});
});
describe('using esversion 5', () => {
test('should get pipeline aggs', () => {
expect(queryDef.getMetricAggTypes(5).length).toBe(15);
});
});
});
});