getRefreshFromUrl.test.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { getRefreshFromUrl } from './getRefreshFromUrl';
  2. describe('getRefreshFromUrl', () => {
  3. describe('when refresh is not part of params', () => {
  4. it('then it should return current refresh value', () => {
  5. const currentRefresh = false;
  6. const minRefreshInterval = '5s';
  7. const isAllowedIntervalFn = () => false;
  8. const actual = getRefreshFromUrl({
  9. urlRefresh: null,
  10. currentRefresh,
  11. minRefreshInterval,
  12. isAllowedIntervalFn,
  13. });
  14. expect(actual).toBe(false);
  15. });
  16. });
  17. describe('when refresh is part of params', () => {
  18. describe('and refresh is an existing and valid interval', () => {
  19. it('then it should return the refresh value', () => {
  20. const currentRefresh = '';
  21. const minRefreshInterval = '5s';
  22. const isAllowedIntervalFn = () => true;
  23. const refreshIntervals = ['5s', '10s', '30s'];
  24. const actual = getRefreshFromUrl({
  25. urlRefresh: '10s',
  26. currentRefresh,
  27. minRefreshInterval,
  28. isAllowedIntervalFn,
  29. refreshIntervals,
  30. });
  31. expect(actual).toBe('10s');
  32. });
  33. });
  34. it.each`
  35. refresh | isAllowedInterval | minRefreshInterval | refreshIntervals | expected
  36. ${'6s'} | ${true} | ${'1s'} | ${['5s', '6s', '10s', '30s']} | ${'6s'}
  37. ${'6s'} | ${true} | ${'10s'} | ${['5s', '10s', '30s']} | ${'10s'}
  38. ${'6s'} | ${true} | ${'1s'} | ${['5s', '10s', '30s']} | ${'5s'}
  39. ${'6s'} | ${true} | ${'1s'} | ${undefined} | ${'5s'}
  40. ${'6s'} | ${true} | ${'10s'} | ${undefined} | ${'10s'}
  41. ${'6s'} | ${true} | ${'1s'} | ${[]} | ${'currentRefresh'}
  42. ${'6s'} | ${true} | ${'10s'} | ${[]} | ${'currentRefresh'}
  43. ${'6s'} | ${false} | ${'1s'} | ${['5s', '6s', '10s', '30s']} | ${'5s'}
  44. ${'6s'} | ${false} | ${'10s'} | ${['5s', '6s', '10s', '30s']} | ${'10s'}
  45. ${'6s'} | ${false} | ${'1s'} | ${['5s', '10s', '30s']} | ${'5s'}
  46. ${'6s'} | ${false} | ${'10s'} | ${['5s', '10s', '30s']} | ${'10s'}
  47. ${'6s'} | ${false} | ${'1s'} | ${undefined} | ${'5s'}
  48. ${'6s'} | ${false} | ${'10s'} | ${undefined} | ${'10s'}
  49. ${'6s'} | ${false} | ${'1s'} | ${[]} | ${'currentRefresh'}
  50. ${'6s'} | ${false} | ${'10s'} | ${[]} | ${'currentRefresh'}
  51. `(
  52. 'when called with refresh:{$refresh}, isAllowedInterval:{$isAllowedInterval}, minRefreshInterval:{$minRefreshInterval}, refreshIntervals:{$refreshIntervals} then it should return: $expected',
  53. ({ refresh, isAllowedInterval, minRefreshInterval, refreshIntervals, expected }) => {
  54. const actual = getRefreshFromUrl({
  55. urlRefresh: refresh,
  56. currentRefresh: 'currentRefresh',
  57. minRefreshInterval,
  58. isAllowedIntervalFn: () => isAllowedInterval,
  59. refreshIntervals,
  60. });
  61. expect(actual).toBe(expected);
  62. }
  63. );
  64. });
  65. });