profileSummaryPage.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import type {Location} from 'history';
  2. import {GlobalSelectionFixture} from 'sentry-fixture/globalSelection';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {RouterContextFixture} from 'sentry-fixture/routerContextFixture';
  6. import {render, screen} from 'sentry-test/reactTestingLibrary';
  7. import OrganizationStore from 'sentry/stores/organizationStore';
  8. import ProfileSummaryPage from 'sentry/views/profiling/profileSummary';
  9. Object.defineProperty(window, 'matchMedia', {
  10. writable: true,
  11. value: jest.fn().mockImplementation(query => ({
  12. matches: false,
  13. media: query,
  14. onchange: null,
  15. addListener: jest.fn(), // Deprecated
  16. removeListener: jest.fn(), // Deprecated
  17. addEventListener: jest.fn(),
  18. removeEventListener: jest.fn(),
  19. dispatchEvent: jest.fn(),
  20. })),
  21. });
  22. // Replace the webgl renderer with a dom renderer for tests
  23. jest.mock('sentry/utils/profiling/renderers/flamegraphRendererWebGL', () => {
  24. const {
  25. FlamegraphRendererDOM,
  26. } = require('sentry/utils/profiling/renderers/flamegraphRendererDOM');
  27. return {
  28. FlamegraphRendererWebGL: FlamegraphRendererDOM,
  29. };
  30. });
  31. window.ResizeObserver =
  32. window.ResizeObserver ||
  33. jest.fn().mockImplementation(() => ({
  34. disconnect: jest.fn(),
  35. observe: jest.fn(),
  36. unobserve: jest.fn(),
  37. }));
  38. describe('ProfileSummaryPage', () => {
  39. it('renders new page', async () => {
  40. const organization = OrganizationFixture({
  41. features: [],
  42. projects: [ProjectFixture()],
  43. });
  44. OrganizationStore.onUpdate(organization);
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/projects/`,
  47. body: [ProjectFixture()],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/profiling/filters/`,
  51. body: [],
  52. });
  53. MockApiClient.addMockResponse({
  54. url: `/organizations/${organization.slug}/events-stats/`,
  55. body: {},
  56. });
  57. MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/profiling/flamegraph/`,
  59. body: [],
  60. });
  61. MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/events/`,
  63. body: {
  64. data: [{'last_seen()': new Date()}],
  65. },
  66. });
  67. MockApiClient.addMockResponse({
  68. url: `/organizations/${organization.slug}/profiling/function-trends/`,
  69. body: [],
  70. });
  71. render(
  72. <ProfileSummaryPage
  73. view="flamegraph"
  74. params={{}}
  75. selection={GlobalSelectionFixture()}
  76. location={
  77. {
  78. query: {transaction: 'fancyservice'},
  79. } as unknown as Location
  80. }
  81. />,
  82. {
  83. organization: OrganizationFixture({
  84. features: ['profiling-summary-redesign'],
  85. }),
  86. context: RouterContextFixture(),
  87. }
  88. );
  89. expect(await screen.findByTestId(/profile-summary-redesign/i)).toBeInTheDocument();
  90. });
  91. });