singlestat_panel_spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { describe, it, expect } from "test/lib/common";
  2. import { getColorForValue } from "../module";
  3. describe("grafanaSingleStat", function() {
  4. describe("legacy thresholds", () => {
  5. describe("positive thresholds", () => {
  6. var data: any = {
  7. colorMap: ["green", "yellow", "red"],
  8. thresholds: [20, 50]
  9. };
  10. it("5 should return green", () => {
  11. expect(getColorForValue(data, 5)).to.be("green");
  12. });
  13. it("19.9 should return green", () => {
  14. expect(getColorForValue(data, 19.9)).to.be("green");
  15. });
  16. it("20 should return yellow", () => {
  17. expect(getColorForValue(data, 20)).to.be("yellow");
  18. });
  19. it("20.1 should return yellow", () => {
  20. expect(getColorForValue(data, 20.1)).to.be("yellow");
  21. });
  22. it("25 should return yellow", () => {
  23. expect(getColorForValue(data, 25)).to.be("yellow");
  24. });
  25. it("50 should return red", () => {
  26. expect(getColorForValue(data, 50)).to.be("red");
  27. });
  28. it("55 should return red", () => {
  29. expect(getColorForValue(data, 55)).to.be("red");
  30. });
  31. });
  32. });
  33. describe("negative thresholds", () => {
  34. var data: any = {
  35. colorMap: ["green", "yellow", "red"],
  36. thresholds: [0, 20]
  37. };
  38. it("-30 should return green", () => {
  39. expect(getColorForValue(data, -30)).to.be("green");
  40. });
  41. it("1 should return green", () => {
  42. expect(getColorForValue(data, 1)).to.be("yellow");
  43. });
  44. it("22 should return green", () => {
  45. expect(getColorForValue(data, 22)).to.be("red");
  46. });
  47. });
  48. describe("negative thresholds", () => {
  49. var data: any = {
  50. colorMap: ["green", "yellow", "red"],
  51. thresholds: [-27, 20]
  52. };
  53. it("-30 should return green", () => {
  54. expect(getColorForValue(data, -26)).to.be("yellow");
  55. });
  56. });
  57. });