threshold_manager_specs.ts 3.5 KB

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