singlestat_panel.test.ts 1.8 KB

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