screensOverview.spec.tsx 5.5 KB

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