utils.spec.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {isSelectionEqual} from 'sentry/components/organizations/pageFilters/utils';
  2. describe('isSelectionEqual', function () {
  3. const base = {
  4. projects: [1, 2],
  5. environments: ['prod'],
  6. datetime: {
  7. period: '14d',
  8. start: new Date(2021, 0, 28, 12, 13, 14),
  9. end: new Date(2021, 0, 28, 23, 59, 59),
  10. utc: null,
  11. },
  12. };
  13. it('compares projects', function () {
  14. let changed = {...base, projects: [1]};
  15. expect(isSelectionEqual(base, changed)).toBe(false);
  16. changed = {...base, projects: []};
  17. expect(isSelectionEqual(base, changed)).toBe(false);
  18. changed = {...base, projects: [2, 3, 4]};
  19. expect(isSelectionEqual(base, changed)).toBe(false);
  20. });
  21. it('compares environments', function () {
  22. let changed = {...base, environments: ['staging']};
  23. expect(isSelectionEqual(base, changed)).toBe(false);
  24. changed = {...base, projects: []};
  25. expect(isSelectionEqual(base, changed)).toBe(false);
  26. changed = {...base, projects: ['prod', 'staging']};
  27. expect(isSelectionEqual(base, changed)).toBe(false);
  28. });
  29. it('compares period', function () {
  30. const changed = {...base};
  31. changed.datetime.period = '7d';
  32. expect(isSelectionEqual(base, changed)).toBe(true);
  33. });
  34. it('compares start/end safely', function () {
  35. // Same datetime but different object.
  36. const changed = {
  37. ...base,
  38. datetime: {...base.datetime, start: null, end: null},
  39. };
  40. expect(isSelectionEqual(base, changed)).toBe(false);
  41. });
  42. it('compares start/end as value', function () {
  43. // Same datetime but different object.
  44. let changed = {
  45. ...base,
  46. datetime: {...base.datetime, start: new Date(2021, 0, 28, 12, 13, 14)},
  47. };
  48. expect(isSelectionEqual(base, changed)).toBe(true);
  49. changed = {
  50. ...base,
  51. datetime: {...base.datetime, end: new Date(2021, 0, 28, 23, 59, 59)},
  52. };
  53. expect(isSelectionEqual(base, changed)).toBe(true);
  54. changed = {
  55. ...base,
  56. datetime: {...base.datetime, end: new Date(2021, 0, 28, 1, 1, 1)},
  57. };
  58. expect(isSelectionEqual(base, changed)).toBe(false);
  59. changed = {
  60. ...base,
  61. datetime: {...base.datetime, start: new Date(2021, 0, 28, 1, 1, 1)},
  62. };
  63. expect(isSelectionEqual(base, changed)).toBe(false);
  64. });
  65. });