Browse Source

test(ui): Reset mock apis in a few tests (#53675)

Scott Cooper 1 year ago
parent
commit
e0ba4579e8

+ 2 - 1
static/app/components/events/interfaces/debugMeta/debugImageDetails/index.spec.tsx

@@ -9,7 +9,8 @@ describe('Debug Meta - Image Details', function () {
   const event = TestStubs.Event({entries: [eventEntryDebugMeta]});
   const {organization, project} = initializeOrg();
 
-  beforeAll(function () {
+  beforeEach(function () {
+    MockApiClient.clearMockResponses();
     MockApiClient.addMockResponse({
       url: `/projects/${organization.slug}/${project.slug}/files/dsyms/?debug_id=${eventEntryDebugMeta.data.images[0].debug_id}`,
       method: 'GET',

+ 7 - 4
static/app/components/modals/inviteMembersModal/index.spec.tsx

@@ -44,10 +44,13 @@ describe('InviteMembersModal', function () {
     },
   ];
 
-  MockApiClient.addMockResponse({
-    url: `/organizations/${org.slug}/members/me/`,
-    method: 'GET',
-    body: {roles},
+  beforeEach(function () {
+    MockApiClient.clearMockResponses();
+    MockApiClient.addMockResponse({
+      url: `/organizations/${org.slug}/members/me/`,
+      method: 'GET',
+      body: {roles},
+    });
   });
 
   it('renders', async function () {

+ 2 - 1
static/app/views/alerts/rules/metric/duplicate.spec.tsx

@@ -8,7 +8,8 @@ import MetricRulesDuplicate from 'sentry/views/alerts/rules/metric/duplicate';
 import {AlertRuleTriggerType} from 'sentry/views/alerts/rules/metric/types';
 
 describe('Incident Rules Duplicate', function () {
-  beforeAll(function () {
+  beforeEach(function () {
+    MockApiClient.clearMockResponses();
     MockApiClient.addMockResponse({
       url: '/organizations/org-slug/users/',
       body: [],

+ 14 - 7
static/app/views/alerts/rules/metric/triggers/chart/index.spec.tsx

@@ -9,14 +9,21 @@ import {
 } from 'sentry/views/alerts/rules/metric/types';
 
 describe('Incident Rules Create', () => {
-  const eventStatsMock = MockApiClient.addMockResponse({
-    url: '/organizations/org-slug/events-stats/',
-    body: TestStubs.EventsStats(),
-  });
+  let eventStatsMock: jest.Func;
+  let eventCountsMock: jest.Func;
+  beforeEach(() => {
+    eventStatsMock = MockApiClient.addMockResponse({
+      url: '/organizations/org-slug/events-stats/',
+      body: TestStubs.EventsStats(),
+    });
 
-  const eventCountsMock = MockApiClient.addMockResponse({
-    url: '/organizations/org-slug/events-meta/',
-    body: {count: 5},
+    eventCountsMock = MockApiClient.addMockResponse({
+      url: '/organizations/org-slug/events-meta/',
+      body: {count: 5},
+    });
+  });
+  afterEach(() => {
+    MockApiClient.clearMockResponses();
   });
 
   const api = new MockApiClient();

+ 3 - 5
static/app/views/issueDetails/groupMerged/index.spec.tsx

@@ -23,17 +23,15 @@ describe('Issues -> Merged View', function () {
     ],
   };
 
-  beforeAll(function () {
+  beforeEach(function () {
+    GroupingStore.init();
+    MockApiClient.clearMockResponses();
     MockApiClient.addMockResponse({
       url: '/issues/groupId/hashes/?limit=50&query=',
       body: mockData.merged,
     });
   });
 
-  beforeEach(() => {
-    GroupingStore.init();
-  });
-
   it('renders initially with loading component', function () {
     const {organization, project, router, routerContext} = initializeOrg({
       project: {

+ 7 - 0
static/app/views/organizationStats/teamInsights/teamReleases.spec.tsx

@@ -3,6 +3,9 @@ import {render, screen} from 'sentry-test/reactTestingLibrary';
 import TeamReleases from './teamReleases';
 
 describe('TeamReleases', () => {
+  beforeEach(() => {
+    MockApiClient.clearMockResponses();
+  });
   it('should compare selected past release count with current week', async () => {
     const team = TestStubs.Team();
     const organization = TestStubs.Organization();
@@ -30,6 +33,10 @@ describe('TeamReleases', () => {
   });
 
   it('should render no release counts', async () => {
+    MockApiClient.addMockResponse({
+      url: `/teams/org-slug/team-slug/release-count/`,
+      body: TestStubs.TeamReleaseCounts(),
+    });
     const team = TestStubs.Team();
     const organization = TestStubs.Organization();
     const noReleaseProject = TestStubs.Project({id: 321});

+ 7 - 2
static/app/views/organizationStats/teamInsights/teamStability.spec.tsx

@@ -3,11 +3,16 @@ import {render, screen} from 'sentry-test/reactTestingLibrary';
 import TeamStability from 'sentry/views/organizationStats/teamInsights/teamStability';
 
 describe('TeamStability', () => {
-  it('should compare selected past crash rate with current week', async () => {
-    const sessionsApi = MockApiClient.addMockResponse({
+  let sessionsApi: jest.Mock;
+  beforeEach(() => {
+    MockApiClient.clearMockResponses();
+    sessionsApi = MockApiClient.addMockResponse({
       url: `/organizations/org-slug/sessions/`,
       body: TestStubs.SessionStatusCountByProjectInPeriod(),
     });
+  });
+
+  it('should compare selected past crash rate with current week', async () => {
     const project = TestStubs.Project({hasSessions: true, id: 123});
     render(
       <TeamStability

+ 5 - 5
static/app/views/replays/list/replaysList.spec.tsx

@@ -59,14 +59,14 @@ function getMockContext(mockOrg: Organization) {
   return TestStubs.routerContext([{organization: mockOrg}]);
 }
 
-MockApiClient.addMockResponse({
-  url: '/organizations/org-slug/sdk-updates/',
-  body: [],
-});
-
 describe('ReplayList', () => {
   beforeEach(() => {
     mockUseReplayList.mockClear();
+    MockApiClient.clearMockResponses();
+    MockApiClient.addMockResponse({
+      url: '/organizations/org-slug/sdk-updates/',
+      body: [],
+    });
   });
 
   it('should render the onboarding panel when the org is on AM1', async () => {

+ 2 - 2
static/app/views/settings/account/accountSecurity/accountSecurityEnroll.spec.tsx

@@ -6,7 +6,6 @@ const ENDPOINT = '/users/me/authenticators/';
 
 describe('AccountSecurityEnroll', function () {
   describe('Totp', function () {
-    MockApiClient.clearMockResponses();
     const authenticator = TestStubs.Authenticators().Totp({
       isEnrolled: false,
       qrcode: 'otpauth://totp/test%40sentry.io?issuer=Sentry&secret=secret',
@@ -29,7 +28,8 @@ describe('AccountSecurityEnroll', function () {
       },
     ]);
 
-    beforeAll(function () {
+    beforeEach(function () {
+      MockApiClient.clearMockResponses();
       MockApiClient.addMockResponse({
         url: `${ENDPOINT}${authenticator.authId}/enroll/`,
         body: authenticator,

+ 12 - 0
static/app/views/settings/account/apiApplications/index.spec.tsx

@@ -4,6 +4,10 @@ import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrar
 import ApiApplications from 'sentry/views/settings/account/apiApplications';
 
 describe('ApiApplications', function () {
+  beforeEach(function () {
+    MockApiClient.clearMockResponses();
+  });
+
   it('renders empty', function () {
     const {router} = initializeOrg();
 
@@ -55,6 +59,10 @@ describe('ApiApplications', function () {
   it('creates application', async function () {
     const {router} = initializeOrg();
 
+    MockApiClient.addMockResponse({
+      url: '/api-applications/',
+      body: [],
+    });
     const createApplicationRequest = MockApiClient.addMockResponse({
       url: '/api-applications/',
       body: TestStubs.ApiApplication({
@@ -89,6 +97,10 @@ describe('ApiApplications', function () {
   });
 
   it('deletes application', async function () {
+    MockApiClient.addMockResponse({
+      url: '/api-applications/',
+      body: [TestStubs.ApiApplication({id: '123'})],
+    });
     const deleteApplicationRequest = MockApiClient.addMockResponse({
       url: '/api-applications/123/',
       method: 'DELETE',

Some files were not shown because too many files changed in this diff