index.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {getReleaseBounds, getReleaseParams} from 'sentry/views/releases/utils';
  3. describe('releases/utils', () => {
  4. describe('getReleaseBounds', () => {
  5. it('returns start and end of a release', () => {
  6. expect(getReleaseBounds(TestStubs.Release())).toEqual({
  7. releaseStart: '2020-03-23T01:02:00Z',
  8. releaseEnd: '2020-03-24T02:04:59Z',
  9. type: 'normal',
  10. });
  11. });
  12. it('higher last session takes precendence over last event', () => {
  13. expect(
  14. getReleaseBounds(
  15. TestStubs.Release({
  16. currentProjectMeta: {sessionsUpperBound: '2020-03-24T03:04:55Z'},
  17. })
  18. )
  19. ).toEqual({
  20. releaseStart: '2020-03-23T01:02:00Z',
  21. releaseEnd: '2020-03-24T03:04:59Z',
  22. type: 'normal',
  23. });
  24. });
  25. it('there is no last session/event, it fallbacks to now', () => {
  26. expect(getReleaseBounds(TestStubs.Release({lastEvent: null}))).toEqual({
  27. releaseStart: '2020-03-23T01:02:00Z',
  28. releaseEnd: '2017-10-17T02:41:59Z',
  29. type: 'normal',
  30. });
  31. });
  32. it('adds 1 minute to end if start and end are within same minute', () => {
  33. expect(
  34. getReleaseBounds(
  35. TestStubs.Release({
  36. dateCreated: '2020-03-23T01:02:30Z',
  37. lastEvent: '2020-03-23T01:02:39Z',
  38. })
  39. )
  40. ).toEqual({
  41. releaseStart: '2020-03-23T01:02:00Z',
  42. releaseEnd: '2020-03-23T01:03:59Z',
  43. type: 'normal',
  44. });
  45. });
  46. it('clamps active releases lasting longer than 90 days', () => {
  47. expect(
  48. getReleaseBounds(
  49. TestStubs.Release({
  50. dateCreated: '2017-05-17T02:41:20Z',
  51. lastEvent: '2017-10-12T02:41:20Z',
  52. })
  53. )
  54. ).toEqual({
  55. releaseStart: '2017-07-19T02:41:20Z',
  56. releaseEnd: '2017-10-12T02:41:59Z',
  57. type: 'clamped',
  58. });
  59. });
  60. it('defaults ancient releases to last 90 days', () => {
  61. expect(
  62. getReleaseBounds(
  63. TestStubs.Release({
  64. dateCreated: '2010-05-17T02:41:20Z',
  65. lastEvent: '2011-10-17T02:41:20Z',
  66. })
  67. )
  68. ).toEqual({
  69. releaseStart: '2017-07-19T02:41:20Z',
  70. releaseEnd: '2017-10-17T02:41:20Z',
  71. type: 'ancient',
  72. });
  73. });
  74. it('handles no lastEvent for ancient releases', () => {
  75. expect(
  76. getReleaseBounds(
  77. TestStubs.Release({
  78. dateCreated: '2010-05-17T02:41:20Z',
  79. lastEvent: null,
  80. })
  81. )
  82. ).toEqual({
  83. releaseStart: '2017-07-19T02:41:20Z',
  84. releaseEnd: '2017-10-17T02:41:20Z',
  85. type: 'ancient',
  86. });
  87. });
  88. });
  89. describe('getReleaseParams', () => {
  90. const {routerContext} = initializeOrg();
  91. const releaseBounds = getReleaseBounds(TestStubs.Release());
  92. it('returns params related to a release', () => {
  93. const location = {
  94. ...routerContext.location,
  95. query: {
  96. pageStatsPeriod: '30d',
  97. project: ['456'],
  98. environment: ['prod'],
  99. somethingBad: 'meh',
  100. },
  101. };
  102. expect(
  103. getReleaseParams({
  104. location,
  105. releaseBounds,
  106. })
  107. ).toEqual({
  108. statsPeriod: '30d',
  109. project: ['456'],
  110. environment: ['prod'],
  111. });
  112. });
  113. it('returns release start/end if no other datetime is present', () => {
  114. expect(
  115. getReleaseParams({
  116. location: {...routerContext.location, query: {}},
  117. releaseBounds,
  118. })
  119. ).toEqual({
  120. start: '2020-03-23T01:02:00Z',
  121. end: '2020-03-24T02:04:59Z',
  122. });
  123. });
  124. it('returns correct start/end when zoomed in', () => {
  125. expect(
  126. getReleaseParams({
  127. location: {
  128. ...routerContext.location,
  129. query: {pageStart: '2021-03-23T01:02:30Z', pageEnd: '2022-03-23T01:02:30Z'},
  130. },
  131. releaseBounds,
  132. })
  133. ).toEqual({
  134. start: '2021-03-23T01:02:30.000',
  135. end: '2022-03-23T01:02:30.000',
  136. });
  137. });
  138. });
  139. });