startDurationWidget.spec.tsx 4.4 KB

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