From 04029a94cd432bf80c1e493668bcf0cf19312edc Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 11:56:03 +0200 Subject: [PATCH 1/7] Karma to Jest: elastic_response --- ...onse_specs.ts => elastic_response.jest.ts} | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) rename public/app/plugins/datasource/elasticsearch/specs/{elastic_response_specs.ts => elastic_response.jest.ts} (72%) diff --git a/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts similarity index 72% rename from public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts rename to public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts index aa27e388256..e02e675cae0 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts @@ -1,13 +1,13 @@ import { describe, beforeEach, it, expect } from 'test/lib/common'; import { ElasticResponse } from '../elastic_response'; -describe('ElasticResponse', function() { +describe('ElasticResponse', () => { var targets; var response; var result; - describe('simple query and count', function() { - beforeEach(function() { + describe('simple query and count', () => { + beforeEach(() => { targets = [ { refId: 'A', @@ -39,19 +39,19 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 1 series', function() { - expect(result.data.length).to.be(1); - expect(result.data[0].target).to.be('Count'); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].datapoints[0][0]).to.be(10); - expect(result.data[0].datapoints[0][1]).to.be(1000); + it('should return 1 series', () => { + expect(result.data.length).toBe(1); + expect(result.data[0].target).toBe('Count'); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].datapoints[0][0]).toBe(10); + expect(result.data[0].datapoints[0][1]).toBe(1000); }); }); - describe('simple query count & avg aggregation', function() { + describe('simple query count & avg aggregation', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -85,22 +85,22 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 2 series', function() { - expect(result.data.length).to.be(2); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].datapoints[0][0]).to.be(10); - expect(result.data[0].datapoints[0][1]).to.be(1000); + it('should return 2 series', () => { + expect(result.data.length).toBe(2); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].datapoints[0][0]).toBe(10); + expect(result.data[0].datapoints[0][1]).toBe(1000); - expect(result.data[1].target).to.be('Average value'); - expect(result.data[1].datapoints[0][0]).to.be(88); - expect(result.data[1].datapoints[1][0]).to.be(99); + expect(result.data[1].target).toBe('Average value'); + expect(result.data[1].datapoints[0][0]).toBe(88); + expect(result.data[1].datapoints[1][0]).toBe(99); }); }); - describe('single group by query one metric', function() { + describe('single group by query one metric', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -141,18 +141,18 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 2 series', function() { - expect(result.data.length).to.be(2); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].target).to.be('server1'); - expect(result.data[1].target).to.be('server2'); + it('should return 2 series', () => { + expect(result.data.length).toBe(2); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].target).toBe('server1'); + expect(result.data[1].target).toBe('server2'); }); }); - describe('single group by query two metrics', function() { + describe('single group by query two metrics', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -199,20 +199,20 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 2 series', function() { - expect(result.data.length).to.be(4); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].target).to.be('server1 Count'); - expect(result.data[1].target).to.be('server1 Average @value'); - expect(result.data[2].target).to.be('server2 Count'); - expect(result.data[3].target).to.be('server2 Average @value'); + it('should return 2 series', () => { + expect(result.data.length).toBe(4); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].target).toBe('server1 Count'); + expect(result.data[1].target).toBe('server1 Average @value'); + expect(result.data[2].target).toBe('server2 Count'); + expect(result.data[3].target).toBe('server2 Average @value'); }); }); - describe('with percentiles ', function() { + describe('with percentiles ', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -246,21 +246,21 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 2 series', function() { - expect(result.data.length).to.be(2); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].target).to.be('p75'); - expect(result.data[1].target).to.be('p90'); - expect(result.data[0].datapoints[0][0]).to.be(3.3); - expect(result.data[0].datapoints[0][1]).to.be(1000); - expect(result.data[1].datapoints[1][0]).to.be(4.5); + it('should return 2 series', () => { + expect(result.data.length).toBe(2); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].target).toBe('p75'); + expect(result.data[1].target).toBe('p90'); + expect(result.data[0].datapoints[0][0]).toBe(3.3); + expect(result.data[0].datapoints[0][1]).toBe(1000); + expect(result.data[1].datapoints[1][0]).toBe(4.5); }); }); - describe('with extended_stats', function() { + describe('with extended_stats', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -322,21 +322,21 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 4 series', function() { - expect(result.data.length).to.be(4); - expect(result.data[0].datapoints.length).to.be(1); - expect(result.data[0].target).to.be('server1 Max'); - expect(result.data[1].target).to.be('server1 Std Dev Upper'); + it('should return 4 series', () => { + expect(result.data.length).toBe(4); + expect(result.data[0].datapoints.length).toBe(1); + expect(result.data[0].target).toBe('server1 Max'); + expect(result.data[1].target).toBe('server1 Std Dev Upper'); - expect(result.data[0].datapoints[0][0]).to.be(10.2); - expect(result.data[1].datapoints[0][0]).to.be(3); + expect(result.data[0].datapoints[0][0]).toBe(10.2); + expect(result.data[1].datapoints[0][0]).toBe(3); }); }); - describe('single group by with alias pattern', function() { + describe('single group by with alias pattern', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -385,19 +385,19 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 2 series', function() { - expect(result.data.length).to.be(3); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].target).to.be('server1 Count and {{not_exist}} server1'); - expect(result.data[1].target).to.be('server2 Count and {{not_exist}} server2'); - expect(result.data[2].target).to.be('0 Count and {{not_exist}} 0'); + it('should return 2 series', () => { + expect(result.data.length).toBe(3); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].target).toBe('server1 Count and {{not_exist}} server1'); + expect(result.data[1].target).toBe('server2 Count and {{not_exist}} server2'); + expect(result.data[2].target).toBe('0 Count and {{not_exist}} 0'); }); }); - describe('histogram response', function() { + describe('histogram response', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -420,16 +420,16 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return table with byte and count', function() { - expect(result.data[0].rows.length).to.be(3); + it('should return table with byte and count', () => { + expect(result.data[0].rows.length).toBe(3); expect(result.data[0].columns).to.eql([{ text: 'bytes', filterable: true }, { text: 'Count' }]); }); }); - describe('with two filters agg', function() { + describe('with two filters agg', () => { var result; - beforeEach(function() { + beforeEach(() => { targets = [ { refId: 'A', @@ -472,16 +472,16 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return 2 series', function() { - expect(result.data.length).to.be(2); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].target).to.be('@metric:cpu'); - expect(result.data[1].target).to.be('@metric:logins.count'); + it('should return 2 series', () => { + expect(result.data.length).toBe(2); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].target).toBe('@metric:cpu'); + expect(result.data[1].target).toBe('@metric:logins.count'); }); }); - describe('with dropfirst and last aggregation', function() { - beforeEach(function() { + describe('with dropfirst and last aggregation', () => { + beforeEach(() => { targets = [ { refId: 'A', @@ -528,14 +528,14 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should remove first and last value', function() { - expect(result.data.length).to.be(2); - expect(result.data[0].datapoints.length).to.be(1); + it('should remove first and last value', () => { + expect(result.data.length).toBe(2); + expect(result.data[0].datapoints.length).toBe(1); }); }); - describe('No group by time', function() { - beforeEach(function() { + describe('No group by time', () => { + beforeEach(() => { targets = [ { refId: 'A', @@ -570,21 +570,21 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return table', function() { - expect(result.data.length).to.be(1); - expect(result.data[0].type).to.be('table'); - expect(result.data[0].rows.length).to.be(2); - expect(result.data[0].rows[0][0]).to.be('server-1'); - expect(result.data[0].rows[0][1]).to.be(1000); - expect(result.data[0].rows[0][2]).to.be(369); + it('should return table', () => { + expect(result.data.length).toBe(1); + expect(result.data[0].type).toBe('table'); + expect(result.data[0].rows.length).toBe(2); + expect(result.data[0].rows[0][0]).toBe('server-1'); + expect(result.data[0].rows[0][1]).toBe(1000); + expect(result.data[0].rows[0][2]).toBe(369); - expect(result.data[0].rows[1][0]).to.be('server-2'); - expect(result.data[0].rows[1][1]).to.be(2000); + expect(result.data[0].rows[1][0]).toBe('server-2'); + expect(result.data[0].rows[1][1]).toBe(2000); }); }); - describe('Multiple metrics of same type', function() { - beforeEach(function() { + describe('Multiple metrics of same type', () => { + beforeEach(() => { targets = [ { refId: 'A', @@ -615,15 +615,15 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should include field in metric name', function() { - expect(result.data[0].type).to.be('table'); - expect(result.data[0].rows[0][1]).to.be(1000); - expect(result.data[0].rows[0][2]).to.be(3000); + it('should include field in metric name', () => { + expect(result.data[0].type).toBe('table'); + expect(result.data[0].rows[0][1]).toBe(1000); + expect(result.data[0].rows[0][2]).toBe(3000); }); }); - describe('Raw documents query', function() { - beforeEach(function() { + describe('Raw documents query', () => { + beforeEach(() => { targets = [ { refId: 'A', @@ -657,13 +657,13 @@ describe('ElasticResponse', function() { result = new ElasticResponse(targets, response).getTimeSeries(); }); - it('should return docs', function() { - expect(result.data.length).to.be(1); - expect(result.data[0].type).to.be('docs'); - expect(result.data[0].total).to.be(100); - expect(result.data[0].datapoints.length).to.be(2); - expect(result.data[0].datapoints[0].sourceProp).to.be('asd'); - expect(result.data[0].datapoints[0].fieldProp).to.be('field'); + it('should return docs', () => { + expect(result.data.length).toBe(1); + expect(result.data[0].type).toBe('docs'); + expect(result.data[0].total).toBe(100); + expect(result.data[0].datapoints.length).toBe(2); + expect(result.data[0].datapoints[0].sourceProp).toBe('asd'); + expect(result.data[0].datapoints[0].fieldProp).toBe('field'); }); }); }); From a911d36dea2baa5375cbe8b3a55a83648e8da326 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 12:00:54 +0200 Subject: [PATCH 2/7] Remove import --- .../datasource/elasticsearch/specs/elastic_response.jest.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts b/public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts index e02e675cae0..ea9d10f989f 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/elastic_response.jest.ts @@ -1,4 +1,3 @@ -import { describe, beforeEach, it, expect } from 'test/lib/common'; import { ElasticResponse } from '../elastic_response'; describe('ElasticResponse', () => { @@ -422,7 +421,7 @@ describe('ElasticResponse', () => { it('should return table with byte and count', () => { expect(result.data[0].rows.length).toBe(3); - expect(result.data[0].columns).to.eql([{ text: 'bytes', filterable: true }, { text: 'Count' }]); + expect(result.data[0].columns).toEqual([{ text: 'bytes', filterable: true }, { text: 'Count' }]); }); }); From 2465f53324f96652814128a17069d3078e2a5f25 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 12:18:11 +0200 Subject: [PATCH 3/7] Karma to Jest: query_def, index_pattern --- ...pattern_specs.ts => index_pattern.jest.ts} | 23 +++-- .../elasticsearch/specs/query_def.jest.ts | 93 ++++++++++++++++++ .../elasticsearch/specs/query_def_specs.ts | 95 ------------------- 3 files changed, 104 insertions(+), 107 deletions(-) rename public/app/plugins/datasource/elasticsearch/specs/{index_pattern_specs.ts => index_pattern.jest.ts} (53%) create mode 100644 public/app/plugins/datasource/elasticsearch/specs/query_def.jest.ts delete mode 100644 public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts 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); - }); - }); - }); -}); From 155ff06cbe9e1216ca8e35e3782eee3a99041274 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 13:22:17 +0200 Subject: [PATCH 4/7] Karma to Jest: threshold_manager --- ...ger_specs.ts => threshold_manager.jest.ts} | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) rename public/app/plugins/panel/graph/specs/{threshold_manager_specs.ts => threshold_manager.jest.ts} (76%) diff --git a/public/app/plugins/panel/graph/specs/threshold_manager_specs.ts b/public/app/plugins/panel/graph/specs/threshold_manager.jest.ts similarity index 76% rename from public/app/plugins/panel/graph/specs/threshold_manager_specs.ts rename to public/app/plugins/panel/graph/specs/threshold_manager.jest.ts index f16d5663f1b..4a7a46fc6b0 100644 --- a/public/app/plugins/panel/graph/specs/threshold_manager_specs.ts +++ b/public/app/plugins/panel/graph/specs/threshold_manager.jest.ts @@ -1,5 +1,3 @@ -import { describe, it, expect } from '../../../../../test/lib/common'; - import angular from 'angular'; import TimeSeries from 'app/core/time_series2'; import { ThresholdManager } from '../threshold_manager'; @@ -38,16 +36,16 @@ describe('ThresholdManager', function() { it('should add fill for threshold with fill: true', function() { var markings = ctx.options.grid.markings; - expect(markings[0].yaxis.from).to.be(300); - expect(markings[0].yaxis.to).to.be(Infinity); - expect(markings[0].color).to.be('rgba(234, 112, 112, 0.12)'); + expect(markings[0].yaxis.from).toBe(300); + expect(markings[0].yaxis.to).toBe(Infinity); + expect(markings[0].color).toBe('rgba(234, 112, 112, 0.12)'); }); it('should add line', function() { var markings = ctx.options.grid.markings; - expect(markings[1].yaxis.from).to.be(300); - expect(markings[1].yaxis.to).to.be(300); - expect(markings[1].color).to.be('rgba(237, 46, 24, 0.60)'); + expect(markings[1].yaxis.from).toBe(300); + expect(markings[1].yaxis.to).toBe(300); + expect(markings[1].color).toBe('rgba(237, 46, 24, 0.60)'); }); }); @@ -59,14 +57,14 @@ describe('ThresholdManager', function() { it('should add fill for first thresholds to next threshold', function() { var markings = ctx.options.grid.markings; - expect(markings[0].yaxis.from).to.be(200); - expect(markings[0].yaxis.to).to.be(300); + expect(markings[0].yaxis.from).toBe(200); + expect(markings[0].yaxis.to).toBe(300); }); it('should add fill for last thresholds to infinity', function() { var markings = ctx.options.grid.markings; - expect(markings[1].yaxis.from).to.be(300); - expect(markings[1].yaxis.to).to.be(Infinity); + expect(markings[1].yaxis.from).toBe(300); + expect(markings[1].yaxis.to).toBe(Infinity); }); }); @@ -78,14 +76,14 @@ describe('ThresholdManager', function() { it('should add fill for first thresholds to next threshold', function() { var markings = ctx.options.grid.markings; - expect(markings[0].yaxis.from).to.be(300); - expect(markings[0].yaxis.to).to.be(200); + expect(markings[0].yaxis.from).toBe(300); + expect(markings[0].yaxis.to).toBe(200); }); it('should add fill for last thresholds to itself', function() { var markings = ctx.options.grid.markings; - expect(markings[1].yaxis.from).to.be(200); - expect(markings[1].yaxis.to).to.be(200); + expect(markings[1].yaxis.from).toBe(200); + expect(markings[1].yaxis.to).toBe(200); }); }); @@ -97,14 +95,14 @@ describe('ThresholdManager', function() { it('should add fill for first thresholds to next threshold', function() { var markings = ctx.options.grid.markings; - expect(markings[0].yaxis.from).to.be(300); - expect(markings[0].yaxis.to).to.be(Infinity); + expect(markings[0].yaxis.from).toBe(300); + expect(markings[0].yaxis.to).toBe(Infinity); }); it('should add fill for last thresholds to itself', function() { var markings = ctx.options.grid.markings; - expect(markings[1].yaxis.from).to.be(200); - expect(markings[1].yaxis.to).to.be(-Infinity); + expect(markings[1].yaxis.from).toBe(200); + expect(markings[1].yaxis.to).toBe(-Infinity); }); }); @@ -130,12 +128,12 @@ describe('ThresholdManager', function() { it('should add first threshold for left axis', function() { var markings = ctx.options.grid.markings; - expect(markings[0].yaxis.from).to.be(100); + expect(markings[0].yaxis.from).toBe(100); }); it('should add second threshold for right axis', function() { var markings = ctx.options.grid.markings; - expect(markings[1].y2axis.from).to.be(200); + expect(markings[1].y2axis.from).toBe(200); }); }); }); From 283b39c397d93cec541b475953599ac72f614f05 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 13:38:03 +0200 Subject: [PATCH 5/7] Karma to Jest: threshold_mapper --- ...pper_specs.ts => threshold_mapper.jest.ts} | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) rename public/app/features/alerting/specs/{threshold_mapper_specs.ts => threshold_mapper.jest.ts} (70%) diff --git a/public/app/features/alerting/specs/threshold_mapper_specs.ts b/public/app/features/alerting/specs/threshold_mapper.jest.ts similarity index 70% rename from public/app/features/alerting/specs/threshold_mapper_specs.ts rename to public/app/features/alerting/specs/threshold_mapper.jest.ts index 1d68fce7050..b9fa45a6e49 100644 --- a/public/app/features/alerting/specs/threshold_mapper_specs.ts +++ b/public/app/features/alerting/specs/threshold_mapper.jest.ts @@ -18,9 +18,9 @@ describe('ThresholdMapper', () => { }; var updated = ThresholdMapper.alertToGraphThresholds(panel); - expect(updated).to.be(true); - expect(panel.thresholds[0].op).to.be('gt'); - expect(panel.thresholds[0].value).to.be(100); + expect(updated).toBe(true); + expect(panel.thresholds[0].op).toBe('gt'); + expect(panel.thresholds[0].value).toBe(100); }); }); @@ -39,12 +39,12 @@ describe('ThresholdMapper', () => { }; var updated = ThresholdMapper.alertToGraphThresholds(panel); - expect(updated).to.be(true); - expect(panel.thresholds[0].op).to.be('lt'); - expect(panel.thresholds[0].value).to.be(100); + expect(updated).toBe(true); + expect(panel.thresholds[0].op).toBe('lt'); + expect(panel.thresholds[0].value).toBe(100); - expect(panel.thresholds[1].op).to.be('gt'); - expect(panel.thresholds[1].value).to.be(200); + expect(panel.thresholds[1].op).toBe('gt'); + expect(panel.thresholds[1].value).toBe(200); }); }); @@ -63,12 +63,12 @@ describe('ThresholdMapper', () => { }; var updated = ThresholdMapper.alertToGraphThresholds(panel); - expect(updated).to.be(true); - expect(panel.thresholds[0].op).to.be('gt'); - expect(panel.thresholds[0].value).to.be(100); + expect(updated).toBe(true); + expect(panel.thresholds[0].op).toBe('gt'); + expect(panel.thresholds[0].value).toBe(100); - expect(panel.thresholds[1].op).to.be('lt'); - expect(panel.thresholds[1].value).to.be(200); + expect(panel.thresholds[1].op).toBe('lt'); + expect(panel.thresholds[1].value).toBe(200); }); }); }); From ef0586acabaad373f7a6e2a3137464eb0d6adeb7 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 14:20:42 +0200 Subject: [PATCH 6/7] Karma to Jest: query_builder --- ...builder_specs.ts => query_builder.jest.ts} | 115 +++++++++--------- 1 file changed, 57 insertions(+), 58 deletions(-) rename public/app/plugins/datasource/elasticsearch/specs/{query_builder_specs.ts => query_builder.jest.ts} (69%) diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_builder.jest.ts similarity index 69% rename from public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts rename to public/app/plugins/datasource/elasticsearch/specs/query_builder.jest.ts index 6d7b160fbef..1dde47915d9 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/query_builder.jest.ts @@ -1,25 +1,24 @@ -import { describe, beforeEach, it, expect } from 'test/lib/common'; import { ElasticQueryBuilder } from '../query_builder'; -describe('ElasticQueryBuilder', function() { +describe('ElasticQueryBuilder', () => { var builder; - beforeEach(function() { + beforeEach(() => { builder = new ElasticQueryBuilder({ timeField: '@timestamp' }); }); - it('with defaults', function() { + it('with defaults', () => { var query = builder.build({ metrics: [{ type: 'Count', id: '0' }], timeField: '@timestamp', bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }], }); - expect(query.query.bool.filter[0].range['@timestamp'].gte).to.be('$timeFrom'); - expect(query.aggs['1'].date_histogram.extended_bounds.min).to.be('$timeFrom'); + expect(query.query.bool.filter[0].range['@timestamp'].gte).toBe('$timeFrom'); + expect(query.aggs['1'].date_histogram.extended_bounds.min).toBe('$timeFrom'); }); - it('with defaults on es5.x', function() { + it('with defaults on es5.x', () => { var builder_5x = new ElasticQueryBuilder({ timeField: '@timestamp', esVersion: 5, @@ -31,11 +30,11 @@ describe('ElasticQueryBuilder', function() { bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }], }); - expect(query.query.bool.filter[0].range['@timestamp'].gte).to.be('$timeFrom'); - expect(query.aggs['1'].date_histogram.extended_bounds.min).to.be('$timeFrom'); + expect(query.query.bool.filter[0].range['@timestamp'].gte).toBe('$timeFrom'); + expect(query.aggs['1'].date_histogram.extended_bounds.min).toBe('$timeFrom'); }); - it('with multiple bucket aggs', function() { + it('with multiple bucket aggs', () => { var query = builder.build({ metrics: [{ type: 'count', id: '1' }], timeField: '@timestamp', @@ -45,11 +44,11 @@ describe('ElasticQueryBuilder', function() { ], }); - expect(query.aggs['2'].terms.field).to.be('@host'); - expect(query.aggs['2'].aggs['3'].date_histogram.field).to.be('@timestamp'); + expect(query.aggs['2'].terms.field).toBe('@host'); + expect(query.aggs['2'].aggs['3'].date_histogram.field).toBe('@timestamp'); }); - it('with select field', function() { + it('with select field', () => { var query = builder.build( { metrics: [{ type: 'avg', field: '@value', id: '1' }], @@ -60,10 +59,10 @@ describe('ElasticQueryBuilder', function() { ); var aggs = query.aggs['2'].aggs; - expect(aggs['1'].avg.field).to.be('@value'); + expect(aggs['1'].avg.field).toBe('@value'); }); - it('with term agg and order by metric agg', function() { + it('with term agg and order by metric agg', () => { var query = builder.build( { metrics: [{ type: 'count', id: '1' }, { type: 'avg', field: '@value', id: '5' }], @@ -84,11 +83,11 @@ describe('ElasticQueryBuilder', function() { var firstLevel = query.aggs['2']; var secondLevel = firstLevel.aggs['3']; - expect(firstLevel.aggs['5'].avg.field).to.be('@value'); - expect(secondLevel.aggs['5'].avg.field).to.be('@value'); + expect(firstLevel.aggs['5'].avg.field).toBe('@value'); + expect(secondLevel.aggs['5'].avg.field).toBe('@value'); }); - it('with metric percentiles', function() { + it('with metric percentiles', () => { var query = builder.build( { metrics: [ @@ -109,11 +108,11 @@ describe('ElasticQueryBuilder', function() { var firstLevel = query.aggs['3']; - expect(firstLevel.aggs['1'].percentiles.field).to.be('@load_time'); - expect(firstLevel.aggs['1'].percentiles.percents).to.eql([1, 2, 3, 4]); + expect(firstLevel.aggs['1'].percentiles.field).toBe('@load_time'); + expect(firstLevel.aggs['1'].percentiles.percents).toEqual([1, 2, 3, 4]); }); - it('with filters aggs', function() { + it('with filters aggs', () => { var query = builder.build({ metrics: [{ type: 'count', id: '1' }], timeField: '@timestamp', @@ -129,12 +128,12 @@ describe('ElasticQueryBuilder', function() { ], }); - expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).to.be('@metric:cpu'); - expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).to.be('@metric:logins.count'); - expect(query.aggs['2'].aggs['4'].date_histogram.field).to.be('@timestamp'); + expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).toBe('@metric:cpu'); + expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).toBe('@metric:logins.count'); + expect(query.aggs['2'].aggs['4'].date_histogram.field).toBe('@timestamp'); }); - it('with filters aggs on es5.x', function() { + it('with filters aggs on es5.x', () => { var builder_5x = new ElasticQueryBuilder({ timeField: '@timestamp', esVersion: 5, @@ -154,31 +153,31 @@ describe('ElasticQueryBuilder', function() { ], }); - expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).to.be('@metric:cpu'); - expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).to.be('@metric:logins.count'); - expect(query.aggs['2'].aggs['4'].date_histogram.field).to.be('@timestamp'); + expect(query.aggs['2'].filters.filters['@metric:cpu'].query_string.query).toBe('@metric:cpu'); + expect(query.aggs['2'].filters.filters['@metric:logins.count'].query_string.query).toBe('@metric:logins.count'); + expect(query.aggs['2'].aggs['4'].date_histogram.field).toBe('@timestamp'); }); - it('with raw_document metric', function() { + it('with raw_document metric', () => { var query = builder.build({ metrics: [{ type: 'raw_document', id: '1', settings: {} }], timeField: '@timestamp', bucketAggs: [], }); - expect(query.size).to.be(500); + expect(query.size).toBe(500); }); - it('with raw_document metric size set', function() { + it('with raw_document metric size set', () => { var query = builder.build({ metrics: [{ type: 'raw_document', id: '1', settings: { size: 1337 } }], timeField: '@timestamp', bucketAggs: [], }); - expect(query.size).to.be(1337); + expect(query.size).toBe(1337); }); - it('with moving average', function() { + it('with moving average', () => { var query = builder.build({ metrics: [ { @@ -198,12 +197,12 @@ describe('ElasticQueryBuilder', function() { var firstLevel = query.aggs['3']; - expect(firstLevel.aggs['2']).not.to.be(undefined); - expect(firstLevel.aggs['2'].moving_avg).not.to.be(undefined); - expect(firstLevel.aggs['2'].moving_avg.buckets_path).to.be('3'); + expect(firstLevel.aggs['2']).not.toBe(undefined); + expect(firstLevel.aggs['2'].moving_avg).not.toBe(undefined); + expect(firstLevel.aggs['2'].moving_avg.buckets_path).toBe('3'); }); - it('with broken moving average', function() { + it('with broken moving average', () => { var query = builder.build({ metrics: [ { @@ -227,13 +226,13 @@ describe('ElasticQueryBuilder', function() { var firstLevel = query.aggs['3']; - expect(firstLevel.aggs['2']).not.to.be(undefined); - expect(firstLevel.aggs['2'].moving_avg).not.to.be(undefined); - expect(firstLevel.aggs['2'].moving_avg.buckets_path).to.be('3'); - expect(firstLevel.aggs['4']).to.be(undefined); + expect(firstLevel.aggs['2']).not.toBe(undefined); + expect(firstLevel.aggs['2'].moving_avg).not.toBe(undefined); + expect(firstLevel.aggs['2'].moving_avg.buckets_path).toBe('3'); + expect(firstLevel.aggs['4']).toBe(undefined); }); - it('with derivative', function() { + it('with derivative', () => { var query = builder.build({ metrics: [ { @@ -252,12 +251,12 @@ describe('ElasticQueryBuilder', function() { var firstLevel = query.aggs['3']; - expect(firstLevel.aggs['2']).not.to.be(undefined); - expect(firstLevel.aggs['2'].derivative).not.to.be(undefined); - expect(firstLevel.aggs['2'].derivative.buckets_path).to.be('3'); + expect(firstLevel.aggs['2']).not.toBe(undefined); + expect(firstLevel.aggs['2'].derivative).not.toBe(undefined); + expect(firstLevel.aggs['2'].derivative.buckets_path).toBe('3'); }); - it('with histogram', function() { + it('with histogram', () => { var query = builder.build({ metrics: [{ id: '1', type: 'count' }], bucketAggs: [ @@ -271,13 +270,13 @@ describe('ElasticQueryBuilder', function() { }); var firstLevel = query.aggs['3']; - expect(firstLevel.histogram.field).to.be('bytes'); - expect(firstLevel.histogram.interval).to.be(10); - expect(firstLevel.histogram.min_doc_count).to.be(2); - expect(firstLevel.histogram.missing).to.be(5); + expect(firstLevel.histogram.field).toBe('bytes'); + expect(firstLevel.histogram.interval).toBe(10); + expect(firstLevel.histogram.min_doc_count).toBe(2); + expect(firstLevel.histogram.missing).toBe(5); }); - it('with adhoc filters', function() { + it('with adhoc filters', () => { var query = builder.build( { metrics: [{ type: 'Count', id: '0' }], @@ -295,12 +294,12 @@ describe('ElasticQueryBuilder', function() { ] ); - expect(query.query.bool.must[0].match_phrase['key1'].query).to.be('value1'); - expect(query.query.bool.must[1].match_phrase['key2'].query).to.be('value2'); - expect(query.query.bool.must_not[0].match_phrase['key2'].query).to.be('value2'); - expect(query.query.bool.filter[2].range['key3'].lt).to.be('value3'); - expect(query.query.bool.filter[3].range['key4'].gt).to.be('value4'); - expect(query.query.bool.filter[4].regexp['key5']).to.be('value5'); - expect(query.query.bool.filter[5].bool.must_not.regexp['key6']).to.be('value6'); + expect(query.query.bool.must[0].match_phrase['key1'].query).toBe('value1'); + expect(query.query.bool.must[1].match_phrase['key2'].query).toBe('value2'); + expect(query.query.bool.must_not[0].match_phrase['key2'].query).toBe('value2'); + expect(query.query.bool.filter[2].range['key3'].lt).toBe('value3'); + expect(query.query.bool.filter[3].range['key4'].gt).toBe('value4'); + expect(query.query.bool.filter[4].regexp['key5']).toBe('value5'); + expect(query.query.bool.filter[5].bool.must_not.regexp['key6']).toBe('value6'); }); }); From dbbd6b9b660f4b759bc4af3d49f4cd6c7293e129 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Thu, 14 Jun 2018 15:27:11 +0200 Subject: [PATCH 7/7] Remove import --- .../app/plugins/datasource/influxdb/specs/query_builder.jest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/public/app/plugins/datasource/influxdb/specs/query_builder.jest.ts b/public/app/plugins/datasource/influxdb/specs/query_builder.jest.ts index eeae987b139..30a9343f56e 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_builder.jest.ts @@ -1,4 +1,3 @@ -import { describe, it, expect } from 'test/lib/common'; import { InfluxQueryBuilder } from '../query_builder'; describe('InfluxQueryBuilder', function() {