Browse Source

ref(ts): Remove usage of `TestStubs.Release` (#62317)

Pretty straight-forward, but had to add some more specific fixtures to
match the required objects.

- Replace `TestStubs.Release` with import
- Use enum for status
- Extract `HealthFixture`
- Allow empty params in `ReleaseMeta` fixture
- Add more specific fixtures
- Use type enum

https://github.com/getsentry/frontend-tsc/issues/49
George Gritsouk 1 year ago
parent
commit
9f089a4104

+ 50 - 0
fixtures/js-stubs/health.tsx

@@ -0,0 +1,50 @@
+import {Health} from 'sentry/types';
+
+export function HealthFixture(params: Partial<Health> = {}): Health {
+  return {
+    totalUsers24h: null,
+    durationP50: 231,
+    hasHealthData: true,
+    sessionsAdoption: 0,
+    totalProjectSessions24h: 0,
+    totalProjectUsers24h: 0,
+    totalSessions24h: 0,
+    totalSessions: 74949,
+    totalUsers: 2544,
+    crashFreeSessions: 99.59839357429719,
+    sessionsErrored: 301,
+    crashFreeUsers: 98.07389937106919,
+    durationP90: 333,
+    adoption: null,
+    sessionsCrashed: 301,
+    stats: {
+      '24h': [
+        [1585472400, 0],
+        [1585476000, 0],
+        [1585479600, 0],
+        [1585483200, 0],
+        [1585486800, 0],
+        [1585490400, 0],
+        [1585494000, 0],
+        [1585497600, 0],
+        [1585501200, 0],
+        [1585504800, 0],
+        [1585508400, 0],
+        [1585512000, 0],
+        [1585515600, 0],
+        [1585519200, 0],
+        [1585522800, 0],
+        [1585526400, 0],
+        [1585530000, 0],
+        [1585533600, 0],
+        [1585537200, 0],
+        [1585540800, 0],
+        [1585544400, 0],
+        [1585548000, 0],
+        [1585551600, 0],
+        [1585555200, 0],
+      ],
+    },
+    ...params,
+  };
+}

+ 3 - 45
fixtures/js-stubs/release.tsx

@@ -1,3 +1,5 @@
+import {HealthFixture} from 'sentry-fixture/health';
+
 import {Health, ReleaseStatus, ReleaseWithHealth} from 'sentry/types';
 
 export function Release(
@@ -53,51 +55,7 @@ export function Release(
     ref: '',
     projects: [
       {
-        healthData: {
-          totalUsers24h: null,
-          durationP50: 231,
-          hasHealthData: true,
-          sessionsAdoption: 0,
-          totalProjectSessions24h: 0,
-          totalProjectUsers24h: 0,
-          totalSessions24h: 0,
-          totalSessions: 74949,
-          totalUsers: 2544,
-          crashFreeSessions: 99.59839357429719,
-          sessionsErrored: 301,
-          crashFreeUsers: 98.07389937106919,
-          durationP90: 333,
-          adoption: null,
-          sessionsCrashed: 301,
-          stats: {
-            '24h': [
-              [1585472400, 0],
-              [1585476000, 0],
-              [1585479600, 0],
-              [1585483200, 0],
-              [1585486800, 0],
-              [1585490400, 0],
-              [1585494000, 0],
-              [1585497600, 0],
-              [1585501200, 0],
-              [1585504800, 0],
-              [1585508400, 0],
-              [1585512000, 0],
-              [1585515600, 0],
-              [1585519200, 0],
-              [1585522800, 0],
-              [1585526400, 0],
-              [1585530000, 0],
-              [1585533600, 0],
-              [1585537200, 0],
-              [1585540800, 0],
-              [1585544400, 0],
-              [1585548000, 0],
-              [1585551600, 0],
-              [1585555200, 0],
-            ],
-          },
-        },
+        healthData: HealthFixture(),
         id: 4383603,
         name: 'Sentry-Android-Shop',
         slug: 'sentry-android-shop',

+ 1 - 1
fixtures/js-stubs/releaseMeta.ts

@@ -2,7 +2,7 @@ import {Project} from 'sentry-fixture/project';
 
 import type {ReleaseMeta as ReleaseMetaType} from 'sentry/types';
 
-export function ReleaseMeta(params: Partial<ReleaseMetaType>): ReleaseMetaType {
+export function ReleaseMeta(params: Partial<ReleaseMetaType> = {}): ReleaseMetaType {
   const project = Project();
   return {
     version: 'sentry-android-shop@1.2.0',

+ 16 - 0
fixtures/js-stubs/releaseProject.tsx

@@ -0,0 +1,16 @@
+import {ReleaseProject} from 'sentry/types';
+
+export function ReleaseProjectFixture(
+  params: Partial<ReleaseProject> = {}
+): ReleaseProject {
+  return {
+    id: 2,
+    name: 'Project Name',
+    newGroups: 0,
+    platform: 'android',
+    platforms: ['android'],
+    slug: 'project-slug',
+    hasHealthData: false,
+    ...params,
+  };
+}

+ 10 - 9
static/app/views/dashboards/detail.spec.tsx

@@ -3,6 +3,7 @@ import {Dashboard as DashboardFixture} from 'sentry-fixture/dashboard';
 import LocationFixture from 'sentry-fixture/locationFixture';
 import {Organization} from 'sentry-fixture/organization';
 import {Project as ProjectFixture} from 'sentry-fixture/project';
+import {Release as ReleaseFixture} from 'sentry-fixture/release';
 import RouteComponentPropsFixture from 'sentry-fixture/routeComponentPropsFixture';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
@@ -479,7 +480,7 @@ describe('Dashboards > Detail', function () {
     it('shows top level release filter', async function () {
       const mockReleases = MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
-        body: [TestStubs.Release()],
+        body: [ReleaseFixture()],
       });
 
       initialData = initializeOrg({
@@ -908,7 +909,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1008,7 +1009,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1072,7 +1073,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1176,7 +1177,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1237,7 +1238,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1450,7 +1451,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1500,7 +1501,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             shortVersion: 'sentry-android-shop@1.2.0',
             version: 'sentry-android-shop@1.2.0',
           }),
@@ -1510,7 +1511,7 @@ describe('Dashboards > Detail', function () {
       MockApiClient.addMockResponse({
         url: '/organizations/org-slug/releases/',
         body: [
-          TestStubs.Release({
+          ReleaseFixture({
             id: '9',
             shortVersion: 'search-result',
             version: 'search-result',

+ 4 - 2
static/app/views/discover/table/quickContext/quickContextHovercard.spec.tsx

@@ -1,10 +1,12 @@
 import {Event as EventFixture} from 'sentry-fixture/event';
 import {Organization} from 'sentry-fixture/organization';
+import {Release as ReleaseFixture} from 'sentry-fixture/release';
 
 import {makeTestQueryClient} from 'sentry-test/queryClient';
 import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
 
 import ConfigStore from 'sentry/stores/configStore';
+import {ReleaseStatus} from 'sentry/types';
 import {EventOrGroupType} from 'sentry/types/event';
 import EventView, {EventData} from 'sentry/utils/discover/eventView';
 import {QueryClientProvider} from 'sentry/utils/queryClient';
@@ -131,14 +133,14 @@ describe('Quick Context', function () {
         url: `/organizations/org-slug/releases/${encodeURIComponent(
           'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76'
         )}/`,
-        body: TestStubs.Release({
+        body: ReleaseFixture({
           id: '1',
           shortVersion: 'sentry-android-shop@1.2.0',
           version: 'sentry-android-shop@1.2.0',
           dateCreated: '2010-05-17T02:41:20Z',
           lastEvent: '2011-10-17T02:41:20Z',
           firstEvent: '2010-05-17T02:41:20Z',
-          status: 'open',
+          status: ReleaseStatus.ACTIVE,
           commitCount: 4,
           lastCommit: mockedCommit,
           newGroups: 21,

+ 4 - 2
static/app/views/discover/table/quickContext/releaseContext.spec.tsx

@@ -1,22 +1,24 @@
 import {Organization} from 'sentry-fixture/organization';
+import {Release as ReleaseFixture} from 'sentry-fixture/release';
 
 import {makeTestQueryClient} from 'sentry-test/queryClient';
 import {render, screen, within} from 'sentry-test/reactTestingLibrary';
 
 import ConfigStore from 'sentry/stores/configStore';
+import {ReleaseStatus} from 'sentry/types';
 import {QueryClientProvider} from 'sentry/utils/queryClient';
 
 import ReleaseContext from './releaseContext';
 import {defaultRow, mockedCommit, mockedUser1, mockedUser2} from './testUtils';
 
-export const mockedReleaseWithHealth = TestStubs.Release({
+export const mockedReleaseWithHealth = ReleaseFixture({
   id: '1',
   shortVersion: 'sentry-android-shop@1.2.0',
   version: 'sentry-android-shop@1.2.0',
   dateCreated: '2010-05-17T02:41:20Z',
   lastEvent: '2011-10-17T02:41:20Z',
   firstEvent: '2010-05-17T02:41:20Z',
-  status: 'open',
+  status: ReleaseStatus.ACTIVE,
   commitCount: 4,
   lastCommit: mockedCommit,
   newGroups: 21,

+ 6 - 5
static/app/views/issueDetails/groupActivity.spec.tsx

@@ -1,6 +1,7 @@
 import {Group as GroupFixture} from 'sentry-fixture/group';
 import {Organization} from 'sentry-fixture/organization';
 import {Project as ProjectFixture} from 'sentry-fixture/project';
+import {Release as ReleaseFixture} from 'sentry-fixture/release';
 import {Repository} from 'sentry-fixture/repository';
 import {Team} from 'sentry-fixture/team';
 import {User} from 'sentry-fixture/user';
@@ -244,7 +245,7 @@ describe('GroupActivity', function () {
               message: '',
               repository: Repository(),
               releases: [
-                TestStubs.Release({
+                ReleaseFixture({
                   dateCreated: '2022-05-01',
                   dateReleased: '2022-05-02',
                   version: 'random',
@@ -276,22 +277,22 @@ describe('GroupActivity', function () {
               message: '',
               repository: Repository(),
               releases: [
-                TestStubs.Release({
+                ReleaseFixture({
                   dateCreated: '2022-05-01',
                   dateReleased: '2022-05-02',
                   version: 'random',
                 }),
-                TestStubs.Release({
+                ReleaseFixture({
                   dateCreated: '2022-06-01',
                   dateReleased: '2022-06-02',
                   version: 'newest',
                 }),
-                TestStubs.Release({
+                ReleaseFixture({
                   dateCreated: '2021-08-03',
                   dateReleased: '2021-08-03',
                   version: 'oldest-release',
                 }),
-                TestStubs.Release({
+                ReleaseFixture({
                   dateCreated: '2022-04-21',
                   dateReleased: '2022-04-21',
                   version: 'randomTwo',

+ 27 - 6
static/app/views/releases/detail/header/releaseActions.spec.tsx

@@ -1,7 +1,11 @@
 import {browserHistory} from 'react-router';
 import {Location} from 'history';
+import {HealthFixture} from 'sentry-fixture/health';
 import LocationFixture from 'sentry-fixture/locationFixture';
 import {Organization} from 'sentry-fixture/organization';
+import {Release as ReleaseFixture} from 'sentry-fixture/release';
+import {ReleaseMeta as ReleaseMetaFixture} from 'sentry-fixture/releaseMeta';
+import {ReleaseProjectFixture} from 'sentry-fixture/releaseProject';
 import RouteComponentPropsFixture from 'sentry-fixture/routeComponentPropsFixture';
 import RouterContextFixture from 'sentry-fixture/routerContextFixture';
 
@@ -13,11 +17,28 @@ import {
   waitFor,
 } from 'sentry-test/reactTestingLibrary';
 
+import {ReleaseProject, ReleaseStatus} from 'sentry/types';
 import ReleaseActions from 'sentry/views/releases/detail/header/releaseActions';
 
 describe('ReleaseActions', function () {
   const organization = Organization();
-  const release = TestStubs.Release({projects: [{slug: 'project1'}, {slug: 'project2'}]});
+
+  const project1 = ReleaseProjectFixture({
+    slug: 'project1',
+    hasHealthData: true,
+    healthData: HealthFixture(),
+  }) as Required<ReleaseProject>;
+
+  const project2 = ReleaseProjectFixture({
+    slug: 'project2',
+    hasHealthData: true,
+    healthData: HealthFixture(),
+  }) as Required<ReleaseProject>;
+
+  const release = ReleaseFixture({
+    projects: [project1, project2],
+  });
+
   const location: Location = {
     ...LocationFixture(),
     pathname: `/organizations/sentry/releases/${release.version}/`,
@@ -47,7 +68,7 @@ describe('ReleaseActions', function () {
         projectSlug={release.projects[0].slug}
         release={release}
         refetchData={jest.fn()}
-        releaseMeta={{...TestStubs.Release(), projects: release.projects}}
+        releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
         location={location}
       />
     );
@@ -94,9 +115,9 @@ describe('ReleaseActions', function () {
         {...RouteComponentPropsFixture()}
         organization={organization}
         projectSlug={release.projects[0].slug}
-        release={{...release, status: 'archived'}}
+        release={{...release, status: ReleaseStatus.ARCHIVED}}
         refetchData={refetchDataMock}
-        releaseMeta={{...TestStubs.Release(), projects: release.projects}}
+        releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
         location={location}
       />
     );
@@ -140,7 +161,7 @@ describe('ReleaseActions', function () {
         projectSlug={release.projects[0].slug}
         release={release}
         refetchData={jest.fn()}
-        releaseMeta={{...TestStubs.Release(), projects: release.projects}}
+        releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
         location={location}
       />,
       {context: routerContext}
@@ -169,7 +190,7 @@ describe('ReleaseActions', function () {
         projectSlug={release.projects[0].slug}
         release={release}
         refetchData={jest.fn()}
-        releaseMeta={{...TestStubs.Release(), projects: release.projects}}
+        releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
         location={{
           ...location,
           pathname: `/organizations/sentry/releases/${release.version}/files-changed/`,