profileSummaryPage.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 new 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. data: [{'last_seen()': new Date()}],
  63. },
  64. });
  65. MockApiClient.addMockResponse({
  66. url: `/organizations/${organization.slug}/profiling/function-trends/`,
  67. body: [],
  68. });
  69. render(
  70. <ProfileSummaryPage
  71. view="flamegraph"
  72. params={{}}
  73. selection={GlobalSelection()}
  74. location={
  75. {
  76. query: {transaction: 'fancyservice'},
  77. } as unknown as Location
  78. }
  79. />,
  80. {
  81. organization: Organization({
  82. features: ['profiling-summary-redesign'],
  83. }),
  84. context: TestStubs.routerContext(),
  85. }
  86. );
  87. expect(await screen.findByTestId(/profile-summary-redesign/i)).toBeInTheDocument();
  88. });
  89. });