profileSummaryPage.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {Location} from 'history';
  2. import {GlobalSelection} from 'sentry-fixture/globalSelection';
  3. import {Organization} from 'sentry-fixture/organization';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import OrganizationStore from 'sentry/stores/organizationStore';
  6. import ProfileSummaryPage from 'sentry/views/profiling/profileSummary';
  7. Object.defineProperty(window, 'matchMedia', {
  8. writable: true,
  9. value: jest.fn().mockImplementation(query => ({
  10. matches: false,
  11. media: query,
  12. onchange: null,
  13. addListener: jest.fn(), // Deprecated
  14. removeListener: jest.fn(), // Deprecated
  15. addEventListener: jest.fn(),
  16. removeEventListener: jest.fn(),
  17. dispatchEvent: jest.fn(),
  18. })),
  19. });
  20. // Replace the webgl renderer with a dom renderer for tests
  21. jest.mock('sentry/utils/profiling/renderers/flamegraphRendererWebGL', () => {
  22. const {
  23. FlamegraphRendererDOM,
  24. } = require('sentry/utils/profiling/renderers/flamegraphRendererDOM');
  25. return {
  26. FlamegraphRendererWebGL: FlamegraphRendererDOM,
  27. };
  28. });
  29. window.ResizeObserver =
  30. window.ResizeObserver ||
  31. jest.fn().mockImplementation(() => ({
  32. disconnect: jest.fn(),
  33. observe: jest.fn(),
  34. unobserve: jest.fn(),
  35. }));
  36. describe('ProfileSummaryPage', () => {
  37. it('renders legacy page', async () => {
  38. const organization = Organization({
  39. features: [],
  40. projects: [TestStubs.Project()],
  41. });
  42. OrganizationStore.onUpdate(organization);
  43. MockApiClient.addMockResponse({
  44. url: `/organizations/${organization.slug}/projects/`,
  45. body: [TestStubs.Project()],
  46. });
  47. MockApiClient.addMockResponse({
  48. url: `/organizations/${organization.slug}/profiling/filters/`,
  49. body: [],
  50. });
  51. MockApiClient.addMockResponse({
  52. url: `/organizations/${organization.slug}/events-stats/`,
  53. body: [],
  54. });
  55. MockApiClient.addMockResponse({
  56. url: `/organizations/${organization.slug}/profiling/flamegraph/`,
  57. body: [],
  58. });
  59. MockApiClient.addMockResponse({
  60. url: `/organizations/${organization.slug}/events/`,
  61. body: [],
  62. });
  63. MockApiClient.addMockResponse({
  64. url: `/organizations/${organization.slug}/profiling/function-trends/`,
  65. body: [],
  66. });
  67. render(
  68. <ProfileSummaryPage
  69. view="flamegraph"
  70. params={{}}
  71. selection={GlobalSelection()}
  72. location={
  73. {
  74. query: {transaction: 'fancyservice'},
  75. } as unknown as Location
  76. }
  77. />,
  78. {
  79. organization,
  80. context: TestStubs.routerContext(),
  81. }
  82. );
  83. expect(await screen.findByTestId(/profile-summary-legacy/i)).toBeInTheDocument();
  84. });
  85. it('renders new page', async () => {
  86. const organization = Organization({
  87. features: [],
  88. projects: [TestStubs.Project()],
  89. });
  90. OrganizationStore.onUpdate(organization);
  91. MockApiClient.addMockResponse({
  92. url: `/organizations/${organization.slug}/projects/`,
  93. body: [TestStubs.Project()],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: `/organizations/${organization.slug}/profiling/filters/`,
  97. body: [],
  98. });
  99. MockApiClient.addMockResponse({
  100. url: `/organizations/${organization.slug}/events-stats/`,
  101. body: {},
  102. });
  103. MockApiClient.addMockResponse({
  104. url: `/organizations/${organization.slug}/profiling/flamegraph/`,
  105. body: [],
  106. });
  107. MockApiClient.addMockResponse({
  108. url: `/organizations/${organization.slug}/events/`,
  109. body: {
  110. data: [{'last_seen()': new Date()}],
  111. },
  112. });
  113. MockApiClient.addMockResponse({
  114. url: `/organizations/${organization.slug}/profiling/function-trends/`,
  115. body: [],
  116. });
  117. render(
  118. <ProfileSummaryPage
  119. view="flamegraph"
  120. params={{}}
  121. selection={GlobalSelection()}
  122. location={
  123. {
  124. query: {transaction: 'fancyservice'},
  125. } as unknown as Location
  126. }
  127. />,
  128. {
  129. organization: Organization({
  130. features: ['profiling-summary-redesign'],
  131. }),
  132. context: TestStubs.routerContext(),
  133. }
  134. );
  135. expect(await screen.findByTestId(/profile-summary-redesign/i)).toBeInTheDocument();
  136. });
  137. });