profileSummaryPage.spec.tsx 4.0 KB

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