From 46e31621b071e36f658788c5b8f9c9ab11ca1aab Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Mon, 23 Jul 2018 14:28:17 +0200 Subject: [PATCH 1/5] Add jest file --- .../influxdb/specs/query_ctrl.jest.ts | 211 ++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts new file mode 100644 index 00000000000..e4dd5b226f4 --- /dev/null +++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts @@ -0,0 +1,211 @@ +import '../query_ctrl'; +import 'app/core/services/segment_srv'; +// import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common'; +// import helpers from 'test/specs/helpers'; +import { InfluxQueryCtrl } from '../query_ctrl'; + +describe('InfluxDBQueryCtrl', function() { + let uiSegmentSrv = { + newPlusButton: () => {}, + }; + + let ctx = { + dataSource: { + metricFindQuery: jest.fn(() => Promise.resolve([])), + }, + }; + + InfluxQueryCtrl.prototype.panelCtrl = { + panel: { + targets: [{}], + }, + }; + + // beforeEach(angularMocks.module('grafana.core')); + // beforeEach(angularMocks.module('grafana.controllers')); + // beforeEach(angularMocks.module('grafana.services')); + // beforeEach( + // angularMocks.module(function($compileProvider) { + // $compileProvider.preAssignBindingsEnabled(true); + // }) + // ); + // beforeEach(ctx.providePhase()); + + // beforeEach( + // angularMocks.inject(($rootScope, $controller, $q) => { + // ctx.$q = $q; + // ctx.scope = $rootScope.$new(); + // ctx.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); + // ctx.target = { target: {} }; + // ctx.panelCtrl = { + // panel: { + // targets: [ctx.target], + // }, + // }; + // ctx.panelCtrl.refresh = sinon.spy(); + // ctx.ctrl = $controller( + // InfluxQueryCtrl, + // { $scope: ctx.scope }, + // { + // panelCtrl: ctx.panelCtrl, + // target: ctx.target, + // datasource: ctx.datasource, + // } + // ); + // }) + // ); + + beforeEach(() => { + ctx.ctrl = new InfluxQueryCtrl({}, {}, {}, {}, uiSegmentSrv); + }); + + describe('init', function() { + it('should init tagSegments', function() { + expect(ctx.ctrl.tagSegments.length).toBe(1); + }); + + it('should init measurementSegment', function() { + expect(ctx.ctrl.measurementSegment.value).toBe('select measurement'); + }); + }); + + describe('when first tag segment is updated', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + }); + + it('should update tag key', function() { + expect(ctx.ctrl.target.tags[0].key).toBe('asd'); + expect(ctx.ctrl.tagSegments[0].type).toBe('key'); + }); + + it('should add tagSegments', function() { + expect(ctx.ctrl.tagSegments.length).toBe(3); + }); + }); + + describe('when last tag value segment is updated', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + }); + + it('should update tag value', function() { + expect(ctx.ctrl.target.tags[0].value).toBe('server1'); + }); + + it('should set tag operator', function() { + expect(ctx.ctrl.target.tags[0].operator).toBe('='); + }); + + it('should add plus button for another filter', function() { + expect(ctx.ctrl.tagSegments[3].fake).toBe(true); + }); + }); + + describe('when last tag value segment is updated to regex', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: '/server.*/', type: 'value' }, 2); + }); + + it('should update operator', function() { + expect(ctx.ctrl.tagSegments[1].value).toBe('=~'); + expect(ctx.ctrl.target.tags[0].operator).toBe('=~'); + }); + }); + + describe('when second tag key is added', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); + }); + + it('should update tag key', function() { + expect(ctx.ctrl.target.tags[1].key).toBe('key2'); + }); + + it('should add AND segment', function() { + expect(ctx.ctrl.tagSegments[3].value).toBe('AND'); + }); + }); + + describe('when condition is changed', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); + ctx.ctrl.tagSegmentUpdated({ value: 'OR', type: 'condition' }, 3); + }); + + it('should update tag condition', function() { + expect(ctx.ctrl.target.tags[1].condition).toBe('OR'); + }); + + it('should update AND segment', function() { + expect(ctx.ctrl.tagSegments[3].value).toBe('OR'); + expect(ctx.ctrl.tagSegments.length).toBe(7); + }); + }); + + describe('when deleting first tag filter after value is selected', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 0); + }); + + it('should remove tags', function() { + expect(ctx.ctrl.target.tags.length).toBe(0); + }); + + it('should remove all segment after 2 and replace with plus button', function() { + expect(ctx.ctrl.tagSegments.length).toBe(1); + expect(ctx.ctrl.tagSegments[0].type).toBe('plus-button'); + }); + }); + + describe('when deleting second tag value before second tag value is complete', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); + ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); + }); + + it('should remove all segment after 2 and replace with plus button', function() { + expect(ctx.ctrl.tagSegments.length).toBe(4); + expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button'); + }); + }); + + describe('when deleting second tag value before second tag value is complete', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); + ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); + }); + + it('should remove all segment after 2 and replace with plus button', function() { + expect(ctx.ctrl.tagSegments.length).toBe(4); + expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button'); + }); + }); + + describe('when deleting second tag value after second tag filter is complete', function() { + beforeEach(function() { + ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); + ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); + ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); + ctx.ctrl.tagSegmentUpdated({ value: 'value', type: 'value' }, 6); + ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); + }); + + it('should remove all segment after 2 and replace with plus button', function() { + expect(ctx.ctrl.tagSegments.length).toBe(4); + expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button'); + }); + }); +}); From bb0af52d34b201a960d3ace19a54e1b44be8748b Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Mon, 23 Jul 2018 14:54:58 +0200 Subject: [PATCH 2/5] Figuring out why it doesn't initialize --- .../app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts index e4dd5b226f4..c3b8d3ae20d 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts @@ -16,8 +16,9 @@ describe('InfluxDBQueryCtrl', function() { }; InfluxQueryCtrl.prototype.panelCtrl = { + target: { target: {} }, panel: { - targets: [{}], + targets: [this.target], }, }; From 81c32780b905fa92ab874e4fac86395f0155f14a Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Tue, 24 Jul 2018 11:27:53 +0200 Subject: [PATCH 3/5] Pass more tests --- .../plugins/datasource/influxdb/query_ctrl.ts | 1 - .../influxdb/specs/query_ctrl.jest.ts | 110 ++++++++++-------- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.ts b/public/app/plugins/datasource/influxdb/query_ctrl.ts index ce669c9f458..2be1ecc7bff 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.ts +++ b/public/app/plugins/datasource/influxdb/query_ctrl.ts @@ -22,7 +22,6 @@ export class InfluxQueryCtrl extends QueryCtrl { /** @ngInject **/ constructor($scope, $injector, private templateSrv, private $q, private uiSegmentSrv) { super($scope, $injector); - this.target = this.target; this.queryModel = new InfluxQuery(this.target, templateSrv, this.panel.scopedVars); this.queryBuilder = new InfluxQueryBuilder(this.target, this.datasource.database); diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts index c3b8d3ae20d..139efbc3afa 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts @@ -4,29 +4,28 @@ import 'app/core/services/segment_srv'; // import helpers from 'test/specs/helpers'; import { InfluxQueryCtrl } from '../query_ctrl'; -describe('InfluxDBQueryCtrl', function() { +describe('InfluxDBQueryCtrl', () => { let uiSegmentSrv = { newPlusButton: () => {}, + newKey: key => key, + newKeyValue: key => key, + newSegment: seg => seg, + newSelectMeasurement: () => { + return { value: 'select measurement' }; + }, + newOperator: op => op, + newFake: () => {}, }; let ctx = { - dataSource: { - metricFindQuery: jest.fn(() => Promise.resolve([])), - }, - }; - - InfluxQueryCtrl.prototype.panelCtrl = { - target: { target: {} }, - panel: { - targets: [this.target], - }, + dataSource: {}, }; // beforeEach(angularMocks.module('grafana.core')); // beforeEach(angularMocks.module('grafana.controllers')); // beforeEach(angularMocks.module('grafana.services')); // beforeEach( - // angularMocks.module(function($compileProvider) { + // angularMocks.module(($ =>compileProvider) { // $compileProvider.preAssignBindingsEnabled(true); // }) // ); @@ -56,147 +55,158 @@ describe('InfluxDBQueryCtrl', function() { // }) // ); - beforeEach(() => { - ctx.ctrl = new InfluxQueryCtrl({}, {}, {}, {}, uiSegmentSrv); + beforeEach(async () => { + InfluxQueryCtrl.prototype.datasource = { + metricFindQuery: jest.fn(() => Promise.resolve([])), + }; + InfluxQueryCtrl.prototype.panelCtrl = { + panel: { + targets: [InfluxQueryCtrl.target], + }, + }; + + InfluxQueryCtrl.prototype.target = { target: {} }; + console.log('creating new instance'); + ctx.ctrl = await new InfluxQueryCtrl({}, {}, {}, {}, uiSegmentSrv); }); - describe('init', function() { - it('should init tagSegments', function() { + describe('init', () => { + it('should init tagSegments', () => { expect(ctx.ctrl.tagSegments.length).toBe(1); }); - it('should init measurementSegment', function() { + it('should init measurementSegment', () => { expect(ctx.ctrl.measurementSegment.value).toBe('select measurement'); }); }); - describe('when first tag segment is updated', function() { - beforeEach(function() { + describe('when first tag segment is updated', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); }); - it('should update tag key', function() { + it('should update tag key', () => { expect(ctx.ctrl.target.tags[0].key).toBe('asd'); expect(ctx.ctrl.tagSegments[0].type).toBe('key'); }); - it('should add tagSegments', function() { + it('should add tagSegments', () => { expect(ctx.ctrl.tagSegments.length).toBe(3); }); }); - describe('when last tag value segment is updated', function() { - beforeEach(function() { + describe('when last tag value segment is updated', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); }); - it('should update tag value', function() { + it('should update tag value', () => { expect(ctx.ctrl.target.tags[0].value).toBe('server1'); }); - it('should set tag operator', function() { + it('should set tag operator', () => { expect(ctx.ctrl.target.tags[0].operator).toBe('='); }); - it('should add plus button for another filter', function() { + it('should add plus button for another filter', () => { expect(ctx.ctrl.tagSegments[3].fake).toBe(true); }); }); - describe('when last tag value segment is updated to regex', function() { - beforeEach(function() { + describe('when last tag value segment is updated to regex', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: '/server.*/', type: 'value' }, 2); }); - it('should update operator', function() { + it('should update operator', () => { expect(ctx.ctrl.tagSegments[1].value).toBe('=~'); expect(ctx.ctrl.target.tags[0].operator).toBe('=~'); }); }); - describe('when second tag key is added', function() { - beforeEach(function() { + describe('when second tag key is added', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); }); - it('should update tag key', function() { + it('should update tag key', () => { expect(ctx.ctrl.target.tags[1].key).toBe('key2'); }); - it('should add AND segment', function() { + it('should add AND segment', () => { expect(ctx.ctrl.tagSegments[3].value).toBe('AND'); }); }); - describe('when condition is changed', function() { - beforeEach(function() { + describe('when condition is changed', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); ctx.ctrl.tagSegmentUpdated({ value: 'OR', type: 'condition' }, 3); }); - it('should update tag condition', function() { + it('should update tag condition', () => { expect(ctx.ctrl.target.tags[1].condition).toBe('OR'); }); - it('should update AND segment', function() { + it('should update AND segment', () => { expect(ctx.ctrl.tagSegments[3].value).toBe('OR'); expect(ctx.ctrl.tagSegments.length).toBe(7); }); }); - describe('when deleting first tag filter after value is selected', function() { - beforeEach(function() { + describe('when deleting first tag filter after value is selected', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 0); }); - it('should remove tags', function() { + it('should remove tags', () => { expect(ctx.ctrl.target.tags.length).toBe(0); }); - it('should remove all segment after 2 and replace with plus button', function() { + it('should remove all segment after 2 and replace with plus button', () => { expect(ctx.ctrl.tagSegments.length).toBe(1); expect(ctx.ctrl.tagSegments[0].type).toBe('plus-button'); }); }); - describe('when deleting second tag value before second tag value is complete', function() { - beforeEach(function() { + describe('when deleting second tag value before second tag value is complete', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); }); - it('should remove all segment after 2 and replace with plus button', function() { + it('should remove all segment after 2 and replace with plus button', () => { expect(ctx.ctrl.tagSegments.length).toBe(4); expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button'); }); }); - describe('when deleting second tag value before second tag value is complete', function() { - beforeEach(function() { + describe('when deleting second tag value before second tag value is complete', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); }); - it('should remove all segment after 2 and replace with plus button', function() { + it('should remove all segment after 2 and replace with plus button', () => { expect(ctx.ctrl.tagSegments.length).toBe(4); expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button'); }); }); - describe('when deleting second tag value after second tag filter is complete', function() { - beforeEach(function() { + describe('when deleting second tag value after second tag filter is complete', () => { + beforeEach(() => { ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); @@ -204,7 +214,7 @@ describe('InfluxDBQueryCtrl', function() { ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); }); - it('should remove all segment after 2 and replace with plus button', function() { + it('should remove all segment after 2 and replace with plus button', () => { expect(ctx.ctrl.tagSegments.length).toBe(4); expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button'); }); From 987a16086bbafeccf3c07a5099e5b3ddf914102b Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Tue, 24 Jul 2018 14:34:37 +0200 Subject: [PATCH 4/5] Karma to Jest --- .../influxdb/specs/query_ctrl.jest.ts | 70 ++++--------------- 1 file changed, 14 insertions(+), 56 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts index 139efbc3afa..6b929432dfa 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts @@ -1,73 +1,31 @@ import '../query_ctrl'; -import 'app/core/services/segment_srv'; +import { uiSegmentSrv } from 'app/core/services/segment_srv'; // import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common'; // import helpers from 'test/specs/helpers'; import { InfluxQueryCtrl } from '../query_ctrl'; describe('InfluxDBQueryCtrl', () => { - let uiSegmentSrv = { - newPlusButton: () => {}, - newKey: key => key, - newKeyValue: key => key, - newSegment: seg => seg, - newSelectMeasurement: () => { - return { value: 'select measurement' }; - }, - newOperator: op => op, - newFake: () => {}, - }; + let ctx = {}; - let ctx = { - dataSource: {}, - }; - - // beforeEach(angularMocks.module('grafana.core')); - // beforeEach(angularMocks.module('grafana.controllers')); - // beforeEach(angularMocks.module('grafana.services')); - // beforeEach( - // angularMocks.module(($ =>compileProvider) { - // $compileProvider.preAssignBindingsEnabled(true); - // }) - // ); - // beforeEach(ctx.providePhase()); - - // beforeEach( - // angularMocks.inject(($rootScope, $controller, $q) => { - // ctx.$q = $q; - // ctx.scope = $rootScope.$new(); - // ctx.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); - // ctx.target = { target: {} }; - // ctx.panelCtrl = { - // panel: { - // targets: [ctx.target], - // }, - // }; - // ctx.panelCtrl.refresh = sinon.spy(); - // ctx.ctrl = $controller( - // InfluxQueryCtrl, - // { $scope: ctx.scope }, - // { - // panelCtrl: ctx.panelCtrl, - // target: ctx.target, - // datasource: ctx.datasource, - // } - // ); - // }) - // ); - - beforeEach(async () => { + beforeEach(() => { InfluxQueryCtrl.prototype.datasource = { - metricFindQuery: jest.fn(() => Promise.resolve([])), + metricFindQuery: () => Promise.resolve([]), }; + InfluxQueryCtrl.prototype.target = { target: {} }; InfluxQueryCtrl.prototype.panelCtrl = { panel: { - targets: [InfluxQueryCtrl.target], + targets: [InfluxQueryCtrl.prototype.target], }, + refresh: () => {}, }; - InfluxQueryCtrl.prototype.target = { target: {} }; - console.log('creating new instance'); - ctx.ctrl = await new InfluxQueryCtrl({}, {}, {}, {}, uiSegmentSrv); + ctx.ctrl = new InfluxQueryCtrl( + {}, + {}, + {}, + {}, + new uiSegmentSrv({ trustAsHtml: html => html }, { highlightVariablesAsHtml: () => {} }) + ); }); describe('init', () => { From 48ae9ec77ebbc5e3b1546a795af1f8fded555ff4 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Tue, 24 Jul 2018 14:35:37 +0200 Subject: [PATCH 5/5] Remove comments and Karm test --- .../influxdb/specs/query_ctrl.jest.ts | 2 - .../influxdb/specs/query_ctrl_specs.ts | 193 ------------------ 2 files changed, 195 deletions(-) delete mode 100644 public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts index 6b929432dfa..4e3fc47a5fd 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl.jest.ts @@ -1,7 +1,5 @@ import '../query_ctrl'; import { uiSegmentSrv } from 'app/core/services/segment_srv'; -// import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common'; -// import helpers from 'test/specs/helpers'; import { InfluxQueryCtrl } from '../query_ctrl'; describe('InfluxDBQueryCtrl', () => { diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts deleted file mode 100644 index 4daa48d6b9d..00000000000 --- a/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts +++ /dev/null @@ -1,193 +0,0 @@ -import '../query_ctrl'; -import 'app/core/services/segment_srv'; -import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common'; -import helpers from 'test/specs/helpers'; -import { InfluxQueryCtrl } from '../query_ctrl'; - -describe('InfluxDBQueryCtrl', function() { - var ctx = new helpers.ControllerTestContext(); - - beforeEach(angularMocks.module('grafana.core')); - beforeEach(angularMocks.module('grafana.controllers')); - beforeEach(angularMocks.module('grafana.services')); - beforeEach( - angularMocks.module(function($compileProvider) { - $compileProvider.preAssignBindingsEnabled(true); - }) - ); - beforeEach(ctx.providePhase()); - - beforeEach( - angularMocks.inject(($rootScope, $controller, $q) => { - ctx.$q = $q; - ctx.scope = $rootScope.$new(); - ctx.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); - ctx.target = { target: {} }; - ctx.panelCtrl = { - panel: { - targets: [ctx.target], - }, - }; - ctx.panelCtrl.refresh = sinon.spy(); - ctx.ctrl = $controller( - InfluxQueryCtrl, - { $scope: ctx.scope }, - { - panelCtrl: ctx.panelCtrl, - target: ctx.target, - datasource: ctx.datasource, - } - ); - }) - ); - - describe('init', function() { - it('should init tagSegments', function() { - expect(ctx.ctrl.tagSegments.length).to.be(1); - }); - - it('should init measurementSegment', function() { - expect(ctx.ctrl.measurementSegment.value).to.be('select measurement'); - }); - }); - - describe('when first tag segment is updated', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - }); - - it('should update tag key', function() { - expect(ctx.ctrl.target.tags[0].key).to.be('asd'); - expect(ctx.ctrl.tagSegments[0].type).to.be('key'); - }); - - it('should add tagSegments', function() { - expect(ctx.ctrl.tagSegments.length).to.be(3); - }); - }); - - describe('when last tag value segment is updated', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - }); - - it('should update tag value', function() { - expect(ctx.ctrl.target.tags[0].value).to.be('server1'); - }); - - it('should set tag operator', function() { - expect(ctx.ctrl.target.tags[0].operator).to.be('='); - }); - - it('should add plus button for another filter', function() { - expect(ctx.ctrl.tagSegments[3].fake).to.be(true); - }); - }); - - describe('when last tag value segment is updated to regex', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: '/server.*/', type: 'value' }, 2); - }); - - it('should update operator', function() { - expect(ctx.ctrl.tagSegments[1].value).to.be('=~'); - expect(ctx.ctrl.target.tags[0].operator).to.be('=~'); - }); - }); - - describe('when second tag key is added', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); - }); - - it('should update tag key', function() { - expect(ctx.ctrl.target.tags[1].key).to.be('key2'); - }); - - it('should add AND segment', function() { - expect(ctx.ctrl.tagSegments[3].value).to.be('AND'); - }); - }); - - describe('when condition is changed', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); - ctx.ctrl.tagSegmentUpdated({ value: 'OR', type: 'condition' }, 3); - }); - - it('should update tag condition', function() { - expect(ctx.ctrl.target.tags[1].condition).to.be('OR'); - }); - - it('should update AND segment', function() { - expect(ctx.ctrl.tagSegments[3].value).to.be('OR'); - expect(ctx.ctrl.tagSegments.length).to.be(7); - }); - }); - - describe('when deleting first tag filter after value is selected', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 0); - }); - - it('should remove tags', function() { - expect(ctx.ctrl.target.tags.length).to.be(0); - }); - - it('should remove all segment after 2 and replace with plus button', function() { - expect(ctx.ctrl.tagSegments.length).to.be(1); - expect(ctx.ctrl.tagSegments[0].type).to.be('plus-button'); - }); - }); - - describe('when deleting second tag value before second tag value is complete', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); - ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); - }); - - it('should remove all segment after 2 and replace with plus button', function() { - expect(ctx.ctrl.tagSegments.length).to.be(4); - expect(ctx.ctrl.tagSegments[3].type).to.be('plus-button'); - }); - }); - - describe('when deleting second tag value before second tag value is complete', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); - ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); - }); - - it('should remove all segment after 2 and replace with plus button', function() { - expect(ctx.ctrl.tagSegments.length).to.be(4); - expect(ctx.ctrl.tagSegments[3].type).to.be('plus-button'); - }); - }); - - describe('when deleting second tag value after second tag filter is complete', function() { - beforeEach(function() { - ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0); - ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2); - ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3); - ctx.ctrl.tagSegmentUpdated({ value: 'value', type: 'value' }, 6); - ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4); - }); - - it('should remove all segment after 2 and replace with plus button', function() { - expect(ctx.ctrl.tagSegments.length).to.be(4); - expect(ctx.ctrl.tagSegments[3].type).to.be('plus-button'); - }); - }); -});