threshold_mapper_specs.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { describe, it, expect } from "test/lib/common";
  2. import { ThresholdMapper } from "../threshold_mapper";
  3. describe("ThresholdMapper", () => {
  4. describe("with greater than evaluator", () => {
  5. it("can mapp query conditions to thresholds", () => {
  6. var panel: any = {
  7. type: "graph",
  8. alert: {
  9. conditions: [
  10. {
  11. type: "query",
  12. evaluator: { type: "gt", params: [100] }
  13. }
  14. ]
  15. }
  16. };
  17. var updated = ThresholdMapper.alertToGraphThresholds(panel);
  18. expect(updated).to.be(true);
  19. expect(panel.thresholds[0].op).to.be("gt");
  20. expect(panel.thresholds[0].value).to.be(100);
  21. });
  22. });
  23. describe("with outside range evaluator", () => {
  24. it("can mapp query conditions to thresholds", () => {
  25. var panel: any = {
  26. type: "graph",
  27. alert: {
  28. conditions: [
  29. {
  30. type: "query",
  31. evaluator: { type: "outside_range", params: [100, 200] }
  32. }
  33. ]
  34. }
  35. };
  36. var updated = ThresholdMapper.alertToGraphThresholds(panel);
  37. expect(updated).to.be(true);
  38. expect(panel.thresholds[0].op).to.be("lt");
  39. expect(panel.thresholds[0].value).to.be(100);
  40. expect(panel.thresholds[1].op).to.be("gt");
  41. expect(panel.thresholds[1].value).to.be(200);
  42. });
  43. });
  44. describe("with inside range evaluator", () => {
  45. it("can mapp query conditions to thresholds", () => {
  46. var panel: any = {
  47. type: "graph",
  48. alert: {
  49. conditions: [
  50. {
  51. type: "query",
  52. evaluator: { type: "within_range", params: [100, 200] }
  53. }
  54. ]
  55. }
  56. };
  57. var updated = ThresholdMapper.alertToGraphThresholds(panel);
  58. expect(updated).to.be(true);
  59. expect(panel.thresholds[0].op).to.be("gt");
  60. expect(panel.thresholds[0].value).to.be(100);
  61. expect(panel.thresholds[1].op).to.be("lt");
  62. expect(panel.thresholds[1].value).to.be(200);
  63. });
  64. });
  65. });