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


TypeScript common.describe函数代码示例

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


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

示例1: describe

describe("rangeUtil", () => {

  describe("Can get range grouped list of ranges", () => {
    it('when custom settings should return default range list', () => {
      var groups = rangeUtil.getRelativeTimesList({time_options: []}, 'Last 5 minutes');
      expect(_.keys(groups).length).to.be(4)
      expect(groups[3][0].active).to.be(true)
    });

    // it('should add custom options to right section', () => {
    //   var groups = rangeUtil.getRelativeTimesList({
    //     time_options: ['12m', '15d']
    //   }, '');
    //   var value = _.findWhere(groups["3"], {display: 'Last 12 minutes'});
    //   expect(value).to.not.be(undefined)
    // });
  });

  describe("Can get range text described", () => {
    it('should handle simple old expression with only amount and unit', () => {
      var info = rangeUtil.describeTextRange('5m');
      expect(info.display).to.be('Last 5 minutes')
    });

    it('should have singular when amount is 1', () => {
      var info = rangeUtil.describeTextRange('1h');
      expect(info.display).to.be('Last 1 hour')
    });

    it('should handle non default amount', () => {
      var info = rangeUtil.describeTextRange('13h');
      expect(info.display).to.be('Last 13 hours')
      expect(info.from).to.be('now-13h')
    });

    it('should handle now/d', () => {
      var info = rangeUtil.describeTextRange('now/d');
      expect(info.display).to.be('The day so far');
    });

    it('should handle now/w', () => {
      var info = rangeUtil.describeTextRange('now/w');
      expect(info.display).to.be('Week to date');
    });
  });

  describe("Can get date range described", () => {
    it('Date range with simple ranges', () => {
      var text = rangeUtil.describeTimeRange({from: 'now-1h', to: 'now'});
      expect(text).to.be('Last 1 hour')
    });

    it('Date range with rounding ranges', () => {
      var text = rangeUtil.describeTimeRange({from: 'now/d+6h', to: 'now'});
      expect(text).to.be('now/d+6h to now')
    });

    it('Date range with absolute to now', () => {
      var text = rangeUtil.describeTimeRange({from: moment([2014,10,10,2,3,4]), to: 'now'});
      expect(text).to.be('Nov 10, 2014 02:03:04 to a few seconds ago')
    });

    it('Date range with absolute to relative', () => {
      var text = rangeUtil.describeTimeRange({from: moment([2014,10,10,2,3,4]), to: 'now-1d'});
      expect(text).to.be('Nov 10, 2014 02:03:04 to a day ago')
    });

    it('Date range with relative to absolute', () => {
      var text = rangeUtil.describeTimeRange({from: 'now-7d', to: moment([2014,10,10,2,3,4])});
      expect(text).to.be('7 days ago to Nov 10, 2014 02:03:04')
    });

    it('Date range with non matching default ranges', () => {
      var text = rangeUtil.describeTimeRange({from: 'now-13h', to: 'now'});
      expect(text).to.be('Last 13 hours')
    });
  });

});
开发者ID:aather,项目名称:abyss,代码行数:79,代码来源:rangeutil_specs.ts

示例2: describe

