]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12195 Activity page: Filter security_review_rating to appear only for portfolio
authorJeremy Davis <jeremy.davis@sonarsource.com>
Thu, 13 Jun 2019 13:44:58 +0000 (15:44 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 14 Jun 2019 18:21:12 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.tsx
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAppContainer-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAppContainer-test.tsx.snap [new file with mode: 0644]

index fcffaf0c37399ae120746f766b268312546f803e..78e118c79500cd82e0d10323b572d687b1c09d63 100644 (file)
@@ -236,6 +236,12 @@ export default class ProjectActivityAppContainer extends React.PureComponent<Pro
     return component.breadcrumbs[current].key;
   };
 
+  filterMetrics({ qualifier }: T.Component, metrics: T.Metric[]) {
+    return ['VW', 'SVW'].includes(qualifier)
+      ? metrics
+      : metrics.filter(metric => metric.key !== 'security_review_rating');
+  }
+
   firstLoadData(query: Query, component: T.Component) {
     const graphMetrics = getHistoryMetrics(query.graph, query.customMetrics);
     const topLevelComponent = this.getTopLevelComponent(component);
@@ -244,15 +250,15 @@ export default class ProjectActivityAppContainer extends React.PureComponent<Pro
       getAllMetrics(),
       this.fetchMeasuresHistory(graphMetrics)
     ]).then(
-      response => {
+      ([{ analyses, paging }, metrics, measuresHistory]) => {
         if (this.mounted) {
           this.setState({
-            analyses: response[0].analyses,
+            analyses,
             graphLoading: false,
             initialized: true,
-            measuresHistory: response[2],
-            metrics: response[1],
-            paging: response[0].paging
+            measuresHistory,
+            metrics: this.filterMetrics(component, metrics),
+            paging
           });
 
           this.fetchAllActivities(topLevelComponent);
diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAppContainer-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAppContainer-test.tsx
new file mode 100644 (file)
index 0000000..7309e39
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import ProjectActivityAppContainer from '../ProjectActivityAppContainer';
+import { mockComponent, mockLocation, mockRouter } from '../../../../helpers/testMocks';
+
+it('should render correctly', () => {
+  expect(shallowRender()).toMatchSnapshot();
+});
+
+function shallowRender(props: Partial<ProjectActivityAppContainer['props']> = {}) {
+  return shallow<ProjectActivityAppContainer>(
+    <ProjectActivityAppContainer
+      component={mockComponent({ breadcrumbs: [mockComponent()] })}
+      location={mockLocation()}
+      router={mockRouter()}
+      {...props}
+    />
+  );
+}
diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAppContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityAppContainer-test.tsx.snap
new file mode 100644 (file)
index 0000000..59c46d1
--- /dev/null
@@ -0,0 +1,74 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<ProjectActivityApp
+  addCustomEvent={[Function]}
+  addVersion={[Function]}
+  analyses={Array []}
+  analysesLoading={false}
+  changeEvent={[Function]}
+  deleteAnalysis={[Function]}
+  deleteEvent={[Function]}
+  graphLoading={true}
+  initializing={true}
+  measuresHistory={Array []}
+  metrics={Array []}
+  project={
+    Object {
+      "breadcrumbs": Array [
+        Object {
+          "breadcrumbs": Array [],
+          "key": "my-project",
+          "name": "MyProject",
+          "organization": "foo",
+          "qualifier": "TRK",
+          "qualityGate": Object {
+            "isDefault": true,
+            "key": "30",
+            "name": "Sonar way",
+          },
+          "qualityProfiles": Array [
+            Object {
+              "deleted": false,
+              "key": "my-qp",
+              "language": "ts",
+              "name": "Sonar way",
+            },
+          ],
+          "tags": Array [],
+        },
+      ],
+      "key": "my-project",
+      "name": "MyProject",
+      "organization": "foo",
+      "qualifier": "TRK",
+      "qualityGate": Object {
+        "isDefault": true,
+        "key": "30",
+        "name": "Sonar way",
+      },
+      "qualityProfiles": Array [
+        Object {
+          "deleted": false,
+          "key": "my-qp",
+          "language": "ts",
+          "name": "Sonar way",
+        },
+      ],
+      "tags": Array [],
+    }
+  }
+  query={
+    Object {
+      "category": "",
+      "customMetrics": Array [],
+      "from": undefined,
+      "graph": "issues",
+      "project": "",
+      "selectedDate": undefined,
+      "to": undefined,
+    }
+  }
+  updateQuery={[Function]}
+/>
+`;