grafanaGraph-specs.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. define([
  2. './helpers',
  3. 'angular',
  4. 'jquery',
  5. 'components/timeSeries',
  6. 'directives/grafanaGraph'
  7. ], function(helpers, angular, $, TimeSeries) {
  8. 'use strict';
  9. describe('grafanaGraph', function() {
  10. beforeEach(module('grafana.directives'));
  11. function graphScenario(desc, func) {
  12. describe(desc, function() {
  13. var ctx = {};
  14. ctx.setup = function (setupFunc) {
  15. beforeEach(module(function($provide) {
  16. $provide.value("timeSrv", new helpers.TimeSrvStub());
  17. }));
  18. beforeEach(inject(function($rootScope, $compile) {
  19. var scope = $rootScope.$new();
  20. var element = angular.element("<div style='width:500px' grafana-graph><div>");
  21. scope.height = '200px';
  22. scope.panel = {
  23. legend: {},
  24. grid: {},
  25. y_formats: [],
  26. seriesOverrides: []
  27. };
  28. scope.dashboard = { timezone: 'browser' };
  29. scope.range = {
  30. from: new Date('2014-08-09 10:00:00'),
  31. to: new Date('2014-09-09 13:00:00')
  32. };
  33. ctx.data = [];
  34. ctx.data.push(new TimeSeries({
  35. datapoints: [[1,1],[2,2]],
  36. info: { alias: 'series1', enable: true }
  37. }));
  38. ctx.data.push(new TimeSeries({
  39. datapoints: [[1,1],[2,2]],
  40. info: { alias: 'series2', enable: true }
  41. }));
  42. setupFunc(scope, ctx.data);
  43. $compile(element)(scope);
  44. scope.$digest();
  45. $.plot = ctx.plotSpy = sinon.spy();
  46. scope.$emit('render', ctx.data);
  47. ctx.plotData = ctx.plotSpy.getCall(0).args[1];
  48. ctx.plotOptions = ctx.plotSpy.getCall(0).args[2];
  49. }));
  50. };
  51. func(ctx);
  52. });
  53. }
  54. graphScenario('simple lines options', function(ctx) {
  55. ctx.setup(function(scope) {
  56. scope.panel.lines = true;
  57. scope.panel.fill = 5;
  58. scope.panel.linewidth = 3;
  59. scope.panel.steppedLine = true;
  60. });
  61. it('should configure plot with correct options', function() {
  62. expect(ctx.plotOptions.series.lines.show).to.be(true);
  63. expect(ctx.plotOptions.series.lines.fill).to.be(0.5);
  64. expect(ctx.plotOptions.series.lines.lineWidth).to.be(3);
  65. expect(ctx.plotOptions.series.lines.steps).to.be(true);
  66. });
  67. });
  68. graphScenario('grid thresholds 100, 200', function(ctx) {
  69. ctx.setup(function(scope) {
  70. scope.panel.grid = {
  71. threshold1: 100,
  72. threshold1Color: "#111",
  73. threshold2: 200,
  74. threshold2Color: "#222",
  75. };
  76. });
  77. it('should add grid markings', function() {
  78. var markings = ctx.plotOptions.grid.markings;
  79. expect(markings[0].yaxis.from).to.be(100);
  80. expect(markings[0].yaxis.to).to.be(200);
  81. expect(markings[0].color).to.be('#111');
  82. expect(markings[1].yaxis.from).to.be(200);
  83. expect(markings[1].yaxis.to).to.be(Infinity);
  84. });
  85. });
  86. graphScenario('inverted grid thresholds 200, 100', function(ctx) {
  87. ctx.setup(function(scope) {
  88. scope.panel.grid = {
  89. threshold1: 200,
  90. threshold1Color: "#111",
  91. threshold2: 100,
  92. threshold2Color: "#222",
  93. };
  94. });
  95. it('should add grid markings', function() {
  96. var markings = ctx.plotOptions.grid.markings;
  97. expect(markings[0].yaxis.from).to.be(200);
  98. expect(markings[0].yaxis.to).to.be(100);
  99. expect(markings[0].color).to.be('#111');
  100. expect(markings[1].yaxis.from).to.be(100);
  101. expect(markings[1].yaxis.to).to.be(-Infinity);
  102. });
  103. });
  104. graphScenario('series option overrides, fill & points', function(ctx) {
  105. ctx.setup(function(scope, data) {
  106. scope.panel.lines = true;
  107. scope.panel.fill = 5;
  108. scope.panel.seriesOverrides = [
  109. { alias: 'test', fill: 0, points: true }
  110. ];
  111. data[1].info.alias = 'test';
  112. });
  113. it('should match second series and fill zero, and enable points', function() {
  114. expect(ctx.plotOptions.series.lines.fill).to.be(0.5);
  115. expect(ctx.plotData[1].lines.fill).to.be(0.001);
  116. expect(ctx.plotData[1].points.show).to.be(true);
  117. });
  118. });
  119. graphScenario('should order series order according to zindex', function(ctx) {
  120. ctx.setup(function(scope) {
  121. scope.panel.seriesOverrides = [{ alias: 'series1', zindex: 2 }];
  122. });
  123. it('should move zindex 2 last', function() {
  124. expect(ctx.plotData[0].info.alias).to.be('series2');
  125. expect(ctx.plotData[1].info.alias).to.be('series1');
  126. });
  127. });
  128. });
  129. });