Browse Source

ref(fixtures): Refactor Project fixture to tsx (#55288)

depends on https://github.com/getsentry/sentry/pull/55287
Ryan Albrecht 1 year ago
parent
commit
0f0a0710fb

+ 0 - 18
fixtures/js-stubs/project.js

@@ -1,18 +0,0 @@
-export function Project(params = {}) {
-  return {
-    id: '2',
-    slug: 'project-slug',
-    name: 'Project Name',
-    access: ['project:read'],
-    hasAccess: true,
-    isMember: true,
-    isBookmarked: false,
-    teams: [],
-    environments: [],
-    features: [],
-    eventProcessing: {
-      symbolicationDegraded: false,
-    },
-    ...params,
-  };
-}

+ 43 - 0
fixtures/js-stubs/project.tsx

@@ -0,0 +1,43 @@
+import type {Project as TProject} from 'sentry/types';
+
+import {Organization} from './organization';
+import {Team} from './team';
+
+export function Project(params: Partial<TProject> = {}): TProject {
+  const team = Team();
+  return {
+    id: '2',
+    slug: 'project-slug',
+    name: 'Project Name',
+    access: ['project:read'],
+    hasAccess: true,
+    isMember: true,
+    isBookmarked: false,
+    team,
+    teams: [],
+    environments: [],
+    features: [],
+    eventProcessing: {
+      symbolicationDegraded: false,
+    },
+    dateCreated: new Date().toISOString(),
+    digestsMaxDelay: 0,
+    digestsMinDelay: 0,
+    dynamicSamplingBiases: null,
+    firstEvent: null,
+    firstTransactionEvent: false,
+    groupingAutoUpdate: false,
+    groupingConfig: '',
+    hasMinifiedStackTrace: false,
+    hasProfiles: false,
+    hasReplays: false,
+    hasSessions: false,
+    isInternal: false,
+    organization: Organization(),
+    plugins: [],
+    processingIssues: 0,
+    relayPiiConfig: '',
+    subjectTemplate: '',
+    ...params,
+  };
+}

+ 11 - 5
static/app/stores/groupStore.spec.tsx

@@ -1,7 +1,11 @@
 import GroupStore from 'sentry/stores/groupStore';
 import {Group, GroupStats, TimeseriesValue} from 'sentry/types';
 
-const g = (id: string, params?: Partial<Group>) => TestStubs.Group({id, ...params});
+const MOCK_PROJECT = TestStubs.Project();
+
+const g = (id: string, params?: Partial<Group>): Group => {
+  return TestStubs.Group({id, project: MOCK_PROJECT, ...params});
+};
 
 describe('GroupStore', function () {
   beforeEach(function () {
@@ -19,10 +23,12 @@ describe('GroupStore', function () {
     it('should update matching existing entries', function () {
       GroupStore.items = [g('1'), g('2')];
 
-      GroupStore.add([{id: '1', foo: 'bar'}, g('3')]);
+      GroupStore.add([g('1', {count: '1337'}), g('3')]);
 
       expect(GroupStore.getAllItemIds()).toEqual(['1', '2', '3']);
-      expect(GroupStore.items[0]).toEqual(expect.objectContaining({id: '1', foo: 'bar'}));
+      expect(GroupStore.items[0]).toEqual(
+        expect.objectContaining({id: '1', count: '1337'})
+      );
     });
 
     it('should attempt to preserve order of ids', function () {
@@ -42,10 +48,10 @@ describe('GroupStore', function () {
     it('should update matching existing entries', function () {
       GroupStore.items = [g('1'), g('2')];
 
-      GroupStore.addToFront([{id: '1', foo: 'bar'}, g('3')]);
+      GroupStore.addToFront([g('1', {count: '1337'}), g('3')]);
 
       expect(GroupStore.getAllItems()).toEqual([
-        expect.objectContaining({id: '1', foo: 'bar'}),
+        expect.objectContaining({id: '1', count: '1337'}),
         g('3'),
         g('2'),
       ]);

+ 14 - 14
static/app/utils/utils.spec.tsx

@@ -178,22 +178,22 @@ describe('utils.explodeSlug', function () {
 describe('utils.projectDisplayCompare', function () {
   it('sorts by bookmark and project slug', function () {
     const projects = [
-      {isBookmarked: true, slug: 'm'},
-      {isBookmarked: false, slug: 'm'},
-      {isBookmarked: false, slug: 'a'},
-      {isBookmarked: true, slug: 'a'},
-      {isBookmarked: true, slug: 'z'},
-      {isBookmarked: false, slug: 'z'},
-    ].map(TestStubs.Project);
+      TestStubs.Project({isBookmarked: true, slug: 'm'}),
+      TestStubs.Project({isBookmarked: false, slug: 'm'}),
+      TestStubs.Project({isBookmarked: false, slug: 'a'}),
+      TestStubs.Project({isBookmarked: true, slug: 'a'}),
+      TestStubs.Project({isBookmarked: true, slug: 'z'}),
+      TestStubs.Project({isBookmarked: false, slug: 'z'}),
+    ];
 
     const expected = [
-      {isBookmarked: true, slug: 'a'},
-      {isBookmarked: true, slug: 'm'},
-      {isBookmarked: true, slug: 'z'},
-      {isBookmarked: false, slug: 'a'},
-      {isBookmarked: false, slug: 'm'},
-      {isBookmarked: false, slug: 'z'},
-    ].map(TestStubs.Project);
+      expect.objectContaining({isBookmarked: true, slug: 'a'}),
+      expect.objectContaining({isBookmarked: true, slug: 'm'}),
+      expect.objectContaining({isBookmarked: true, slug: 'z'}),
+      expect.objectContaining({isBookmarked: false, slug: 'a'}),
+      expect.objectContaining({isBookmarked: false, slug: 'm'}),
+      expect.objectContaining({isBookmarked: false, slug: 'z'}),
+    ];
 
     const sortedProjects = sortProjects(projects);