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

test: Import from sentry-fixture inside test files [3] (#56812)

<!-- Describe your PR here. -->
Ryan Albrecht 1 год назад
Родитель
Сommit
6047aa2fa9

+ 1 - 27
fixtures/js-stubs/types.tsx

@@ -1,4 +1,4 @@
-import {EntryException, ReleaseMeta} from 'sentry/types';
+import {EntryException} from 'sentry/types';
 import type {
   ReplayError,
   ReplayListRecord,
@@ -42,42 +42,16 @@ type TestStubFixtures = {
   Member: OverridableStub;
   Members: OverridableStubList;
   MetricRule: OverridableStub;
-  MetricsField: (field: string, params?: Partial<any>) => any;
-  MetricsMeta: OverridableStub;
-  MetricsSessionUserCountByStatusByRelease: SimpleStub;
-  MetricsTotalCountByReleaseIn24h: SimpleStub;
-  MissingMembers: OverridableStubList;
-  NotificationDefaults: SimpleStub;
-  OpsgenieIntegration: OverridableStub;
-  OpsgenieIntegrationProvider: OverridableStub;
-  OrgOwnedApps: SimpleStub;
   OrgRoleList: OverridableStub;
   Organization: OverridableStub;
-  OrganizationEvent: OverridableStub;
-  OrganizationIntegrations: OverridableStub;
-  Organizations: OverridableStub;
-  Outcomes: SimpleStub;
-  OutcomesWithLowProcessedEvents: SimpleStub;
-  OutcomesWithReason: SimpleStub;
-  OutcomesWithoutClientDiscarded: SimpleStub;
   PageFilters: OverridableStub;
-  PhabricatorCreate: SimpleStub;
-  PhabricatorPlugin: SimpleStub;
   PlatformExternalIssue: OverridableStub;
   Plugin: OverridableStub;
-  PluginListConfig: SimpleStub;
   Plugins: OverridableStubList;
   Project: OverridableStub;
   ProjectAlertRule: OverridableStub;
-  ProjectAlertRuleConfiguration: OverridableStub;
-  ProjectDetails: OverridableStub;
-  ProjectFilters: OverridableStubList;
   ProjectKeys: OverridableStubList;
-  ProviderList: SimpleStub;
-  PublishedApps: SimpleStub;
-  PullRequest: OverridableStub;
   Release: (params?: any, healthParams?: any) => any;
-  ReleaseMeta: OverridableStub<ReleaseMeta>;
   Replay: typeof Replay;
   ReplayError: OverridableStub<ReplayError>;
   ReplayList: OverridableStubList<ReplayListRecord>;

+ 4 - 2
static/app/components/inactivePlugins.spec.tsx

@@ -1,3 +1,5 @@
+import {Plugins} from 'sentry-fixture/plugins';
+
 import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
 
 import InactivePlugins from 'sentry/components/inactivePlugins';
@@ -11,12 +13,12 @@ describe('InactivePlugins', function () {
   });
 
   it('renders plugins list', function () {
-    render(<InactivePlugins onEnablePlugin={() => {}} plugins={TestStubs.Plugins()} />);
+    render(<InactivePlugins onEnablePlugin={() => {}} plugins={Plugins()} />);
   });
 
   it('enables a plugin', async function () {
     const enableFn = jest.fn();
-    const plugins = TestStubs.Plugins();
+    const plugins = Plugins();
     render(<InactivePlugins onEnablePlugin={enableFn} plugins={plugins} />);
     await userEvent.click(screen.getByRole('button', {name: plugins[0].name}));
     expect(enableFn).toHaveBeenCalledWith(expect.objectContaining(plugins[0]));

+ 2 - 1
static/app/components/modals/inviteMissingMembersModal/index.spec.tsx

@@ -1,5 +1,6 @@
 import selectEvent from 'react-select-event';
 import styled from '@emotion/styled';
+import {MissingMembers} from 'sentry-fixture/missingMembers';
 
 import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
 
@@ -29,7 +30,7 @@ describe('InviteMissingMembersModal', function () {
   const team = TestStubs.Team();
   const org = TestStubs.Organization({access: ['member:write'], teams: [team]});
   TeamStore.loadInitialData([team]);
-  const missingMembers = {integration: 'github', users: TestStubs.MissingMembers()};
+  const missingMembers = {integration: 'github', users: MissingMembers()};
 
   const styledWrapper = styled(c => c.children);
   const modalProps: InviteMissingMembersModalProps = {

+ 2 - 1
static/app/components/modals/widgetViewerModal.spec.tsx

@@ -1,4 +1,5 @@
 import ReactEchartsCore from 'echarts-for-react/lib/core';
+import {MetricsTotalCountByReleaseIn24h} from 'sentry-fixture/metrics';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
@@ -1275,7 +1276,7 @@ describe('Modals -> WidgetViewerModal', function () {
       jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
       metricsMock = MockApiClient.addMockResponse({
         url: '/organizations/org-slug/metrics/data/',
-        body: TestStubs.MetricsTotalCountByReleaseIn24h(),
+        body: MetricsTotalCountByReleaseIn24h(),
         headers: {
           link:
             '<http://localhost/api/0/organizations/org-slug/metrics/data/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +

+ 8 - 6
static/app/components/pullRequestLink.spec.tsx

@@ -1,3 +1,5 @@
+import {PullRequest} from 'sentry-fixture/pullRequest';
+
 import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import PullRequestLink from 'sentry/components/pullRequestLink';
@@ -5,9 +7,9 @@ import PullRequestLink from 'sentry/components/pullRequestLink';
 describe('PullRequestLink', () => {
   it('renders no url on missing externalUrl', () => {
     const repository = TestStubs.Repository({provider: null});
-    const pullRequest = TestStubs.PullRequest({
+    const pullRequest = PullRequest({
       repository,
-      externalUrl: null,
+      externalUrl: undefined,
     });
     render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
 
@@ -21,7 +23,7 @@ describe('PullRequestLink', () => {
         id: 'integrations:github',
       },
     });
-    const pullRequest = TestStubs.PullRequest({repository});
+    const pullRequest = PullRequest({repository});
     render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
 
     expect(screen.getByTestId('pull-request-github')).toBeInTheDocument();
@@ -37,7 +39,7 @@ describe('PullRequestLink', () => {
         id: 'github',
       },
     });
-    const pullRequest = TestStubs.PullRequest({repository});
+    const pullRequest = PullRequest({repository});
     render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
 
     expect(screen.getByTestId('pull-request-github')).toBeInTheDocument();
@@ -52,7 +54,7 @@ describe('PullRequestLink', () => {
         id: 'integrations:gitlab',
       },
     });
-    const pullRequest = TestStubs.PullRequest({repository});
+    const pullRequest = PullRequest({repository});
     render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
 
     expect(screen.getByTestId('pull-request-gitlab')).toBeInTheDocument();
@@ -67,7 +69,7 @@ describe('PullRequestLink', () => {
         id: 'gitlab',
       },
     });
-    const pullRequest = TestStubs.PullRequest({repository});
+    const pullRequest = PullRequest({repository});
     render(<PullRequestLink repository={repository} pullRequest={pullRequest} />);
 
     expect(screen.getByTestId('pull-request-gitlab')).toBeInTheDocument();

+ 10 - 7
static/app/stores/pluginsStore.spec.tsx

@@ -1,3 +1,6 @@
+import {Plugin} from 'sentry-fixture/plugin';
+import {Plugins} from 'sentry-fixture/plugins';
+
 import PluginsStore from 'sentry/stores/pluginsStore';
 
 describe('PluginsStore', function () {
@@ -30,13 +33,13 @@ describe('PluginsStore', function () {
         plugins: [],
       });
 
-      PluginsStore.onFetchAllSuccess(TestStubs.Plugins(), {pageLinks: undefined});
+      PluginsStore.onFetchAllSuccess(Plugins(), {pageLinks: undefined});
 
       expect(triggerSpy).toHaveBeenCalledWith({
         loading: false,
         error: null,
         pageLinks: null,
-        plugins: TestStubs.Plugins(),
+        plugins: Plugins(),
       });
     });
 
@@ -71,13 +74,13 @@ describe('PluginsStore', function () {
         plugins: [],
       });
 
-      PluginsStore.onFetchAllSuccess(TestStubs.Plugins(), {pageLinks: undefined});
+      PluginsStore.onFetchAllSuccess(Plugins(), {pageLinks: undefined});
 
       expect(triggerSpy).toHaveBeenCalledWith({
         loading: false,
         error: null,
         pageLinks: null,
-        plugins: TestStubs.Plugins(),
+        plugins: Plugins(),
       });
 
       PluginsStore.onFetchAll();
@@ -85,16 +88,16 @@ describe('PluginsStore', function () {
         loading: false,
         error: null,
         pageLinks: null,
-        plugins: TestStubs.Plugins(),
+        plugins: Plugins(),
       });
     });
   });
 
   describe('update', function () {
-    const plugin = TestStubs.Plugin();
+    const plugin = Plugin();
     beforeEach(function () {
       PluginsStore.reset();
-      PluginsStore.plugins = new Map(TestStubs.Plugins().map(p => [p.id, p]));
+      PluginsStore.plugins = new Map(Plugins().map(p => [p.id, p]));
     });
 
     it('has optimistic state when updating', function () {

+ 2 - 1
static/app/utils/discover/eventView.spec.tsx

@@ -1,4 +1,5 @@
 import shuffle from 'lodash/shuffle';
+import {PageFilters} from 'sentry-fixture/pageFilters';
 
 import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
 import {NewQuery, SavedQuery} from 'sentry/types';
@@ -515,7 +516,7 @@ describe('EventView.fromNewQueryWithPageFilters()', function () {
   };
 
   it('maps basic properties of a prebuilt query', function () {
-    const pageFilters = TestStubs.PageFilters();
+    const pageFilters = PageFilters();
 
     const eventView = EventView.fromNewQueryWithPageFilters(prebuiltQuery, pageFilters);
 

+ 9 - 7
static/app/views/alerts/create.spec.tsx

@@ -1,5 +1,7 @@
 import selectEvent from 'react-select-event';
 import {Groups} from 'sentry-fixture/groups';
+import {ProjectAlertRule} from 'sentry-fixture/projectAlertRule';
+import {ProjectAlertRuleConfiguration} from 'sentry-fixture/projectAlertRuleConfiguration';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
@@ -40,11 +42,11 @@ describe('ProjectAlertsCreate', function () {
     TeamStore.loadInitialData([], false, null);
     MockApiClient.addMockResponse({
       url: '/projects/org-slug/project-slug/rules/configuration/',
-      body: TestStubs.ProjectAlertRuleConfiguration(),
+      body: ProjectAlertRuleConfiguration(),
     });
     MockApiClient.addMockResponse({
       url: '/projects/org-slug/project-slug/rules/1/',
-      body: TestStubs.ProjectAlertRule(),
+      body: ProjectAlertRule(),
     });
     MockApiClient.addMockResponse({
       url: '/projects/org-slug/project-slug/environments/',
@@ -145,7 +147,7 @@ describe('ProjectAlertsCreate', function () {
       const mock = MockApiClient.addMockResponse({
         url: '/projects/org-slug/project-slug/rules/',
         method: 'POST',
-        body: TestStubs.ProjectAlertRule(),
+        body: ProjectAlertRule(),
       });
 
       // Change name of alert rule
@@ -188,7 +190,7 @@ describe('ProjectAlertsCreate', function () {
       const mock = MockApiClient.addMockResponse({
         url: '/projects/org-slug/project-slug/rules/',
         method: 'POST',
-        body: TestStubs.ProjectAlertRule(),
+        body: ProjectAlertRule(),
       });
       // delete node
       await userEvent.click(screen.getByLabelText('Delete Node'));
@@ -238,7 +240,7 @@ describe('ProjectAlertsCreate', function () {
       const mock = MockApiClient.addMockResponse({
         url: '/projects/org-slug/project-slug/rules/',
         method: 'POST',
-        body: TestStubs.ProjectAlertRule(),
+        body: ProjectAlertRule(),
       });
 
       // Change name of alert rule
@@ -283,7 +285,7 @@ describe('ProjectAlertsCreate', function () {
         mock = MockApiClient.addMockResponse({
           url: '/projects/org-slug/project-slug/rules/',
           method: 'POST',
-          body: TestStubs.ProjectAlertRule(),
+          body: ProjectAlertRule(),
         });
       });
 
@@ -650,7 +652,7 @@ describe('ProjectAlertsCreate', function () {
     const mock = MockApiClient.addMockResponse({
       url: '/projects/org-slug/project-slug/rules/',
       method: 'POST',
-      body: TestStubs.ProjectAlertRule(),
+      body: ProjectAlertRule(),
     });
 
     createWrapper({organization: {features: ['noisy-alert-warning']}});

+ 2 - 1
static/app/views/alerts/list/incidents/index.spec.tsx

@@ -1,6 +1,7 @@
 import selectEvent from 'react-select-event';
 import {Incident} from 'sentry-fixture/incident';
 import {IncidentStats} from 'sentry-fixture/incidentStats';
+import {MetricRule} from 'sentry-fixture/metricRule';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {act, render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
@@ -245,7 +246,7 @@ describe('IncidentsList', () => {
           identifier: '1',
           title: 'First incident',
           projects: projects1,
-          alertRule: TestStubs.MetricRule({owner: `team:${team.id}`}),
+          alertRule: MetricRule({owner: `team:${team.id}`}),
         }),
       ],
     });

+ 9 - 7
static/app/views/alerts/list/rules/alertRulesList.spec.tsx

@@ -1,4 +1,6 @@
 import {Incident} from 'sentry-fixture/incident';
+import {MetricRule} from 'sentry-fixture/metricRule';
+import {ProjectAlertRule} from 'sentry-fixture/projectAlertRule';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {
@@ -35,20 +37,20 @@ describe('AlertRulesList', () => {
       url: '/organizations/org-slug/combined-rules/',
       headers: {Link: pageLinks},
       body: [
-        TestStubs.ProjectAlertRule({
+        ProjectAlertRule({
           id: '123',
           name: 'First Issue Alert',
           projects: ['earth'],
           createdBy: {name: 'Samwise', id: 1, email: ''},
         }),
-        TestStubs.MetricRule({
+        MetricRule({
           id: '345',
           projects: ['earth'],
           latestIncident: Incident({
             status: IncidentStatus.CRITICAL,
           }),
         }),
-        TestStubs.MetricRule({
+        MetricRule({
           id: '678',
           projects: ['earth'],
           latestIncident: null,
@@ -335,7 +337,7 @@ describe('AlertRulesList', () => {
       url: '/organizations/org-slug/combined-rules/',
       headers: {Link: pageLinks},
       body: [
-        TestStubs.ProjectAlertRule({
+        ProjectAlertRule({
           name: 'First Issue Alert',
           projects: ['earth'],
           status: 'disabled',
@@ -353,7 +355,7 @@ describe('AlertRulesList', () => {
       url: '/organizations/org-slug/combined-rules/',
       headers: {Link: pageLinks},
       body: [
-        TestStubs.ProjectAlertRule({
+        ProjectAlertRule({
           name: 'First Issue Alert',
           projects: ['earth'],
           // both disabled and muted
@@ -374,7 +376,7 @@ describe('AlertRulesList', () => {
       url: '/organizations/org-slug/combined-rules/',
       headers: {Link: pageLinks},
       body: [
-        TestStubs.ProjectAlertRule({
+        ProjectAlertRule({
           name: 'First Issue Alert',
           projects: ['earth'],
           snooze: true,
@@ -392,7 +394,7 @@ describe('AlertRulesList', () => {
       url: '/organizations/org-slug/combined-rules/',
       headers: {Link: pageLinks},
       body: [
-        TestStubs.MetricRule({
+        MetricRule({
           projects: ['earth'],
           snooze: true,
         }),

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