123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import {Location} from 'history';
- import {GlobalSelection} from 'sentry-fixture/globalSelection';
- import {Organization} from 'sentry-fixture/organization';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import OrganizationStore from 'sentry/stores/organizationStore';
- import ProfileSummaryPage from 'sentry/views/profiling/profileSummary';
- Object.defineProperty(window, 'matchMedia', {
- writable: true,
- value: jest.fn().mockImplementation(query => ({
- matches: false,
- media: query,
- onchange: null,
- addListener: jest.fn(), // Deprecated
- removeListener: jest.fn(), // Deprecated
- addEventListener: jest.fn(),
- removeEventListener: jest.fn(),
- dispatchEvent: jest.fn(),
- })),
- });
- // Replace the webgl renderer with a dom renderer for tests
- jest.mock('sentry/utils/profiling/renderers/flamegraphRendererWebGL', () => {
- const {
- FlamegraphRendererDOM,
- } = require('sentry/utils/profiling/renderers/flamegraphRendererDOM');
- return {
- FlamegraphRendererWebGL: FlamegraphRendererDOM,
- };
- });
- window.ResizeObserver =
- window.ResizeObserver ||
- jest.fn().mockImplementation(() => ({
- disconnect: jest.fn(),
- observe: jest.fn(),
- unobserve: jest.fn(),
- }));
- describe('ProfileSummaryPage', () => {
- it('renders legacy page', async () => {
- const organization = Organization({
- features: [],
- projects: [TestStubs.Project()],
- });
- OrganizationStore.onUpdate(organization);
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [TestStubs.Project()],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/profiling/filters/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events-stats/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/profiling/flamegraph/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/profiling/function-trends/`,
- body: [],
- });
- render(
- <ProfileSummaryPage
- view="flamegraph"
- params={{}}
- selection={GlobalSelection()}
- location={
- {
- query: {transaction: 'fancyservice'},
- } as unknown as Location
- }
- />,
- {
- organization,
- context: TestStubs.routerContext(),
- }
- );
- expect(await screen.findByTestId(/profile-summary-legacy/i)).toBeInTheDocument();
- });
- it('renders new page', async () => {
- const organization = Organization({
- features: [],
- projects: [TestStubs.Project()],
- });
- OrganizationStore.onUpdate(organization);
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [TestStubs.Project()],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/profiling/filters/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events-stats/`,
- body: {},
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/profiling/flamegraph/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: {
- data: [{'last_seen()': new Date()}],
- },
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/profiling/function-trends/`,
- body: [],
- });
- render(
- <ProfileSummaryPage
- view="flamegraph"
- params={{}}
- selection={GlobalSelection()}
- location={
- {
- query: {transaction: 'fancyservice'},
- } as unknown as Location
- }
- />,
- {
- organization: Organization({
- features: ['profiling-summary-redesign'],
- }),
- context: TestStubs.routerContext(),
- }
- );
- expect(await screen.findByTestId(/profile-summary-redesign/i)).toBeInTheDocument();
- });
- });
|