Просмотр исходного кода

test(js): Remove more unnecessary uses of org/router context (#40484)

Malachi Willey 2 лет назад
Родитель
Сommit
8f4cdac40a

+ 110 - 133
static/app/components/eventOrGroupHeader.spec.tsx

@@ -4,7 +4,6 @@ import {textWithMarkupMatcher} from 'sentry-test/utils';
 
 import EventOrGroupHeader from 'sentry/components/eventOrGroupHeader';
 import {EventOrGroupType} from 'sentry/types';
-import {OrganizationContext} from 'sentry/views/organizationContext';
 
 const group = TestStubs.Group({
   level: 'error',
@@ -40,9 +39,7 @@ describe('EventOrGroupHeader', function () {
   describe('Group', function () {
     it('renders with `type = error`', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader organization={organization} data={group} {...router} />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader organization={organization} data={group} {...router} />
       );
 
       expect(container).toSnapshot();
@@ -50,16 +47,14 @@ describe('EventOrGroupHeader', function () {
 
     it('renders with `type = csp`', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...group,
-              type: EventOrGroupType.CSP,
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...group,
+            type: EventOrGroupType.CSP,
+          }}
+          {...router}
+        />
       );
 
       expect(container).toSnapshot();
@@ -67,20 +62,18 @@ describe('EventOrGroupHeader', function () {
 
     it('renders with `type = default`', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...group,
-              type: EventOrGroupType.DEFAULT,
-              metadata: {
-                ...group.metadata,
-                title: 'metadata title',
-              },
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...group,
+            type: EventOrGroupType.DEFAULT,
+            metadata: {
+              ...group.metadata,
+              title: 'metadata title',
+            },
+          }}
+          {...router}
+        />
       );
 
       expect(container).toSnapshot();
@@ -88,16 +81,14 @@ describe('EventOrGroupHeader', function () {
 
     it('renders metadata values in message for error events', function () {
       render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...group,
-              type: EventOrGroupType.ERROR,
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...group,
+            type: EventOrGroupType.ERROR,
+          }}
+          {...router}
+        />
       );
 
       expect(screen.getByText('metadata value')).toBeInTheDocument();
@@ -105,20 +96,18 @@ describe('EventOrGroupHeader', function () {
 
     it('renders location', function () {
       render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...group,
-              metadata: {
-                filename: 'path/to/file.swift',
-              },
-              platform: 'swift',
-              type: EventOrGroupType.ERROR,
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...group,
+            metadata: {
+              filename: 'path/to/file.swift',
+            },
+            platform: 'swift',
+            type: EventOrGroupType.ERROR,
+          }}
+          {...router}
+        />
       );
 
       expect(
@@ -130,97 +119,87 @@ describe('EventOrGroupHeader', function () {
   describe('Event', function () {
     it('renders with `type = error`', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...event,
-              type: EventOrGroupType.ERROR,
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...event,
+            type: EventOrGroupType.ERROR,
+          }}
+          {...router}
+        />
       );
       expect(container).toSnapshot();
     });
 
     it('renders with `type = csp`', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...event,
-              type: EventOrGroupType.CSP,
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...event,
+            type: EventOrGroupType.CSP,
+          }}
+          {...router}
+        />
       );
       expect(container).toSnapshot();
     });
 
     it('renders with `type = default`', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...event,
-              type: EventOrGroupType.DEFAULT,
-              metadata: {
-                ...event.metadata,
-                title: 'metadata title',
-              },
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...event,
+            type: EventOrGroupType.DEFAULT,
+            metadata: {
+              ...event.metadata,
+              title: 'metadata title',
+            },
+          }}
+          {...router}
+        />
       );
       expect(container).toSnapshot();
     });
 
     it('hides level tag', function () {
       const {container} = render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            projectId="projectId"
-            hideLevel
-            organization={organization}
-            data={{
-              ...event,
-              type: EventOrGroupType.DEFAULT,
-              metadata: {
-                ...event.metadata,
-                title: 'metadata title',
-              },
-            }}
-            {...router}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          projectId="projectId"
+          hideLevel
+          organization={organization}
+          data={{
+            ...event,
+            type: EventOrGroupType.DEFAULT,
+            metadata: {
+              ...event.metadata,
+              title: 'metadata title',
+            },
+          }}
+          {...router}
+        />
       );
       expect(container).toSnapshot();
     });
 
     it('keeps sort in link when query has sort', function () {
       render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...event,
-              type: EventOrGroupType.DEFAULT,
-            }}
-            {...router}
-            location={{
-              ...router.location,
-              query: {
-                ...router.location.query,
-                sort: 'freq',
-              },
-            }}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...event,
+            type: EventOrGroupType.DEFAULT,
+          }}
+          {...router}
+          location={{
+            ...router.location,
+            query: {
+              ...router.location.query,
+              sort: 'freq',
+            },
+          }}
+        />
       );
 
       expect(screen.getByRole('link')).toHaveAttribute(
@@ -231,20 +210,18 @@ describe('EventOrGroupHeader', function () {
 
     it('lack of project adds allp parameter', function () {
       render(
-        <OrganizationContext.Provider value={organization}>
-          <EventOrGroupHeader
-            organization={organization}
-            data={{
-              ...event,
-              type: EventOrGroupType.DEFAULT,
-            }}
-            {...router}
-            location={{
-              ...router.location,
-              query: {},
-            }}
-          />
-        </OrganizationContext.Provider>
+        <EventOrGroupHeader
+          organization={organization}
+          data={{
+            ...event,
+            type: EventOrGroupType.DEFAULT,
+          }}
+          {...router}
+          location={{
+            ...router.location,
+            query: {},
+          }}
+        />
       );
 
       expect(screen.getByRole('link')).toHaveAttribute(

+ 54 - 81
static/app/components/eventOrGroupTitle.spec.tsx

@@ -1,11 +1,7 @@
-import {FC} from 'react';
-
-import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
 import {BaseGroup, EventOrGroupType, IssueCategory} from 'sentry/types';
-import {OrganizationContext} from 'sentry/views/organizationContext';
 
 describe('EventOrGroupTitle', function () {
   const data = {
@@ -17,28 +13,18 @@ describe('EventOrGroupTitle', function () {
     culprit: 'culprit',
   };
 
-  const {organization} = initializeOrg();
-
-  const TestComponent: FC = ({children}) => (
-    <OrganizationContext.Provider value={organization}>
-      {children}
-    </OrganizationContext.Provider>
-  );
-
   it('renders with subtitle when `type = error`', function () {
     const wrapper = render(
-      <TestComponent>
-        <EventOrGroupTitle
-          data={
-            {
-              ...data,
-              ...{
-                type: EventOrGroupType.ERROR,
-              },
-            } as BaseGroup
-          }
-        />
-      </TestComponent>
+      <EventOrGroupTitle
+        data={
+          {
+            ...data,
+            ...{
+              type: EventOrGroupType.ERROR,
+            },
+          } as BaseGroup
+        }
+      />
     );
 
     expect(wrapper.container).toSnapshot();
@@ -46,18 +32,16 @@ describe('EventOrGroupTitle', function () {
 
   it('renders with subtitle when `type = csp`', function () {
     const wrapper = render(
-      <TestComponent>
-        <EventOrGroupTitle
-          data={
-            {
-              ...data,
-              ...{
-                type: EventOrGroupType.CSP,
-              },
-            } as BaseGroup
-          }
-        />
-      </TestComponent>
+      <EventOrGroupTitle
+        data={
+          {
+            ...data,
+            ...{
+              type: EventOrGroupType.CSP,
+            },
+          } as BaseGroup
+        }
+      />
     );
 
     expect(wrapper.container).toSnapshot();
@@ -65,20 +49,18 @@ describe('EventOrGroupTitle', function () {
 
   it('renders with no subtitle when `type = default`', function () {
     const wrapper = render(
-      <TestComponent>
-        <EventOrGroupTitle
-          data={
-            {
-              ...data,
-              type: EventOrGroupType.DEFAULT,
-              metadata: {
-                ...data.metadata,
-                title: 'metadata title',
-              },
-            } as BaseGroup
-          }
-        />
-      </TestComponent>
+      <EventOrGroupTitle
+        data={
+          {
+            ...data,
+            type: EventOrGroupType.DEFAULT,
+            metadata: {
+              ...data.metadata,
+              title: 'metadata title',
+            },
+          } as BaseGroup
+        }
+      />
     );
 
     expect(wrapper.container).toSnapshot();
@@ -90,20 +72,18 @@ describe('EventOrGroupTitle', function () {
     ]);
 
     render(
-      <TestComponent>
-        <EventOrGroupTitle
-          data={
-            {
-              ...data,
-              type: EventOrGroupType.ERROR,
-              metadata: {
-                ...data.metadata,
-                title: 'metadata title',
-              },
-            } as BaseGroup
-          }
-        />
-      </TestComponent>,
+      <EventOrGroupTitle
+        data={
+          {
+            ...data,
+            type: EventOrGroupType.ERROR,
+            metadata: {
+              ...data.metadata,
+              title: 'metadata title',
+            },
+          } as BaseGroup
+        }
+      />,
       {context: routerContext}
     );
 
@@ -112,17 +92,15 @@ describe('EventOrGroupTitle', function () {
 
   it('does not render stack trace when issueCategory is performance', () => {
     render(
-      <TestComponent>
-        <EventOrGroupTitle
-          data={
-            {
-              ...data,
-              issueCategory: IssueCategory.PERFORMANCE,
-            } as BaseGroup
-          }
-          withStackTracePreview
-        />
-      </TestComponent>
+      <EventOrGroupTitle
+        data={
+          {
+            ...data,
+            issueCategory: IssueCategory.PERFORMANCE,
+          } as BaseGroup
+        }
+        withStackTracePreview
+      />
     );
 
     expect(screen.queryByTestId('stacktrace-preview')).not.toBeInTheDocument();
@@ -144,12 +122,7 @@ describe('EventOrGroupTitle', function () {
         {organization: TestStubs.Organization({features: ['custom-event-title']})},
       ]);
 
-      render(
-        <TestComponent>
-          <EventOrGroupTitle data={perfData} />
-        </TestComponent>,
-        {context: routerContext}
-      );
+      render(<EventOrGroupTitle data={perfData} />, {context: routerContext});
 
       expect(screen.getByText('N+1 Query')).toBeInTheDocument();
       expect(screen.getByText('transaction name')).toBeInTheDocument();

+ 60 - 99
static/app/components/events/eventTagsAndScreenshot/index.spec.tsx

@@ -1,41 +1,14 @@
-import {InjectedRouter} from 'react-router';
+import {Fragment} from 'react';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
 
 import EventTagsAndScreenshot from 'sentry/components/events/eventTagsAndScreenshot';
 import GlobalModal from 'sentry/components/globalModal';
-import {EventAttachment, Organization} from 'sentry/types';
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
+import {EventAttachment} from 'sentry/types';
 
 import {deviceNameMapper} from '../../../../../static/app/components/deviceName';
 
-function TestComponent({
-  organization,
-  router,
-  children,
-}: {
-  children: React.ReactNode;
-  organization: Organization;
-  router: InjectedRouter;
-}) {
-  return (
-    <OrganizationContext.Provider value={organization}>
-      <RouteContext.Provider
-        value={{
-          router,
-          location: router.location,
-          params: {},
-          routes: [],
-        }}
-      >
-        {children}
-      </RouteContext.Provider>
-    </OrganizationContext.Provider>
-  );
-}
-
 describe('EventTagsAndScreenshot', function () {
   const contexts = {
     app: {
@@ -181,17 +154,15 @@ describe('EventTagsAndScreenshot', function () {
   describe('renders tags only', function () {
     it('not shared event - without attachments', function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
-          <EventTagsAndScreenshot
-            event={{...event, tags, contexts}}
-            organization={organization}
-            projectId={project.slug}
-            location={router.location}
-            attachments={[]}
-            onDeleteScreenshot={() => jest.fn()}
-            hasContext
-          />
-        </TestComponent>
+        <EventTagsAndScreenshot
+          event={{...event, tags, contexts}}
+          organization={organization}
+          projectId={project.slug}
+          location={router.location}
+          attachments={[]}
+          onDeleteScreenshot={() => jest.fn()}
+          hasContext
+        />
       );
 
       // Screenshot Container
@@ -234,18 +205,16 @@ describe('EventTagsAndScreenshot', function () {
 
     it('shared event - without attachments', function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
-          <EventTagsAndScreenshot
-            event={{...event, tags, contexts}}
-            organization={organization}
-            projectId={project.slug}
-            location={router.location}
-            attachments={[]}
-            onDeleteScreenshot={() => jest.fn()}
-            hasContext
-            isShare
-          />
-        </TestComponent>
+        <EventTagsAndScreenshot
+          event={{...event, tags, contexts}}
+          organization={organization}
+          projectId={project.slug}
+          location={router.location}
+          attachments={[]}
+          onDeleteScreenshot={() => jest.fn()}
+          hasContext
+          isShare
+        />
       );
 
       // Screenshot Container
@@ -259,18 +228,16 @@ describe('EventTagsAndScreenshot', function () {
 
     it('shared event - with attachments', function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
-          <EventTagsAndScreenshot
-            event={{...event, tags, contexts}}
-            organization={organization}
-            projectId={project.slug}
-            location={router.location}
-            attachments={attachments}
-            onDeleteScreenshot={() => jest.fn()}
-            hasContext
-            isShare
-          />
-        </TestComponent>
+        <EventTagsAndScreenshot
+          event={{...event, tags, contexts}}
+          organization={organization}
+          projectId={project.slug}
+          location={router.location}
+          attachments={attachments}
+          onDeleteScreenshot={() => jest.fn()}
+          hasContext
+          isShare
+        />
       );
 
       // Screenshot Container
@@ -301,7 +268,7 @@ describe('EventTagsAndScreenshot', function () {
 
     it('no context and no tags', async function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
+        <Fragment>
           <GlobalModal />
           <EventTagsAndScreenshot
             event={event}
@@ -312,7 +279,7 @@ describe('EventTagsAndScreenshot', function () {
             onDeleteScreenshot={() => jest.fn()}
             hasContext={false}
           />
-        </TestComponent>
+        </Fragment>
       );
 
       // Tags Container
@@ -353,17 +320,15 @@ describe('EventTagsAndScreenshot', function () {
   describe('renders screenshot and tags', function () {
     it('has context, tags and attachments', function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
-          <EventTagsAndScreenshot
-            event={{...event, tags, contexts}}
-            organization={organization}
-            projectId={project.slug}
-            location={router.location}
-            attachments={attachments}
-            onDeleteScreenshot={() => jest.fn()}
-            hasContext
-          />
-        </TestComponent>
+        <EventTagsAndScreenshot
+          event={{...event, tags, contexts}}
+          organization={organization}
+          projectId={project.slug}
+          location={router.location}
+          attachments={attachments}
+          onDeleteScreenshot={() => jest.fn()}
+          hasContext
+        />
       );
 
       // Screenshot Container
@@ -388,17 +353,15 @@ describe('EventTagsAndScreenshot', function () {
 
     it('has context and attachments only', function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
-          <EventTagsAndScreenshot
-            event={{...event, contexts}}
-            organization={organization}
-            projectId={project.slug}
-            location={router.location}
-            attachments={attachments}
-            onDeleteScreenshot={() => jest.fn()}
-            hasContext
-          />
-        </TestComponent>
+        <EventTagsAndScreenshot
+          event={{...event, contexts}}
+          organization={organization}
+          projectId={project.slug}
+          location={router.location}
+          attachments={attachments}
+          onDeleteScreenshot={() => jest.fn()}
+          hasContext
+        />
       );
 
       // Screenshot Container
@@ -423,17 +386,15 @@ describe('EventTagsAndScreenshot', function () {
 
     it('has tags and attachments only', function () {
       const {container} = render(
-        <TestComponent organization={organization} router={router}>
-          <EventTagsAndScreenshot
-            event={{...event, tags}}
-            organization={organization}
-            projectId={project.slug}
-            location={router.location}
-            attachments={attachments}
-            onDeleteScreenshot={() => jest.fn()}
-            hasContext={false}
-          />
-        </TestComponent>
+        <EventTagsAndScreenshot
+          event={{...event, tags}}
+          organization={organization}
+          projectId={project.slug}
+          location={router.location}
+          attachments={attachments}
+          onDeleteScreenshot={() => jest.fn()}
+          hasContext={false}
+        />
       );
 
       // Screenshot Container

+ 15 - 22
static/app/components/groupPreviewTooltip/spanEvidencePreview.spec.tsx

@@ -1,4 +1,3 @@
-import {initializeOrg} from 'sentry-test/initializeOrg';
 import {
   MockSpan,
   ProblemSpan,
@@ -7,8 +6,6 @@ import {
 import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
 
 import * as useApi from 'sentry/utils/useApi';
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
 
 import {SpanEvidencePreview} from './spanEvidencePreview';
 
@@ -18,27 +15,19 @@ describe('SpanEvidencePreview', () => {
     jest.restoreAllMocks();
   });
 
-  const {organization, router} = initializeOrg();
-
-  const TestComponent: typeof SpanEvidencePreview = props => (
-    <OrganizationContext.Provider value={organization}>
-      <RouteContext.Provider
-        value={{router, location: router.location, params: {}, routes: []}}
-      >
-        <SpanEvidencePreview {...props} />
-      </RouteContext.Provider>
-    </OrganizationContext.Provider>
-  );
-
   it('does not fetch before hover', () => {
     const api = new MockApiClient();
     jest.spyOn(useApi, 'default').mockReturnValue(api);
     const spy = jest.spyOn(api, 'requestPromise');
 
     render(
-      <TestComponent eventId="event-id" projectSlug="project-slug" groupId="group-id">
+      <SpanEvidencePreview
+        eventId="event-id"
+        projectSlug="project-slug"
+        groupId="group-id"
+      >
         Hover me
-      </TestComponent>
+      </SpanEvidencePreview>
     );
 
     jest.runAllTimers();
@@ -53,9 +42,13 @@ describe('SpanEvidencePreview', () => {
     });
 
     render(
-      <TestComponent eventId="event-id" projectSlug="project-slug" groupId="group-id">
+      <SpanEvidencePreview
+        eventId="event-id"
+        projectSlug="project-slug"
+        groupId="group-id"
+      >
         Hover me
-      </TestComponent>
+      </SpanEvidencePreview>
     );
 
     userEvent.hover(screen.getByText('Hover me'));
@@ -71,7 +64,7 @@ describe('SpanEvidencePreview', () => {
       body: null,
     });
 
-    render(<TestComponent groupId="group-id">Hover me</TestComponent>);
+    render(<SpanEvidencePreview groupId="group-id">Hover me</SpanEvidencePreview>);
 
     userEvent.hover(screen.getByText('Hover me'));
 
@@ -85,7 +78,7 @@ describe('SpanEvidencePreview', () => {
     jest.spyOn(useApi, 'default').mockReturnValue(api);
     jest.spyOn(api, 'requestPromise').mockRejectedValue(new Error());
 
-    render(<TestComponent groupId="group-id">Hover me</TestComponent>);
+    render(<SpanEvidencePreview groupId="group-id">Hover me</SpanEvidencePreview>);
 
     userEvent.hover(screen.getByText('Hover me'));
 
@@ -151,7 +144,7 @@ describe('SpanEvidencePreview', () => {
       body: event,
     });
 
-    render(<TestComponent groupId="group-id">Hover me</TestComponent>);
+    render(<SpanEvidencePreview groupId="group-id">Hover me</SpanEvidencePreview>);
 
     userEvent.hover(screen.getByText('Hover me'));
 

+ 10 - 48
static/app/components/groupPreviewTooltip/stackTracePreview.spec.tsx

@@ -1,11 +1,8 @@
-import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
 
-import {EventError, Organization} from 'sentry/types';
+import {EventError} from 'sentry/types';
 import {EntryType, Event, ExceptionType, ExceptionValue, Frame} from 'sentry/types/event';
 import useApi from 'sentry/utils/useApi';
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
 
 import {StackTracePreview} from './stackTracePreview';
 
@@ -18,25 +15,6 @@ const makeEvent = (event: Partial<Event> = {}): Event => {
   return evt;
 };
 
-function TestComponent({org, children}: {children: React.ReactNode; org?: Organization}) {
-  const {organization, router} = initializeOrg();
-
-  return (
-    <OrganizationContext.Provider value={org ?? organization}>
-      <RouteContext.Provider
-        value={{
-          router,
-          location: router.location,
-          params: {},
-          routes: [],
-        }}
-      >
-        {children}
-      </RouteContext.Provider>
-    </OrganizationContext.Provider>
-  );
-}
-
 jest.mock('sentry/utils/useApi');
 
 describe('StackTracePreview', () => {
@@ -51,11 +29,9 @@ describe('StackTracePreview', () => {
     useApi.mockReturnValue(api);
 
     render(
-      <TestComponent>
-        <StackTracePreview issueId="issue" eventId="event_id" projectSlug="project_slug">
-          Preview Trigger
-        </StackTracePreview>
-      </TestComponent>
+      <StackTracePreview issueId="issue" eventId="event_id" projectSlug="project_slug">
+        Preview Trigger
+      </StackTracePreview>
     );
 
     userEvent.hover(screen.getByText(/Preview Trigger/));
@@ -76,11 +52,7 @@ describe('StackTracePreview', () => {
     // @ts-ignore useApi is mocked
     useApi.mockReturnValue(api);
 
-    render(
-      <TestComponent>
-        <StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>
-      </TestComponent>
-    );
+    render(<StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>);
 
     userEvent.hover(screen.getByText(/Preview Trigger/));
 
@@ -100,11 +72,7 @@ describe('StackTracePreview', () => {
     // @ts-ignore useApi is mocked
     useApi.mockReturnValue(api);
 
-    render(
-      <TestComponent>
-        <StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>
-      </TestComponent>
-    );
+    render(<StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>);
 
     userEvent.hover(screen.getByText(/Preview Trigger/));
 
@@ -120,11 +88,7 @@ describe('StackTracePreview', () => {
     // @ts-ignore useApi is mocked
     useApi.mockReturnValue(api);
 
-    render(
-      <TestComponent>
-        <StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>
-      </TestComponent>
-    );
+    render(<StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>);
 
     userEvent.hover(screen.getByText(/Preview Trigger/));
 
@@ -194,11 +158,9 @@ describe('StackTracePreview', () => {
     // @ts-ignore useApi is mocked
     useApi.mockReturnValue(api);
 
-    render(
-      <TestComponent org={TestStubs.Organization({features})}>
-        <StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>
-      </TestComponent>
-    );
+    render(<StackTracePreview issueId="issue">Preview Trigger</StackTracePreview>, {
+      organization: {features},
+    });
 
     userEvent.hover(screen.getByText(/Preview Trigger/));
 

+ 2 - 21
static/app/components/profiling/functionsTable.spec.tsx

@@ -1,38 +1,19 @@
-import {ReactElement, useEffect, useMemo} from 'react';
+import {ReactElement, useEffect} from 'react';
 
-import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import {FunctionsTable} from 'sentry/components/profiling/functionsTable';
 import ProjectsStore from 'sentry/stores/projectsStore';
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
 
-const organization = TestStubs.Organization();
 const project = TestStubs.Project();
 
 function TestContext({children}: {children: ReactElement}) {
-  const {router} = useMemo(() => initializeOrg({organization, project} as any), []);
-
   useEffect(() => {
     ProjectsStore.loadInitialData([project]);
     return () => ProjectsStore.reset();
   }, []);
 
-  return (
-    <RouteContext.Provider
-      value={{
-        router,
-        location: router.location,
-        params: {},
-        routes: [],
-      }}
-    >
-      <OrganizationContext.Provider value={organization}>
-        {children}
-      </OrganizationContext.Provider>
-    </RouteContext.Provider>
-  );
+  return children;
 }
 
 describe('FunctionsTable', function () {

+ 2 - 21
static/app/components/profiling/profilesTable.spec.tsx

@@ -1,38 +1,19 @@
-import {ReactElement, useEffect, useMemo} from 'react';
+import {ReactElement, useEffect} from 'react';
 
-import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import {ProfilesTable} from 'sentry/components/profiling/profilesTable';
 import ProjectsStore from 'sentry/stores/projectsStore';
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
 
-const organization = TestStubs.Organization();
 const project = TestStubs.Project();
 
 function TestContext({children}: {children: ReactElement}) {
-  const {router} = useMemo(() => initializeOrg({organization, project} as any), []);
-
   useEffect(() => {
     ProjectsStore.loadInitialData([project]);
     return () => ProjectsStore.reset();
   }, []);
 
-  return (
-    <RouteContext.Provider
-      value={{
-        router,
-        location: router.location,
-        params: {},
-        routes: [],
-      }}
-    >
-      <OrganizationContext.Provider value={organization}>
-        {children}
-      </OrganizationContext.Provider>
-    </RouteContext.Provider>
-  );
+  return children;
 }
 
 describe('ProfilesTable', function () {

+ 8 - 45
static/app/components/replays/replayTagsTableRow.spec.tsx

@@ -1,9 +1,5 @@
-import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
-
 import ReplayTagsTableRow from './replayTagsTableRow';
 
 const releaseTag = {
@@ -16,32 +12,9 @@ const genericTag = {
   value: ['bar', 'baz'],
 };
 
-function TestComponent({children}) {
-  const {organization, router} = initializeOrg();
-
-  return (
-    <OrganizationContext.Provider value={organization}>
-      <RouteContext.Provider
-        value={{
-          router,
-          location: router.location,
-          params: {},
-          routes: [],
-        }}
-      >
-        {children}
-      </RouteContext.Provider>
-    </OrganizationContext.Provider>
-  );
-}
-
 describe('ReplayTagsTableRow', () => {
   it('Should render tag key and value correctly', () => {
-    render(
-      <TestComponent>
-        <ReplayTagsTableRow tag={genericTag} />
-      </TestComponent>
-    );
+    render(<ReplayTagsTableRow tag={genericTag} />);
 
     expect(screen.getByText('foo')).toBeInTheDocument();
     expect(screen.getByText('bar')).toBeInTheDocument();
@@ -49,11 +22,7 @@ describe('ReplayTagsTableRow', () => {
   });
 
   it('Should render release tags correctly', () => {
-    render(
-      <TestComponent>
-        <ReplayTagsTableRow tag={releaseTag} />
-      </TestComponent>
-    );
+    render(<ReplayTagsTableRow tag={releaseTag} />);
 
     expect(screen.getByText('release')).toBeInTheDocument();
     expect(screen.getByText('1.0.0')).toBeInTheDocument();
@@ -61,11 +30,7 @@ describe('ReplayTagsTableRow', () => {
   });
 
   it('Should render the tag value as a link if we get a link result from generateUrl', () => {
-    render(
-      <TestComponent>
-        <ReplayTagsTableRow tag={genericTag} generateUrl={() => 'https://foo.bar'} />
-      </TestComponent>
-    );
+    render(<ReplayTagsTableRow tag={genericTag} generateUrl={() => 'https://foo.bar'} />);
 
     expect(screen.getByText('foo')).toBeInTheDocument();
     expect(screen.getByText('bar')).toBeInTheDocument();
@@ -77,13 +42,11 @@ describe('ReplayTagsTableRow', () => {
 
   it('Should not render the tag value as a link if we get the value in the query prop', () => {
     render(
-      <TestComponent>
-        <ReplayTagsTableRow
-          tag={genericTag}
-          generateUrl={() => 'https://foo.bar'}
-          query="foo:bar"
-        />
-      </TestComponent>
+      <ReplayTagsTableRow
+        tag={genericTag}
+        generateUrl={() => 'https://foo.bar'}
+        query="foo:bar"
+      />
     );
 
     expect(screen.getByText('foo')).toBeInTheDocument();

+ 3 - 16
static/app/components/sidebar/index.spec.jsx

@@ -5,8 +5,6 @@ import * as incidentActions from 'sentry/actionCreators/serviceIncidents';
 import SidebarContainer from 'sentry/components/sidebar';
 import ConfigStore from 'sentry/stores/configStore';
 import {PersistedStoreProvider} from 'sentry/stores/persistedStore';
-import {OrganizationContext} from 'sentry/views/organizationContext';
-import {RouteContext} from 'sentry/views/routeContext';
 
 jest.mock('sentry/actionCreators/serviceIncidents');
 
@@ -19,20 +17,9 @@ describe('Sidebar', function () {
   const location = {...router.location, ...{pathname: '/test/'}};
 
   const getElement = props => (
-    <RouteContext.Provider
-      value={{
-        location,
-        params: {},
-        router,
-        routes: [],
-      }}
-    >
-      <OrganizationContext.Provider value={organization}>
-        <PersistedStoreProvider>
-          <SidebarContainer organization={organization} location={location} {...props} />
-        </PersistedStoreProvider>
-      </OrganizationContext.Provider>
-    </RouteContext.Provider>
+    <PersistedStoreProvider>
+      <SidebarContainer organization={organization} location={location} {...props} />
+    </PersistedStoreProvider>
   );
 
   const renderSidebar = props => render(getElement(props));

+ 70 - 102
static/app/components/sidebar/sidebarDropdown/switchOrganization.spec.tsx

@@ -1,33 +1,18 @@
 import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
 
 import {SwitchOrganization} from 'sentry/components/sidebar/sidebarDropdown/switchOrganization';
-import {Organization} from 'sentry/types';
-import {OrganizationContext} from 'sentry/views/organizationContext';
 
 describe('SwitchOrganization', function () {
-  function mountWithOrg(children, organization?: Organization) {
-    if (!organization) {
-      organization = TestStubs.Organization() as Organization;
-    }
-    return (
-      <OrganizationContext.Provider value={organization}>
-        {children}
-      </OrganizationContext.Provider>
-    );
-  }
-
   it('can list organizations', function () {
     jest.useFakeTimers();
     render(
-      mountWithOrg(
-        <SwitchOrganization
-          canCreateOrganization={false}
-          organizations={[
-            TestStubs.Organization({name: 'Organization 1'}),
-            TestStubs.Organization({name: 'Organization 2', slug: 'org2'}),
-          ]}
-        />
-      )
+      <SwitchOrganization
+        canCreateOrganization={false}
+        organizations={[
+          TestStubs.Organization({name: 'Organization 1'}),
+          TestStubs.Organization({name: 'Organization 2', slug: 'org2'}),
+        ]}
+      />
     );
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
@@ -53,23 +38,21 @@ describe('SwitchOrganization', function () {
   it('uses organizationUrl when customer domain is enabled', function () {
     jest.useFakeTimers();
     render(
-      mountWithOrg(
-        <SwitchOrganization
-          canCreateOrganization={false}
-          organizations={[
-            TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
-            TestStubs.Organization({
-              name: 'Organization 2',
-              slug: 'org2',
-              links: {
-                organizationUrl: 'http://org2.sentry.io',
-                regionUrl: 'http://eu.sentry.io',
-              },
-              features: ['customer-domains'],
-            }),
-          ]}
-        />
-      )
+      <SwitchOrganization
+        canCreateOrganization={false}
+        organizations={[
+          TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
+          TestStubs.Organization({
+            name: 'Organization 2',
+            slug: 'org2',
+            links: {
+              organizationUrl: 'http://org2.sentry.io',
+              regionUrl: 'http://eu.sentry.io',
+            },
+            features: ['customer-domains'],
+          }),
+        ]}
+      />
     );
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
@@ -93,23 +76,21 @@ describe('SwitchOrganization', function () {
   it('does not use organizationUrl when customer domain is disabled', function () {
     jest.useFakeTimers();
     render(
-      mountWithOrg(
-        <SwitchOrganization
-          canCreateOrganization={false}
-          organizations={[
-            TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
-            TestStubs.Organization({
-              name: 'Organization 2',
-              slug: 'org2',
-              links: {
-                organizationUrl: 'http://org2.sentry.io',
-                regionUrl: 'http://eu.sentry.io',
-              },
-              features: [],
-            }),
-          ]}
-        />
-      )
+      <SwitchOrganization
+        canCreateOrganization={false}
+        organizations={[
+          TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
+          TestStubs.Organization({
+            name: 'Organization 2',
+            slug: 'org2',
+            links: {
+              organizationUrl: 'http://org2.sentry.io',
+              regionUrl: 'http://eu.sentry.io',
+            },
+            features: [],
+          }),
+        ]}
+      />
     );
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
@@ -139,16 +120,14 @@ describe('SwitchOrganization', function () {
       features: ['customer-domains'],
     });
     render(
-      mountWithOrg(
-        <SwitchOrganization
-          canCreateOrganization={false}
-          organizations={[
-            TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
-            currentOrg,
-          ]}
-        />,
-        currentOrg
-      )
+      <SwitchOrganization
+        canCreateOrganization={false}
+        organizations={[
+          TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
+          currentOrg,
+        ]}
+      />,
+      {organization: currentOrg}
     );
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
@@ -186,24 +165,22 @@ describe('SwitchOrganization', function () {
       features: [],
     });
     render(
-      mountWithOrg(
-        <SwitchOrganization
-          canCreateOrganization={false}
-          organizations={[
-            TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
-            TestStubs.Organization({
-              name: 'Organization 3',
-              slug: 'org3',
-              links: {
-                organizationUrl: 'http://org3.sentry.io',
-                regionUrl: 'http://eu.sentry.io',
-              },
-              features: ['customer-domains'],
-            }),
-          ]}
-        />,
-        currentOrg
-      )
+      <SwitchOrganization
+        canCreateOrganization={false}
+        organizations={[
+          TestStubs.Organization({name: 'Organization 1', slug: 'org1'}),
+          TestStubs.Organization({
+            name: 'Organization 3',
+            slug: 'org3',
+            links: {
+              organizationUrl: 'http://org3.sentry.io',
+              regionUrl: 'http://eu.sentry.io',
+            },
+            features: ['customer-domains'],
+          }),
+        ]}
+      />,
+      {organization: currentOrg}
     );
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
@@ -226,7 +203,7 @@ describe('SwitchOrganization', function () {
 
   it('shows "Create an Org" if they have permission', function () {
     jest.useFakeTimers();
-    render(mountWithOrg(<SwitchOrganization canCreateOrganization organizations={[]} />));
+    render(<SwitchOrganization canCreateOrganization organizations={[]} />);
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
     act(() => void jest.advanceTimersByTime(500));
@@ -241,11 +218,7 @@ describe('SwitchOrganization', function () {
 
   it('does not have "Create an Org" if they do not have permission', function () {
     jest.useFakeTimers();
-    render(
-      mountWithOrg(
-        <SwitchOrganization canCreateOrganization={false} organizations={[]} />
-      )
-    );
+    render(<SwitchOrganization canCreateOrganization={false} organizations={[]} />);
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
     act(() => void jest.advanceTimersByTime(500));
@@ -266,12 +239,9 @@ describe('SwitchOrganization', function () {
     });
 
     jest.useFakeTimers();
-    render(
-      mountWithOrg(
-        <SwitchOrganization canCreateOrganization organizations={[]} />,
-        currentOrg
-      )
-    );
+    render(<SwitchOrganization canCreateOrganization organizations={[]} />, {
+      organization: currentOrg,
+    });
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));
     act(() => void jest.advanceTimersByTime(500));
@@ -292,12 +262,10 @@ describe('SwitchOrganization', function () {
 
     jest.useFakeTimers();
     render(
-      mountWithOrg(
-        <SwitchOrganization
-          canCreateOrganization
-          organizations={[TestStubs.Organization(), orgPendingDeletion]}
-        />
-      )
+      <SwitchOrganization
+        canCreateOrganization
+        organizations={[TestStubs.Organization(), orgPendingDeletion]}
+      />
     );
 
     userEvent.hover(screen.getByTestId('sidebar-switch-org'));

Некоторые файлы не были показаны из-за большого количества измененных файлов