• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript helpers.ControllerTestContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中test/specs/helpers.ControllerTestContext的典型用法代码示例。如果您正苦于以下问题:TypeScript ControllerTestContext类的具体用法?TypeScript ControllerTestContext怎么用?TypeScript ControllerTestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ControllerTestContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

describe('SeriesOverridesCtrl', function() {
  var ctx = new helpers.ControllerTestContext();
  var popoverSrv = {};

  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(angularMocks.module('grafana.controllers'));

  beforeEach(
    ctx.providePhase({
      popoverSrv: popoverSrv,
    })
  );

  beforeEach(
    angularMocks.inject(function($rootScope, $controller) {
      ctx.scope = $rootScope.$new();
      ctx.scope.ctrl = {
        refresh: sinon.spy(),
        render: sinon.spy(),
        seriesList: [],
      };
      ctx.scope.render = function() {};
      ctx.controller = $controller('SeriesOverridesCtrl', {
        $scope: ctx.scope,
      });
    })
  );

  describe('When setting an override', function() {
    beforeEach(function() {
      ctx.scope.setOverride({ propertyName: 'lines' }, { value: true });
    });

    it('should set override property', function() {
      expect(ctx.scope.override.lines).to.be(true);
    });

    it('should update view model', function() {
      expect(ctx.scope.currentOverrides[0].name).to.be('Lines');
      expect(ctx.scope.currentOverrides[0].value).to.be('true');
    });
  });

  describe('When removing overide', function() {
    it('click should include option and value index', function() {
      ctx.scope.setOverride(1, 0);
      ctx.scope.removeOverride({ propertyName: 'lines' });
      expect(ctx.scope.currentOverrides.length).to.be(0);
    });
  });
});
开发者ID:GPegel,项目名称:grafana,代码行数:51,代码来源:series_override_ctrl_specs.ts


示例2: describe

describe('ElasticQueryCtrl', function() {
  var ctx = new helpers.ControllerTestContext();

  beforeEach(angularMocks.module('grafana.controllers'));
  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(ctx.providePhase());
  beforeEach(ctx.createControllerPhase('ElasticQueryCtrl'));

  beforeEach(function() {
    ctx.scope.target = {};
    ctx.scope.$parent = { get_data: sinon.spy() };

    ctx.scope.datasource = ctx.datasource;
    ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
  });

  describe('init', function() {
    beforeEach(function() {
      ctx.scope.init();
    });
  });
});
开发者ID:eddawley,项目名称:grafana,代码行数:22,代码来源:query_ctrl_specs.ts


示例3: describe

