screenLoadSpansTable.spec.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import type {Location} from 'history';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {render, screen, within} from 'sentry-test/reactTestingLibrary';
  4. import {browserHistory} from 'sentry/utils/browserHistory';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. import {ScreenLoadSpansTable} from 'sentry/views/insights/mobile/screenload/components/tables/screenLoadSpansTable';
  8. jest.mock('sentry/utils/useLocation');
  9. jest.mock('sentry/utils/usePageFilters');
  10. describe('ScreenLoadSpansTable', function () {
  11. const organization = OrganizationFixture({
  12. features: ['insights-initial-modules'],
  13. });
  14. jest.mocked(useLocation).mockReturnValue({
  15. action: 'PUSH',
  16. hash: '',
  17. key: '',
  18. pathname: '/organizations/org-slug/performance/mobile/screens/',
  19. query: {},
  20. search: '',
  21. state: undefined,
  22. } as Location);
  23. jest.mocked(usePageFilters).mockReturnValue({
  24. isReady: true,
  25. desyncedFilters: new Set(),
  26. pinnedFilters: new Set(),
  27. shouldPersist: true,
  28. selection: {
  29. datetime: {
  30. period: '10d',
  31. start: null,
  32. end: null,
  33. utc: false,
  34. },
  35. environments: [],
  36. projects: [],
  37. },
  38. });
  39. let eventsMock;
  40. beforeEach(function () {
  41. browserHistory.push = jest.fn();
  42. MockApiClient.addMockResponse({
  43. url: `/organizations/${organization.slug}/releases/`,
  44. body: [],
  45. });
  46. eventsMock = MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/events/`,
  48. body: {
  49. meta: {},
  50. data: [],
  51. },
  52. });
  53. });
  54. afterEach(function () {
  55. MockApiClient.clearMockResponses();
  56. jest.clearAllMocks();
  57. });
  58. it('renders table with the right columns', async function () {
  59. render(
  60. <ScreenLoadSpansTable
  61. transaction="MainActivity"
  62. primaryRelease="io.sentry.samples.android@7.0.0+2"
  63. secondaryRelease="io.sentry.samples.android@6.27.0+2"
  64. />,
  65. {organization}
  66. );
  67. expect(eventsMock).toHaveBeenCalledTimes(2);
  68. // Span op selector
  69. expect(eventsMock).toHaveBeenNthCalledWith(
  70. 1,
  71. expect.anything(),
  72. expect.objectContaining({
  73. query: expect.objectContaining({
  74. dataset: 'spansMetrics',
  75. environment: [],
  76. field: ['span.op', 'count()'],
  77. per_page: 25,
  78. project: [],
  79. query:
  80. 'transaction.op:ui.load transaction:MainActivity span.op:[file.read,file.write,ui.load,http.client,db,db.sql.room,db.sql.query,db.sql.transaction] has:span.description ( release:io.sentry.samples.android@7.0.0+2 OR release:io.sentry.samples.android@6.27.0+2 )',
  81. referrer: 'api.starfish.get-span-operations',
  82. statsPeriod: '14d',
  83. }),
  84. })
  85. );
  86. // Spans table
  87. expect(eventsMock).toHaveBeenNthCalledWith(
  88. 2,
  89. expect.anything(),
  90. expect.objectContaining({
  91. query: expect.objectContaining({
  92. dataset: 'spansMetrics',
  93. environment: [],
  94. field: [
  95. 'project.id',
  96. 'span.op',
  97. 'span.group',
  98. 'span.description',
  99. 'avg_if(span.self_time,release,io.sentry.samples.android@7.0.0+2)',
  100. 'avg_if(span.self_time,release,io.sentry.samples.android@6.27.0+2)',
  101. 'ttid_contribution_rate()',
  102. 'ttfd_contribution_rate()',
  103. 'count()',
  104. 'time_spent_percentage()',
  105. 'sum(span.self_time)',
  106. ],
  107. per_page: 25,
  108. project: [],
  109. query:
  110. 'transaction.op:ui.load transaction:MainActivity has:span.description span.op:[file.read,file.write,ui.load,http.client,db,db.sql.room,db.sql.query,db.sql.transaction] ( release:io.sentry.samples.android@7.0.0+2 OR release:io.sentry.samples.android@6.27.0+2 )',
  111. referrer: 'api.starfish.mobile-span-table',
  112. sort: '-time_spent_percentage()',
  113. statsPeriod: '14d',
  114. }),
  115. })
  116. );
  117. const header = await screen.findAllByTestId('grid-head-row');
  118. const headerCells = within(header[0]).getAllByTestId('grid-head-cell');
  119. const headerCell = headerCells[4];
  120. expect(headerCell).toHaveTextContent('Affects TTID');
  121. expect(await screen.findByRole('link', {name: 'Affects TTID'})).toHaveAttribute(
  122. 'href',
  123. '/organizations/org-slug/performance/mobile/screens/?spansSort=-ttid_contribution_rate%28%29'
  124. );
  125. });
  126. it('sorts ttfd contribution', async function () {
  127. jest.mocked(useLocation).mockReturnValue({
  128. action: 'PUSH',
  129. hash: '',
  130. key: '',
  131. pathname: '/organizations/org-slug/performance/mobile/screens/',
  132. query: {spansSort: '-ttid_contribution_rate()'},
  133. search: '',
  134. state: undefined,
  135. } as Location);
  136. render(
  137. <ScreenLoadSpansTable
  138. transaction="MainActivity"
  139. primaryRelease="io.sentry.samples.android@7.0.0+2"
  140. secondaryRelease="io.sentry.samples.android@6.27.0+2"
  141. />,
  142. {organization}
  143. );
  144. const header = await screen.findAllByTestId('grid-head-row');
  145. const headerCells = within(header[0]).getAllByTestId('grid-head-cell');
  146. const headerCell = headerCells[4];
  147. expect(headerCell).toHaveTextContent('Affects TTID');
  148. expect(await screen.findByRole('link', {name: 'Affects TTID'})).toHaveAttribute(
  149. 'href',
  150. '/organizations/org-slug/performance/mobile/screens/?spansSort=-ttfd_contribution_rate%28%29'
  151. );
  152. });
  153. });