profileSummaryPage.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. params={{}}
  70. selection={GlobalSelection()}
  71. location={
  72. {
  73. query: {transaction: 'fancyservice'},
  74. } as unknown as Location
  75. }
  76. />,
  77. {
  78. organization,
  79. context: TestStubs.routerContext(),
  80. }
  81. );
  82. expect(await screen.findByTestId(/profile-summary-legacy/i)).toBeInTheDocument();
  83. });
  84. it('renders new page', async () => {
  85. const organization = Organization({
  86. features: [],
  87. projects: [TestStubs.Project()],
  88. });
  89. OrganizationStore.onUpdate(organization);
  90. MockApiClient.addMockResponse({
  91. url: `/organizations/${organization.slug}/projects/`,
  92. body: [TestStubs.Project()],
  93. });
  94. MockApiClient.addMockResponse({
  95. url: `/organizations/${organization.slug}/profiling/filters/`,
  96. body: [],
  97. });
  98. MockApiClient.addMockResponse({
  99. url: `/organizations/${organization.slug}/events-stats/`,
  100. body: {},
  101. });
  102. MockApiClient.addMockResponse({
  103. url: `/organizations/${organization.slug}/profiling/flamegraph/`,
  104. body: [],
  105. });
  106. MockApiClient.addMockResponse({
  107. url: `/organizations/${organization.slug}/events/`,
  108. body: {
  109. data: [{'last_seen()': new Date()}],
  110. },
  111. });
  112. MockApiClient.addMockResponse({
  113. url: `/organizations/${organization.slug}/profiling/function-trends/`,
  114. body: [],
  115. });
  116. render(
  117. <ProfileSummaryPage
  118. params={{}}
  119. selection={GlobalSelection()}
  120. location={
  121. {
  122. query: {transaction: 'fancyservice'},
  123. } as unknown as Location
  124. }
  125. />,
  126. {
  127. organization: Organization({
  128. features: ['profiling-summary-redesign'],
  129. }),
  130. context: TestStubs.routerContext(),
  131. }
  132. );
  133. expect(await screen.findByTestId(/profile-summary-redesign/i)).toBeInTheDocument();
  134. });
  135. });