profileSummaryPage.spec.tsx 2.8 KB

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