graph_ctrl_specs.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ///<reference path="../../../../headers/common.d.ts" />
  2. import {describe, beforeEach, it, sinon, expect, angularMocks} from '../../../../../test/lib/common';
  3. import angular from 'angular';
  4. import {GraphCtrl} from '../module';
  5. import helpers from '../../../../../test/specs/helpers';
  6. describe('GraphCtrl', function() {
  7. var ctx = new helpers.ControllerTestContext();
  8. beforeEach(angularMocks.module('grafana.services'));
  9. beforeEach(angularMocks.module('grafana.controllers'));
  10. beforeEach(ctx.providePhase());
  11. beforeEach(ctx.createPanelController(GraphCtrl));
  12. describe('get_data with 2 series', function() {
  13. beforeEach(function() {
  14. ctx.annotationsSrv.getAnnotations = sinon.stub().returns(ctx.$q.when([]));
  15. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  16. data: [
  17. { target: 'test.cpu1', datapoints: [[1, 10]]},
  18. { target: 'test.cpu2', datapoints: [[1, 10]]}
  19. ]
  20. }));
  21. ctx.ctrl.render = sinon.spy();
  22. ctx.ctrl.refreshData(ctx.datasource);
  23. ctx.scope.$digest();
  24. });
  25. it('should send time series to render', function() {
  26. var data = ctx.ctrl.render.getCall(0).args[0];
  27. expect(data.length).to.be(2);
  28. });
  29. describe('get_data failure following success', function() {
  30. beforeEach(function() {
  31. ctx.datasource.query = sinon.stub().returns(ctx.$q.reject('Datasource Error'));
  32. ctx.ctrl.refreshData(ctx.datasource);
  33. ctx.scope.$digest();
  34. });
  35. });
  36. });
  37. describe('msResolution with second resolution timestamps', function() {
  38. beforeEach(function() {
  39. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  40. data: [
  41. { target: 'test.cpu1', datapoints: [[1234567890, 45], [1234567899, 60]]},
  42. { target: 'test.cpu2', datapoints: [[1236547890, 55], [1234456709, 90]]}
  43. ]
  44. }));
  45. ctx.ctrl.panel.tooltip.msResolution = false;
  46. ctx.ctrl.refreshData(ctx.datasource);
  47. ctx.scope.$digest();
  48. });
  49. it('should not show millisecond resolution tooltip', function() {
  50. expect(ctx.ctrl.panel.tooltip.msResolution).to.be(false);
  51. });
  52. });
  53. describe('msResolution with millisecond resolution timestamps', function() {
  54. beforeEach(function() {
  55. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  56. data: [
  57. { target: 'test.cpu1', datapoints: [[1234567890000, 45], [1234567899000, 60]]},
  58. { target: 'test.cpu2', datapoints: [[1236547890001, 55], [1234456709000, 90]]}
  59. ]
  60. }));
  61. ctx.ctrl.panel.tooltip.msResolution = false;
  62. ctx.ctrl.refreshData(ctx.datasource);
  63. ctx.scope.$digest();
  64. });
  65. it('should show millisecond resolution tooltip', function() {
  66. expect(ctx.ctrl.panel.tooltip.msResolution).to.be(true);
  67. });
  68. });
  69. describe('msResolution with millisecond resolution timestamps but with trailing zeroes', function() {
  70. beforeEach(function() {
  71. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  72. data: [
  73. { target: 'test.cpu1', datapoints: [[1234567890000, 45], [1234567899000, 60]]},
  74. { target: 'test.cpu2', datapoints: [[1236547890000, 55], [1234456709000, 90]]}
  75. ]
  76. }));
  77. ctx.ctrl.panel.tooltip.msResolution = false;
  78. ctx.ctrl.refreshData(ctx.datasource);
  79. ctx.scope.$digest();
  80. });
  81. it('should not show millisecond resolution tooltip', function() {
  82. expect(ctx.ctrl.panel.tooltip.msResolution).to.be(false);
  83. });
  84. });
  85. describe('msResolution with millisecond resolution timestamps in one of the series', function() {
  86. beforeEach(function() {
  87. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  88. data: [
  89. { target: 'test.cpu1', datapoints: [[1234567890000, 45], [1234567899000, 60]]},
  90. { target: 'test.cpu2', datapoints: [[1236547890010, 55], [1234456709000, 90]]},
  91. { target: 'test.cpu3', datapoints: [[1236547890000, 65], [1234456709000, 120]]}
  92. ]
  93. }));
  94. ctx.ctrl.panel.tooltip.msResolution = false;
  95. ctx.ctrl.refreshData(ctx.datasource);
  96. ctx.scope.$digest();
  97. });
  98. it('should show millisecond resolution tooltip', function() {
  99. expect(ctx.ctrl.panel.tooltip.msResolution).to.be(true);
  100. });
  101. });
  102. });