utils.spec.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {getInterval, getDiffInMinutes} from 'app/components/charts/utils';
  2. describe('Chart Utils', function() {
  3. describe('getInterval()', function() {
  4. describe('with high fidelity', function() {
  5. it('greater than 24 hours', function() {
  6. expect(getInterval({period: '25h'}, true)).toBe('30m');
  7. });
  8. it('less than 30 minutes', function() {
  9. expect(getInterval({period: '20m'}, true)).toBe('1m');
  10. });
  11. it('between 30 minutes and 24 hours', function() {
  12. expect(getInterval({period: '12h'}, true)).toBe('5m');
  13. });
  14. });
  15. describe('with low fidelity', function() {
  16. it('greater than 24 hours', function() {
  17. expect(getInterval({period: '25h'})).toBe('24h');
  18. });
  19. it('less than 30 minutes', function() {
  20. expect(getInterval({period: '20m'})).toBe('5m');
  21. });
  22. it('between 30 minutes and 24 hours', function() {
  23. expect(getInterval({period: '12h'})).toBe('15m');
  24. });
  25. });
  26. });
  27. describe('getDiffInMinutes()', function() {
  28. describe('with period string', function() {
  29. it('can parse a period string in seconds', function() {
  30. expect(getDiffInMinutes({period: '30s'})).toBe(0.5);
  31. });
  32. it('can parse a period string in minutes', function() {
  33. expect(getDiffInMinutes({period: '15m'})).toBe(15);
  34. });
  35. it('can parse a period string in hours', function() {
  36. expect(getDiffInMinutes({period: '1h'})).toBe(60);
  37. });
  38. it('can parse a period string in days', function() {
  39. expect(getDiffInMinutes({period: '5d'})).toBe(7200);
  40. });
  41. it('can parse a period string in weeks', function() {
  42. expect(getDiffInMinutes({period: '1w'})).toBe(10080);
  43. });
  44. });
  45. // This uses moment so we probably don't need to test it too extensively
  46. describe('with absolute dates', function() {});
  47. });
  48. });