diff --git a/public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/index_pattern.jest.ts similarity index 53% rename from public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts rename to public/app/plugins/datasource/elasticsearch/specs/index_pattern.jest.ts index f9b4206a4bc..2f921e10425 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/index_pattern.jest.ts @@ -1,38 +1,37 @@ /// -import { describe, it, expect } from 'test/lib/common'; import moment from 'moment'; import { IndexPattern } from '../index_pattern'; -describe('IndexPattern', function() { - describe('when getting index for today', function() { - it('should return correct index name', function() { +describe('IndexPattern', () => { + describe('when getting index for today', () => { + test('should return correct index name', () => { var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily'); var expected = 'asd-' + moment.utc().format('YYYY.MM.DD'); - expect(pattern.getIndexForToday()).to.be(expected); + expect(pattern.getIndexForToday()).toBe(expected); }); }); - describe('when getting index list for time range', function() { - describe('no interval', function() { - it('should return correct index', function() { + describe('when getting index list for time range', () => { + describe('no interval', () => { + test('should return correct index', () => { var pattern = new IndexPattern('my-metrics', null); var from = new Date(2015, 4, 30, 1, 2, 3); var to = new Date(2015, 5, 1, 12, 5, 6); - expect(pattern.getIndexList(from, to)).to.eql('my-metrics'); + expect(pattern.getIndexList(from, to)).toEqual('my-metrics'); }); }); - describe('daily', function() { - it('should return correct index list', function() { + describe('daily', () => { + test('should return correct index list', () => { var pattern = new IndexPattern('[asd-]YYYY.MM.DD', 'Daily'); var from = new Date(1432940523000); var to = new Date(1433153106000); var expected = ['asd-2015.05.29', 'asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']; - expect(pattern.getIndexList(from, to)).to.eql(expected); + expect(pattern.getIndexList(from, to)).toEqual(expected); }); }); }); diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_def.jest.ts b/public/app/plugins/datasource/elasticsearch/specs/query_def.jest.ts new file mode 100644 index 00000000000..0102e5febfb --- /dev/null +++ b/public/app/plugins/datasource/elasticsearch/specs/query_def.jest.ts @@ -0,0 +1,93 @@ +import * as queryDef from '../query_def'; + +describe('ElasticQueryDef', () => { + describe('getPipelineAggOptions', () => { + describe('with zero targets', () => { + var response = queryDef.getPipelineAggOptions([]); + + test('should return zero', () => { + expect(response.length).toBe(0); + }); + }); + + describe('with count and sum targets', () => { + var targets = { + metrics: [{ type: 'count', field: '@value' }, { type: 'sum', field: '@value' }], + }; + + var response = queryDef.getPipelineAggOptions(targets); + + test('should return zero', () => { + expect(response.length).toBe(2); + }); + }); + + describe('with count and moving average targets', () => { + var targets = { + metrics: [{ type: 'count', field: '@value' }, { type: 'moving_avg', field: '@value' }], + }; + + var response = queryDef.getPipelineAggOptions(targets); + + test('should return one', () => { + expect(response.length).toBe(1); + }); + }); + + describe('with derivatives targets', () => { + var targets = { + metrics: [{ type: 'derivative', field: '@value' }], + }; + + var response = queryDef.getPipelineAggOptions(targets); + + test('should return zero', () => { + expect(response.length).toBe(0); + }); + }); + }); + + describe('isPipelineMetric', () => { + describe('moving_avg', () => { + var result = queryDef.isPipelineAgg('moving_avg'); + + test('is pipe line metric', () => { + expect(result).toBe(true); + }); + }); + + describe('count', () => { + var result = queryDef.isPipelineAgg('count'); + + test('is not pipe line metric', () => { + 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(9); + }); + }); + + describe('using esversion 1', () => { + test('should not get pipeline aggs', () => { + expect(queryDef.getMetricAggTypes(1).length).toBe(9); + }); + }); + + describe('using esversion 2', () => { + test('should get pipeline aggs', () => { + expect(queryDef.getMetricAggTypes(2).length).toBe(11); + }); + }); + + describe('using esversion 5', () => { + test('should get pipeline aggs', () => { + expect(queryDef.getMetricAggTypes(5).length).toBe(11); + }); + }); + }); +}); diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts deleted file mode 100644 index 17d8b12661e..00000000000 --- a/public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { describe, it, expect } from 'test/lib/common'; - -import * as queryDef from '../query_def'; - -describe('ElasticQueryDef', function() { - describe('getPipelineAggOptions', function() { - describe('with zero targets', function() { - var response = queryDef.getPipelineAggOptions([]); - - it('should return zero', function() { - expect(response.length).to.be(0); - }); - }); - - describe('with count and sum targets', function() { - var targets = { - metrics: [{ type: 'count', field: '@value' }, { type: 'sum', field: '@value' }], - }; - - var response = queryDef.getPipelineAggOptions(targets); - - it('should return zero', function() { - expect(response.length).to.be(2); - }); - }); - - describe('with count and moving average targets', function() { - var targets = { - metrics: [{ type: 'count', field: '@value' }, { type: 'moving_avg', field: '@value' }], - }; - - var response = queryDef.getPipelineAggOptions(targets); - - it('should return one', function() { - expect(response.length).to.be(1); - }); - }); - - describe('with derivatives targets', function() { - var targets = { - metrics: [{ type: 'derivative', field: '@value' }], - }; - - var response = queryDef.getPipelineAggOptions(targets); - - it('should return zero', function() { - expect(response.length).to.be(0); - }); - }); - }); - - describe('isPipelineMetric', function() { - describe('moving_avg', function() { - var result = queryDef.isPipelineAgg('moving_avg'); - - it('is pipe line metric', function() { - expect(result).to.be(true); - }); - }); - - describe('count', function() { - var result = queryDef.isPipelineAgg('count'); - - it('is not pipe line metric', function() { - expect(result).to.be(false); - }); - }); - }); - - describe('pipeline aggs depending on esverison', function() { - describe('using esversion undefined', function() { - it('should not get pipeline aggs', function() { - expect(queryDef.getMetricAggTypes(undefined).length).to.be(9); - }); - }); - - describe('using esversion 1', function() { - it('should not get pipeline aggs', function() { - expect(queryDef.getMetricAggTypes(1).length).to.be(9); - }); - }); - - describe('using esversion 2', function() { - it('should get pipeline aggs', function() { - expect(queryDef.getMetricAggTypes(2).length).to.be(11); - }); - }); - - describe('using esversion 5', function() { - it('should get pipeline aggs', function() { - expect(queryDef.getMetricAggTypes(5).length).to.be(11); - }); - }); - }); -});