|
|
@@ -2,6 +2,7 @@ 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();
|
|
|
@@ -14,179 +15,164 @@ describe('InfluxDBQueryCtrl', function() {
|
|
|
beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
|
|
|
ctx.$q = $q;
|
|
|
ctx.scope = $rootScope.$new();
|
|
|
- ctx.scope.ctrl = {panel: ctx.panel};
|
|
|
- ctx.scope.datasource = ctx.datasource;
|
|
|
- ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
|
|
|
- ctx.panelCtrl = ctx.scope.ctrl;
|
|
|
- ctx.controller = $controller('InfluxQueryCtrl', {$scope: ctx.scope});
|
|
|
- }));
|
|
|
-
|
|
|
- beforeEach(function() {
|
|
|
- ctx.scope.target = {};
|
|
|
+ ctx.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
|
|
|
+ ctx.panelCtrl = {panel: {}};
|
|
|
ctx.panelCtrl.refresh = sinon.spy();
|
|
|
- });
|
|
|
-
|
|
|
- describe('init', function() {
|
|
|
- beforeEach(function() {
|
|
|
- ctx.scope.init();
|
|
|
+ ctx.target = {target: {}};
|
|
|
+ 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.scope.tagSegments.length).to.be(1);
|
|
|
+ expect(ctx.ctrl.tagSegments.length).to.be(1);
|
|
|
});
|
|
|
|
|
|
it('should init measurementSegment', function() {
|
|
|
- expect(ctx.scope.measurementSegment.value).to.be('select measurement');
|
|
|
+ expect(ctx.ctrl.measurementSegment.value).to.be('select measurement');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('when first tag segment is updated', function() {
|
|
|
beforeEach(function() {
|
|
|
- ctx.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
|
|
|
+ ctx.ctrl.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
|
|
|
});
|
|
|
|
|
|
it('should update tag key', function() {
|
|
|
- expect(ctx.scope.target.tags[0].key).to.be('asd');
|
|
|
- expect(ctx.scope.tagSegments[0].type).to.be('key');
|
|
|
+ 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.scope.tagSegments.length).to.be(3);
|
|
|
+ expect(ctx.ctrl.tagSegments.length).to.be(3);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('when last tag value segment is updated', function() {
|
|
|
beforeEach(function() {
|
|
|
- ctx.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
+ 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.scope.target.tags[0].value).to.be('server1');
|
|
|
+ expect(ctx.ctrl.target.tags[0].value).to.be('server1');
|
|
|
});
|
|
|
|
|
|
it('should set tag operator', function() {
|
|
|
- expect(ctx.scope.target.tags[0].operator).to.be('=');
|
|
|
+ expect(ctx.ctrl.target.tags[0].operator).to.be('=');
|
|
|
});
|
|
|
|
|
|
it('should add plus button for another filter', function() {
|
|
|
- expect(ctx.scope.tagSegments[3].fake).to.be(true);
|
|
|
+ expect(ctx.ctrl.tagSegments[3].fake).to.be(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('when last tag value segment is updated to regex', function() {
|
|
|
beforeEach(function() {
|
|
|
- ctx.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: '/server.*/', type: 'value'}, 2);
|
|
|
+ ctx.ctrl.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
|
|
|
+ ctx.ctrl.tagSegmentUpdated({value: '/server.*/', type: 'value'}, 2);
|
|
|
});
|
|
|
|
|
|
it('should update operator', function() {
|
|
|
- expect(ctx.scope.tagSegments[1].value).to.be('=~');
|
|
|
- expect(ctx.scope.target.tags[0].operator).to.be('=~');
|
|
|
+ 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.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
|
|
|
+ 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.scope.target.tags[1].key).to.be('key2');
|
|
|
+ expect(ctx.ctrl.target.tags[1].key).to.be('key2');
|
|
|
});
|
|
|
|
|
|
it('should add AND segment', function() {
|
|
|
- expect(ctx.scope.tagSegments[3].value).to.be('AND');
|
|
|
+ expect(ctx.ctrl.tagSegments[3].value).to.be('AND');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('when condition is changed', function() {
|
|
|
beforeEach(function() {
|
|
|
- ctx.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'OR', type: 'condition'}, 3);
|
|
|
+ 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.scope.target.tags[1].condition).to.be('OR');
|
|
|
+ expect(ctx.ctrl.target.tags[1].condition).to.be('OR');
|
|
|
});
|
|
|
|
|
|
it('should update AND segment', function() {
|
|
|
- expect(ctx.scope.tagSegments[3].value).to.be('OR');
|
|
|
- expect(ctx.scope.tagSegments.length).to.be(7);
|
|
|
+ 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.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
- ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 0);
|
|
|
+ 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.scope.target.tags.length).to.be(0);
|
|
|
+ expect(ctx.ctrl.target.tags.length).to.be(0);
|
|
|
});
|
|
|
|
|
|
it('should remove all segment after 2 and replace with plus button', function() {
|
|
|
- expect(ctx.scope.tagSegments.length).to.be(1);
|
|
|
- expect(ctx.scope.tagSegments[0].type).to.be('plus-button');
|
|
|
+ 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.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
|
|
|
- ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 4);
|
|
|
+ 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.scope.tagSegments.length).to.be(4);
|
|
|
- expect(ctx.scope.tagSegments[3].type).to.be('plus-button');
|
|
|
+ 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.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
|
|
|
- ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 4);
|
|
|
+ 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.scope.tagSegments.length).to.be(4);
|
|
|
- expect(ctx.scope.tagSegments[3].type).to.be('plus-button');
|
|
|
+ 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.scope.init();
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
|
|
|
- ctx.scope.tagSegmentUpdated({value: 'value', type: 'value'}, 6);
|
|
|
- ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 4);
|
|
|
+ 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.scope.tagSegments.length).to.be(4);
|
|
|
- expect(ctx.scope.tagSegments[3].type).to.be('plus-button');
|
|
|
+ expect(ctx.ctrl.tagSegments.length).to.be(4);
|
|
|
+ expect(ctx.ctrl.tagSegments[3].type).to.be('plus-button');
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
});
|