chartUtils.spec.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {fitToValueRect} from 'sentry/views/ddm/chart/chartUtils';
  2. describe('fitToValueRect', () => {
  3. it('should return original x and y if rect is undefined', () => {
  4. const x = 5;
  5. const y = 10;
  6. const rect = undefined;
  7. const result = fitToValueRect(x, y, rect);
  8. expect(result).toEqual([x, y]);
  9. });
  10. it('should return original x and y if they are within the value rect', () => {
  11. const x = 5;
  12. const y = 10;
  13. const rect = {xMin: 0, xMax: 10, yMin: 0, yMax: 20};
  14. const result = fitToValueRect(x, y, rect);
  15. expect(result).toEqual([x, y]);
  16. });
  17. it('should return x as xMin if it is below the minimum xValue', () => {
  18. const x = -5;
  19. const y = 10;
  20. const rect = {xMin: 0, xMax: 10, yMin: 0, yMax: 20};
  21. const result = fitToValueRect(x, y, rect);
  22. expect(result).toEqual([rect.xMin, y]);
  23. });
  24. it('should return x as xMax if it is above the maximum xValue', () => {
  25. const x = 15;
  26. const y = 10;
  27. const rect = {xMin: 0, xMax: 10, yMin: 0, yMax: 20};
  28. const result = fitToValueRect(x, y, rect);
  29. expect(result).toEqual([rect.xMax, y]);
  30. });
  31. it('should return y as yMin if it is below the minimum yValue', () => {
  32. const x = 5;
  33. const y = -5;
  34. const rect = {xMin: 0, xMax: 10, yMin: 0, yMax: 20};
  35. const result = fitToValueRect(x, y, rect);
  36. expect(result).toEqual([x, rect.yMin]);
  37. });
  38. it('should return y as yMax if it is above the maximum yValue', () => {
  39. const x = 5;
  40. const y = 25;
  41. const rect = {xMin: 0, xMax: 10, yMin: 0, yMax: 20};
  42. const result = fitToValueRect(x, y, rect);
  43. expect(result).toEqual([x, rect.yMax]);
  44. });
  45. });