Browse Source

ref(ts): Convert performance/data.spec to tsx (#53215)

Evan Purkhiser 1 year ago
parent
commit
b1603c4bb5
1 changed files with 56 additions and 42 deletions
  1. 56 42
      static/app/views/performance/data.spec.tsx

+ 56 - 42
static/app/views/performance/data.spec.jsx → static/app/views/performance/data.spec.tsx

@@ -8,10 +8,15 @@ import {
 } from 'sentry/views/performance/data';
 
 describe('generatePerformanceEventView()', function () {
+  const organization = TestStubs.Organization();
+
   it('generates default values', function () {
-    const result = generatePerformanceEventView({
-      query: {},
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {}}),
+      [],
+      {},
+      organization
+    );
 
     expect(result.id).toBeUndefined();
     expect(result.name).toEqual('Performance');
@@ -23,45 +28,50 @@ describe('generatePerformanceEventView()', function () {
   });
 
   it('applies sort from location', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        sort: ['-p50', '-count'],
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {sort: ['-p50', '-count']}}),
+      [],
+      {},
+      organization
+    );
 
     expect(result.sorts).toEqual([{kind: 'desc', field: 'p50'}]);
     expect(result.statsPeriod).toEqual(DEFAULT_STATS_PERIOD);
   });
 
   it('does not override statsPeriod from location', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        statsPeriod: ['90d', '45d'],
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {statsPeriod: ['90d', '45d']}}),
+      [],
+      {},
+      organization
+    );
     expect(result.start).toBeUndefined();
     expect(result.end).toBeUndefined();
     expect(result.statsPeriod).toEqual('90d');
   });
 
   it('does not apply range when start and end are present', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        start: '2020-04-25T12:00:00',
-        end: '2020-05-25T12:00:00',
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({
+        query: {start: '2020-04-25T12:00:00', end: '2020-05-25T12:00:00'},
+      }),
+      [],
+      {},
+      organization
+    );
     expect(result.start).toEqual('2020-04-25T12:00:00.000');
     expect(result.end).toEqual('2020-05-25T12:00:00.000');
     expect(result.statsPeriod).toBeUndefined();
   });
 
   it('converts bare query into transaction name wildcard', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        query: 'things.update',
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {query: 'things.update'}}),
+      [],
+      {},
+      organization
+    );
     expect(result.query).toEqual(expect.stringContaining('transaction:*things.update*'));
     expect(result.getQueryWithAdditionalConditions()).toEqual(
       expect.stringContaining('event.type:transaction')
@@ -69,11 +79,12 @@ describe('generatePerformanceEventView()', function () {
   });
 
   it('bare query overwrites transaction condition', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        query: 'things.update transaction:thing.gone',
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {query: 'things.update transaction:thing.gone'}}),
+      [],
+      {},
+      organization
+    );
     expect(result.query).toEqual(expect.stringContaining('transaction:*things.update*'));
     expect(result.getQueryWithAdditionalConditions()).toEqual(
       expect.stringContaining('event.type:transaction')
@@ -82,11 +93,12 @@ describe('generatePerformanceEventView()', function () {
   });
 
   it('retains tag filter conditions', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        query: 'key:value tag:value',
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {query: 'key:value tag:value'}}),
+      [],
+      {},
+      organization
+    );
     expect(result.query).toEqual(expect.stringContaining('key:value'));
     expect(result.query).toEqual(expect.stringContaining('tag:value'));
     expect(result.getQueryWithAdditionalConditions()).toEqual(
@@ -95,11 +107,12 @@ describe('generatePerformanceEventView()', function () {
   });
 
   it('gets the right column', function () {
-    const result = generatePerformanceEventView({
-      query: {
-        query: 'key:value tag:value',
-      },
-    });
+    const result = generatePerformanceEventView(
+      TestStubs.location({query: {query: 'key:value tag:value'}}),
+      [],
+      {},
+      organization
+    );
     expect(result.fields).toEqual(
       expect.arrayContaining([expect.objectContaining({field: 'user_misery()'})])
     );
@@ -113,14 +126,15 @@ describe('generatePerformanceEventView()', function () {
 
   it('removes unsupported tokens for limited search', function () {
     const result = generatePerformanceEventView(
-      {
+      TestStubs.location({
         query: {
           query: 'tag:value transaction:*auth*',
           [METRIC_SEARCH_SETTING_PARAM]: MEPState.METRICS_ONLY,
         },
-      },
+      }),
       [],
-      {withStaticFilters: true}
+      {withStaticFilters: true},
+      organization
     );
     expect(result.query).toEqual('transaction:*auth*');
   });