describe('PrometheusMetricFindQuery', function() {

  var ctx = new helpers.ServiceTestContext();
  var instanceSettings = {url: 'proxied', directUrl: 'direct', user: 'test', password: 'mupp' };
  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
    ctx.$q = $q;
    ctx.$httpBackend =  $httpBackend;
    ctx.$rootScope = $rootScope;
    ctx.ds = $injector.instantiate(PrometheusDatasource, {instanceSettings: instanceSettings});
  }));

  describe('When performing metricFindQuery', function() {
    var results;
    var response;
    it('label_values(resource) should generate label search query', function() {
      response = {
        status: "success",
        data: ["value1", "value2", "value3"]
      };
      ctx.$httpBackend.expect('GET', 'proxied/api/v1/label/resource/values').respond(response);
      var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(resource)');
      pm.process().then(function(data) { results = data; });
      ctx.$httpBackend.flush();
      ctx.$rootScope.$apply();
      expect(results.length).to.be(3);
    });
    it('label_values(metric, resource) should generate series query', function() {
      response = {
        status: "success",
        data: [
          {__name__: "metric", resource: "value1"},
          {__name__: "metric", resource: "value2"},
          {__name__: "metric", resource: "value3"}
        ]
      };
      ctx.$httpBackend.expect('GET', 'proxied/api/v1/series?match[]=metric').respond(response);
      var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)');
      pm.process().then(function(data) { results = data; });
      ctx.$httpBackend.flush();
      ctx.$rootScope.$apply();
      expect(results.length).to.be(3);
    });
    it('metrics(metric.*) should generate metric name query', function() {
      response = {
        status: "success",
        data: ["metric1","metric2","metric3","nomatch"]
      };
      ctx.$httpBackend.expect('GET', 'proxied/api/v1/label/__name__/values').respond(response);
      var pm = new PrometheusMetricFindQuery(ctx.ds, 'metrics(metric.*)');
      pm.process().then(function(data) { results = data; });
      ctx.$httpBackend.flush();
      ctx.$rootScope.$apply();
      expect(results.length).to.be(3);
    });
    it('query_result(metric) should generate metric name query', function() {
      response = {
        status: "success",
        data: {
          resultType: "vector",
          result: [{
            metric: {"__name__": "metric", job: "testjob"},
            value: [1443454528.000, "3846"]
          }]
        }
      };
      ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/query\?query=metric&time=.*/).respond(response);
      var pm = new PrometheusMetricFindQuery(ctx.ds, 'query_result(metric)');
      pm.process().then(function(data) { results = data; });
      ctx.$httpBackend.flush();
      ctx.$rootScope.$apply();
      expect(results.length).to.be(1);
      expect(results[0].text).to.be('metric{job="testjob"} 3846 1443454528000');
    });
  });
});
开发者ID:AutogrowSystems,项目名称:grafana,代码行数:77,代码来源:metric_find_query_specs.ts

示例3: describe

describe('PlaylistEditCtrl', () => {
  var ctx: any;
  beforeEach(() => {
    let navModelSrv = {
      getNav: () => {
        return { breadcrumbs: [], node: {} };
      },
    };

    ctx = new PlaylistEditCtrl(null, null, null, { current: { params: {} } }, navModelSrv);

    ctx.dashboardresult = [{ id: 2, title: 'dashboard: 2' }, { id: 3, title: 'dashboard: 3' }];

    ctx.tagresult = [{ term: 'graphite', count: 1 }, { term: 'nyc', count: 2 }];
  });

  describe('searchresult returns 2 dashboards, ', () => {
    it('found dashboard should be 2', () => {
      expect(ctx.dashboardresult.length).to.be(2);
    });

    it('filtred result should be 2', () => {
      ctx.filterFoundPlaylistItems();
      expect(ctx.filteredDashboards.length).to.be(2);
      expect(ctx.filteredTags.length).to.be(2);
    });

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

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

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

      it('found dashboard should be 2', () => {
        expect(ctx.dashboardresult.length).to.be(2);
      });

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

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

        it('found dashboard should be 2', () => {
          expect(ctx.dashboardresult.length).to.be(2);
          expect(ctx.filteredDashboards.length).to.be(2);
          expect(ctx.filteredTags.length).to.be(2);
          expect(ctx.tagresult.length).to.be(2);
        });
      });
    });
  });
});
开发者ID:GPegel,项目名称:grafana,代码行数:68,代码来源:playlist_edit_ctrl_specs.ts

示例4: describe

