screensOverview.spec.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import type {Location} from 'history';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import usePageFilters from 'sentry/utils/usePageFilters';
  8. import useCrossPlatformProject from 'sentry/views/insights/mobile/common/queries/useCrossPlatformProject';
  9. import {ScreensOverview} from 'sentry/views/insights/mobile/screens/components/screensOverview';
  10. jest.mock('sentry/utils/useOrganization');
  11. jest.mock('sentry/views/insights/mobile/common/queries/useCrossPlatformProject');
  12. jest.mock('sentry/utils/usePageFilters');
  13. jest.mock('sentry/utils/useLocation');
  14. describe('ScreensOverview', () => {
  15. const organization = OrganizationFixture({
  16. features: ['insights-addon-modules'],
  17. });
  18. const project = ProjectFixture();
  19. jest.mocked(useLocation).mockReturnValue({
  20. action: 'PUSH',
  21. hash: '',
  22. key: '',
  23. pathname: '/organizations/org-slug/performance/mobile/mobile-screens',
  24. query: {
  25. project: project.id,
  26. },
  27. search: '',
  28. state: undefined,
  29. } as Location);
  30. jest.mocked(usePageFilters).mockReturnValue({
  31. isReady: true,
  32. desyncedFilters: new Set(),
  33. pinnedFilters: new Set(),
  34. shouldPersist: true,
  35. selection: {
  36. datetime: {
  37. period: '10d',
  38. start: null,
  39. end: null,
  40. utc: false,
  41. },
  42. environments: [],
  43. projects: [parseInt(project.id, 10)],
  44. },
  45. });
  46. jest.mocked(useCrossPlatformProject).mockReturnValue({
  47. project: project,
  48. isProjectCrossPlatform: true,
  49. selectedPlatform: 'Android',
  50. });
  51. jest.mocked(useOrganization).mockReturnValue(organization);
  52. it('renders search bar and table', async () => {
  53. MockApiClient.addMockResponse({
  54. url: `/organizations/${organization.slug}/events/`,
  55. });
  56. render(<ScreensOverview />, {organization});
  57. expect(await screen.findByPlaceholderText('Search for Screen')).toBeInTheDocument();
  58. expect(await screen.findByRole('table')).toBeInTheDocument();
  59. });
  60. it('queries both dataset correctly', async () => {
  61. const transactionMetricsMock = MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/events/`,
  63. body: {
  64. data: [
  65. {
  66. transaction: 'Screen A',
  67. 'project.id': project.id,
  68. 'avg(measurements.time_to_full_display)': 100,
  69. 'avg(measurements.time_to_initial_display)': 200,
  70. 'count()': 10000,
  71. 'avg(measurements.app_start_cold)': 300,
  72. 'avg(measurements.app_start_warm)': 400,
  73. },
  74. {
  75. transaction: 'Screen B',
  76. 'project.id': project.id,
  77. 'avg(measurements.time_to_full_display)': 5,
  78. 'avg(measurements.time_to_initial_display)': 600,
  79. 'count()': 5000,
  80. 'avg(measurements.app_start_cold)': 700,
  81. 'avg(measurements.app_start_warm)': 800,
  82. },
  83. ],
  84. meta: {
  85. fields: {
  86. transaction: 'string',
  87. 'project.id': 'integer',
  88. 'avg(measurements.time_to_full_display)': 'duration',
  89. 'avg(measurements.time_to_initial_display)': 'duration',
  90. 'count()': 'integer',
  91. 'avg(measurements.app_start_cold)': 'duration',
  92. 'avg(measurements.app_start_warm)': 'duration',
  93. },
  94. units: {
  95. transaction: null,
  96. 'project.id': null,
  97. 'avg(measurements.time_to_full_display)': 'millisecond',
  98. 'avg(measurements.time_to_initial_display)': 'millisecond',
  99. 'count()': null,
  100. 'avg(measurements.app_start_cold)': 'millisecond',
  101. 'avg(measurements.app_start_warm)': 'millisecond',
  102. },
  103. isMetricsData: true,
  104. isMetricsExtractedData: false,
  105. tips: {},
  106. datasetReason: 'unchanged',
  107. dataset: 'metrics',
  108. },
  109. },
  110. match: [MockApiClient.matchQuery({dataset: 'metrics'})],
  111. });
  112. const spanMetricsMock = MockApiClient.addMockResponse({
  113. url: `/organizations/${organization.slug}/events/`,
  114. body: {
  115. data: [
  116. {
  117. 'project.id': project.id,
  118. transaction: 'Screen A',
  119. 'avg(mobile.frozen_frames)': 1,
  120. 'avg(mobile.frames_delay)': 2,
  121. 'avg(mobile.slow_frames)': 3,
  122. },
  123. {
  124. 'project.id': project.id,
  125. transaction: 'Screen B',
  126. 'avg(mobile.frozen_frames)': 4,
  127. 'avg(mobile.frames_delay)': 5,
  128. 'avg(mobile.slow_frames)': 6,
  129. },
  130. ],
  131. meta: {
  132. fields: {
  133. 'project.id': 'integer',
  134. transaction: 'string',
  135. 'avg(mobile.frozen_frames)': 'number',
  136. 'avg(mobile.frames_delay)': 'number',
  137. 'avg(mobile.slow_frames)': 'number',
  138. },
  139. units: {
  140. 'project.id': null,
  141. transaction: null,
  142. 'avg(mobile.frozen_frames)': null,
  143. 'avg(mobile.frames_delay)': null,
  144. 'avg(mobile.slow_frames)': null,
  145. },
  146. isMetricsData: false,
  147. isMetricsExtractedData: false,
  148. tips: {},
  149. datasetReason: 'unchanged',
  150. dataset: 'spansMetrics',
  151. },
  152. },
  153. match: [MockApiClient.matchQuery({dataset: 'spansMetrics'})],
  154. });
  155. render(<ScreensOverview />, {organization});
  156. await waitFor(() => {
  157. expect(transactionMetricsMock).toHaveBeenCalled();
  158. expect(spanMetricsMock).toHaveBeenCalled();
  159. });
  160. });
  161. });