index.spec.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import type {Project} from 'sentry/types';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import {Referrer} from 'sentry/views/performance/mobile/ui/referrers';
  6. import {UIScreens} from 'sentry/views/performance/mobile/ui/screens';
  7. import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases';
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/views/starfish/queries/useReleases');
  10. jest.mocked(useReleaseSelection).mockReturnValue({
  11. primaryRelease: 'com.example.vu.android@2.10.5',
  12. isLoading: false,
  13. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  14. });
  15. const createMockTablePayload = ({
  16. transaction,
  17. project,
  18. }: {
  19. project: Project;
  20. transaction: string;
  21. }) => ({
  22. 'avg_compare(mobile.frames_delay,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)':
  23. null,
  24. 'avg_compare(mobile.frozen_frames,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)':
  25. null,
  26. 'avg_compare(mobile.slow_frames,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)':
  27. null,
  28. 'avg_if(mobile.frames_delay,release,com.example.vu.android@2.10.5)': 0,
  29. 'avg_if(mobile.frames_delay,release,com.example.vu.android@2.10.3+42)': 0.259326119,
  30. 'avg_if(mobile.frozen_frames,release,com.example.vu.android@2.10.5)': 0,
  31. 'avg_if(mobile.frozen_frames,release,com.example.vu.android@2.10.3+42)': 0,
  32. 'avg_if(mobile.slow_frames,release,com.example.vu.android@2.10.5)': 0,
  33. 'avg_if(mobile.slow_frames,release,com.example.vu.android@2.10.3+42)': 2,
  34. 'project.id': project.id,
  35. transaction,
  36. });
  37. describe('Performance Mobile UI Screens', () => {
  38. const project = ProjectFixture({platform: 'apple-ios'});
  39. beforeEach(() => {
  40. MockApiClient.clearMockResponses();
  41. jest.mocked(usePageFilters).mockReturnValue({
  42. isReady: true,
  43. desyncedFilters: new Set(),
  44. pinnedFilters: new Set(),
  45. shouldPersist: true,
  46. selection: {
  47. datetime: {
  48. period: '10d',
  49. start: null,
  50. end: null,
  51. utc: false,
  52. },
  53. environments: [],
  54. projects: [parseInt(project.id, 10)],
  55. },
  56. });
  57. });
  58. it('queries for the correct table data', async () => {
  59. const tableRequestMock = MockApiClient.addMockResponse({
  60. url: '/organizations/org-slug/events/',
  61. body: [],
  62. match: [MockApiClient.matchQuery({referrer: Referrer.OVERVIEW_SCREENS_TABLE})],
  63. });
  64. render(<UIScreens />);
  65. expect(await screen.findByRole('columnheader', {name: 'Screen'})).toBeInTheDocument();
  66. [
  67. 'Slow (R1)',
  68. 'Slow (R2)',
  69. 'Frozen (R1)',
  70. 'Frozen (R2)',
  71. 'Delay (R1)',
  72. 'Delay (R2)',
  73. ].forEach(header => {
  74. expect(screen.getByRole('columnheader', {name: header})).toBeInTheDocument();
  75. });
  76. expect(screen.getAllByRole('columnheader', {name: 'Change'})).toHaveLength(3);
  77. expect(tableRequestMock).toHaveBeenCalledWith(
  78. '/organizations/org-slug/events/',
  79. expect.objectContaining({
  80. query: expect.objectContaining({
  81. field: [
  82. 'project.id',
  83. 'transaction',
  84. 'avg_if(mobile.slow_frames,release,com.example.vu.android@2.10.5)',
  85. 'avg_if(mobile.slow_frames,release,com.example.vu.android@2.10.3+42)',
  86. 'avg_if(mobile.frozen_frames,release,com.example.vu.android@2.10.5)',
  87. 'avg_if(mobile.frozen_frames,release,com.example.vu.android@2.10.3+42)',
  88. 'avg_if(mobile.frames_delay,release,com.example.vu.android@2.10.5)',
  89. 'avg_if(mobile.frames_delay,release,com.example.vu.android@2.10.3+42)',
  90. 'avg_compare(mobile.slow_frames,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)',
  91. 'avg_compare(mobile.frozen_frames,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)',
  92. 'avg_compare(mobile.frames_delay,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)',
  93. ],
  94. }),
  95. })
  96. );
  97. });
  98. it('queries for the correct chart data using the top transactions', async () => {
  99. MockApiClient.addMockResponse({
  100. url: '/organizations/org-slug/events/',
  101. body: {
  102. data: [
  103. createMockTablePayload({transaction: 'top 1', project}),
  104. createMockTablePayload({transaction: 'top 2', project}),
  105. createMockTablePayload({transaction: 'top 3', project}),
  106. createMockTablePayload({transaction: 'top 4', project}),
  107. createMockTablePayload({transaction: 'top 5', project}),
  108. createMockTablePayload({transaction: 'top 6', project}), // excluded
  109. ],
  110. },
  111. match: [MockApiClient.matchQuery({referrer: Referrer.OVERVIEW_SCREENS_TABLE})],
  112. });
  113. const chartDataRequest = MockApiClient.addMockResponse({
  114. url: '/organizations/org-slug/events/',
  115. body: [],
  116. match: [MockApiClient.matchQuery({referrer: Referrer.MOBILE_UI_BAR_CHART})],
  117. });
  118. render(<UIScreens />);
  119. await screen.findByText('top 1');
  120. screen.getByText('Top 5 Screen Slow Frames');
  121. screen.getByText('Top 5 Screen Frozen Frames');
  122. screen.getByText('Top 5 Screen Frames Delay');
  123. expect(chartDataRequest).toHaveBeenCalledWith(
  124. '/organizations/org-slug/events/',
  125. expect.objectContaining({
  126. query: expect.objectContaining({
  127. field: [
  128. 'transaction',
  129. 'release',
  130. 'avg(mobile.slow_frames)',
  131. 'avg(mobile.frozen_frames)',
  132. 'avg(mobile.frames_delay)',
  133. ],
  134. query:
  135. 'release:[com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42] transaction:["top 1","top 2","top 3","top 4","top 5"]',
  136. }),
  137. })
  138. );
  139. });
  140. });