describe('ElasticDatasource', function() {
  var ctx = new helpers.ServiceTestContext();
  var instanceSettings: any = {jsonData: {}};

  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(ctx.providePhase(['templateSrv', 'backendSrv', 'timeSrv']));

  beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
    ctx.$q = $q;
    ctx.$httpBackend =  $httpBackend;
    ctx.$rootScope = $rootScope;
    ctx.$injector = $injector;
    $httpBackend.when('GET', /\.html$/).respond('');
  }));

  function createDatasource(instanceSettings) {
    instanceSettings.jsonData = instanceSettings.jsonData || {};
    ctx.ds = ctx.$injector.instantiate(ElasticDatasource, {instanceSettings: instanceSettings});
  }

  describe('When testing datasource with index pattern', function() {
    beforeEach(function() {
      createDatasource({url: 'http://es.com', index: '[asd-]YYYY.MM.DD', jsonData: {interval: 'Daily', esVersion: '2'}});
    });

    it('should translate index pattern to current day', function() {
      var requestOptions;
      ctx.backendSrv.datasourceRequest = function(options) {
        requestOptions = options;
        return ctx.$q.when({data: {}});
      };

      ctx.ds.testDatasource();
      ctx.$rootScope.$apply();

      var today = moment.utc().format("YYYY.MM.DD");
      expect(requestOptions.url).to.be("http://es.com/asd-" + today + '/_mapping');
    });
  });

  describe('When issueing metric query with interval pattern', function() {
    var requestOptions, parts, header;

    beforeEach(function() {
      createDatasource({url: 'http://es.com', index: '[asd-]YYYY.MM.DD', jsonData: {interval: 'Daily', esVersion: '2'}});

      ctx.backendSrv.datasourceRequest = function(options) {
        requestOptions = options;
        return ctx.$q.when({data: {responses: []}});
      };

      ctx.ds.query({
        range: {
          from: moment.utc([2015, 4, 30, 10]),
          to: moment.utc([2015, 5, 1, 10])
        },
        targets: [{ bucketAggs: [], metrics: [{type: 'raw_document'}], query: 'escape\\:test' }]
      });

      ctx.$rootScope.$apply();

      parts = requestOptions.data.split('\n');
      header = angular.fromJson(parts[0]);
    });

    it('should translate index pattern to current day', function() {
      expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
    });

    it('should json escape lucene query', function() {
      var body = angular.fromJson(parts[1]);
      expect(body.query.bool.filter[1].query_string.query).to.be('escape\\:test');
    });
  });

  describe('When issueing document query', function() {
    var requestOptions, parts, header;

    beforeEach(function() {
      createDatasource({url: 'http://es.com', index: 'test', jsonData: {esVersion: '2'}});

      ctx.backendSrv.datasourceRequest = function(options) {
        requestOptions = options;
        return ctx.$q.when({data: {responses: []}});
      };

      ctx.ds.query({
        range: { from: moment([2015, 4, 30, 10]), to: moment([2015, 5, 1, 10]) },
        targets: [{ bucketAggs: [], metrics: [{type: 'raw_document'}], query: 'test' }]
      });

      ctx.$rootScope.$apply();
      parts = requestOptions.data.split('\n');
      header = angular.fromJson(parts[0]);
    });

    it('should set search type to query_then_fetch', function() {
      expect(header.search_type).to.eql('query_then_fetch');
    });
//.........这里部分代码省略.........
开发者ID:casaria,项目名称:grafana-trillium-src-fork,代码行数:101,代码来源:datasource_specs.ts

示例5: describe

describe('DashboardModel', function() {

  describe('when creating new dashboard model defaults only', function() {
    var model;

    beforeEach(function() {
      model = new DashboardModel({}, {});
    });

    it('should have title', function() {
      expect(model.title).to.be('No Title');
    });

    it('should have meta', function() {
      expect(model.meta.canSave).to.be(true);
      expect(model.meta.canShare).to.be(true);
    });

    it('should have default properties', function() {
      expect(model.rows.length).to.be(0);
    });
  });

  describe('when getting next panel id', function() {
    var model;

    beforeEach(function() {
      model = new DashboardModel({
        rows: [{ panels: [{ id: 5 }]}]
      });
    });

    it('should return max id + 1', function() {
      expect(model.getNextPanelId()).to.be(6);
    });
  });

  describe('getSaveModelClone', function() {
    it('should sort keys', () => {
      var model = new DashboardModel({});
      var saveModel = model.getSaveModelClone();
      var keys = _.keys(saveModel);

      expect(keys[0]).to.be('addBuiltInAnnotationQuery');
      expect(keys[1]).to.be('addEmptyRow');
    });
  });

  describe('row and panel manipulation', function() {
    var dashboard;

    beforeEach(function() {
      dashboard = new DashboardModel({});
    });

    it('adding default should split span in half', function() {
      dashboard.addEmptyRow();
      dashboard.rows[0].addPanel({span: 12});
      dashboard.rows[0].addPanel({span: 12});

      expect(dashboard.rows[0].panels[0].span).to.be(6);
      expect(dashboard.rows[0].panels[1].span).to.be(6);
    });

    it('duplicate panel should try to add it to same row', function() {
      var panel = { span: 4, attr: '123', id: 10 };

      dashboard.addEmptyRow();
      dashboard.rows[0].addPanel(panel);
      dashboard.duplicatePanel(panel, dashboard.rows[0]);

      expect(dashboard.rows[0].panels[0].span).to.be(4);
      expect(dashboard.rows[0].panels[1].span).to.be(4);
      expect(dashboard.rows[0].panels[1].attr).to.be('123');
      expect(dashboard.rows[0].panels[1].id).to.be(11);
    });

    it('duplicate panel should remove repeat data', function() {
      var panel = { span: 4, attr: '123', id: 10, repeat: 'asd', scopedVars: { test: 'asd' }};

      dashboard.addEmptyRow();
      dashboard.rows[0].addPanel(panel);
      dashboard.duplicatePanel(panel, dashboard.rows[0]);

      expect(dashboard.rows[0].panels[1].repeat).to.be(undefined);
      expect(dashboard.rows[0].panels[1].scopedVars).to.be(undefined);
    });

  });

  describe('when creating dashboard with old schema', function() {
    var model;
    var graph;
    var singlestat;
    var table;

    beforeEach(function() {
      model = new DashboardModel({
        services: { filter: { time: { from: 'now-1d', to: 'now'}, list: [{}] }},
        pulldowns: [
//.........这里部分代码省略.........
开发者ID:PaulMest,项目名称:grafana,代码行数:101,代码来源:dashboard_model_specs.ts

示例6: describe

describe('QueryVariable', () => {

  describe('when creating from model', () => {

    it('should set defaults', () => {
      var variable = new QueryVariable({}, null, null, null, null, null);
      expect(variable.datasource).to.be(null);
      expect(variable.refresh).to.be(0);
      expect(variable.sort).to.be(0);
      expect(variable.name).to.be('');
      expect(variable.hide).to.be(0);
      expect(variable.options.length).to.be(0);
      expect(variable.multi).to.be(false);
      expect(variable.includeAll).to.be(false);
    });

    it('get model should copy changes back to model', () => {
      var variable = new QueryVariable({}, null, null, null, null, null);
      variable.options = [{text: 'test'}];
      variable.datasource = 'google';
      variable.regex = 'asd';
      variable.sort = 50;

      var model = variable.getSaveModel();
      expect(model.options.length).to.be(1);
      expect(model.options[0].text).to.be('test');
      expect(model.datasource).to.be('google');
      expect(model.regex).to.be('asd');
      expect(model.sort).to.be(50);
    });

    it('if refresh != 0 then remove options in presisted mode', () => {
      var variable = new QueryVariable({}, null, null, null, null, null);
      variable.options = [{text: 'test'}];
      variable.refresh = 1;

      var model = variable.getSaveModel();
      expect(model.options.length).to.be(0);
    });
  });

  describe('can convert and sort metric names',() => {
    var variable = new QueryVariable({}, null, null, null, null, null);
    variable.sort = 3; // Numerical (asc)

    describe('can sort a mixed array of metric variables', () => {
      var input = [
        {text: '0', value: '0'},
        {text: '1', value: '1'},
        {text: null, value: 3},
        {text: undefined, value: 4},
        {text: '5', value: null},
        {text: '6', value: undefined},
        {text: null, value: '7'},
        {text: undefined, value: '8'},
        {text: 9, value: null},
        {text: 10, value: undefined},
        {text: '', value: undefined},
        {text: undefined, value: ''},
      ];

      var result = variable.metricNamesToVariableValues(input);
      it('should return in same order', () => {
        var i = 0;

        expect(result.length).to.be(11);
        expect(result[i++].text).to.be('');
        expect(result[i++].text).to.be('0');
        expect(result[i++].text).to.be('1');
        expect(result[i++].text).to.be('3');
        expect(result[i++].text).to.be('4');
        expect(result[i++].text).to.be('5');
        expect(result[i++].text).to.be('6');
      });
    });
  });
});
开发者ID:postsql,项目名称:grafana,代码行数:77,代码来源:query_variable_specs.ts

示例7: describe

describe('graphiteDatasource', function() {
  var ctx = new helpers.ServiceTestContext();
  var instanceSettings: any = {url: [''], name: 'graphiteProd'};

  beforeEach(angularMocks.module('grafana.core'));
  beforeEach(angularMocks.module('grafana.services'));
  beforeEach(ctx.providePhase(['backendSrv']));
  beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
    ctx.$q = $q;
    ctx.$httpBackend =  $httpBackend;
    ctx.$rootScope = $rootScope;
    ctx.$injector = $injector;
    $httpBackend.when('GET', /\.html$/).respond('');
  }));

  beforeEach(function() {
    ctx.ds = ctx.$injector.instantiate(GraphiteDatasource, {instanceSettings: instanceSettings});
  });

  describe('When querying influxdb with one target using query editor target spec', function() {
    var query = {
      panelId: 3,
      rangeRaw: { from: 'now-1h', to: 'now' },
      targets: [{ target: 'prod1.count' }, {target: 'prod2.count'}],
      maxDataPoints: 500,
    };

    var results;
    var requestOptions;

    beforeEach(function() {
      ctx.backendSrv.datasourceRequest = function(options) {
        requestOptions = options;
        return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
      };

      ctx.ds.query(query).then(function(data) { results = data; });
      ctx.$rootScope.$apply();
    });

    it('should generate the correct query', function() {
      expect(requestOptions.url).to.be('/render');
    });

    it('should set unique requestId', function() {
      expect(requestOptions.requestId).to.be('graphiteProd.panelId.3');
    });

    it('should query correctly', function() {
      var params = requestOptions.data.split('&');
      expect(params).to.contain('target=prod1.count');
      expect(params).to.contain('target=prod2.count');
      expect(params).to.contain('from=-1h');
      expect(params).to.contain('until=now');
    });

    it('should exclude undefined params', function() {
      var params = requestOptions.data.split('&');
      expect(params).to.not.contain('cacheTimeout=undefined');
    });

    it('should return series list', function() {
      expect(results.data.length).to.be(1);
      expect(results.data[0].target).to.be('prod1.count');
    });

    it('should convert to millisecond resolution', function() {
      expect(results.data[0].datapoints[0][0]).to.be(10);
    });

  });

  describe('building graphite params', function() {
    it('should return empty array if no targets', function() {
      var results = ctx.ds.buildGraphiteParams({
        targets: [{}]
      });
      expect(results.length).to.be(0);
    });

    it('should uri escape targets', function() {
      var results = ctx.ds.buildGraphiteParams({
      targets: [{target: 'prod1.{test,test2}'}, {target: 'prod2.count'}]
      });
      expect(results).to.contain('target=prod1.%7Btest%2Ctest2%7D');
    });

    it('should replace target placeholder', function() {
      var results = ctx.ds.buildGraphiteParams({
      targets: [{target: 'series1'}, {target: 'series2'}, {target: 'asPercent(#A,#B)'}]
      });
      expect(results[2]).to.be('target=asPercent(series1%2Cseries2)');
    });

    it('should replace target placeholder for hidden series', function() {
      var results = ctx.ds.buildGraphiteParams({
      targets: [{target: 'series1', hide: true}, {target: 'sumSeries(#A)', hide: true}, {target: 'asPercent(#A,#B)'}]
      });
      expect(results[0]).to.be('target=' + encodeURIComponent('asPercent(series1,sumSeries(series1))'));
    });
//.........这里部分代码省略.........
开发者ID:IndianOnRun,项目名称:grafana,代码行数:101,代码来源:datasource_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() {
      expect(ctx.data.valueFormatted).to.be(moment(1505634997920).format('MM/DD/YYYY h:mm:ss a'));
    });
  });

  singleStatScenario('showing last time from now instead of value', function(ctx) {
    beforeEach(() => {
      clock = sinon.useFakeTimers(epoch);
    });

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

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

示例10: describe

describe('given dashboard with repeated panels', function() {
  var dash, exported;

  beforeEach(done => {
    dash = {
      rows: [],
      templating: { list: [] },
      annotations: { list: [] },
    };

    config.buildInfo = {
      version: "3.0.2"
    };

    dash.templating.list.push({
      name: 'apps',
      type: 'query',
      datasource: 'gfdb',
      current: {value: 'Asd', text: 'Asd'},
      options: [{value: 'Asd', text: 'Asd'}]
    });

    dash.templating.list.push({
      name: 'prefix',
      type: 'constant',
      current: {value: 'collectd', text: 'collectd'},
      options: []
    });

    dash.templating.list.push({
      name: 'ds',
      type: 'datasource',
      query: 'testdb',
      current: {value: 'prod', text: 'prod'},
      options: []
    });

    dash.annotations.list.push({
      name: 'logs',
      datasource: 'gfdb',
    });

    dash.rows.push({
      repeat: 'test',
      panels: [
        {id: 2, repeat: 'apps', datasource: 'gfdb', type: 'graph'},
        {id: 3, repeat: null, repeatPanelId: 2},
        {
          id: 4,
          datasource: '-- Mixed --',
          targets: [{datasource: 'other'}],
        },
        {id: 5, datasource: '$ds'},
      ]
    });

    dash.rows.push({
      repeat: null,
      repeatRowId: 1,
      panels: [],
    });

    var datasourceSrvStub = {get: sinon.stub()};
    datasourceSrvStub.get.withArgs('gfdb').returns(Promise.resolve({
      name: 'gfdb',
      meta: {id: "testdb", info: {version: "1.2.1"}, name: "TestDB"}
    }));
    datasourceSrvStub.get.withArgs('other').returns(Promise.resolve({
      name: 'other',
      meta: {id: "other", info: {version: "1.2.1"}, name: "OtherDB"}
    }));
    datasourceSrvStub.get.withArgs('-- Mixed --').returns(Promise.resolve({
      name: 'mixed',
      meta: {id: "mixed", info: {version: "1.2.1"}, name: "Mixed", builtIn: true}
    }));

    config.panels['graph'] = {
      id: "graph",
      name: "Graph",
      info: {version: "1.1.0"}
    };

    dash = new DashboardModel(dash, {});
    var exporter = new DashboardExporter(datasourceSrvStub);
    exporter.makeExportable(dash).then(clean => {
      exported = clean;
      done();
    });
  });

  it('exported dashboard should not contain repeated panels', function() {
    expect(exported.rows[0].panels.length).to.be(3);
  });

  it('exported dashboard should not contain repeated rows', function() {
    expect(exported.rows.length).to.be(1);
  });

  it('should replace datasource refs', function() {
    var panel = exported.rows[0].panels[0];
//.........这里部分代码省略.........
开发者ID:Sensetif,项目名称:grafana,代码行数:101,代码来源:exporter_specs.ts


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