threshold_manager_specs.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ///<reference path="../../../../headers/common.d.ts" />
  2. import { describe, it, expect } from '../../../../../test/lib/common';
  3. import { ThresholdManager } from '../threshold_manager';
  4. describe('ThresholdManager', function() {
  5. function plotOptionsScenario(desc, func) {
  6. describe(desc, function() {
  7. var ctx: any = {
  8. panel: {
  9. thresholds: [],
  10. },
  11. options: {
  12. grid: { markings: [] },
  13. },
  14. panelCtrl: {},
  15. };
  16. ctx.setup = function(thresholds) {
  17. ctx.panel.thresholds = thresholds;
  18. var manager = new ThresholdManager(ctx.panelCtrl);
  19. manager.addFlotOptions(ctx.options, ctx.panel);
  20. };
  21. func(ctx);
  22. });
  23. }
  24. describe('When creating plot markings', () => {
  25. plotOptionsScenario('for simple gt threshold', ctx => {
  26. ctx.setup([{ op: 'gt', value: 300, fill: true, line: true, colorMode: 'critical' }]);
  27. it('should add fill for threshold with fill: true', function() {
  28. var markings = ctx.options.grid.markings;
  29. expect(markings[0].yaxis.from).to.be(300);
  30. expect(markings[0].yaxis.to).to.be(Infinity);
  31. expect(markings[0].color).to.be('rgba(234, 112, 112, 0.12)');
  32. });
  33. it('should add line', function() {
  34. var markings = ctx.options.grid.markings;
  35. expect(markings[1].yaxis.from).to.be(300);
  36. expect(markings[1].yaxis.to).to.be(300);
  37. expect(markings[1].color).to.be('rgba(237, 46, 24, 0.60)');
  38. });
  39. });
  40. plotOptionsScenario('for two gt thresholds', ctx => {
  41. ctx.setup([
  42. { op: 'gt', value: 200, fill: true, colorMode: 'warning' },
  43. { op: 'gt', value: 300, fill: true, colorMode: 'critical' },
  44. ]);
  45. it('should add fill for first thresholds to next threshold', function() {
  46. var markings = ctx.options.grid.markings;
  47. expect(markings[0].yaxis.from).to.be(200);
  48. expect(markings[0].yaxis.to).to.be(300);
  49. });
  50. it('should add fill for last thresholds to infinity', function() {
  51. var markings = ctx.options.grid.markings;
  52. expect(markings[1].yaxis.from).to.be(300);
  53. expect(markings[1].yaxis.to).to.be(Infinity);
  54. });
  55. });
  56. plotOptionsScenario('for lt then gt threshold (inside)', ctx => {
  57. ctx.setup([
  58. { op: 'lt', value: 300, fill: true, colorMode: 'critical' },
  59. { op: 'gt', value: 200, fill: true, colorMode: 'critical' },
  60. ]);
  61. it('should add fill for first thresholds to next threshold', function() {
  62. var markings = ctx.options.grid.markings;
  63. expect(markings[0].yaxis.from).to.be(300);
  64. expect(markings[0].yaxis.to).to.be(200);
  65. });
  66. it('should add fill for last thresholds to itself', function() {
  67. var markings = ctx.options.grid.markings;
  68. expect(markings[1].yaxis.from).to.be(200);
  69. expect(markings[1].yaxis.to).to.be(200);
  70. });
  71. });
  72. plotOptionsScenario('for gt then lt threshold (outside)', ctx => {
  73. ctx.setup([
  74. { op: 'gt', value: 300, fill: true, colorMode: 'critical' },
  75. { op: 'lt', value: 200, fill: true, colorMode: 'critical' },
  76. ]);
  77. it('should add fill for first thresholds to next threshold', function() {
  78. var markings = ctx.options.grid.markings;
  79. expect(markings[0].yaxis.from).to.be(300);
  80. expect(markings[0].yaxis.to).to.be(Infinity);
  81. });
  82. it('should add fill for last thresholds to itself', function() {
  83. var markings = ctx.options.grid.markings;
  84. expect(markings[1].yaxis.from).to.be(200);
  85. expect(markings[1].yaxis.to).to.be(-Infinity);
  86. });
  87. });
  88. });
  89. });