timeSeries-specs.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. define([
  2. 'components/timeSeries'
  3. ], function(TimeSeries) {
  4. 'use strict';
  5. describe("TimeSeries", function() {
  6. var points, series;
  7. var yAxisFormats = ['short', 'ms'];
  8. var testData = {
  9. info: { alias: 'test' },
  10. datapoints: [
  11. [1,2],[null,3],[10,4],[8,5]
  12. ]
  13. };
  14. describe('when getting flot pairs', function() {
  15. it('with connected style, should ignore nulls', function() {
  16. series = new TimeSeries(testData);
  17. points = series.getFlotPairs('connected', yAxisFormats);
  18. expect(points.length).to.be(3);
  19. });
  20. it('with null as zero style, should replace nulls with zero', function() {
  21. series = new TimeSeries(testData);
  22. points = series.getFlotPairs('null as zero', yAxisFormats);
  23. expect(points.length).to.be(4);
  24. expect(points[1][1]).to.be(0);
  25. });
  26. });
  27. describe('series overrides', function() {
  28. var series;
  29. beforeEach(function() {
  30. series = new TimeSeries(testData);
  31. });
  32. describe('fill & points', function() {
  33. beforeEach(function() {
  34. series.info.alias = 'test';
  35. series.applySeriesOverrides([{ alias: 'test', fill: 0, points: true }]);
  36. });
  37. it('should set fill zero, and enable points', function() {
  38. expect(series.lines.fill).to.be(0.001);
  39. expect(series.points.show).to.be(true);
  40. });
  41. });
  42. describe('series option overrides, bars, true & lines false', function() {
  43. beforeEach(function() {
  44. series.info.alias = 'test';
  45. series.applySeriesOverrides([{ alias: 'test', bars: true, lines: false }]);
  46. });
  47. it('should disable lines, and enable bars', function() {
  48. expect(series.lines.show).to.be(false);
  49. expect(series.bars.show).to.be(true);
  50. });
  51. });
  52. describe('series option overrides, linewidth, stack', function() {
  53. beforeEach(function() {
  54. series.info.alias = 'test';
  55. series.applySeriesOverrides([{ alias: 'test', linewidth: 5, stack: false }]);
  56. });
  57. it('should disable stack, and set lineWidth', function() {
  58. expect(series.stack).to.be(false);
  59. expect(series.lines.lineWidth).to.be(5);
  60. });
  61. });
  62. describe('series option overrides, fill below to', function() {
  63. beforeEach(function() {
  64. series.info.alias = 'test';
  65. series.applySeriesOverrides([{ alias: 'test', fillBelowTo: 'min' }]);
  66. });
  67. it('should disable line fill and add fillBelowTo', function() {
  68. expect(series.fillBelowTo).to.be('min');
  69. });
  70. });
  71. describe('series option overrides, pointradius, steppedLine', function() {
  72. beforeEach(function() {
  73. series.info.alias = 'test';
  74. series.applySeriesOverrides([{ alias: 'test', pointradius: 5, steppedLine: true }]);
  75. });
  76. it('should set pointradius, and set steppedLine', function() {
  77. expect(series.points.radius).to.be(5);
  78. expect(series.lines.steps).to.be(true);
  79. });
  80. });
  81. describe('override match on regex', function() {
  82. beforeEach(function() {
  83. series.info.alias = 'test_01';
  84. series.applySeriesOverrides([{ alias: '/.*01/', lines: false }]);
  85. });
  86. it('should match second series', function() {
  87. expect(series.lines.show).to.be(false);
  88. });
  89. });
  90. describe('override series y-axis, and z-index', function() {
  91. beforeEach(function() {
  92. series.info.alias = 'test';
  93. series.applySeriesOverrides([{ alias: 'test', yaxis: 2, zindex: 2 }]);
  94. });
  95. it('should set yaxis', function() {
  96. expect(series.info.yaxis).to.be(2);
  97. });
  98. it('should set zindex', function() {
  99. expect(series.zindex).to.be(2);
  100. });
  101. });
  102. });
  103. });
  104. });