utils.spec.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {DEFAULT_STATS_PERIOD} from 'app/constants';
  2. import {getParams} from 'app/views/organizationEvents/utils';
  3. describe('OrganizationEvents utils', function() {
  4. describe('getParams', function() {
  5. it('has a default `statsPeriod` by default', function() {
  6. expect(getParams()).toEqual({
  7. statsPeriod: DEFAULT_STATS_PERIOD,
  8. });
  9. });
  10. it('transforms `period` parameter to `statsPeriod`', function() {
  11. expect(getParams({period: '24h'})).toEqual({
  12. statsPeriod: '24h',
  13. });
  14. });
  15. it('can be passed `statsPeriod` instead of `period`', function() {
  16. expect(
  17. getParams({
  18. statsPeriod: '24h',
  19. })
  20. ).toEqual({
  21. statsPeriod: '24h',
  22. });
  23. });
  24. it('prefers `statsPeriod` over `period`', function() {
  25. expect(
  26. getParams({
  27. statsPeriod: '24h',
  28. period: '2h',
  29. })
  30. ).toEqual({
  31. statsPeriod: '24h',
  32. });
  33. });
  34. it('only returns `statsPeriod` if absolute range is supplied as well', function() {
  35. // NOTE: This is an arbitrary decision, change as needed
  36. expect(getParams({start: 'start', end: 'end', period: '24h'})).toEqual({
  37. statsPeriod: '24h',
  38. });
  39. });
  40. it('does not change other parameters', function() {
  41. expect(getParams({foo: 'bar', period: '24h'})).toEqual({
  42. foo: 'bar',
  43. statsPeriod: '24h',
  44. });
  45. });
  46. it('filters out only null and undefined, values', function() {
  47. expect(
  48. getParams({
  49. foo: null,
  50. bar: 0,
  51. start: null,
  52. period: '24h',
  53. })
  54. ).toEqual({
  55. bar: 0,
  56. statsPeriod: '24h',
  57. });
  58. });
  59. });
  60. });