pageOverview.spec.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import PageOverview from 'sentry/views/performance/browser/webVitals/pageOverview';
  6. jest.mock('sentry/utils/useLocation');
  7. jest.mock('sentry/utils/usePageFilters');
  8. describe('PageOverview', function () {
  9. const organization = OrganizationFixture({
  10. features: ['spans-first-ui'],
  11. });
  12. let eventsMock;
  13. beforeEach(function () {
  14. jest.mocked(useLocation).mockReturnValue({
  15. pathname: '',
  16. search: '',
  17. query: {},
  18. hash: '',
  19. state: undefined,
  20. action: 'PUSH',
  21. key: '',
  22. });
  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. eventsMock = MockApiClient.addMockResponse({
  40. url: `/organizations/${organization.slug}/events/`,
  41. body: {
  42. data: [],
  43. },
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/events-stats/`,
  47. body: {},
  48. });
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/spans-aggregation/`,
  51. body: {},
  52. });
  53. });
  54. afterEach(function () {
  55. jest.clearAllMocks();
  56. });
  57. it('renders FID deprecation alert', async () => {
  58. jest.mocked(useLocation).mockReturnValue({
  59. pathname: '',
  60. search: '',
  61. query: {useStoredScores: 'true', transaction: '/'},
  62. hash: '',
  63. state: undefined,
  64. action: 'PUSH',
  65. key: '',
  66. });
  67. render(<PageOverview />, {organization});
  68. await screen.findByText(/\(Interaction to Next Paint\) will replace/);
  69. await screen.findByText(
  70. /\(First Input Delay\) in our performance score calculation./
  71. );
  72. });
  73. it('renders interaction samples', async () => {
  74. const organizationWithInp = OrganizationFixture({
  75. features: ['spans-first-ui'],
  76. });
  77. jest.mocked(useLocation).mockReturnValue({
  78. pathname: '',
  79. search: '',
  80. query: {useStoredScores: 'true', transaction: '/', type: 'interactions'},
  81. hash: '',
  82. state: undefined,
  83. action: 'PUSH',
  84. key: '',
  85. });
  86. render(<PageOverview />, {organization: organizationWithInp});
  87. await waitFor(() =>
  88. expect(eventsMock).toHaveBeenCalledWith(
  89. '/organizations/org-slug/events/',
  90. expect.objectContaining({
  91. query: expect.objectContaining({
  92. dataset: 'spansIndexed',
  93. field: [
  94. 'measurements.inp',
  95. 'measurements.score.inp',
  96. 'measurements.score.weight.inp',
  97. 'measurements.score.total',
  98. 'span_id',
  99. 'timestamp',
  100. 'profile_id',
  101. 'replay.id',
  102. 'user',
  103. 'origin.transaction',
  104. 'project',
  105. 'browser.name',
  106. 'span.self_time',
  107. 'span.description',
  108. ],
  109. query:
  110. 'span.op:ui.interaction.click measurements.score.weight.inp:>0 origin.transaction:/',
  111. }),
  112. })
  113. )
  114. );
  115. });
  116. it('escapes transaction name before querying discover', async () => {
  117. const organizationWithInp = OrganizationFixture({
  118. features: ['spans-first-ui'],
  119. });
  120. jest.mocked(useLocation).mockReturnValue({
  121. pathname: '',
  122. search: '',
  123. query: {
  124. useStoredScores: 'true',
  125. transaction: '/page-with-a-*/',
  126. type: 'interactions',
  127. },
  128. hash: '',
  129. state: undefined,
  130. action: 'PUSH',
  131. key: '',
  132. });
  133. render(<PageOverview />, {organization: organizationWithInp});
  134. await waitFor(() =>
  135. expect(eventsMock).toHaveBeenCalledWith(
  136. '/organizations/org-slug/events/',
  137. expect.objectContaining({
  138. query: expect.objectContaining({
  139. dataset: 'spansIndexed',
  140. field: [
  141. 'measurements.inp',
  142. 'measurements.score.inp',
  143. 'measurements.score.weight.inp',
  144. 'measurements.score.total',
  145. 'span_id',
  146. 'timestamp',
  147. 'profile_id',
  148. 'replay.id',
  149. 'user',
  150. 'origin.transaction',
  151. 'project',
  152. 'browser.name',
  153. 'span.self_time',
  154. 'span.description',
  155. ],
  156. query:
  157. 'span.op:ui.interaction.click measurements.score.weight.inp:>0 origin.transaction:"/page-with-a-\\*/"',
  158. }),
  159. })
  160. )
  161. );
  162. });
  163. });