startDurationWidget.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import type {Location} from 'history';
  2. import {LocationFixture} from 'sentry-fixture/locationFixture';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import type {MultiSeriesEventsStats} from 'sentry/types/organization';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import usePageFilters from 'sentry/utils/usePageFilters';
  9. import {
  10. PRIMARY_RELEASE_COLOR,
  11. SECONDARY_RELEASE_COLOR,
  12. } from 'sentry/views/insights/colors';
  13. import StartDurationWidget, {transformData} from './startDurationWidget';
  14. jest.mock('sentry/utils/usePageFilters');
  15. jest.mock('sentry/utils/useLocation');
  16. describe('StartDurationWidget', () => {
  17. const organization = OrganizationFixture();
  18. const project = ProjectFixture();
  19. beforeEach(function () {
  20. jest.mocked(usePageFilters).mockReturnValue({
  21. isReady: true,
  22. desyncedFilters: new Set(),
  23. pinnedFilters: new Set(),
  24. shouldPersist: true,
  25. selection: {
  26. datetime: {
  27. period: '10d',
  28. start: null,
  29. end: null,
  30. utc: false,
  31. },
  32. environments: [],
  33. projects: [parseInt(project.id, 10)],
  34. },
  35. });
  36. MockApiClient.addMockResponse({
  37. url: `/organizations/${organization.slug}/releases/`,
  38. body: [
  39. {
  40. id: 970136705,
  41. version: 'com.example.vu.android@2.10.5',
  42. dateCreated: '2023-12-19T21:37:53.895495Z',
  43. },
  44. {
  45. id: 969902997,
  46. version: 'com.example.vu.android@2.10.3+42',
  47. dateCreated: '2023-12-19T18:04:06.953025Z',
  48. },
  49. ],
  50. });
  51. MockApiClient.addMockResponse({
  52. url: `/organizations/${organization.slug}/events-stats/`,
  53. body: {
  54. data: {},
  55. },
  56. });
  57. MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/events/`,
  59. body: {
  60. data: [],
  61. },
  62. });
  63. });
  64. afterEach(function () {
  65. MockApiClient.clearMockResponses();
  66. jest.clearAllMocks();
  67. });
  68. it('renders correct title for cold start duration', async () => {
  69. jest.mocked(useLocation).mockReturnValue({
  70. ...LocationFixture(),
  71. query: {
  72. app_start_type: 'cold',
  73. },
  74. } as Location);
  75. render(<StartDurationWidget chartHeight={200} />);
  76. expect(await screen.findByText('Average Cold Start')).toBeInTheDocument();
  77. });
  78. it('renders correct title for warm start duration', async () => {
  79. jest.mocked(useLocation).mockReturnValue({
  80. ...LocationFixture(),
  81. query: {
  82. app_start_type: 'warm',
  83. },
  84. } as Location);
  85. render(<StartDurationWidget chartHeight={200} />);
  86. expect(await screen.findByText('Average Warm Start')).toBeInTheDocument();
  87. });
  88. describe('transformData', () => {
  89. it('properly sets the release color and transforms timestamps', () => {
  90. const mockData = {
  91. 'com.example.vu.android@2.10.5': {
  92. data: [
  93. [
  94. 1703937600,
  95. [
  96. {
  97. count: 100,
  98. },
  99. ],
  100. ],
  101. ],
  102. order: 0,
  103. isMetricsData: false,
  104. start: 1703937600,
  105. end: 1706529600,
  106. meta: {
  107. fields: {},
  108. units: {},
  109. isMetricsData: false,
  110. isMetricsExtractedData: false,
  111. tips: {},
  112. datasetReason: 'unchanged',
  113. dataset: 'spansMetrics',
  114. },
  115. },
  116. 'com.example.vu.android@2.10.3+42': {
  117. data: [
  118. [
  119. 1703937600,
  120. [
  121. {
  122. count: 200,
  123. },
  124. ],
  125. ],
  126. ],
  127. order: 1,
  128. isMetricsData: false,
  129. start: 1703937600,
  130. end: 1706529600,
  131. meta: {
  132. fields: {},
  133. units: {},
  134. isMetricsData: false,
  135. isMetricsExtractedData: false,
  136. tips: {},
  137. datasetReason: 'unchanged',
  138. dataset: 'spansMetrics',
  139. },
  140. },
  141. } as MultiSeriesEventsStats;
  142. // com.example.vu.android@2.10.5 is noted as the primary, so the series with
  143. // com.example.vu.android@2.10.3+42 should be colored differently.
  144. const transformedData = transformData(mockData, 'com.example.vu.android@2.10.5');
  145. expect(transformedData).toEqual({
  146. 'com.example.vu.android@2.10.5': {
  147. seriesName: 'com.example.vu.android@2.10.5',
  148. color: PRIMARY_RELEASE_COLOR,
  149. data: [
  150. {
  151. name: 1703937600000,
  152. value: 100,
  153. },
  154. ],
  155. },
  156. 'com.example.vu.android@2.10.3+42': {
  157. seriesName: 'com.example.vu.android@2.10.3+42',
  158. color: SECONDARY_RELEASE_COLOR,
  159. data: [
  160. {
  161. name: 1703937600000,
  162. value: 200,
  163. },
  164. ],
  165. lineStyle: {
  166. type: 'dashed',
  167. },
  168. },
  169. });
  170. });
  171. });
  172. });