pagePerformanceTable.spec.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {
  4. render,
  5. screen,
  6. waitFor,
  7. waitForElementToBeRemoved,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import usePageFilters from 'sentry/utils/usePageFilters';
  11. import useProjects from 'sentry/utils/useProjects';
  12. import {PagePerformanceTable} from 'sentry/views/insights/browser/webVitals/components/tables/pagePerformanceTable';
  13. jest.mock('sentry/utils/useLocation');
  14. jest.mock('sentry/utils/useProjects');
  15. jest.mock('sentry/utils/usePageFilters');
  16. describe('PagePerformanceTable', function () {
  17. const organization = OrganizationFixture();
  18. let eventsMock;
  19. beforeEach(function () {
  20. jest.mocked(useLocation).mockReturnValue({
  21. pathname: '',
  22. search: '',
  23. query: {},
  24. hash: '',
  25. state: undefined,
  26. action: 'PUSH',
  27. key: '',
  28. });
  29. jest.mocked(usePageFilters).mockReturnValue({
  30. isReady: true,
  31. desyncedFilters: new Set(),
  32. pinnedFilters: new Set(),
  33. shouldPersist: true,
  34. selection: {
  35. datetime: {
  36. period: '10d',
  37. start: null,
  38. end: null,
  39. utc: false,
  40. },
  41. environments: [],
  42. projects: [],
  43. },
  44. });
  45. jest.mocked(useProjects).mockReturnValue({
  46. projects: [
  47. ProjectFixture({
  48. id: '11276',
  49. name: 'frontend',
  50. slug: 'frontend',
  51. platform: 'python',
  52. }),
  53. ],
  54. onSearch: jest.fn(),
  55. placeholders: [],
  56. fetching: false,
  57. hasMore: null,
  58. fetchError: null,
  59. initiallyLoaded: false,
  60. });
  61. MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/projects/`,
  63. body: [ProjectFixture({id: '11276', name: 'frontend', slug: 'frontend'})],
  64. });
  65. eventsMock = MockApiClient.addMockResponse({
  66. url: `/organizations/${organization.slug}/events/`,
  67. body: {
  68. data: [
  69. {
  70. 'project.id': 11276,
  71. project: 'frontend',
  72. transaction: '/insights/browser/',
  73. 'count()': 492,
  74. 'count_scores(measurements.score.inp)': 985,
  75. 'count_scores(measurements.score.total)': 985,
  76. 'avg(measurements.score.total)': 0.847767385770207,
  77. 'total_opportunity_score()': 6.956683571915815e-5,
  78. 'opportunity_score(measurements.score.total)': 179.76662400002692,
  79. 'p75(measurements.inp)': 144.0,
  80. 'p75(measurements.ttfb)': 783.125,
  81. 'p75(measurements.lcp)': 700.2999782562256,
  82. 'p75(measurements.cls)': 0.17772871140057198,
  83. 'p75(measurements.fcp)': 563.2752180099487,
  84. 'count_scores(measurements.score.cls)': 311,
  85. 'count_scores(measurements.score.fcp)': 414,
  86. 'count_scores(measurements.score.ttfb)': 477,
  87. 'count_scores(measurements.score.lcp)': 391,
  88. },
  89. ],
  90. meta: {
  91. fields: {
  92. transaction: 'string',
  93. 'project.id': 'number',
  94. project: 'string',
  95. },
  96. },
  97. },
  98. });
  99. });
  100. afterEach(function () {
  101. jest.clearAllMocks();
  102. });
  103. it('escapes user input search filter', async () => {
  104. jest.mocked(useLocation).mockReturnValue({
  105. pathname: '',
  106. search: '',
  107. query: {query: '/issues/*'},
  108. hash: '',
  109. state: undefined,
  110. action: 'PUSH',
  111. key: '',
  112. });
  113. render(<PagePerformanceTable />, {organization});
  114. await waitFor(() => {
  115. expect(eventsMock).toHaveBeenCalledTimes(1);
  116. expect(eventsMock).toHaveBeenLastCalledWith(
  117. '/organizations/org-slug/events/',
  118. expect.objectContaining({
  119. query: expect.objectContaining({
  120. query: expect.stringContaining('transaction:"*/issues/\\**"'),
  121. }),
  122. })
  123. );
  124. });
  125. });
  126. it('renders a list of pages', async function () {
  127. render(<PagePerformanceTable />, {organization});
  128. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  129. expect(screen.getByRole('table', {name: 'Pages'})).toBeInTheDocument();
  130. expect(screen.getByRole('columnheader', {name: 'Pages'})).toBeInTheDocument();
  131. expect(screen.getByRole('columnheader', {name: 'Project'})).toBeInTheDocument();
  132. expect(screen.getByRole('columnheader', {name: 'Pageloads'})).toBeInTheDocument();
  133. expect(screen.getByRole('columnheader', {name: 'LCP'})).toBeInTheDocument();
  134. expect(screen.getByRole('columnheader', {name: 'LCP'})).toBeInTheDocument();
  135. expect(screen.getByRole('columnheader', {name: 'INP'})).toBeInTheDocument();
  136. expect(screen.getByRole('columnheader', {name: 'CLS'})).toBeInTheDocument();
  137. expect(screen.getByRole('columnheader', {name: 'TTFB'})).toBeInTheDocument();
  138. expect(screen.getByRole('columnheader', {name: 'Perf Score'})).toBeInTheDocument();
  139. expect(screen.getByRole('columnheader', {name: 'Opportunity'})).toBeInTheDocument();
  140. expect(screen.getByRole('cell', {name: '/insights/browser/'})).toBeInTheDocument();
  141. expect(screen.getByRole('link', {name: '/insights/browser/'})).toHaveAttribute(
  142. 'href',
  143. 'overview/?project=11276&transaction=%2Finsights%2Fbrowser%2F'
  144. );
  145. expect(screen.getByRole('cell', {name: 'frontend'})).toBeInTheDocument();
  146. expect(screen.getByRole('link', {name: 'frontend'})).toHaveAttribute(
  147. 'href',
  148. '/organizations/org-slug/projects/frontend/?project=11276'
  149. );
  150. expect(screen.getByRole('cell', {name: '492'})).toBeInTheDocument();
  151. expect(screen.getByRole('cell', {name: '700ms'})).toBeInTheDocument();
  152. expect(screen.getByRole('cell', {name: '563ms'})).toBeInTheDocument();
  153. expect(screen.getByRole('cell', {name: '144ms'})).toBeInTheDocument();
  154. expect(screen.getByRole('cell', {name: '0.18'})).toBeInTheDocument();
  155. expect(screen.getByRole('cell', {name: '783ms'})).toBeInTheDocument();
  156. expect(screen.getByRole('cell', {name: 'Meh 85'})).toBeInTheDocument();
  157. expect(screen.getByRole('cell', {name: '0.01'})).toBeInTheDocument();
  158. });
  159. });