index.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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, within} from 'sentry-test/reactTestingLibrary';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. import {ScreenSummary} from 'sentry/views/performance/mobile/appStarts/screenSummary';
  8. import {SpanMetricsField} from 'sentry/views/starfish/types';
  9. jest.mock('sentry/utils/usePageFilters');
  10. jest.mock('sentry/utils/useLocation');
  11. describe('Screen Summary', function () {
  12. const organization = OrganizationFixture();
  13. const project = ProjectFixture();
  14. jest.mocked(useLocation).mockReturnValue({
  15. action: 'PUSH',
  16. hash: '',
  17. key: '',
  18. pathname: '/organizations/org-slug/performance/mobile/screens/spans/',
  19. query: {
  20. project: project.id,
  21. transaction: 'MainActivity',
  22. primaryRelease: 'com.example.vu.android@2.10.5',
  23. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  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. describe('Native Project', function () {
  45. let eventsMock;
  46. beforeEach(() => {
  47. MockApiClient.addMockResponse({
  48. url: `/organizations/${organization.slug}/releases/`,
  49. body: [
  50. {
  51. id: 970136705,
  52. version: 'com.example.vu.android@2.10.5',
  53. dateCreated: '2023-12-19T21:37:53.895495Z',
  54. },
  55. {
  56. id: 969902997,
  57. version: 'com.example.vu.android@2.10.3+42',
  58. dateCreated: '2023-12-19T18:04:06.953025Z',
  59. },
  60. ],
  61. });
  62. MockApiClient.addMockResponse({
  63. url: `/organizations/${organization.slug}/events-stats/`,
  64. });
  65. eventsMock = MockApiClient.addMockResponse({
  66. url: `/organizations/${organization.slug}/events/`,
  67. });
  68. });
  69. afterEach(() => {
  70. MockApiClient.clearMockResponses();
  71. jest.clearAllMocks();
  72. });
  73. it('renders the top level metrics data correctly', async function () {
  74. jest.mocked(useLocation).mockReturnValue({
  75. action: 'PUSH',
  76. hash: '',
  77. key: '',
  78. pathname: '/organizations/org-slug/performance/mobile/screens/spans/',
  79. query: {
  80. project: project.id,
  81. transaction: 'MainActivity',
  82. primaryRelease: 'com.example.vu.android@2.10.5',
  83. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  84. [SpanMetricsField.APP_START_TYPE]: 'cold',
  85. },
  86. search: '',
  87. state: undefined,
  88. } as Location);
  89. eventsMock = MockApiClient.addMockResponse({
  90. url: `/organizations/${organization.slug}/events/`,
  91. body: {
  92. data: [
  93. {
  94. 'span.op': 'app.start.cold',
  95. 'avg_if(span.duration,release,com.example.vu.android@2.10.5)': 1000,
  96. 'avg_if(span.duration,release,com.example.vu.android@2.10.3+42)': 2000,
  97. 'avg_compare(span.duration,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)':
  98. -0.5,
  99. 'count()': 20,
  100. },
  101. ],
  102. },
  103. match: [
  104. MockApiClient.matchQuery({referrer: 'api.starfish.mobile-startup-totals'}),
  105. ],
  106. });
  107. render(<ScreenSummary />, {organization});
  108. await waitFor(() => {
  109. expect(eventsMock).toHaveBeenCalled();
  110. });
  111. const blocks = [
  112. {header: 'Cold Start (R1)', value: '1.00s'},
  113. {header: 'Cold Start (R2)', value: '2.00s'},
  114. {header: 'Change', value: '-50%'},
  115. {header: 'Count', value: '20'},
  116. ];
  117. for (const block of blocks) {
  118. const blockEl = screen.getByRole('heading', {name: block.header}).closest('div');
  119. await within(blockEl!).findByText(block.value);
  120. }
  121. });
  122. });
  123. });