grafanaGraph-specs.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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(inject(function($rootScope, $compile) {
  16. var scope = $rootScope.$new();
  17. var element = angular.element("<div style='width:500px' grafana-graph><div>");
  18. scope.height = '200px';
  19. scope.panel = {
  20. legend: {},
  21. grid: {},
  22. y_formats: [],
  23. seriesOverrides: []
  24. };
  25. scope.dashboard = { timezone: 'browser' };
  26. scope.range = {
  27. from: new Date('2014-08-09 10:00:00'),
  28. to: new Date('2014-09-09 13:00:00')
  29. };
  30. ctx.data = [];
  31. ctx.data.push(new TimeSeries({
  32. datapoints: [[1,1],[2,2]],
  33. info: { alias: 'series1', enable: true }
  34. }));
  35. ctx.data.push(new TimeSeries({
  36. datapoints: [[1,1],[2,2]],
  37. info: { alias: 'series2', enable: true }
  38. }));
  39. setupFunc(scope, ctx.data);
  40. $compile(element)(scope);
  41. scope.$digest();
  42. $.plot = ctx.plotSpy = sinon.spy();
  43. scope.$emit('render', ctx.data);
  44. ctx.plotData = ctx.plotSpy.getCall(0).args[1];
  45. ctx.plotOptions = ctx.plotSpy.getCall(0).args[2];
  46. }));
  47. };
  48. func(ctx);
  49. });
  50. }
  51. graphScenario('simple lines options', function(ctx) {
  52. ctx.setup(function(scope) {
  53. scope.panel.lines = true;
  54. scope.panel.fill = 5;
  55. scope.panel.linewidth = 3;
  56. scope.panel.steppedLine = true;
  57. });
  58. it('should configure plot with correct options', function() {
  59. expect(ctx.plotOptions.series.lines.show).to.be(true);
  60. expect(ctx.plotOptions.series.lines.fill).to.be(0.5);
  61. expect(ctx.plotOptions.series.lines.lineWidth).to.be(3);
  62. expect(ctx.plotOptions.series.lines.steps).to.be(true);
  63. });
  64. });
  65. graphScenario('series option overrides, fill & points', function(ctx) {
  66. ctx.setup(function(scope, data) {
  67. scope.panel.lines = true;
  68. scope.panel.fill = 5;
  69. scope.panel.seriesOverrides = [
  70. { alias: 'test', fill: 0, points: true }
  71. ];
  72. data[1].info.alias = 'test';
  73. });
  74. it('should match second series and fill zero, and enable points', function() {
  75. expect(ctx.plotOptions.series.lines.fill).to.be(0.5);
  76. expect(ctx.plotData[1].lines.fill).to.be(0.001);
  77. expect(ctx.plotData[1].points.show).to.be(true);
  78. });
  79. });
  80. graphScenario('series option overrides, bars, true & lines false', function(ctx) {
  81. ctx.setup(function(scope, data) {
  82. scope.panel.lines = true;
  83. scope.panel.seriesOverrides = [
  84. { alias: 'test', bars: true, lines: false }
  85. ];
  86. data[1].info.alias = 'test';
  87. });
  88. it('should match second series and disable lines, and enable bars', function() {
  89. expect(ctx.plotOptions.series.lines.show).to.be(true);
  90. expect(ctx.plotData[1].lines.show).to.be(false);
  91. expect(ctx.plotData[1].bars.show).to.be(true);
  92. });
  93. });
  94. });
  95. });