pageOverview.spec.tsx 5.0 KB

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