describe('ShareModalCtrl', function() {
  var ctx = new helpers.ControllerTestContext();

  function setTime(range) {
    ctx.timeSrv.timeRange = sinon.stub().returns(range);
  }

  beforeEach(function() {
    config.bootData = {
      user: {
        orgId: 1
      }
    };
  });

  setTime({ from: new Date(1000), to: new Date(2000) });

  beforeEach(angularMocks.module('grafana.controllers'));
  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(angularMocks.module(function($compileProvider) {
    $compileProvider.preAssignBindingsEnabled(true);
  }));

  beforeEach(ctx.providePhase());

  beforeEach(ctx.createControllerPhase('ShareModalCtrl'));

  describe('shareUrl with current time range and panel', function() {
    it('should generate share url absolute time', function() {
      ctx.$location.path('/test');
      ctx.scope.panel = { id: 22 };

      ctx.scope.init();
      expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&panelId=22&fullscreen');
    });

    it('should generate render url', function() {
      ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/db/my-dash';

      ctx.scope.panel = { id: 22 };

      ctx.scope.init();
      var base = 'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
      var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
      expect(ctx.scope.imageUrl).to.contain(base + params);
    });

    it('should remove panel id when no panel in scope', function() {
      ctx.$location.path('/test');
      ctx.scope.options.forCurrent = true;
      ctx.scope.panel = null;

      ctx.scope.init();
      expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1');
    });

    it('should add theme when specified', function() {
      ctx.$location.path('/test');
      ctx.scope.options.theme = 'light';
      ctx.scope.panel = null;

      ctx.scope.init();
      expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&theme=light');
    });

    it('should remove fullscreen from image url when is first param in querystring and modeSharePanel is true', function() {
      ctx.$location.url('/test?fullscreen&edit');
      ctx.scope.modeSharePanel = true;
      ctx.scope.panel = { id: 1 };

      ctx.scope.buildUrl();

      expect(ctx.scope.shareUrl).to.contain('?fullscreen&edit&from=1000&to=2000&orgId=1&panelId=1');
      expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');

    });

    it('should remove edit from image url when is first param in querystring and modeSharePanel is true', function() {
      ctx.$location.url('/test?edit&fullscreen');
      ctx.scope.modeSharePanel = true;
      ctx.scope.panel = { id: 1 };

      ctx.scope.buildUrl();

      expect(ctx.scope.shareUrl).to.contain('?edit&fullscreen&from=1000&to=2000&orgId=1&panelId=1');
      expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');

    });

    it('should include template variables in url', function() {
      ctx.$location.path('/test');
      ctx.scope.options.includeTemplateVars = true;

      ctx.templateSrv.fillVariableValuesForUrl = function(params) {
        params['var-app'] = 'mupp';
        params['var-server'] = 'srv-01';
      };

      ctx.scope.buildUrl();
      expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&var-app=mupp&var-server=srv-01');
//.........这里部分代码省略.........
开发者ID:PaulMest,项目名称:grafana,代码行数:101,代码来源:share_modal_ctrl_specs.ts


示例4: describe

describe('VariableSrv init', 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(['datasourceSrv', 'timeSrv', 'templateSrv', '$location']));
  beforeEach(
    angularMocks.inject(($rootScope, $q, $location, $injector) => {
      ctx.$q = $q;
      ctx.$rootScope = $rootScope;
      ctx.$location = $location;
      ctx.variableSrv = $injector.get('variableSrv');
      ctx.$rootScope.$digest();
    })
  );

  function describeInitScenario(desc, fn) {
    describe(desc, function() {
      var scenario: any = {
        urlParams: {},
        setup: setupFn => {
          scenario.setupFn = setupFn;
        },
      };

      beforeEach(function() {
        scenario.setupFn();
        ctx.datasource = {};
        ctx.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when(scenario.queryResult));

        ctx.datasourceSrv.get = sinon.stub().returns(ctx.$q.when(ctx.datasource));
        ctx.datasourceSrv.getMetricSources = sinon.stub().returns(scenario.metricSources);

        ctx.$location.search = sinon.stub().returns(scenario.urlParams);
        ctx.dashboard = {
          templating: { list: scenario.variables },
          events: new Emitter(),
        };

        ctx.variableSrv.init(ctx.dashboard);
        ctx.$rootScope.$digest();

        scenario.variables = ctx.variableSrv.variables;
      });

      fn(scenario);
    });
  }

  ['query', 'interval', 'custom', 'datasource'].forEach(type => {
    describeInitScenario('when setting ' + type + ' variable via url', scenario => {
      scenario.setup(() => {
        scenario.variables = [
          {
            name: 'apps',
            type: type,
            current: { text: 'test', value: 'test' },
            options: [{ text: 'test', value: 'test' }],
          },
        ];
        scenario.urlParams['var-apps'] = 'new';
        scenario.metricSources = [];
      });

      it('should update current value', () => {
        expect(scenario.variables[0].current.value).to.be('new');
        expect(scenario.variables[0].current.text).to.be('new');
      });
    });
  });

  describe('given dependent variables', () => {
    var variableList = [
      {
        name: 'app',
        type: 'query',
        query: '',
        current: { text: 'app1', value: 'app1' },
        options: [{ text: 'app1', value: 'app1' }],
      },
      {
        name: 'server',
        type: 'query',
        refresh: 1,
        query: '$app.*',
        current: { text: 'server1', value: 'server1' },
        options: [{ text: 'server1', value: 'server1' }],
      },
    ];

    describeInitScenario('when setting parent var from url', scenario => {
      scenario.setup(() => {
        scenario.variables = _.cloneDeep(variableList);
//.........这里部分代码省略.........
开发者ID:GPegel,项目名称:grafana,代码行数:101,代码来源:variable_srv_init_specs.ts


示例5: describe

describe('OpenfalconQueryCtrl', function() {
  var ctx = new helpers.ControllerTestContext();

  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.controllers'));
  beforeEach(angularMocks.module('grafana.services'));

  beforeEach(ctx.providePhase());
  beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
    ctx.$q = $q;
    ctx.scope = $rootScope.$new();
    ctx.target = {target: 'aliasByNode(scaleToSeconds(test.prod.*,1),2)'};
    ctx.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
    ctx.panelCtrl = {panel: {}};
    ctx.panelCtrl.refresh = sinon.spy();

    ctx.ctrl = $controller(OpenfalconQueryCtrl, {$scope: ctx.scope}, {
      panelCtrl: ctx.panelCtrl,
      datasource: ctx.datasource,
      target: ctx.target
    });
    ctx.scope.$digest();
  }));

  describe('init', function() {
    it('should validate metric key exists', function() {
      expect(ctx.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*');
    });

    it('should delete last segment if no metrics are found', function() {
      expect(ctx.ctrl.segments[2].value).to.be('select metric');
    });

    it('should parse expression and build function model', function() {
      expect(ctx.ctrl.functions.length).to.be(2);
    });
  });

  describe('when adding function', function() {
    beforeEach(function() {
      ctx.ctrl.target.target = 'test.prod.*.count';
      ctx.ctrl.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([{expandable: false}]));
      ctx.ctrl.parseTarget();
      ctx.ctrl.addFunction(gfunc.getFuncDef('aliasByNode'));
    });

    it('should add function with correct node number', function() {
      expect(ctx.ctrl.functions[0].params[0]).to.be(2);
    });

    it('should update target', function() {
      expect(ctx.ctrl.target.target).to.be('aliasByNode(test.prod.*.count, 2)');
    });

    it('should call refresh', function() {
      expect(ctx.panelCtrl.refresh.called).to.be(true);
    });
  });

  describe('when adding function before any metric segment', function() {
    beforeEach(function() {
      ctx.ctrl.target.target = '';
      ctx.ctrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}]));
      ctx.ctrl.parseTarget();
      ctx.ctrl.addFunction(gfunc.getFuncDef('asPercent'));
    });

    it('should add function and remove select metric link', function() {
      expect(ctx.ctrl.segments.length).to.be(0);
    });
  });

  describe('when initalizing target without metric expression and only function', function() {
    beforeEach(function() {
      ctx.ctrl.target.target = 'asPercent(#A, #B)';
      ctx.ctrl.datasource.metricFindQuery.returns(ctx.$q.when([]));
      ctx.ctrl.parseTarget();
      ctx.scope.$digest();
    });

    it('should not add select metric segment', function() {
      expect(ctx.ctrl.segments.length).to.be(0);
    });

    it('should add both series refs as params', function() {
      expect(ctx.ctrl.functions[0].params.length).to.be(2);
    });
  });

  describe('when initializing a target with single param func using variable', function() {
    beforeEach(function() {
      ctx.ctrl.target.target = 'movingAverage(prod.count, $var)';
      ctx.ctrl.datasource.metricFindQuery.returns(ctx.$q.when([]));
      ctx.ctrl.parseTarget();
    });

    it('should add 2 segments', function() {
      expect(ctx.ctrl.segments.length).to.be(2);
    });

//.........这里部分代码省略.........
开发者ID:Ryan817,项目名称:grafana-openfalcon-datasource,代码行数:101,代码来源:query_ctrl_specs.ts


示例6: describe

describe('VariableSrv', function() {
  var ctx = new helpers.ControllerTestContext();

  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.controllers'));
  beforeEach(angularMocks.module('grafana.services'));

  beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv', '$location']));
  beforeEach(
    angularMocks.inject(($rootScope, $q, $location, $injector) => {
      ctx.$q = $q;
      ctx.$rootScope = $rootScope;
      ctx.$location = $location;
      ctx.variableSrv = $injector.get('variableSrv');
      ctx.variableSrv.init({
        templating: { list: [] },
        events: new Emitter(),
        updateSubmenuVisibility: sinon.stub(),
      });
      ctx.$rootScope.$digest();
    })
  );

  function describeUpdateVariable(desc, fn) {
    describe(desc, function() {
      var scenario: any = {};
      scenario.setup = function(setupFn) {
        scenario.setupFn = setupFn;
      };

      beforeEach(function() {
        scenario.setupFn();
        var ds: any = {};
        ds.metricFindQuery = sinon.stub().returns(ctx.$q.when(scenario.queryResult));
        ctx.datasourceSrv.get = sinon.stub().returns(ctx.$q.when(ds));
        ctx.datasourceSrv.getMetricSources = sinon.stub().returns(scenario.metricSources);

        scenario.variable = ctx.variableSrv.createVariableFromModel(scenario.variableModel);
        ctx.variableSrv.addVariable(scenario.variable);

        ctx.variableSrv.updateOptions(scenario.variable);
        ctx.$rootScope.$digest();
      });

      fn(scenario);
    });
  }

  describeUpdateVariable('interval variable without auto', scenario => {
    scenario.setup(() => {
      scenario.variableModel = {
        type: 'interval',
        query: '1s,2h,5h,1d',
        name: 'test',
      };
    });

    it('should update options array', () => {
      expect(scenario.variable.options.length).to.be(4);
      expect(scenario.variable.options[0].text).to.be('1s');
      expect(scenario.variable.options[0].value).to.be('1s');
    });
  });

  //
  // Interval variable update
  //
  describeUpdateVariable('interval variable with auto', scenario => {
    scenario.setup(() => {
      scenario.variableModel = {
        type: 'interval',
        query: '1s,2h,5h,1d',
        name: 'test',
        auto: true,
        auto_count: 10,
      };

      var range = {
        from: moment(new Date())
          .subtract(7, 'days')
          .toDate(),
        to: new Date(),
      };

      ctx.timeSrv.timeRange = sinon.stub().returns(range);
      ctx.templateSrv.setGrafanaVariable = sinon.spy();
    });

    it('should update options array', function() {
      expect(scenario.variable.options.length).to.be(5);
      expect(scenario.variable.options[0].text).to.be('auto');
      expect(scenario.variable.options[0].value).to.be('$__auto_interval_test');
    });

    it('should set $__auto_interval_test', function() {
      var call = ctx.templateSrv.setGrafanaVariable.firstCall;
      expect(call.args[0]).to.be('$__auto_interval_test');
      expect(call.args[1]).to.be('12h');
    });

//.........这里部分代码省略.........
开发者ID:GPegel,项目名称:grafana,代码行数:101,代码来源:variable_srv_specs.ts


示例7: describe

describe('OpenTsQueryCtrl', function() {
  var ctx = new helpers.ControllerTestContext();

  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(angularMocks.module(function($compileProvider) {
    $compileProvider.preAssignBindingsEnabled(true);
  }));

  beforeEach(ctx.providePhase(['backendSrv','templateSrv']));

  beforeEach(ctx.providePhase());
  beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
    ctx.$q = $q;
    ctx.scope = $rootScope.$new();
    ctx.target = {target: ''};
    ctx.panelCtrl = {panel: {}};
    ctx.panelCtrl.refresh = sinon.spy();
    ctx.datasource.getAggregators = sinon.stub().returns(ctx.$q.when([]));
    ctx.datasource.getFilterTypes = sinon.stub().returns(ctx.$q.when([]));

    ctx.ctrl = $controller(OpenTsQueryCtrl, {$scope: ctx.scope}, {
      panelCtrl: ctx.panelCtrl,
      datasource: ctx.datasource,
      target: ctx.target,
    });
    ctx.scope.$digest();
  }));

  describe('init query_ctrl variables', function() {

    it('filter types should be initialized', function() {
      expect(ctx.ctrl.filterTypes.length).to.be(7);
    });

    it('aggregators should be initialized', function() {
      expect(ctx.ctrl.aggregators.length).to.be(8);
    });

    it('fill policy options should be initialized', function() {
      expect(ctx.ctrl.fillPolicies.length).to.be(4);
    });

  });

  describe('when adding filters and tags', function() {

    it('addTagMode should be false when closed', function() {
      ctx.ctrl.addTagMode = true;
      ctx.ctrl.closeAddTagMode();
      expect(ctx.ctrl.addTagMode).to.be(false);
    });

    it('addFilterMode should be false when closed', function() {
      ctx.ctrl.addFilterMode = true;
      ctx.ctrl.closeAddFilterMode();
      expect(ctx.ctrl.addFilterMode).to.be(false);
    });

    it('removing a tag from the tags list', function() {
      ctx.ctrl.target.tags = {"tagk": "tag_key", "tagk2": "tag_value2"};
      ctx.ctrl.removeTag("tagk");
      expect(Object.keys(ctx.ctrl.target.tags).length).to.be(1);
    });

    it('removing a filter from the filters list', function() {
      ctx.ctrl.target.filters = [{"tagk": "tag_key", "filter": "tag_value2", "type": "wildcard", "groupBy": true}];
      ctx.ctrl.removeFilter(0);
      expect(ctx.ctrl.target.filters.length).to.be(0);
    });

    it('adding a filter when tags exist should generate error', function() {
      ctx.ctrl.target.tags = {"tagk": "tag_key", "tagk2": "tag_value2"};
      ctx.ctrl.addFilter();
      expect(ctx.ctrl.errors.filters).to.be('Please remove tags to use filters, tags and filters are mutually exclusive.');
    });

    it('adding a tag when filters exist should generate error', function() {
      ctx.ctrl.target.filters = [{"tagk": "tag_key", "filter": "tag_value2", "type": "wildcard", "groupBy": true}];
      ctx.ctrl.addTag();
      expect(ctx.ctrl.errors.tags).to.be('Please remove filters to use tags, tags and filters are mutually exclusive.');
    });

  });

});
开发者ID:Sensetif,项目名称:grafana,代码行数:86,代码来源:query-ctrl-specs.ts


示例8: describe

describe('SingleStatCtrl', function() {
  var ctx = new helpers.ControllerTestContext();
  var epoch = 1505826363746;
  var clock;

  function singleStatScenario(desc, func) {

    describe(desc, function() {

      ctx.setup = function (setupFunc) {

        beforeEach(angularMocks.module('grafana.services'));
        beforeEach(angularMocks.module('grafana.controllers'));
        beforeEach(angularMocks.module(function($compileProvider) {
          $compileProvider.preAssignBindingsEnabled(true);
        }));

        beforeEach(ctx.providePhase());
        beforeEach(ctx.createPanelController(SingleStatCtrl));

        beforeEach(function() {
          setupFunc();
          ctx.ctrl.onDataReceived(ctx.data);
          ctx.data = ctx.ctrl.data;
        });
      };

      func(ctx);
    });
  }

  singleStatScenario('with defaults', function(ctx) {
    ctx.setup(function() {
      ctx.data = [
        {target: 'test.cpu1', datapoints: [[10,1], [20,2]]}
      ];
    });

    it('Should use series avg as default main value', function() {
      expect(ctx.data.value).to.be(15);
      expect(ctx.data.valueRounded).to.be(15);
    });

    it('should set formatted falue', function() {
      expect(ctx.data.valueFormatted).to.be('15');
    });
  });

  singleStatScenario('showing serie name instead of value', function(ctx) {
    ctx.setup(function() {
       ctx.data = [
        {target: 'test.cpu1', datapoints: [[10,1], [20,2]]}
       ];
      ctx.ctrl.panel.valueName = 'name';
    });

    it('Should use series avg as default main value', function() {
      expect(ctx.data.value).to.be(0);
      expect(ctx.data.valueRounded).to.be(0);
    });

    it('should set formatted value', function() {
      expect(ctx.data.valueFormatted).to.be('test.cpu1');
    });
  });

  singleStatScenario('showing last iso time instead of value', function(ctx) {
    ctx.setup(function() {
       ctx.data = [
        {target: 'test.cpu1', datapoints: [[10, 12], [20,1505634997920]]}
       ];
      ctx.ctrl.panel.valueName = 'last_time';
      ctx.ctrl.panel.format = 'dateTimeAsIso';
    });

    it('Should use time instead of value', function() {
      expect(ctx.data.value).to.be(1505634997920);
      expect(ctx.data.valueRounded).to.be(1505634997920);
    });

    it('should set formatted value', function() {
      expect(ctx.data.valueFormatted).to.be(moment(1505634997920).format('YYYY-MM-DD HH:mm:ss'));
    });
  });

  singleStatScenario('showing last us time instead of value', function(ctx) {
    ctx.setup(function() {
       ctx.data = [
        {target: 'test.cpu1', datapoints: [[10, 12], [20,1505634997920]]}
       ];
      ctx.ctrl.panel.valueName = 'last_time';
      ctx.ctrl.panel.format = 'dateTimeAsUS';
    });

    it('Should use time instead of value', function() {
      expect(ctx.data.value).to.be(1505634997920);
      expect(ctx.data.valueRounded).to.be(1505634997920);
    });

    it('should set formatted value', function() {
//.........这里部分代码省略.........
开发者ID:PaulMest,项目名称:grafana,代码行数:101,代码来源:singlestat_specs.ts


示例9: describe

describe('InfluxDBQueryCtrl', function() {
  var ctx = new helpers.ControllerTestContext();

  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.controllers'));
  beforeEach(angularMocks.module('grafana.services'));
  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.panelCtrl = {panel: {}};
    ctx.panelCtrl.refresh = sinon.spy();
    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.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);
//.........这里部分代码省略.........
开发者ID:0x01feng,项目名称:grafana,代码行数:101,代码来源:query_ctrl_specs.ts


示例10: function

      ctx.setup = function (setupFunc) {

        beforeEach(angularMocks.module('grafana.services'));
        beforeEach(angularMocks.module('grafana.controllers'));
        beforeEach(angularMocks.module(function($compileProvider) {
          $compileProvider.preAssignBindingsEnabled(true);
        }));

        beforeEach(ctx.providePhase());
        beforeEach(ctx.createPanelController(SingleStatCtrl));

        beforeEach(function() {
          setupFunc();
          ctx.ctrl.onDataReceived(ctx.data);
          ctx.data = ctx.ctrl.data;
        });
      };
开发者ID:PaulMest,项目名称:grafana,代码行数:17,代码来源:singlestat_specs.ts



注:本文中的test/specs/helpers.ControllerTestContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript helpers.ServiceTestContext类代码示例发布时间:2022-05-25
下一篇:
TypeScript hooks.attachDefaultHooks函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap