webVitalsLandingPage.spec.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import WebVitalsLandingPage from 'sentry/views/performance/browser/webVitals/webVitalsLandingPage';
  6. jest.mock('sentry/utils/useLocation');
  7. jest.mock('sentry/utils/usePageFilters');
  8. describe('WebVitalsLandingPage', function () {
  9. const organization = OrganizationFixture({
  10. features: ['insights-initial-modules'],
  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. });
  50. afterEach(function () {
  51. jest.resetAllMocks();
  52. });
  53. it('renders', async () => {
  54. render(<WebVitalsLandingPage />, {organization});
  55. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  56. // Project performance score ring query
  57. expect(eventsMock).toHaveBeenNthCalledWith(
  58. 1,
  59. expect.anything(),
  60. expect.objectContaining({
  61. query: expect.objectContaining({
  62. dataset: 'metrics',
  63. field: [
  64. 'performance_score(measurements.score.lcp)',
  65. 'performance_score(measurements.score.fcp)',
  66. 'performance_score(measurements.score.cls)',
  67. `performance_score(measurements.score.inp)`,
  68. 'performance_score(measurements.score.ttfb)',
  69. 'avg(measurements.score.total)',
  70. 'avg(measurements.score.weight.lcp)',
  71. 'avg(measurements.score.weight.fcp)',
  72. 'avg(measurements.score.weight.cls)',
  73. `avg(measurements.score.weight.inp)`,
  74. 'avg(measurements.score.weight.ttfb)',
  75. 'count()',
  76. 'count_scores(measurements.score.total)',
  77. 'count_scores(measurements.score.lcp)',
  78. 'count_scores(measurements.score.fcp)',
  79. 'count_scores(measurements.score.cls)',
  80. 'count_scores(measurements.score.ttfb)',
  81. `count_scores(measurements.score.inp)`,
  82. ],
  83. query:
  84. 'transaction.op:[pageload,""] span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press,""] !transaction:"<< unparameterized >>"',
  85. }),
  86. })
  87. );
  88. // Table query
  89. expect(eventsMock).toHaveBeenNthCalledWith(
  90. 2,
  91. expect.anything(),
  92. expect.objectContaining({
  93. query: expect.objectContaining({
  94. dataset: 'metrics',
  95. field: [
  96. 'transaction',
  97. 'p75(measurements.lcp)',
  98. 'p75(measurements.fcp)',
  99. 'p75(measurements.cls)',
  100. 'p75(measurements.ttfb)',
  101. 'p75(measurements.fid)',
  102. 'p75(measurements.inp)',
  103. 'opportunity_score(measurements.score.total)',
  104. 'avg(measurements.score.total)',
  105. 'count()',
  106. 'count_scores(measurements.score.lcp)',
  107. 'count_scores(measurements.score.fcp)',
  108. 'count_scores(measurements.score.cls)',
  109. 'count_scores(measurements.score.fid)',
  110. 'count_scores(measurements.score.inp)',
  111. 'count_scores(measurements.score.ttfb)',
  112. ],
  113. query:
  114. 'transaction.op:[pageload,""] span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press,""] !transaction:"<< unparameterized >>" avg(measurements.score.total):>=0',
  115. }),
  116. })
  117. );
  118. // Raw web vital metric tile queries
  119. expect(eventsMock).toHaveBeenNthCalledWith(
  120. 3,
  121. expect.anything(),
  122. expect.objectContaining({
  123. query: expect.objectContaining({
  124. dataset: 'metrics',
  125. field: [
  126. 'p75(measurements.lcp)',
  127. 'p75(measurements.fcp)',
  128. 'p75(measurements.cls)',
  129. 'p75(measurements.ttfb)',
  130. 'p75(measurements.fid)',
  131. 'p75(measurements.inp)',
  132. 'p75(transaction.duration)',
  133. 'count_web_vitals(measurements.lcp, any)',
  134. 'count_web_vitals(measurements.fcp, any)',
  135. 'count_web_vitals(measurements.cls, any)',
  136. 'count_web_vitals(measurements.fid, any)',
  137. 'count_web_vitals(measurements.ttfb, any)',
  138. 'count()',
  139. ],
  140. query:
  141. 'transaction.op:[pageload,""] span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press,""] !transaction:"<< unparameterized >>"',
  142. }),
  143. })
  144. );
  145. });
  146. });