table.spec.tsx 5.5 KB

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