uiScreens.spec.tsx 5.4 KB

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