当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ControllerTestContext.createControllerPhase方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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(ctx.createControllerPhase('InfluxQueryCtrl'));

  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();
    });

    it('should init tagSegments', function() {
      expect(ctx.scope.tagSegments.length).to.be(1);
    });

    it('should init measurementSegment', function() {
      expect(ctx.scope.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);
    });

    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');
    });

    it('should add tagSegments', function() {
      expect(ctx.scope.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);
    });

    it('should update tag value', function() {
      expect(ctx.scope.target.tags[0].value).to.be('server1');
    });

    it('should set tag operator', function() {
      expect(ctx.scope.target.tags[0].operator).to.be('=');
    });

    it('should add plus button for another filter', function() {
      expect(ctx.scope.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);
    });

    it('should update operator', function() {
      expect(ctx.scope.tagSegments[1].value).to.be('=~');
      expect(ctx.scope.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);
    });

    it('should update tag key', function() {
      expect(ctx.scope.target.tags[1].key).to.be('key2');
    });

    it('should add AND segment', function() {
      expect(ctx.scope.tagSegments[3].value).to.be('AND');
    });
  });

  describe('when condition is changed', function() {
    beforeEach(function() {
      ctx.scope.init();
//.........这里部分代码省略.........
开发者ID:eddawley,项目名称:grafana,代码行数:101,代码来源:query_ctrl_specs.ts

示例4: describe

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

    var searchResult = [
        {
            id: 2,
            title: 'dashboard: 2'
        },
        {
            id: 3,
            title: 'dashboard: 3'
        }
    ];

    var playlistSrv = {};
    var backendSrv = {
      search: (query) => {
        return ctx.$q.when(searchResult);
      }
    };

    beforeEach(angularMocks.module('grafana.core'));
    beforeEach(angularMocks.module('grafana.controllers'));
    beforeEach(angularMocks.module('grafana.services'));
    beforeEach(ctx.providePhase({
        playlistSrv: playlistSrv,
        backendSrv: backendSrv,
        $route: { current: { params: { } } },
    }));

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

    beforeEach(() => {
        ctx.scope.$digest();
    });

    describe('searchresult returns 2 dashboards', function() {
        it('found dashboard should be 2', function() {
            expect(ctx.scope.foundPlaylistItems.length).to.be(2);
        });

        it('filtred dashboard should be 2', function() {
            expect(ctx.scope.filteredPlaylistItems.length).to.be(2);
        });

        describe('adds one dashboard to playlist', () => {
            beforeEach(() => {
                ctx.scope.addPlaylistItem({ id: 2, title: 'dashboard: 2' });
            });

            it('playlistitems should be increased by one', () => {
                expect(ctx.scope.playlistItems.length).to.be(1);
            });

            it('filtred playlistitems should be reduced by one', () => {
                expect(ctx.scope.filteredPlaylistItems.length).to.be(1);
            });

            it('found dashboard should be 2', function() {
                expect(ctx.scope.foundPlaylistItems.length).to.be(2);
            });

            describe('removes one dashboard from playlist', () => {
              beforeEach(() => {
                  ctx.scope.removePlaylistItem(ctx.scope.playlistItems[0]);
              });

              it('playlistitems should be increased by one', () => {
                  expect(ctx.scope.playlistItems.length).to.be(0);
              });

              it('found dashboard should be 2', function() {
                  expect(ctx.scope.foundPlaylistItems.length).to.be(2);
              });

              it('filtred playlist should be reduced by one', () => {
                  expect(ctx.scope.filteredPlaylistItems.length).to.be(2);
              });
            });
        });
    });
});
开发者ID:windyStreet,项目名称:grafana,代码行数:82,代码来源:playlist-edit-ctrl-specs.ts

示例5: describe

describe('GraphiteQueryCtrl', 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(ctx.createControllerPhase('GraphiteQueryCtrl'));

  beforeEach(function() {
    ctx.scope.target = {target: 'aliasByNode(scaleToSeconds(test.prod.*,1),2)'};

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

  describe('init', function() {
    beforeEach(function() {
      ctx.scope.init();
      ctx.scope.$digest();
    });

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

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

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

  describe('when adding function', function() {
    beforeEach(function() {
      ctx.scope.target.target = 'test.prod.*.count';
      ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));
      ctx.scope.init();
      ctx.scope.$digest();

      ctx.scope.$parent = { get_data: sinon.spy() };
      ctx.scope.addFunction(gfunc.getFuncDef('aliasByNode'));
    });

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

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

    it('should call get_data', function() {
      expect(ctx.scope.$parent.get_data.called).to.be(true);
    });
  });

  describe('when adding function before any metric segment', function() {
    beforeEach(function() {
      ctx.scope.target.target = '';
      ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}]));
      ctx.scope.init();
      ctx.scope.$digest();

      ctx.scope.$parent = { get_data: sinon.spy() };
      ctx.scope.addFunction(gfunc.getFuncDef('asPercent'));
    });

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

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

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

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

  });

  describe('when initializing a target with single param func using variable', function() {
    beforeEach(function() {
      ctx.scope.target.target = 'movingAverage(prod.count, $var)';
      ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([]));
      ctx.scope.init();
//.........这里部分代码省略.........
开发者ID:eddawley,项目名称:grafana,代码行数:101,代码来源:query_ctrl_specs.ts


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