timeSeries-specs.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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, pointradius, steppedLine', function() {
  63. beforeEach(function() {
  64. series.info.alias = 'test';
  65. series.applySeriesOverrides([{ alias: 'test', pointradius: 5, steppedLine: true }]);
  66. });
  67. it('should set pointradius, and set steppedLine', function() {
  68. expect(series.points.radius).to.be(5);
  69. expect(series.lines.steps).to.be(true);
  70. });
  71. });
  72. describe('override match on regex', function() {
  73. beforeEach(function() {
  74. series.info.alias = 'test_01';
  75. series.applySeriesOverrides([{ alias: '/.*01/', lines: false }]);
  76. });
  77. it('should match second series', function() {
  78. expect(series.lines.show).to.be(false);
  79. });
  80. });
  81. describe('override series y-axis, and z-index', function() {
  82. beforeEach(function() {
  83. series.info.alias = 'test';
  84. series.applySeriesOverrides([{ alias: 'test', yaxis: 2, zindex: 2 }]);
  85. });
  86. it('should set yaxis', function() {
  87. expect(series.info.yaxis).to.be(2);
  88. });
  89. it('should set zindex', function() {
  90. expect(series.zindex).to.be(2);
  91. });
  92. });
  93. });
  94. });
  95. });