threshold_manager_specs.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ///<reference path="../../../../headers/common.d.ts" />
  2. import {describe, beforeEach, it, sinon, expect, angularMocks} 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([
  27. {op: 'gt', value: 300, fill: true, line: true, colorMode: 'critical'},
  28. ]);
  29. it('should add fill for threshold with fill: true', function() {
  30. var markings = ctx.options.grid.markings;
  31. expect(markings[0].yaxis.from).to.be(300);
  32. expect(markings[0].yaxis.to).to.be(Infinity);
  33. expect(markings[0].color).to.be('rgba(234, 112, 112, 0.12)');
  34. });
  35. it('should add line', function() {
  36. var markings = ctx.options.grid.markings;
  37. expect(markings[1].yaxis.from).to.be(300);
  38. expect(markings[1].yaxis.to).to.be(300);
  39. expect(markings[1].color).to.be('rgba(237, 46, 24, 0.60)');
  40. });
  41. });
  42. plotOptionsScenario("for two gt thresholds", ctx => {
  43. ctx.setup([
  44. {op: 'gt', value: 200, fill: true, colorMode: 'warning'},
  45. {op: 'gt', value: 300, fill: true, colorMode: 'critical'},
  46. ]);
  47. it('should add fill for first thresholds to next threshold', function() {
  48. var markings = ctx.options.grid.markings;
  49. expect(markings[0].yaxis.from).to.be(200);
  50. expect(markings[0].yaxis.to).to.be(300);
  51. });
  52. it('should add fill for last thresholds to infinity', function() {
  53. var markings = ctx.options.grid.markings;
  54. expect(markings[1].yaxis.from).to.be(300);
  55. expect(markings[1].yaxis.to).to.be(Infinity);
  56. });
  57. });
  58. plotOptionsScenario("for lt then gt threshold (inside)", ctx => {
  59. ctx.setup([
  60. {op: 'lt', value: 300, fill: true, colorMode: 'critical'},
  61. {op: 'gt', value: 200, fill: true, colorMode: 'critical'},
  62. ]);
  63. it('should add fill for first thresholds to next threshold', function() {
  64. var markings = ctx.options.grid.markings;
  65. expect(markings[0].yaxis.from).to.be(300);
  66. expect(markings[0].yaxis.to).to.be(200);
  67. });
  68. it('should add fill for last thresholds to itself', function() {
  69. var markings = ctx.options.grid.markings;
  70. expect(markings[1].yaxis.from).to.be(200);
  71. expect(markings[1].yaxis.to).to.be(200);
  72. });
  73. });
  74. plotOptionsScenario("for gt then lt threshold (outside)", ctx => {
  75. ctx.setup([
  76. {op: 'gt', value: 300, fill: true, colorMode: 'critical'},
  77. {op: 'lt', value: 200, fill: true, colorMode: 'critical'},
  78. ]);
  79. it('should add fill for first thresholds to next threshold', function() {
  80. var markings = ctx.options.grid.markings;
  81. expect(markings[0].yaxis.from).to.be(300);
  82. expect(markings[0].yaxis.to).to.be(Infinity);
  83. });
  84. it('should add fill for last thresholds to itself', function() {
  85. var markings = ctx.options.grid.markings;
  86. expect(markings[1].yaxis.from).to.be(200);
  87. expect(markings[1].yaxis.to).to.be(-Infinity);
  88. });
  89. });
  90. });
  91. });